Skip to content

Commit

Permalink
Merge pull request #31 from jdaniel-cpts/jdaniel/GitbashSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
benjivesterby authored Oct 7, 2022
2 parents 105a0b8 + 3afc320 commit ada6fa1
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions gvm
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,15 @@ upgrade() {
curl -sL "$GVMURL" > .gvm.tmp

# shellcheck disable=SC2002
DOWNLOADEDSUM=$(cat .gvm.tmp | shasum -a 256)

# Gitbash/Windows certutil with explit sha256 can be used
if [[ "$OSTYPE" == "msys"* ]]
then
DOWNLOADEDSUM=$(certutil -hashfile .gvm.tmp sha256 | tail -n2 | head -n1)
else
DOWNLOADEDSUM=$(cat .gvm.tmp | shasum -a 256)
fi

if [[ $DOWNLOADEDSUM != "$EXPECTEDSUM" ]]
then
printf "Checksum does not match new version of GVM [%s]\n" "$SCRIPTVERSION"
Expand Down Expand Up @@ -226,7 +233,17 @@ update() {
EXPECTEDSUM=$(curl -sL "$SUMPATH")

# shellcheck disable=SC2086
FILESUM=$(cat $0 | shasum -a 256)

if [[ "$OSTYPE" == "msys"* ]]
then
FILESUM=$(certutil -hashfile $0 sha256 | tail -n2 | head -n1)
EXPECTEDSUM=$(curl -sL "$SUMPATH" | sed 's/ -//') # ⚠️ additional 2xspace + dash may also need to be addressed on unix installs
else
FILESUM=$(cat $0 | shasum -a 256)
EXPECTEDSUM=$(curl -sL "$SUMPATH")
fi



if [[ "$EXPECTEDSUM" != "Not Found" ]]
then
Expand Down Expand Up @@ -294,6 +311,7 @@ then
fi

arch="amd64"
extention=".tar.gz"
if uname -a | grep "arm64"&> /dev/null
then
arch="arm64"
Expand All @@ -306,6 +324,11 @@ then
elif [[ "$OSTYPE" == "linux"* ]]
then
os="linux"
elif [[ "$OSTYPE" == "msys"* ]]
then
os="windows"
arch="amd64"
extention=".zip"
elif [[ "$OSTYPE" == "freebsd"* ]]
then
os="freebsd"
Expand Down Expand Up @@ -386,7 +409,8 @@ then
else
if [[ ! -d "$versionroot" ]]
then
pkg="go$version.$os-$arch.tar.gz"

pkg="go$version.$os-$arch$extention"
url="$dlroot$pkg"
pkgDir="$gvmroot/$pkg"

Expand All @@ -407,10 +431,18 @@ else
fail "$(printf "Unable to create %s\n" "$versionroot")"
fi

if ! tar -C "$versionroot" -xzf "$pkgDir"
then
fail "$(printf "Unable to extract %s\n" "$pkgDir" rm -rf "$versionroot")"
fi
if [[ "$extention" == ".zip" ]]
then
if ! unzip -qd "$versionroot" "$pkgDir"
then
fail "$(printf "Unable to zip extract %s\n" "$pkgDir" rm -rf "$versionroot")"
fi
else
if ! tar -C "$versionroot" -xzf "$pkgDir"
then
fail "$(printf "Unable to tar extract %s\n" "$pkgDir" rm -rf "$versionroot")"
fi
fi

rm "$pkgDir"
fi
Expand All @@ -420,6 +452,14 @@ fi
lnsrc="$versionroot/go"

printf "Updating symlink %s => %s\n" "$lnsrc" "$gvmroot"

#Windows + Gitbash require an explicit delete of the previously linked folder
if [[ "$os" == "windows" ]]
then
printf "Removing %s/go if the directory exists\n" "$gvmroot"
rm -rf "$gvmroot/go"
fi

if ! ln -sf "$lnsrc" "$gvmroot"
then
fail "$(printf "Unable to symlink directory %s\n" "$lnsrc")"
Expand Down Expand Up @@ -461,4 +501,4 @@ then
fi

printf "Go %s Active\n" "$version"
fi
fi

0 comments on commit ada6fa1

Please sign in to comment.