From 24524ea7807303d77f4fb2785fe00e5a3c4df978 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 5 Apr 2024 15:37:15 +0300 Subject: [PATCH 1/2] fix(install.sh): remove extracted files after installation --- install.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index cdb0bed420223..41b6061d50bec 100755 --- a/install.sh +++ b/install.sh @@ -645,10 +645,11 @@ install_standalone() { fi "$sh_c" mkdir -p "$STANDALONE_INSTALL_PREFIX/bin" + "$sh_c" mkdir -p "$CACHE_DIR/tmp" if [ "$STANDALONE_ARCHIVE_FORMAT" = tar.gz ]; then - "$sh_c" tar -C "$CACHE_DIR" -xzf "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.tar.gz" + "$sh_c" tar -C "$CACHE_DIR/tmp" -xzf "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.tar.gz" else - "$sh_c" unzip -d "$CACHE_DIR" -o "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.zip" + "$sh_c" unzip -d "$CACHE_DIR/tmp" -o "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.zip" fi STANDALONE_BINARY_LOCATION="$STANDALONE_INSTALL_PREFIX/bin/$STANDALONE_BINARY_NAME" @@ -660,7 +661,8 @@ install_standalone() { fi # Copy the binary to the correct location. - "$sh_c" cp "$CACHE_DIR/coder" "$STANDALONE_BINARY_LOCATION" + "$sh_c" cp "$CACHE_DIR/tmp/coder" "$STANDALONE_BINARY_LOCATION" + "$sh_c" rm -rv "$CACHE_DIR/tmp" echo_standalone_postinstall } From 0889bfb7ef966d0c5df1d4f5f57f2685d93cae58 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 5 Apr 2024 15:48:26 +0300 Subject: [PATCH 2/2] extract as non-root --- install.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/install.sh b/install.sh index 41b6061d50bec..50c3c85a8f020 100755 --- a/install.sh +++ b/install.sh @@ -639,20 +639,21 @@ install_standalone() { # fails we can ignore the error as the -w check will then swap us to sudo. sh_c mkdir -p "$STANDALONE_INSTALL_PREFIX" 2>/dev/null || true + sh_c mkdir -p "$CACHE_DIR/tmp" + if [ "$STANDALONE_ARCHIVE_FORMAT" = tar.gz ]; then + sh_c tar -C "$CACHE_DIR/tmp" -xzf "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.tar.gz" + else + sh_c unzip -d "$CACHE_DIR/tmp" -o "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.zip" + fi + + STANDALONE_BINARY_LOCATION="$STANDALONE_INSTALL_PREFIX/bin/$STANDALONE_BINARY_NAME" + sh_c="sh_c" if [ ! -w "$STANDALONE_INSTALL_PREFIX" ]; then sh_c="sudo_sh_c" fi "$sh_c" mkdir -p "$STANDALONE_INSTALL_PREFIX/bin" - "$sh_c" mkdir -p "$CACHE_DIR/tmp" - if [ "$STANDALONE_ARCHIVE_FORMAT" = tar.gz ]; then - "$sh_c" tar -C "$CACHE_DIR/tmp" -xzf "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.tar.gz" - else - "$sh_c" unzip -d "$CACHE_DIR/tmp" -o "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.zip" - fi - - STANDALONE_BINARY_LOCATION="$STANDALONE_INSTALL_PREFIX/bin/$STANDALONE_BINARY_NAME" # Remove the file if it already exists to # avoid https://github.com/coder/coder/issues/2086 @@ -662,7 +663,9 @@ install_standalone() { # Copy the binary to the correct location. "$sh_c" cp "$CACHE_DIR/tmp/coder" "$STANDALONE_BINARY_LOCATION" - "$sh_c" rm -rv "$CACHE_DIR/tmp" + + # Clean up the extracted files (note, not using sudo: $sh_c -> sh_c). + sh_c rm -rv "$CACHE_DIR/tmp" echo_standalone_postinstall }