forked from rocket-pool/smartnode-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·273 lines (211 loc) · 9.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
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
#!/bin/bash
##
# Rocket Pool service installation script
# Prints progress messages to stdout
# All command output is redirected to stderr
##
# Print a failure message to stderr and exit
fail() {
MESSAGE=$1
RED='\033[0;31m'
>&2 echo -e "\n${RED}**ERROR**\n$MESSAGE"
exit 1
}
# Get CPU architecture
UNAME_VAL=$(uname -m)
ARCH=""
case $UNAME_VAL in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
*) fail "CPU architecture not supported: $UNAME_VAL" ;;
esac
# Get the platform type
PLATFORM=$(uname -s)
if [ "$PLATFORM" = "Linux" ]; then
if command -v lsb_release &>/dev/null ; then
PLATFORM=$(lsb_release -si)
elif [ -f "/etc/centos-release" ]; then
PLATFORM="CentOS"
elif [ -f "/etc/fedora-release" ]; then
PLATFORM="Fedora"
fi
fi
##
# Config
##
# The total number of steps in the installation process
TOTAL_STEPS="7"
# The Rocket Pool user data path
RP_PATH="$HOME/.rocketpool"
# The default smart node package version to download
PACKAGE_VERSION="latest"
# The default network to run Rocket Pool on
NETWORK="pyrmont"
# The version of docker-compose to install
DOCKER_COMPOSE_VERSION="1.26.2"
##
# Utils
##
# Print progress
progress() {
STEP_NUMBER=$1
MESSAGE=$2
echo "Step $STEP_NUMBER of $TOTAL_STEPS: $MESSAGE"
}
# Docker installation steps
install_docker_compose() {
if [ $ARCH = "amd64" ]; then
sudo curl -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose || fail "Could not download docker-compose."
sudo chmod a+x /usr/local/bin/docker-compose || fail "Could not set executable permissions on docker-compose."
elif [ $ARCH = "arm64" ]; then
if command -v apt &> /dev/null ; then
sudo apt install -y libffi-dev libssl-dev
sudo apt install -y python3 python3-pip
sudo apt remove -y python-configparser
sudo pip3 install docker-compose
else
RED='\033[0;31m'
echo ""
echo -e "${RED}**ERROR**"
echo "Automatic installation of docker-compose for the $PLATFORM operating system on ARM64 is not currently supported."
echo "Please install docker-compose manually, then try this again with the '-d' flag to skip OS dependency installation."
echo "Be sure to add yourself to the docker group (e.g. 'sudo usermod -aG docker $USER') after installing docker."
echo "Log out and back in, or restart your system after you run this command."
exit 1
fi
fi
}
add_user_docker() {
sudo usermod -aG docker $USER || fail "Could not add user to docker group."
}
# Install
install() {
##
# Initialization
##
# Parse arguments
while getopts "dn:v:" FLAG; do
case "$FLAG" in
d) NO_DEPS=true ;;
n) NETWORK="$OPTARG" ;;
v) PACKAGE_VERSION="$OPTARG" ;;
*) fail "Incorrect usage." ;;
esac
done
# Get package files URL
if [ "$PACKAGE_VERSION" = "latest" ]; then
PACKAGE_URL="https://github.com/rocket-pool/smartnode-install/releases/latest/download/rp-smartnode-install-$ARCH.tar.xz"
else
# Check the version for backwards compatibility
BETA_VERSION=$(echo "$PACKAGE_VERSION" | rev | cut -d "." -f1 | rev)
if [ $BETA_VERSION -ge 4 ]; then
# Modern version
PACKAGE_URL="https://github.com/rocket-pool/smartnode-install/releases/download/$PACKAGE_VERSION/rp-smartnode-install-$ARCH.tar.xz"
else
# Legacy version
if [ "$ARCH" = "amd64" ]; then
PACKAGE_URL="https://github.com/rocket-pool/smartnode-install/releases/download/$PACKAGE_VERSION/rp-smartnode-install.tar.xz"
else
fail "This version does not support arm64 systems."
fi
fi
fi
# Create temporary data folder; clean up on exit
TEMPDIR=$(mktemp -d 2>/dev/null) || fail "Could not create temporary data directory."
trap 'rm -rf "$TEMPDIR"' EXIT
# Get temporary data paths
PACKAGE_FILES_PATH="$TEMPDIR/rp-smartnode-install"
NETWORK_FILES_PATH="$PACKAGE_FILES_PATH/network/$NETWORK"
##
# Installation
##
# OS dependencies
if [ -z "$NO_DEPS" ]; then
case "$PLATFORM" in
# Ubuntu / Debian / Raspbian
Ubuntu|Debian|Raspbian)
# Get platform name
PLATFORM_NAME=$(echo "$PLATFORM" | tr '[:upper:]' '[:lower:]')
# Install OS dependencies
progress 1 "Installing OS dependencies..."
{ sudo apt-get -y update || fail "Could not update OS package definitions."; } >&2
{ sudo apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common ntp || fail "Could not install OS packages."; } >&2
# Install docker
progress 2 "Installing docker..."
{ curl -fsSL "https://download.docker.com/linux/$PLATFORM_NAME/gpg" | sudo apt-key add - || fail "Could not add docker repository key."; } >&2
{ sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$PLATFORM_NAME $(lsb_release -cs) stable" || fail "Could not add docker repository."; } >&2
{ sudo apt-get -y update || fail "Could not update OS package definitions."; } >&2
{ sudo apt-get -y install docker-ce docker-ce-cli containerd.io || fail "Could not install docker packages."; } >&2
# Install docker-compose
progress 3 "Installing docker-compose..."
>&2 install_docker_compose
# Add user to docker group
progress 4 "Adding user to docker group..."
>&2 add_user_docker
;;
# Centos
CentOS)
# Install OS dependencies
progress 1 "Installing OS dependencies..."
{ sudo yum install -y yum-utils chrony || fail "Could not install OS packages."; } >&2
{ sudo systemctl start chronyd || fail "Could not start chrony daemon."; } >&2
# Install docker
progress 2 "Installing docker..."
{ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo || fail "Could not add docker repository."; } >&2
{ sudo yum install -y --nobest docker-ce docker-ce-cli containerd.io || fail "Could not install docker packages."; } >&2
{ sudo systemctl start docker || fail "Could not start docker daemon."; } >&2
# Install docker-compose
progress 3 "Installing docker-compose..."
>&2 install_docker_compose
# Add user to docker group
progress 4 "Adding user to docker group..."
>&2 add_user_docker
;;
# Fedora
Fedora)
# Install OS dependencies
progress 1 "Installing OS dependencies..."
{ sudo dnf -y install dnf-plugins-core chrony || fail "Could not install OS packages."; } >&2
{ sudo systemctl start chronyd || fail "Could not start chrony daemon."; } >&2
# Install docker
progress 2 "Installing docker..."
{ sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo || fail "Could not add docker repository."; } >&2
{ sudo dnf -y install docker-ce docker-ce-cli containerd.io || fail "Could not install docker packages."; } >&2
{ sudo systemctl start docker || fail "Could not start docker daemon."; } >&2
# Install docker-compose
progress 3 "Installing docker-compose..."
>&2 install_docker_compose
# Add user to docker group
progress 4 "Adding user to docker group..."
>&2 add_user_docker
;;
# Unsupported OS
*)
RED='\033[0;31m'
echo ""
echo -e "${RED}**ERROR**"
echo "Automatic dependency installation for the $PLATFORM operating system is not supported."
echo "Please install docker and docker-compose manually, then try again with the '-d' flag to skip OS dependency installation."
echo "Be sure to add yourself to the docker group with 'sudo usermod -aG docker $USER' after installing docker."
echo "Log out and back in, or restart your system after you run this command."
exit 1
;;
esac
else
echo "Skipping steps 1 - 4 (OS dependencies & docker)"
fi
# Create ~/.rocketpool dir & files
progress 5 "Creating Rocket Pool user data directory..."
{ mkdir -p "$RP_PATH/data/validators" || fail "Could not create the Rocket Pool user data directory."; } >&2
{ touch -a "$RP_PATH/settings.yml" || fail "Could not create the Rocket Pool user settings file."; } >&2
# Download and extract package files
progress 6 "Downloading Rocket Pool package files..."
{ curl -L "$PACKAGE_URL" | tar -xJ -C "$TEMPDIR" || fail "Could not download and extract the Rocket Pool package files."; } >&2
{ test -d "$PACKAGE_FILES_PATH" || fail "Could not extract the Rocket Pool package files."; } >&2
# Copy package files
progress 7 "Copying package files to Rocket Pool user data directory..."
{ test -d "$NETWORK_FILES_PATH" || fail "No package files were found for the selected network."; } >&2
{ cp -r "$NETWORK_FILES_PATH/"* "$RP_PATH" || fail "Could not copy network package files to the Rocket Pool user data directory."; } >&2
{ find "$RP_PATH/chains" -name "*.sh" -exec chmod +x {} \; 2>/dev/null || fail "Could not set executable permissions on package files."; } >&2
}
install "$@"