Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0889bfb

Browse files
committed
extract as non-root
1 parent 24524ea commit 0889bfb

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

install.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -639,20 +639,21 @@ install_standalone() {
639639
# fails we can ignore the error as the -w check will then swap us to sudo.
640640
sh_c mkdir -p "$STANDALONE_INSTALL_PREFIX" 2>/dev/null || true
641641

642+
sh_c mkdir -p "$CACHE_DIR/tmp"
643+
if [ "$STANDALONE_ARCHIVE_FORMAT" = tar.gz ]; then
644+
sh_c tar -C "$CACHE_DIR/tmp" -xzf "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.tar.gz"
645+
else
646+
sh_c unzip -d "$CACHE_DIR/tmp" -o "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.zip"
647+
fi
648+
649+
STANDALONE_BINARY_LOCATION="$STANDALONE_INSTALL_PREFIX/bin/$STANDALONE_BINARY_NAME"
650+
642651
sh_c="sh_c"
643652
if [ ! -w "$STANDALONE_INSTALL_PREFIX" ]; then
644653
sh_c="sudo_sh_c"
645654
fi
646655

647656
"$sh_c" mkdir -p "$STANDALONE_INSTALL_PREFIX/bin"
648-
"$sh_c" mkdir -p "$CACHE_DIR/tmp"
649-
if [ "$STANDALONE_ARCHIVE_FORMAT" = tar.gz ]; then
650-
"$sh_c" tar -C "$CACHE_DIR/tmp" -xzf "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.tar.gz"
651-
else
652-
"$sh_c" unzip -d "$CACHE_DIR/tmp" -o "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.zip"
653-
fi
654-
655-
STANDALONE_BINARY_LOCATION="$STANDALONE_INSTALL_PREFIX/bin/$STANDALONE_BINARY_NAME"
656657

657658
# Remove the file if it already exists to
658659
# avoid https://github.com/coder/coder/issues/2086
@@ -662,7 +663,9 @@ install_standalone() {
662663

663664
# Copy the binary to the correct location.
664665
"$sh_c" cp "$CACHE_DIR/tmp/coder" "$STANDALONE_BINARY_LOCATION"
665-
"$sh_c" rm -rv "$CACHE_DIR/tmp"
666+
667+
# Clean up the extracted files (note, not using sudo: $sh_c -> sh_c).
668+
sh_c rm -rv "$CACHE_DIR/tmp"
666669

667670
echo_standalone_postinstall
668671
}

0 commit comments

Comments
 (0)