-
Notifications
You must be signed in to change notification settings - Fork 217
/
install.sh
executable file
·82 lines (67 loc) · 1.77 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
75
76
77
78
79
80
81
82
#!/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)}')
}
function main() {
local release="1.7.0"
local os=$(get_os)
local arch=$(get_arch)
local dest_file="${HOME}/.g/downloads/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}/.g/downloads" "${url}"
else
curl -s -S -L --create-dirs -o "${dest_file}" "${url}"
fi
echo "[2/3] Install g to the ${HOME}/.g/bin"
mkdir -p "${HOME}/.g/bin"
tar -xz -f "${dest_file}" -C "${HOME}/.g/bin"
chmod +x "${HOME}/.g/bin/g"
echo "[3/3] Set environment variables"
cat >${HOME}/.g/env <<-'EOF'
#!/bin/sh
# g shell setup
export GOROOT="${HOME}/.g/go"
export PATH="${HOME}/.g/bin:${GOROOT}/bin:${GOPATH}/bin:$PATH"
export G_MIRROR=https://golang.google.cn/dl/
EOF
if [ -x "$(command -v bash)" ]; then
cat >>${HOME}/.bashrc <<-'EOF'
[ -s "${HOME}/.g/env" ] && \. "${HOME}/.g/env" # g shell setup
EOF
fi
if [ -x "$(command -v zsh)" ]; then
cat >>${HOME}/.zshrc <<-'EOF'
[ -s "${HOME}/.g/env" ] && \. "${HOME}/.g/env" # g shell setup
EOF
fi
echo -e "\nTo configure your current shell, run:\nsource \"$HOME/.g/env\""
exit 0
}
main