-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall.sh
executable file
·75 lines (64 loc) · 1.57 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
#!/bin/sh
PKG_URL="github.com/go-gilbert/gilbert"
URL_DOWNLOAD_PREFIX="https://${PKG_URL}/releases/latest/download"
ISSUE_URL="https://${PKG_URL}/issues"
NIL="nil"
PATH="${PATH}"
RED="\033[0;31m"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
warn() {
printf "${YELLOW}${1}${NC}\n"
}
panic() {
printf "${RED}ERROR: ${1}${NC}\n" >&2
printf "${RED}Installation Failed${NC}\n"
exit 1
}
get_gilbert_name() {
os=$(uname -s | awk '{print tolower($0)}')
arc=$(get_arch)
if [ "${arc}" = "${NIL}" ]; then
echo "${NIL}"
else
echo "gilbert_${os}-${arc}"
fi
}
get_arch() {
a=$(uname -m)
case ${a} in
"x86_64" | "amd64" )
echo "amd64"
;;
"i386" | "i486" | "i586")
echo "386"
;;
*)
echo ${NIL}
;;
esac
}
main() {
local gb_name=$(get_gilbert_name)
if [ "$gb_name" = "$NIL" ]; then
panic "No prebuilt binaries available, try to check out release for your platform at https://${PKG_URL}/releases"
fi
local download_dir="${HOME}/bin"
if command -v "go" > /dev/null; then
download_dir="$(go env GOPATH)/bin"
fi
mkdir -p ${download_dir}
local dest_file="${download_dir}/gilbert"
local lnk=${URL_DOWNLOAD_PREFIX}/${gb_name}
echo "-> Downloading '${lnk}'..."
if ! curl -sS -L -o "${dest_file}" ${lnk}; then
warn "Download failed, trying to compile manually..."
compile_install
fi
chmod +x ${dest_file}
echo "-> Successfully installed to '${dest_file}'"
printf "${GREEN}Done!${NC}\n"
exit 0
}
main