-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
396 lines (309 loc) · 8.79 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#!/bin/bash
##############################################################################################################
# Configuration
SOFTWARE_NAME="rns_server_management"
SOFTWARE_PATH=$(dirname $(realpath $0))
SOFTWARE_PATH_SRC="$SOFTWARE_PATH/bin"
SOFTWARE_PATH_DST="/usr/local/bin/rns"
SOFTWARE_CONFIG_SRC="$SOFTWARE_PATH/config"
SOFTWARE_CONFIG_DST="$HOME/.config/$SOFTWARE_NAME"
RETICULUM_CONFIG_DST=("$HOME/.config/reticulum" "$HOME/.reticulum")
##############################################################################################################
# Functions
_divider() {
echo -e "..............................................................................."
}
_settings_user() {
SETTINGS_USER=$USER
SETTINGS_USER_TARGET=""
USERS=()
USERS+=("root")
USERLIST=$(cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1)
for s in $USERLIST; do
USERS+=("$s")
done
if [ ${#USERS[@]} -ne 1 ]; then
echo -e "Do you want the installed services to run under a different user? If so, please select a user."
select OPTION in "${USERS[@]}"; do
REPLY=$REPLY-1
if [[ ${USERS[$REPLY]} ]]; then
if [ "${USERS[$REPLY]}" != "root" ]; then
SETTINGS_USER="${USERS[$REPLY]}"
SETTINGS_USER_TARGET="user_target = ${USERS[$REPLY]}"
RETICULUM_CONFIG_DST_TMP=("/home/${USERS[$REPLY]}/.config/reticulum" "/home/${USERS[$REPLY]}/.reticulum", "${RETICULUM_CONFIG_DST[@]}")
RETICULUM_CONFIG_DST=("${RETICULUM_CONFIG_DST_TMP[@]}")
fi
fi
break
done
fi
}
_install_core_software() {
if ! command -v python3-pip; then
apt -y -q update
apt install python3-pip
fi
pip3 install rns
pip3 install pyserial netifaces
pip3 install lxmf
pip3 install nomadnet
}
_install_core_config() {
if [ "$SETTINGS_USER" != "$USER" ]; then
CONFIG_FOLDER="/home/$SETTINGS_USER/.config/reticulum"
else
CONFIG_FOLDER="$HOME/.config/reticulum"
fi
mkdir -p "$CONFIG_FOLDER"
cat <<EOF | tee "$CONFIG_FOLDER/config" > /dev/null
[reticulum]
enable_transport = True
share_instance = Yes
shared_instance_port = 37428
instance_control_port = 37429
panic_on_interface_error = No
[logging]
loglevel = 4
[interfaces]
[[Default Interface]]
type = AutoInterface
enabled = True
mode = gateway
EOF
if [ "$SETTINGS_USER" != "$USER" ]; then
chown -R $SETTINGS_USER $CONFIG_FOLDER
fi
}
_install_core_service() {
cat <<EOF | tee "/etc/systemd/system/reticulum.service" > /dev/null
[Unit]
Description=Reticulum Network Stack Daemon
After=multi-user.target
[Service]
#ExecStartPre=/bin/sleep 5
Type=simple
Restart=always
RestartSec=3
User=$SETTINGS_USER
ExecStart=rnsd --service
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable reticulum
systemctl start reticulum
}
_install_software() {
#pip3 install polib
apt -y -q update
apt -y -q install python3-polib
mkdir -p "$SOFTWARE_PATH_DST"
cp -a "$SOFTWARE_PATH_SRC"/* "$SOFTWARE_PATH_DST"
chmod +x "$SOFTWARE_PATH_DST"/*.py
}
_install_config() {
mkdir -p "$SOFTWARE_CONFIG_DST"
cp -r "$SOFTWARE_CONFIG_SRC"/* "$SOFTWARE_CONFIG_DST"
find "$SOFTWARE_CONFIG_DST" -type f -name "*.sh" -exec chmod +x {} \;
find "$SOFTWARE_CONFIG_DST" -type f -name "*.py" -exec chmod +x {} \;
read -p "Enter the display name for the application: " SETTINGS_DISPLAY_NAME_RAW
SETTINGS_DISPLAY_NAME="$SETTINGS_DISPLAY_NAME_RAW"
read -p "Enter the admin user address: " SETTINGS_ALLOWED_RAW
SETTINGS_ALLOWED="$SETTINGS_ALLOWED_RAW"
cat <<EOF | tee "$SOFTWARE_CONFIG_DST/config.cfg.owr" > /dev/null
# This is the user configuration file to override the default configuration file.
# All settings made here have precedence.
# This file can be used to clearly summarize all settings that deviate from the default.
# This also has the advantage that all changed settings can be kept when updating the program.
#### RNS server settings ####
[rns_server]
display_name = $SETTINGS_DISPLAY_NAME
announce_startup = Yes
announce_startup_delay = 0 #Seconds
announce_periodic = Yes
announce_periodic_interval = 120 #Minutes
#### Telemetry settings ####
[telemetry]
location_enabled = False
location_lat = 0
location_lon = 0
owner_enabled = True
owner_data = $SETTINGS_ALLOWED
state_enabled = False
state_data = 0
#### Right settings ####
[allowed]
$SETTINGS_ALLOWED
#### Environment settings ####
[environment_variables]
$SETTINGS_USER_TARGET
#### Paths where the configuration files of the service are located. ####
[services_files]
/home/$SETTINGS_USER_TARGET/.config
/home/$SETTINGS_USER_TARGET
/root/.config
/root/
EOF
}
_install_service() {
RETICULUM_CONFIG=""
for folder in "${RETICULUM_CONFIG_DST[@]}"; do
if [ -e "$folder" ]; then
RETICULUM_CONFIG=" -pr $folder"
break
fi
done
cat <<EOF | tee "/etc/systemd/system/$SOFTWARE_NAME.service" > /dev/null
[Unit]
Description=$SOFTWARE_NAME
After=multi-user.target
[Service]
ExecStartPre=/bin/sleep 5
Type=simple
Restart=always
RestartSec=3
User=$USER
ExecStart=$SOFTWARE_PATH_DST/$SOFTWARE_NAME.py$RETICULUM_CONFIG
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable "$SOFTWARE_NAME"
systemctl start "$SOFTWARE_NAME"
}
_install_footer() {
_divider
echo -e "You have successfully installed $SOFTWARE_NAME"
echo -e "To edit the configuration please edit the files in the following folder and then restart the service:"
echo -e $SOFTWARE_CONFIG_DST
_divider
}
_uninstall_software() {
echo -e ""
}
_uninstall_service() {
systemctl stop "$SOFTWARE_NAME" || true
systemctl disable "$SOFTWARE_NAME" || true
rm -f "/etc/systemd/system/$SOFTWARE_NAME"
systemctl daemon-reload
}
_uninstall_footer() {
_divider
echo -e "You have successfully uninstalled $SOFTWARE_NAME"
_divider
}
_update_software() {
mkdir -p "$SOFTWARE_PATH_DST"
cp -a "$SOFTWARE_PATH_SRC"/* "$SOFTWARE_PATH_DST"
chmod +x "$SOFTWARE_PATH_DST"/*.py
}
_update_config() {
mkdir -p "$SOFTWARE_CONFIG_DST"
cp -r "$SOFTWARE_CONFIG_SRC"/* "$SOFTWARE_CONFIG_DST"
find "$SOFTWARE_CONFIG_DST" -type f -name "*.sh" -exec chmod +x {} \;
find "$SOFTWARE_CONFIG_DST" -type f -name "*.py" -exec chmod +x {} \;
}
_update_footer() {
_divider
echo -e "You have successfully updated $SOFTWARE_NAME"
echo -e "In order for it to become active, you must restart the individual services or restart the entire operating system."
_divider
}
_reboot() {
echo -e "You need to reboot the system."
echo -e "Do you want to do this now?"
LOOP=1
while [ $LOOP -eq 1 ]; do
options=("Yes, reboot now" "No, reboot manually")
select opt in "${options[@]}"; do
case $opt in
"Yes, reboot now"*)
echo -e ""
echo -e "Rebooting..."
init 6
LOOP=0
break;;
"No, reboot manually"*)
echo -e ""
LOOP=0
break;;
*)
echo -e ""
echo -e "Invalid choice!";;
esac
done
done
}
##############################################################################################################
# Setup/Start
if [[ $EUID -ne 0 ]]; then
echo -e "Error: You need to run this script as root (UID=0)"
exit 1
fi
if [ -p /dev/stdin ]; then
echo -e "Error: This script can't be piped!"
exit 1
fi
_divider
echo -e "Installer/uninstaller for $SOFTWARE_NAME"
_divider
echo -e "If Reticulum is already installed, please select 2, otherwise please select 1."
echo -e "The installation of the dependencies may not work on some systems. In this case, please install Reticulum manually and then select 2."
LOOP=1
while [ $LOOP -eq 1 ]; do
echo -e ""
echo -e "Select a function:"
options=("Install Core+Software" "Install" "Uninstall" "Update Software+Config" "Update" "None/Exit")
select opt in "${options[@]}"; do
case $opt in
"Install Core+Software"*)
echo -e ""
_settings_user
_install_core_software
_install_core_config
_install_core_service
_install_software
_install_config
_install_service
_install_footer
_reboot
LOOP=0
break;;
"Install"*)
echo -e ""
_settings_user
_install_software
_install_config
_install_service
_install_footer
_reboot
LOOP=0
break;;
"Uninstall"*)
echo -e ""
_uninstall_software
_uninstall_service
_uninstall_footer
LOOP=0
break;;
"Update Software+Config"*)
_update_software
_update_config
_update_footer
LOOP=0
break;;
"Update"*)
_update_software
_update_footer
LOOP=0
break;;
"None/Exit"*)
echo -e ""
LOOP=0
break;;
*)
echo -e ""
echo -e "Invalid choice!";;
esac
done
done