-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·325 lines (276 loc) · 7.86 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/bin/sh
# Pallium install script
# This script will attempt to automatically detect the package manager, perform a system upgrade and install the
# required dependencies.
# Base URL for binaries. Must not end with a slash.
BASE_URL="https://github.com/blechschmidt/pallium/releases/latest/download"
echo 'Pallium Installation Script'
OPTS=$(getopt -o '' --long "dependencies-only,noconfirm,test-dependencies,no-dependencies,binary" -- "$@")
eval set -- "$OPTS"
CONFIRM=1
FROM_SOURCE=1
while true; do
case "$1" in
--dependencies-only) DEPENDENCIES_ONLY=1; shift;;
--no-dependencies) NO_DEPENDENCIES=1; shift;;
--test-dependencies) TEST_DEPENDENCIES=1; shift;; # Install dependencies required for tests. Not in use yet.
--noconfirm) CONFIRM=0; shift;;
--binary) FROM_SOURCE=0; shift;; # Whether to install from source
--) shift; break;;
*) echo "Error."; exit 1;;
esac
done
contains() { case "$1" in *"$2"*) true ;; *) false ;; esac }
# shellcheck disable=SC2039
is_root() { [ "${EUID:-$(id -u)}" -eq 0 ]; }
get_goarch() {
# https://github.com/golang/go/blob/016d7552138077741a9c3fdadc73c0179f5d3ff7/src/cmd/dist/main.go#L94
OUT=$(uname -m)
OUT_ALL=$(uname -r)
export RESULT
if contains "$OUT_ALL" "RELEASE_ARM64"; then
RESULT="arm64"
elif contains "$OUT" "x86_64" || contains "$OUT" "amd64"; then
RESULT="amd64"
elif contains "$OUT" "86"; then
RESULT="386"
# Darwin case ignored
elif contains "$OUT" "aarch64" || contains "$OUT" "arm64"; then
RESULT="arm64"
elif contains "$OUT" "arm"; then
RESULT="arm"
# NetBSD case ignored
elif contains "$OUT" "ppc64le"; then
RESULT="ppc64le"
elif contains "$OUT" "ppc64"; then
RESULT="ppc64"
elif contains "$OUT" "mips64"; then
RESULT="mips64"
LE=$(python3 -c "import sys;sys.exit(int(sys.byteorder=='little'))")
test "$LE" = "1" && RESULT="mips64le"
elif contains "$OUT" "mips"; then
RESULT="mips"
LE=$(python3 -c "import sys;sys.exit(int(sys.byteorder=='little'))")
test "$LE" = "1" && RESULT="mipsle"
elif contains "$OUT" "loongarch64"; then
RESULT="loong64"
elif contains "$OUT" "riscv64"; then
RESULT="riscv64"
elif contains "$OUT" "s390x"; then
RESULT="s390x"
fi
}
download_file() {
# This breaks if the arguments contain quotes
SRC="$1"
DST="$2"
if command -v wget >/dev/null 2>&1; then
wget -O- "$SRC" > "$DST"
elif command -v curl >/dev/null 2>&1; then
curl "$SRC" > "$DST"
else
echo "curl or wget are required. Aborting."
exit 1
fi
}
install_binary() {
get_goarch
ARCH="$RESULT"
DOWNLOAD_URL="$BASE_URL/pallium-x86_64-bundle-linux"
DST_DIR=~/".local/share/applications"
is_root && {
DST_DIR="/usr/local/bin"
}
DST_FILENAME="pallium"
# If stdout is a terminal.
test -t 1 && {
printf "Installation directory [Default: %s]: " "$DST_DIR" >&2
read -r OVERRIDDEN_DST_DIR
}
test -z "$OVERRIDDEN_DST_DIR" || {
DST_DIR="$OVERRIDDEN_DST_DIR"
}
DST_PATH="$DST_DIR/$DST_FILENAME"
mkdir -p "$DST_DIR"
download_file "$DOWNLOAD_URL" "$DST_PATH"
chmod a+x "$DST_PATH"
}
test "$FROM_SOURCE" != "1" && {
install_binary
exit 0
}
test "$(id -u)" -eq 0 || {
echo "You must be root."
exit 1
}
cd "$(dirname "$0")" || (echo "Failed to change directory"; exit 1)
# Alpine Linux
if command -v apk >/dev/null 2>&1; then
PKGMGR=apk
UPDATE="$PKGMGR update; $PKGMGR upgrade"
INSTALL="$PKGMGR add"
fi
# Fedora, CentOS
if command -v yum >/dev/null 2>&1; then
PKGMGR=yum
INSTALL="$PKGMGR install -y"
fi
# Fedora, CentOS
if command -v dnf >/dev/null 2>&1; then
PKGMGR=dnf
INSTALL="$PKGMGR install -y"
fi
# Debian and Ubuntu
if command -v apt >/dev/null 2>&1; then
PKGMGR=apt
UPDATE="$PKGMGR update"
INSTALL="$PKGMGR install -y"
fi
# Debian and Ubuntu
if command -v apt-get >/dev/null 2>&1; then
PKGMGR=apt-get
INSTALL="$PKGMGR install -y"
fi
# Arch Linux
if command -v pacman >/dev/null 2>&1; then
PKGMGR=pacman
UPDATE="pacman -Syyu --noconfirm"
INSTALL="$PKGMGR -S --noconfirm"
fi
# openSUSE
if command -v zypper >/dev/null 2>&1; then
PKGMGR=zypper
UPDATE="zypper refresh"
INSTALL="$PKGMGR -n install"
fi
test "$PKGMGR" != "" || (echo "Failed to determine package manager"; exit 1)
echo "Detected package manager: $PKGMGR"
ask_continue() {
echo "$1"
test "$CONFIRM" = "1" && {
printf "Do you want to continue? (y/n) "
read -r choice
case "$choice" in
y|Y ) ;;
* ) exit 1;;
esac
}
}
install_pkg() {
ask_continue "\"$1\" will be installed using \"$INSTALL $1\"."
$INSTALL "$1"
}
test "$UPDATE" != "" && {
ask_continue "Your system will be updated using \"$UPDATE\"."
eval "$UPDATE"
}
install_python() {
command -v python3 >/dev/null 2>&1
test $? -eq 0 || install_pkg python3
}
install_pip() {
python3 -m pip >/dev/null 2>&1
test $? -eq 0 || {
if [ "$PKGMGR" = "pacman" ]; then
install_pkg python-pip
elif [ "$PKGMGR" = "apk" ]; then
install_pkg py3-pip
else
install_pkg python3-pip
fi
}
}
install_setuptools() {
python3 -m pip install setuptools
}
install_pallium_profiles() {
mkdir -p /etc/pallium/profiles
install -m 0600 extra/profiles/tor.json /etc/pallium/profiles/tor.json
}
install_pallium() {
install_python
install_pip
install_setuptools
python3 -m pip install .
}
install_tor() {
command -v tor >/dev/null 2>&1
test $? -eq 0 || {
# https://support.torproject.org/rpm/
if [ "$PKGMGR" = "dnf" ]; then
install_pkg epel-release
fi
install_pkg tor
}
}
install_unzip() {
command -v unzip >/dev/null 2>&1
test $? -eq 0 || install_pkg unzip
}
install_curl() {
command -v curl >/dev/null 2>&1
test $? -eq 0 || install_pkg curl
}
install_slirp4netns() {
command -v slirp4netns >/dev/null 2>&1
test $? -eq 0 || install_pkg slirp4netns
}
install_slirpnetstack() {
command -v slirpnetstack >/dev/null 2>&1
{ test $? -eq 0 || test -f /usr/local/bin/slirpnetstack; } && return
get_goarch
SUFFIX="$RESULT"
URL=https://github.com/tun2proxy/slirpnetstack/releases/latest/download/slirpnetstack-linux-"$SUFFIX"
ask_continue "$URL will be downloaded and extracted to /usr/local/bin/."
curl -L "$URL" > /usr/local/bin/slirpnetstack
chmod 755 /usr/local/bin/slirpnetstack
}
install_tun2socks() {
command -v tun2socks >/dev/null 2>&1
{ test $? -eq 0 || test -f /usr/local/bin/tun2socks; } && return
get_goarch
SUFFIX="$RESULT"
test "$SUFFIX" = "arm" && SUFFIX=armv5
{ test "$SUFFIX" = "mipsle" || test "$SUFFIX" = "mips"; } && test -d "/lib/arm-linux-gnueabihf" && SUFFIX="$SUFFIX-hardfloat"
install_curl
TMP=$(mktemp -d)
URL=https://github.com/xjasonlyu/tun2socks/releases/latest/download/tun2socks-linux-"$SUFFIX".zip
ask_continue "$URL will be downloaded and extracted to /usr/local/bin/."
curl -L "$URL" >"$TMP/tun2socks.zip"
install_unzip
unzip -d "$TMP" "$TMP/tun2socks.zip" tun2socks-linux-"$SUFFIX"
install -m 0755 "$TMP/tun2socks-linux-$SUFFIX" /usr/local/bin/tun2socks
rm -r "$TMP"
}
install_gvisor() {
command -v runsc >/dev/null 2>&1
{ test $? -eq 0 || test -f /usr/local/bin/runsc; } && return
ARCH=$(uname -m)
URL=https://storage.googleapis.com/gvisor/releases/release/latest/${ARCH}
ask_continue "$URL/runsc will be downloaded and extracted to /usr/local/bin/."
# https://gvisor.dev/docs/user_guide/install/
(
WD="$(pwd)"
TMP=$(mktemp -d)
cd "$TMP"
set -e
wget "${URL}"/runsc "${URL}"/runsc.sha512 \
"${URL}"/containerd-shim-runsc-v1 "${URL}"/containerd-shim-runsc-v1.sha512
sha512sum -c runsc.sha512 -c containerd-shim-runsc-v1.sha512
rm -f -- *.sha512
chmod a+rx runsc containerd-shim-runsc-v1
mv runsc containerd-shim-runsc-v1 /usr/local/bin
cd "$WD"
rm -r "$TMP"
)
}
test "$DEPENDENCIES_ONLY" = "1" || {
install_pallium
install_pallium_profiles
}
test "$NO_DEPENDENCIES" != "1" && {
install_tor
install_tun2socks
install_slirpnetstack
install_gvisor
}