forked from mysteriumnetwork/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·149 lines (117 loc) · 3.84 KB
/
install.sh
File metadata and controls
executable file
·149 lines (117 loc) · 3.84 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
#!/bin/sh
# Install latest release of myst for debian/raspbian
#
# Variables:
# - SNAPSHOT (default: false) - set to "true" to install development snapshot
#
set -e
if [[ "$SNAPSHOT" == "true" ]]; then
releases_url="http://api.github.com/repos/mysteriumnetwork/node-builds/releases"
else
releases_url="http://api.github.com/repos/mysteriumnetwork/node/releases"
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_LIKE" { print $2 ;}' /etc/os-release)
if [[ -z "$id" ]]; then
id=$(awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)
fi
result="$id"
else
result="unknown"
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'"
}
download_latest_package() {
local __resultvar=$1
local result
readonly local os=$2
readonly local arch=$3
readonly local distro=$4
local package_file
if [[ "$distro" == "debian" ]] && [[ "$arch" == "amd64" ]]; then
package_file="myst_linux_amd64.deb"
elif [[ "$distro" == "debian" ]] && [[ "$arch" == "armhf" ]]; then
package_file="myst_linux_armhf.deb"
fi
if [[ -z "$package_file" ]]; then
echo "Error: could not determine package to download, aborting"
exit 1
fi
latest_release_json=$(curl --silent --location "$releases_url/latest")
latest_tag=$(echo "$latest_release_json" | jq --raw-output '.tag_name')
echo "Latest release: $latest_tag"
package_url=$(echo "$latest_release_json" | jq --raw-output --arg package "$package_file" '.assets[] | select(.name==$package) | .browser_download_url')
echo "Package URL: $package_url"
curl --write-out '%{http_code}\n' --location "$package_url" --output "$package_file"
result="$package_file"
echo $result
eval $__resultvar="'$result'"
}
install_if_not_exists() {
dep=$1
if ! [[ -x "$(command -v $dep)" ]]; then
echo "$dep not found, installing"
apt-get -y install "$dep"
else
echo "$dep found"
fi
}
install_script_dependencies() {
install_if_not_exists curl
install_if_not_exists jq
}
install_dependencies() {
# Wireguard
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
apt-get install dirmngr
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ECCB6A56B22C536D
apt-get update
apt-get install -y wireguard
}
install_myst() {
readonly local package_file=$1
apt install -y --allow-downgrades "./$package_file"
service mysterium-node restart
}
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
echo "OS: $OS | architecture: $ARCH | distribution: $DISTRO"
echo "### Detecting platform - done"
echo "### Downloading latest package"
download_latest_package PACKAGE_FILE $OS $ARCH $DISTRO
echo "### Downloading latest package - done: $PACKAGE_FILE"
echo "### Installing myst dependencies"
install_dependencies
echo "### Installing myst dependencies - done"
echo "### Installing myst & restarting service"
install_myst $PACKAGE_FILE
echo "### Installation complete!"