forked from dusk-network/node-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-installer.sh
335 lines (285 loc) · 10.6 KB
/
node-installer.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
326
327
328
329
330
331
332
333
334
335
#!/bin/bash
# Detect the user running the script
CURRENT_USER=$(logname)
CURRENT_HOME=$(eval echo ~"$CURRENT_USER")
echo "Detected current user: $CURRENT_USER"
echo "Home directory: $CURRENT_HOME"
declare -A VERSIONS
# Define versions per network, per component
VERSIONS=(
["mainnet-rusk"]="1.0.0-rc.0"
["mainnet-rusk-wallet"]="0.1.0-rc.0"
["testnet-rusk"]="1.0.0-rc.0"
["testnet-rusk-wallet"]="0.1.0-rc.0"
["devnet-rusk"]="1.0.0-rc.0"
["devnet-rusk-wallet"]="0.1.0-rc.0"
)
# Select network (default to mainnet if no argument passed)
NETWORK="${1:-mainnet}"
case "$NETWORK" in
mainnet|testnet|devnet)
echo "Selected network: $NETWORK"
;;
*)
echo "Error: Unknown network $NETWORK. Use 'mainnet', 'testnet', or 'devnet'."
exit 1
;;
esac
# Feature flag ("default" if not set, "archive" also possible)
FEATURE="${FEATURE:-default}"
# Retrieve architecture
arch=""
case "$(uname -m)" in
x86_64) arch="x64";;
aarch64) arch="arm64";;
*) echo "Unsupported architecture: $(uname -m). Only x64 and arm64 are supported."; exit 1;;
esac
# Check for Linux
if [ "$(uname -s | tr '[:upper:]' '[:lower:]')" != "linux" ]; then
echo "Unsupported platform: $(uname -s). This installer only supports Linux."
exit 1
fi
# Detect the Linux distribution
distro="unknown"
if [ -f /etc/os-release ]; then
. /etc/os-release
distro=$(echo "$ID" | tr '[:upper:]' '[:lower:]')
else
echo "Unable to detect the Linux distribution. Ensure this is an Ubuntu-based system."
exit 1
fi
if [ "$distro" != "ubuntu" ]; then
echo "Unsupported Linux distribution: $distro. This installer only supports Ubuntu."
exit 1
fi
echo "Detected supported distro: $distro ($arch)"
# Installs a given component for a given network
install_component() {
local network="$1"
local component="$2"
local key="${network}-${component}"
local version="${VERSIONS[$key]}"
if [[ -z "$version" ]]; then
echo "Error: Version not found for $key"
exit 1
fi
# Apply the FEATURE suffix only for Rusk
local feature_suffix=""
if [[ "$component" == "rusk" ]]; then
feature_suffix="-${FEATURE}"
fi
# Removes any RC version from the URL
local sanitized_version="${version%-rc.*}"
# Construct the download URL
local url="https://github.com/dusk-network/rusk/releases/download/${component}-${version}/${component}-${sanitized_version}-linux-${arch}${feature_suffix}.tar.gz"
echo "Installing $component version $version for $network ($arch${feature_suffix})"
echo "Downloading from $url"
local component_dir="/opt/dusk/installer/${component}"
mkdir -p "$component_dir"
curl -so /opt/dusk/installer/${component}.tar.gz -L "$url" || { echo "Failed to download $component"; exit 1; }
tar xf /opt/dusk/installer/${component}.tar.gz --strip-components 1 --directory "$component_dir"
}
# Check for OpenSSL 3 or higher
if ! command -v openssl >/dev/null 2>&1 || [ "$(openssl version | awk '{print $2}' | cut -d. -f1)" -lt 3 ]; then
echo "The required OpenSSL version is not available. Please install OpenSSL 3 or higher"
echo "You likely need to upgrade your OS or install a newer OS"
exit 1
fi
update_pkg_database() {
echo "Updating package database..."
apt update
}
check_installed() {
binary_name=$1
package_name=$2
if ! which $binary_name >/dev/null 2>&1; then
echo "$binary_name missing"
echo "Installing $package_name"
NEEDRESTART_MODE=a apt install $package_name -y
else
echo "$binary_name is already installed."
fi
}
# Configure your local installation based on the selected network
configure_network() {
local network=$1
local kadcast_id
local bootstrapping_nodes
local genesis_timestamp
local base_state
local prover_url
case "$network" in
mainnet)
kadcast_id="41"
bootstrapping_nodes="['134.209.203.150:9000', '209.38.242.80:9000', '137.184.15.177:9000']"
genesis_timestamp="'2025-01-04T12:00:00Z'"
base_state="https://nodes.dusk.network/genesis-state-dryrun2"
prover_url="https://provers.dusk.network"
;;
testnet)
kadcast_id="0x2"
bootstrapping_nodes="['134.122.62.88:9000','165.232.64.16:9000','137.184.118.43:9000']"
genesis_timestamp="'2024-12-23T17:00:00Z'"
base_state="https://testnet.nodes.dusk.network/genesis-state"
prover_url="https://testnet.provers.dusk.network"
;;
devnet)
kadcast_id="0x3"
bootstrapping_nodes="['128.199.32.54', '159.223.29.22', '143.198.225.158']"
genesis_timestamp="'2024-12-23T12:00:00Z'"
base_state="https://devnet.nodes.dusk.network/genesis-state"
prover_url="https://devnet.provers.dusk.network"
;;
*)
echo "Unknown network: $network. Defaulting to testnet."
configure_network "testnet"
return
;;
esac
# Create genesis.toml
cat > /opt/dusk/conf/genesis.toml <<EOF
base_state = "$base_state"
EOF
# Update the rusk.toml file with kadcast_id, bootstrapping_nodes & genesis_timestamp
sed -i "s/^kadcast_id =.*/kadcast_id = $kadcast_id/" /opt/dusk/conf/rusk.toml
sed -i "s/^bootstrapping_nodes =.*/bootstrapping_nodes = $bootstrapping_nodes/" /opt/dusk/conf/rusk.toml
sed -i "s/^genesis_timestamp =.*/genesis_timestamp = $genesis_timestamp/" /opt/dusk/conf/rusk.toml
# Update the wallet.toml with the appropriate prover URL for the given network
sed -i "s|^prover = .*|prover = \"$prover_url\"|" $CURRENT_HOME/.dusk/rusk-wallet/config.toml
}
echo "Stopping previous services"
if systemctl is-active --quiet rusk; then
systemctl stop rusk
echo "Stopped rusk service."
else
echo "Rusk service not running."
fi
rm -rf /opt/dusk/installer || true
rm -rf /opt/dusk/installer/installer.tar.gz || true
echo "Checking prerequisites"
update_pkg_database
check_installed unzip unzip
check_installed curl curl
check_installed route net-tools
check_installed jq jq
check_installed logrotate logrotate
check_installed dig dnsutils
# Ensure dusk group and user exist
if ! id -u dusk >/dev/null 2>&1; then
echo "Creating dusk system user and group."
groupadd --system dusk
useradd --system --create-home --shell /usr/sbin/nologin --gid dusk dusk
echo "User 'dusk' and group 'dusk' created."
else
echo "User 'dusk' and group 'dusk' already exist."
fi
# Add the current user to the dusk group for access
echo "Adding current user to dusk group for access."
if ! id -nG "$CURRENT_USER" | grep -qw "dusk"; then
usermod -aG dusk "$CURRENT_USER"
echo "User $CURRENT_USER has been added to the dusk group. Please log out and back in to apply changes."
fi
mkdir -p /opt/dusk/bin
mkdir -p /opt/dusk/conf
mkdir -p /opt/dusk/rusk
mkdir -p /opt/dusk/services
mkdir -p /opt/dusk/installer
mkdir -p $CURRENT_HOME/.dusk/rusk-wallet
chown -R "$CURRENT_USER:dusk" "$CURRENT_HOME/.dusk"
chmod -R 770 "$CURRENT_HOME/.dusk"
INSTALLER_URL="https://github.com/dusk-network/node-installer/tarball/main"
echo "Downloading installer package for additional scripts and configurations"
curl -so /opt/dusk/installer/installer.tar.gz -L "$INSTALLER_URL"
tar xf /opt/dusk/installer/installer.tar.gz --strip-components 1 --directory /opt/dusk/installer
# Handle scripts, configs, and service definitions
mv -f /opt/dusk/installer/bin/* /opt/dusk/bin/
mv /opt/dusk/installer/conf/* /opt/dusk/conf/
mv -n /opt/dusk/installer/services/* /opt/dusk/services/
# Download, unpack and install Rusk
install_component "$NETWORK" "rusk"
mv /opt/dusk/installer/rusk/rusk /opt/dusk/bin/
# Download, unpack and install Rusk wallet
install_component "$NETWORK" "rusk-wallet"
mv /opt/dusk/installer/rusk-wallet/rusk-wallet /opt/dusk/bin/
mv -f /opt/dusk/conf/wallet.toml $CURRENT_HOME/.dusk/rusk-wallet/config.toml
# Make bin folder scripts and bins executable, symlink to make available system-wide
chmod +x /opt/dusk/bin/*
ln -sf /opt/dusk/bin/rusk /usr/bin/rusk
ln -sf /opt/dusk/bin/ruskquery /usr/bin/ruskquery
ln -sf /opt/dusk/bin/ruskreset /usr/bin/ruskreset
ln -sf /opt/dusk/bin/download_state.sh /usr/bin/download_state
ln -sf /opt/dusk/bin/rusk-wallet /usr/bin/rusk-wallet
echo "Downloading verifier keys"
echo "Selected network: $NETWORK"
VERIFIER_KEYS_URL="https://testnet.nodes.dusk.network/keys"
case "$NETWORK" in
mainnet)
VERIFIER_KEYS_URL="https://nodes.dusk.network/keys"
;;
testnet)
VERIFIER_KEYS_URL="https://testnet.nodes.dusk.network/keys"
;;
devnet)
VERIFIER_KEYS_URL="https://devnet.nodes.dusk.network/keys"
;;
*)
echo "Unknown network: $network. Defaulting to mainnet."
return
;;
esac
rm -rf /opt/dusk/rusk/circuits || true
rm -rf /opt/dusk/rusk/keys || true
curl -so /opt/dusk/installer/rusk-vd-keys.zip -L "$VERIFIER_KEYS_URL"
unzip -d /opt/dusk/rusk/ -o /opt/dusk/installer/rusk-vd-keys.zip
configure_network "$NETWORK"
# Set permissions for dusk user and group
chown -R dusk:dusk /opt/dusk
chmod -R 770 /opt/dusk
# Set system parameters
mv -f /opt/dusk/conf/dusk.conf /etc/sysctl.d/dusk.conf
sysctl -p /etc/sysctl.d/dusk.conf
echo "Installing services"
# Overwrite previous service definitions
mv -f /opt/dusk/services/rusk.service /etc/systemd/system/rusk.service
# Configure logrotate with 644 permissions otherwise configuration is ignored
mv -f /opt/dusk/services/logrotate.conf /etc/logrotate.d/dusk.conf
chown root:root /etc/logrotate.d/dusk.conf
chmod 644 /etc/logrotate.d/dusk.conf
# Enable the Rusk service
systemctl enable rusk
systemctl daemon-reload
echo "Dusk node installed"
echo "-----"
echo "Prerequisites for launching:"
echo "1. Provide CONSENSUS_KEYS file (default in /opt/dusk/conf/consensus.keys)"
echo "Run the following commands:"
echo "rusk-wallet restore"
echo "rusk-wallet export -d /opt/dusk/conf -n consensus.keys"
echo
echo "2. Set DUSK_CONSENSUS_KEYS_PASS (use /opt/dusk/bin/setup_consensus_pwd.sh)"
echo "Run the following command:"
echo "sh /opt/dusk/bin/setup_consensus_pwd.sh"
echo
echo "-----"
echo "To launch the node: "
echo "service rusk start"
echo
echo "To run the Rusk wallet:"
echo "rusk-wallet"
echo
echo "To check the logs:"
echo "tail -F /var/log/rusk.log"
echo
echo "The installer also adds a small Rusk querying utility called ruskquery."
echo "To see what you can query with it:"
echo "ruskquery"
echo
echo "To query the the node for the latest block height:"
echo "ruskquery block-height"
echo
echo "To check if your node installer is up to date:"
echo "ruskquery version"
echo
echo "To reset your Rusk state and wallet cache:"
echo "ruskreset"
rm -rf /opt/dusk/installer