Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ wget -q -O - https://raw.githubusercontent.com/canha/golang-tools-install-script
curl https://raw.githubusercontent.com/canha/golang-tools-install-script/master/goinstall.sh | bash
```

## :dvd: Downloads the installation package from the specified mirror URL

Pass the `--mirror` option into the script including the mirror URL that you wish to download from, and you can also append `--version` option.

##### Example:

```shell
wget -q -O - https://git.io/vQhTU | bash -s -- --mirror https://mirrors.ustc.edu.cn/golang

# or...
curl -L https://git.io/vQhTU | bash -s -- --mirror https://mirrors.ustc.edu.cn/golang

# and use custom version...
curl -L https://git.io/vQhTU | bash -s -- --mirror https://mirrors.ustc.edu.cn/golang --version 1.13.2
```

## :package: Install a custom Go version

Pass the `--version` option into the script including the version that you wish to install.
Expand Down
23 changes: 19 additions & 4 deletions goinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -e

VERSION="1.17.3"
MIRROR="https://storage.googleapis.com/golang"

[ -z "$GOROOT" ] && GOROOT="$HOME/.go"
[ -z "$GOPATH" ] && GOPATH="$HOME/go"
Expand Down Expand Up @@ -40,7 +41,8 @@ print_help() {
echo "Usage: bash goinstall.sh OPTIONS"
echo -e "\nOPTIONS:"
echo -e " --remove\tRemove currently installed version"
echo -e " --version\tSpecify a version number to install"
echo -e " --mirror\tProvides a mirror URL for the installer to download"
echo -e " --version\tSpecify a version number to install, Can be appended to the --mirror parameter"
}

if [ -z "$PLATFORM" ]; then
Expand Down Expand Up @@ -101,6 +103,19 @@ elif [ "$1" == "--version" ]; then
else
VERSION=$2
fi
elif [ "$1" == "--mirror" ]; then
if [ -z "$2" ];then
echo "Please provide a mirror URL for: $1"
else
MIRROR=$2
fi
if [ "$3" == "--version" ]; then
if [ -z "$4" ]; then # Check if --version has a second positional parameter
echo "Please provide a version number for: $4"
else
VERSION=$4
fi
fi
elif [ ! -z "$1" ]; then
echo "Unrecognized option: $1"
exit 1
Expand All @@ -114,11 +129,11 @@ fi
PACKAGE_NAME="go$VERSION.$PLATFORM.tar.gz"
TEMP_DIRECTORY=$(mktemp -d)

echo "Downloading $PACKAGE_NAME ..."
echo "Downloading $MIRROR/$PACKAGE_NAME ..."
if hash wget 2>/dev/null; then
wget https://storage.googleapis.com/golang/$PACKAGE_NAME -O "$TEMP_DIRECTORY/go.tar.gz"
wget $MIRROR/$PACKAGE_NAME -O "$TEMP_DIRECTORY/go.tar.gz"
else
curl -o "$TEMP_DIRECTORY/go.tar.gz" https://storage.googleapis.com/golang/$PACKAGE_NAME
curl -o "$TEMP_DIRECTORY/go.tar.gz" $MIRROR/$PACKAGE_NAME
fi

if [ $? -ne 0 ]; then
Expand Down
6 changes: 6 additions & 0 deletions tests/install-from-custom-mirror-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

unset GOROOT
unset GOPATH
"$(dirname "$0")/../goinstall.sh" --mirror https://mirrors.ustc.edu.cn/golang --version "${REQVER}"
6 changes: 6 additions & 0 deletions tests/install-from-custom-mirror.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

unset GOROOT
unset GOPATH
"$(dirname "$0")/../goinstall.sh" --mirror https://mirrors.ustc.edu.cn/golang