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

Added in support for Gitbash on Windows OS #31

Merged
merged 3 commits into from
Oct 7, 2022
Merged
Changes from 2 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
56 changes: 48 additions & 8 deletions gvm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

###############################################################################
# GENERATED VERSION! DO NOT CHANGE! #
SCRIPTVERSION="local-dev"
SCRIPTVERSION="latest"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update this to local-dev? The script version should be local-dev for changes. It's updated by the CI/CD pipeline to match the tagged version prior to generating the sum file for comparison on update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. Just updated in latest commit.

###############################################################################

# Static variable definintions
Expand Down 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was interesting as I noticed the additional spaces and dash being appended to $EXPECTEDSUM coming from the $SUMPATH request. I don't have a lot of experience in bash so this may be expected in the Unix environment. Specifically when using shasum. Just thought I'd call it out that I had to strip these appended characters in order to accurately compare the file downloaded to the expected checksum.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into this

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