Skip to content

Commit

Permalink
Make sure that install path is created before untarring
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeville committed Aug 12, 2024
1 parent b13dcd1 commit 7c292ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions bin/common/.local/bin/goswitch
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

set -eu -o pipefail

# TODO(damien): get version from $1
version=""
if [ $# -eq 0 ] || [[ ! $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Usage: goswitch 1.2.3"
exit 1
fi

version="$1"

plat="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
Expand All @@ -15,12 +19,7 @@ case "$arch" in
esac

toolchain_dir="$HOME/.local/toolchains/go"
versions_dir="$toolchain_dir/versions"
if [[ ! -d $versions_dir ]]; then
mkdir -p "$versions_dir"
fi

install_dir="$versions_dir/$version"
install_dir="$toolchain_dir/versions/$version"

if [[ ! -d $install_dir ]]; then
tmpdir="$(mktemp -d)"
Expand All @@ -29,6 +28,7 @@ if [[ ! -d $install_dir ]]; then
pushd "$tmpdir"

curl -L "https://go.dev/dl/go${version}.${plat}-${arch}.tar.gz" -o go.tar.gz
mkdir -p "$install_dir"
tar -xzf go.tar.gz -C "$install_dir" --strip-components 1

popd
Expand Down
16 changes: 8 additions & 8 deletions bin/common/.local/bin/nodeswitch
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

set -eu -o pipefail

# TODO(damien): get version from $1
version=""
if [ $# -eq 0 ] || [[ ! $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Usage: nodeswitch 1.2.3"
exit 1
fi

version="$1"

plat="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
Expand All @@ -15,12 +19,7 @@ case "$arch" in
esac

toolchain_dir="$HOME/.local/toolchains/node"
versions_dir="$toolchain_dir/versions"
if [[ ! -d $versions_dir ]]; then
mkdir -p "$versions_dir"
fi

install_dir="$versions_dir/$version"
install_dir="$toolchain_dir/versions/$version"

if [[ ! -d $install_dir ]]; then
tmpdir="$(mktemp -d)"
Expand All @@ -29,6 +28,7 @@ if [[ ! -d $install_dir ]]; then
pushd "$tmpdir"

curl -L "https://nodejs.org/download/release/v${version}/node-v${version}-${plat}-${arch}.tar.gz" -o node.tar.gz
mkdir -p "$install_dir"
sudo tar -xzf node.tar.gz -C "$install_dir" --strip-components 1

popd
Expand Down

0 comments on commit 7c292ba

Please sign in to comment.