Skip to content

Commit 6b893ce

Browse files
committed
Use a mktemp random directory for installation
Do not hardcode a static directory for temporary files, as it might cause problems when running in a multi-user system (ie: orphan files owned by other users). Use mktemp -d instead. Fixes #241
1 parent b8cb806 commit 6b893ce

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

install-binary.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,20 @@ getDownloadURL() {
8383
fi
8484
}
8585

86+
# Temporary dir
87+
mkTempDir() {
88+
HELM_TMP="$(mktemp -d -t "${PROJECT_NAME}-XXXX")"
89+
}
90+
rmTempDir() {
91+
if [ -d "${HELM_TMP:-/tmp/helm-diff-tmp}" ]; then
92+
rm -rf "${HELM_TMP:-/tmp/helm-diff-tmp}"
93+
fi
94+
}
95+
8696
# downloadFile downloads the latest binary package and also the checksum
8797
# for that binary.
8898
downloadFile() {
89-
PLUGIN_TMP_FILE="/tmp/${PROJECT_NAME}.tgz"
99+
PLUGIN_TMP_FILE="${HELM_TMP}/${PROJECT_NAME}.tgz"
90100
echo "Downloading $DOWNLOAD_URL"
91101
if type "curl" >/dev/null; then
92102
curl -L "$DOWNLOAD_URL" -o "$PLUGIN_TMP_FILE"
@@ -98,8 +108,6 @@ downloadFile() {
98108
# installFile verifies the SHA256 for the file, then unpacks and
99109
# installs it.
100110
installFile() {
101-
HELM_TMP="/tmp/$PROJECT_NAME"
102-
mkdir -p "$HELM_TMP"
103111
tar xf "$PLUGIN_TMP_FILE" -C "$HELM_TMP"
104112
HELM_TMP_BIN="$HELM_TMP/diff/bin/diff"
105113
echo "Preparing to install into ${HELM_PLUGIN_DIR}"
@@ -110,6 +118,7 @@ installFile() {
110118
# fail_trap is executed if an error occurs.
111119
fail_trap() {
112120
result=$?
121+
rmTempDir
113122
if [ "$result" != "0" ]; then
114123
echo "Failed to install $PROJECT_NAME"
115124
printf '\tFor support, go to https://github.com/databus23/helm-diff.\n'
@@ -134,6 +143,7 @@ initArch
134143
initOS
135144
verifySupported
136145
getDownloadURL
146+
mkTempDir
137147
downloadFile
138148
installFile
139149
testVersion

0 commit comments

Comments
 (0)