-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·74 lines (65 loc) · 1.64 KB
/
install.sh
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
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
set -e
function get_arch() {
a=$(uname -m)
case ${a} in
"x86_64" | "amd64")
echo "amd64"
;;
"i386" | "i486" | "i586")
echo "386"
;;
"aarch64" | "arm64")
echo "arm64"
;;
"armv6l" | "armv7l")
echo "arm"
;;
"s390x")
echo "s390x"
;;
*)
echo ${NIL}
;;
esac
}
function get_os() {
echo $(uname -s | awk '{print tolower($0)}')
}
main() {
local release="1.4.0"
local os=$(get_os)
local arch=$(get_arch)
local dest_file="${HOME}/g${release}.${os}-${arch}.tar.gz"
local url="https://github.com/voidint/g/releases/download/v${release}/g${release}.${os}-${arch}.tar.gz"
echo "[1/3] Downloading ${url}"
rm -f "${dest_file}"
if [ -x "$(command -v wget)" ]; then
wget -q -P "${HOME}" "${url}"
else
curl -s -S -L -o "${dest_file}" "${url}"
fi
echo "[2/3] Install g to the ${HOME}/bin"
mkdir -p "${HOME}/bin"
tar -xz -f "${dest_file}" -C "${HOME}/bin"
chmod +x "${HOME}/bin/g"
echo "[3/3] Set environment variables"
if [ -x "$(command -v bash)" ]; then
cat >>${HOME}/.bashrc <<-'EOF'
# ===== set g environment variables =====
export GOROOT="${HOME}/.g/go"
export PATH="${HOME}/bin:${HOME}/.g/go/bin:$PATH"
export G_MIRROR=https://golang.google.cn/dl/
EOF
fi
if [ -x "$(command -v zsh)" ]; then
cat >>${HOME}/.zshrc <<-'EOF'
# ===== set g environment variables =====
export GOROOT="${HOME}/.g/go"
export PATH="${HOME}/bin:${HOME}/.g/go/bin:$PATH"
export G_MIRROR=https://golang.google.cn/dl/
EOF
fi
exit 0
}
main