Skip to content

fix(install.sh): remove extracted files after installation #12879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -639,19 +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"
if [ "$STANDALONE_ARCHIVE_FORMAT" = tar.gz ]; then
"$sh_c" tar -C "$CACHE_DIR" -xzf "$CACHE_DIR/coder_${VERSION}_${OS}_${ARCH}.tar.gz"
else
"$sh_c" unzip -d "$CACHE_DIR" -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
Expand All @@ -660,7 +662,10 @@ 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"

# Clean up the extracted files (note, not using sudo: $sh_c -> sh_c).
sh_c rm -rv "$CACHE_DIR/tmp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit it's possible to perform cleanup using traps too. Would implementing this practice here be helpful, or would it add unnecessary complexity?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good suggestion and definitely an option (unless shell compatibility is weak for some reason, haven't checked). Another option would be to split it up into two functions, where we:

mkdir .../tmp
if ! install_bin; then
  rm -rf .../tmp
  echo install failed
  exit 1
fi
rm -rf .../tmp

For now though, I only want to make small changes to the script in stages/as needed, so we don't suddenly break it as there aren't really any tests I believe. 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, thanks for the guidance!


echo_standalone_postinstall
}
Expand Down
Loading