forked from mysteriumnetwork/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·257 lines (216 loc) · 6.58 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
#!/usr/bin/env bash
shopt -s extglob
set -e
set -o errtrace
set -o errexit
set -o pipefail
export DEBIAN_FRONTEND="noninteractive"
# Install latest release of myst for debian/ubuntu/raspbian
#
# Variables:
# - SNAPSHOT (default: false) - set to "true" to install development snapshot
#
if [[ "$SNAPSHOT" == "true" ]]; then
PPA="ppa:mysteriumnetwork/node-dev"
PPA_URL="http://ppa.launchpad.net/mysteriumnetwork/node-dev/ubuntu"
PPA_FINGER="ECCB6A56B22C536D"
else
PPA="ppa:mysteriumnetwork/node"
PPA_URL="http://ppa.launchpad.net/mysteriumnetwork/node/ubuntu"
PPA_FINGER="ECCB6A56B22C536D"
fi
get_os() {
local __resultvar=$1
local result
result=$(uname | tr '[:upper:]' '[:lower:]')
eval $__resultvar="'$result'"
}
get_linux_distribution() {
local __resultvar=$1
local result
if [[ -f "/etc/os-release" ]]; then
local id=$(awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)
if [[ -z "$id" ]]; then
id=$(awk -F= '$1=="ID_LIKE" { print $2 ;}' /etc/os-release)
fi
result="$id"
else
result="unknown"
fi
eval $__resultvar="'$result'"
}
get_version_codename() {
local __resultvar=$1
local result
if [[ -f "/etc/os-release" ]]; then
local id=$(awk -F= '$1=="VERSION_CODENAME" { print $2 ;}' /etc/os-release)
result="$id"
else
result="unknown"
fi
eval $__resultvar="'$result'"
}
get_matching_ubuntu_codename() {
local __resultvar=$1
local result
readonly local mdistro=$2
readonly local mvcodename=$3
if [[ "$mdistro" == "debian" || "$mdistro" == "raspbian" ]]; then
case "$mvcodename" in
eoan)
result="eoan"
;;
buster)
result="bionic"
;;
stretch)
result="xenial"
;;
*)
result="bionic"
esac
else
result="bionic"
fi
eval $__resultvar="'$result'"
}
get_architecture() {
local __resultvar=$1
local result
if [[ -x "$(command -v dpkg)" ]]; then
result=$(dpkg --print-architecture)
else
result=$(uname -m)
fi
if [[ "$result" == "x86_64" ]]; then
result="amd64"
fi
eval $__resultvar="'$result'"
}
install_if_not_exists() {
dep=$1
if ! [[ -x "$(command -v $dep)" ]]; then
echo "$dep not found, installing"
apt -y install "$dep"
else
echo "$dep found"
fi
}
install_script_dependencies() {
apt update
install_if_not_exists curl
install_if_not_exists libcap2-bin
install_if_not_exists jq
apt install -y dirmngr
}
install_ubuntu() {
# openvpn, etc.
if [[ "$VERSION_CODENAME" == "xenial" ]]; then
curl -s https://swupdate.openvpn.net/repos/repo-public.gpg | apt-key add -
echo "deb http://build.openvpn.net/debian/openvpn/stable xenial main" > /etc/apt/sources.list.d/openvpn-aptrepo.list
fi
apt update
apt install -y ipset resolvconf openvpn
# add-apt-repository may not be available in Ubuntu server out of the box
apt install -y software-properties-common
# Wireguard
# If kernel module installs successfully, the following commands should give no errors:
# ip link add dev wg0 type wireguard
# ip link delete wg0
if [[ "$container" != "docker" ]]; then
apt install -y "linux-headers-$(uname -r)"
fi
add-apt-repository -y ppa:wireguard/wireguard
apt update
apt install -y wireguard wireguard-dkms
dpkg-reconfigure wireguard-dkms
# myst
add-apt-repository -y "$PPA"
apt update
apt-get --only-upgrade install -y myst
apt install -y myst
service mysterium-node restart
}
install_raspbian() {
# openvpn, etc.
apt update
apt install -y ipset resolvconf openvpn
# Wireguard
apt install -y git bc bison flex libssl-dev libncurses5-dev # For rpi-source
wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/local/bin/rpi-source \
&& chmod +x /usr/local/bin/rpi-source \
&& rpi-source -q --tag-update
rpi-source --default-config || true
echo "deb http://ppa.launchpad.net/wireguard/wireguard/ubuntu $UBUNTU_VERSION_CODENAME main" > /etc/apt/sources.list.d/wireguard.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AE33835F504A1A25
apt update
apt install -y wireguard wireguard-dkms
dpkg-reconfigure wireguard-dkms
# myst
echo "deb $PPA_URL $UBUNTU_VERSION_CODENAME main" > /etc/apt/sources.list.d/mysterium.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys "$PPA_FINGER"
apt update
apt-get --only-upgrade install -y myst
apt install -y myst
service mysterium-node restart
}
install_debian() {
# openvpn, etc.
apt update
apt install -y ipset resolvconf openvpn bc
# Wireguard
prepare_sources_list
apt update
if [[ "$container" != "docker" ]]; then
apt install -y "linux-headers-$(uname -r)"
fi
apt install -y wireguard wireguard-dkms
dpkg-reconfigure wireguard-dkms
# myst
echo "deb $PPA_URL $UBUNTU_VERSION_CODENAME main" > /etc/apt/sources.list.d/mysterium.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys "$PPA_FINGER"
apt update
apt-get --only-upgrade install -y myst
apt install -y myst
service mysterium-node restart
}
prepare_sources_list() {
if [[ "$VERSION_CODENAME" == "buster" ]]; then
echo "deb http://deb.debian.org/debian ${VERSION_CODENAME}-backports main" > /etc/apt/sources.list.d/backports.list
else
echo "deb http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/unstable.list
printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' > /etc/apt/preferences.d/limit-unstable
fi
}
install() {
case "$DISTRO" in
ubuntu)
install_ubuntu
;;
raspbian)
install_raspbian
;;
*)
install_debian
esac
}
echo "### Installing script dependencies"
install_script_dependencies
echo "### Installing script dependencies - done"
echo "### Detecting platform"
get_os OS
get_architecture ARCH
get_linux_distribution DISTRO
get_version_codename VERSION_CODENAME
get_matching_ubuntu_codename UBUNTU_VERSION_CODENAME "$DISTRO" "$VERSION_CODENAME"
echo "System info:
OS: $OS
Architecture: $ARCH
Distribution: $DISTRO
Version codename: $VERSION_CODENAME
Matching ubuntu version codename: $UBUNTU_VERSION_CODENAME"
echo "### Detecting platform - done"
echo "### Installing myst & dependencies"
install
echo "### Installing myst & dependencies - done"
echo "### Installation complete!"