-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·176 lines (143 loc) · 2.72 KB
/
install.sh
File metadata and controls
executable file
·176 lines (143 loc) · 2.72 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/sh
log_info() {
echo "[info] ${1}"
}
log_err() {
echo "[error] ${1} (please install manually via https://keygen.sh/docs/relay/)"
exit 1
}
get_os() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
case "${os}"
in
msys*|mingw*)
os='windows'
;;
cygwin*)
os='linux'
;;
esac
if [ -z "${os}" ]
then
log_err 'unable to detect operating system'
fi
echo "${os}"
}
get_arch() {
arch=$(uname -m)
case "${arch}"
in
x86_64|amd64p32)
arch='amd64'
;;
x86)
arch='386'
;;
aarch64)
arch='arm64'
;;
armv8)
arch='arm64'
;;
armv*)
arch='arm'
;;
i686|i386)
arch='386'
;;
esac
if [ -z "${arch}" ]
then
log_err 'unable to detect architecture'
fi
echo "${arch}"
}
get_tmp_path() {
path=$(mktemp -d /tmp/relay.XXXXXXXXXX)
if [ -z "${path}" ]
then
log_err 'unable to make tmp install path'
fi
echo "${path}/${BIN_NAME}"
}
get_bin_name() {
name='relay'
if [ "${OS}" = 'windows' ]
then
name="${name}.exe"
fi
echo "${name}"
}
get_bin_path() {
path="/usr/local/bin/${BIN_NAME}"
if [ "${OS}" = 'windows' ]
then
path="./${BIN_NAME}"
fi
echo "${path}"
}
get_bin_version() {
version=$(curl -sSL 'https://raw.pkg.keygen.sh/keygen/relay/latest/version')
if [ -z "${version}" ]
then
log_err 'unable to get latest version'
fi
echo "${version}"
}
get_bin_url() {
filename="relay_${OS}_${ARCH}"
if [ "${OS}" = 'windows' ]
then
filename="${filename}.exe"
fi
echo "https://raw.pkg.keygen.sh/keygen/relay/${BIN_VERSION}/${filename}"
}
assert_os_support() {
case "${OS}"
in
linux) return ;;
esac
log_err "unsupported operating system: ${OS}"
}
assert_arch_support() {
case "${ARCH}"
in
386) return ;;
amd64) return ;;
arm64) return ;;
arm) return ;;
esac
log_err "unsupported architecture: ${ARCH}"
}
assert_platform_support() {
assert_os_support
assert_arch_support
}
main() {
assert_platform_support
status=$(curl -sSL "${BIN_URL}" --write-out "%{http_code}" -o "${BIN_TMP}")
if [ "${status}" -eq 200 ]
then
log_info "successfully downloaded v${BIN_VERSION} for ${PLATFORM}: ${BIN_TMP}"
else
log_err "failed to download v${BIN_VERSION} for ${PLATFORM}: ${status}"
fi
mv "${BIN_TMP}" "${BIN_PATH}" && \
chmod +x "${BIN_PATH}"
if [ $? -eq 0 ]
then
log_info "successfully installed v${BIN_VERSION} for ${PLATFORM}: ${BIN_PATH}"
else
log_err "failed to installed v${BIN_VERSION} for ${PLATFORM}"
fi
${BIN_PATH} --help
}
OS=$(get_os)
ARCH=$(get_arch)
PLATFORM="${OS}/${ARCH}"
BIN_VERSION=$(get_bin_version)
BIN_NAME=$(get_bin_name)
BIN_PATH=$(get_bin_path)
BIN_TMP=$(get_tmp_path)
BIN_URL=$(get_bin_url)
main