-
Notifications
You must be signed in to change notification settings - Fork 33
/
go-install
executable file
·62 lines (49 loc) · 1.44 KB
/
go-install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
while getopts fh OPT
do
case $OPT in
"f") FLAG_FORCE="TRUE" ;;
"h") FLAG_HELP="TRUE" ;;
* ) FLAG_HELP="TRUE" ;;
esac
done
shift `expr $OPTIND - 1`
TARGET_VERSION="$1"
LOCATION="$2"
OS="$3"
ARCH="$4"
if [ "x"$FLAG_HELP != "x" -o "x$LOCATION" = "x" ]; then
echo "[usage] go-install [-f] VERSION LOCATION"
echo " ex: go-install 1.3.3 ~/local/go-1.3.3"
echo " ex: go-install 1.3.3 ~/local/go-1.3.3 linux amd64"
echo " default os is 'linux'"
echo " default arch is 'amd64'"
exit 0
fi
if [ "x$OS" = "x" ]; then
OS="linux"
fi
if [ "x$ARCH" = "x" ]; then
ARCH="amd64"
fi
cd $(dirname $0)
if [ "x"$FLAG_FORCE = "x" -a -d "$LOCATION" -a -x "$LOCATION/bin/go" ]; then
current_ver=$("$LOCATION"/bin/go version)
expected_ver="$TARGET_VERSION $OS/$ARCH"
hit=$(echo $current_ver | grep "$expected_ver")
if [ "x$hit" != "x" ]; then
echo "go $TARGET_VERSION already installed on $LOCATION"
echo "To do force re-install, use '-f' option"
exit 0
fi
fi
ARCHIVE_FILENAME="go$TARGET_VERSION.$OS-$ARCH.tar.gz"
DL_GOLANG_ORG="https://storage.googleapis.com/golang"
echo "Start to install go $TARGET_VERSION ..."
set -e
mkdir -p $LOCATION
curl -s $DL_GOLANG_ORG/$ARCHIVE_FILENAME | tar -C $LOCATION -xzf -
cp -a $LOCATION/go/* $LOCATION/
rm -rf $LOCATION/go
echo "go $TARGET_VERSION successfully installed on $LOCATION"
echo "To use this go, do 'export PATH=$LOCATION/bin:\$PATH' and 'export GOROOT=$LOCATION'."