Skip to content

Commit

Permalink
tools: use mktemp to create the workspace directory
Browse files Browse the repository at this point in the history
On some platforms, the TMPDIR environment variable is not set.
  • Loading branch information
lpinca committed Apr 27, 2021
1 parent 47207e5 commit 111c5b2
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions tools/update-npm.sh
Expand Up @@ -11,16 +11,15 @@ if [ "$#" -le 0 ]; then
exit 1
fi

WORKSPACE="$TMPDIR"update-npm-$NPM_VERSION/
echo "Making temporary workspace"

if [ -d "$WORKSPACE" ]; then
echo "Cleaning up old workspace"
rm -rf "$WORKSPACE"
fi
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')

echo "Making temporary workspace"
cleanup () {
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
}

mkdir -p "$WORKSPACE"
trap cleanup INT TERM EXIT

cd "$WORKSPACE"

Expand All @@ -40,11 +39,7 @@ rm -rf npm/

echo "Copying new npm"

tar zxf "$WORKSPACE"cli/release/npm-"$NPM_VERSION".tgz

echo "Deleting temporary workspace"

rm -rf "$WORKSPACE"
tar zxf "$WORKSPACE"/cli/release/npm-"$NPM_VERSION".tgz

echo ""
echo "All done!"
Expand Down

0 comments on commit 111c5b2

Please sign in to comment.