-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·107 lines (92 loc) · 2.13 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
set -e
max_retry=3
retry_delay=1
tag_name=""
ghproxy=""
while getopts "r:d:t:p" opt; do
case $opt in
r) max_retry="${OPTARG}" ;;
d) retry_delay="${OPTARG}" ;;
t) tag_name="${OPTARG}" ;;
p) ghproxy="1" ;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
echo "${ghproxy}"
shift $((OPTIND-1))
os="$(uname -s)"
case "${os}" in
Linux)
goos=linux
;;
Darwin)
goos=darwin
;;
*)
echo "Unsupported OS $(uname -a)"
exit 1
;;
esac
arch="$(uname -m)"
case "${arch}" in
x86_64 | x64 | amd64)
goarch=amd64
;;
arm64 | aarch64 | armv8*)
goarch=arm64
;;
x86 | i686 | i386)
goarch=386
;;
armv5*)
goarch=armv5
;;
armv6*)
goarch=armv6
;;
armv7*)
goarch=armv7
;;
*)
echo "Unsupported ARCH $(uname -a)"
exit 1
;;
esac
function download_cmdr() {
if [[ -z "${tag_name}" ]]; then
download_url="https://github.com/MrLYC/cmdr/releases/latest/download/cmdr_${goos}_${goarch}"
else
download_url="https://github.com/MrLYC/cmdr/releases/download/${tag_name}/cmdr_${goos}_${goarch}"
fi
if [[ "${ghproxy}" == "1" ]]; then
download_url="https://ghproxy.com/${download_url}"
fi
target="$1"
echo "Downloading cmdr ${tag_name}..."
curl -L -o "${target}" "${download_url}"
chmod +x "${target}"
}
echo "Downloading cmdr..."
target="/tmp/cmdr_${RANDOM}"
retry=0
until download_cmdr "${target}"; do
if [[ "${retry}" -gt "${max_retry}" ]]; then
echo "Failed to download cmdr"
exit 1
elif [[ "${retry}" = "${max_retry}" ]]; then
echo "Activating proxy automaticly..."
ghproxy="1"
fi
echo "Failed to download cmdr, retry after ${retry_delay} second"
retry=$((retry+1))
sleep "${retry_delay}"
done
echo "Initializing cmdr..."
"${target}" init
"${target}" command list -n cmdr
rm -f "${target}"
echo "Please restart your terminal to activate the cmdr command"