Skip to content
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

Use a mktemp random directory for installation (repeated PR) #301

Merged
merged 3 commits into from
Jan 8, 2022
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
22 changes: 16 additions & 6 deletions install-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,20 @@ getDownloadURL() {
fi
}

# Temporary dir
mkTempDir() {
HELM_TMP="$(mktemp -d -t "${PROJECT_NAME}-XXXX")"
}
rmTempDir() {
if [ -d "${HELM_TMP:-/tmp/helm-diff-tmp}" ]; then
rm -rf "${HELM_TMP:-/tmp/helm-diff-tmp}"
fi
}

# downloadFile downloads the latest binary package and also the checksum
# for that binary.
downloadFile() {
PLUGIN_TMP_FILE="/tmp/${PROJECT_NAME}.tgz"
PLUGIN_TMP_FILE="${HELM_TMP}/${PROJECT_NAME}.tgz"
echo "Downloading $DOWNLOAD_URL"
if type "curl" >/dev/null; then
curl -L "$DOWNLOAD_URL" -o "$PLUGIN_TMP_FILE"
Expand All @@ -104,18 +114,17 @@ downloadFile() {
# installFile verifies the SHA256 for the file, then unpacks and
# installs it.
installFile() {
HELM_TMP="/tmp/$PROJECT_NAME"
mkdir -p "$HELM_TMP"
tar xvzf "$PLUGIN_TMP_FILE" -C "$HELM_TMP"
HELM_TMP_BIN="$HELM_TMP/diff/bin/diff"
echo "Preparing to install into ${HELM_PLUGIN_DIR}"
mkdir -p "$HELM_PLUGIN_DIR/bin"
cp "$HELM_TMP_BIN" "$HELM_PLUGIN_DIR/bin"
}

# fail_trap is executed if an error occurs.
fail_trap() {
# exit_trap is executed if on exit (error or not).
exit_trap() {
result=$?
rmTempDir
if [ "$result" != "0" ]; then
echo "Failed to install $PROJECT_NAME"
printf '\tFor support, go to https://github.com/databus23/helm-diff.\n'
Expand All @@ -134,12 +143,13 @@ testVersion() {
# Execution

#Stop execution on any error
trap "fail_trap" EXIT
trap "exit_trap" EXIT
set -e
initArch
initOS
verifySupported
getDownloadURL
mkTempDir
downloadFile
installFile
testVersion