-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·568 lines (460 loc) · 14.3 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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
#!/usr/bin/env bash
set -euo pipefail
# System Configuration for automated installation
export DEBIAN_FRONTEND=noninteractive
needrestart_conf_dir="/etc/needrestart/conf.d"
needrestart_conf_file="${needrestart_conf_dir}/temp-disable-for-edgebox-install.conf"
sudo mkdir -p "${needrestart_conf_dir}"
echo "# Restart services (l)ist only, (i)nteractive or (a)utomatically.
\$nrconf{restart} = 'l';
# Disable hints on pending kernel upgrades.
\$nrconf{kernelhints} = 0; " | sudo tee "${needrestart_conf_file}" > /dev/null
trap "sudo rm -f ${needrestart_conf_file}" EXIT
# Default Installation Options
VERBOSE_MODE="false"
SKIP_PROMPT="false"
UPDATE_APT="true"
INSTALL_APT_DEPS="true"
INSTALL_AVAHI="true"
INSTALL_YQ="true"
INSTALL_DOCKER="true"
INSTALL_DOCKER_COMPOSE="true"
INSTALL_CLOUDFLARED="true"
INSTALL_SSHX="true"
INSTALL_EDGEBOXCTL="true"
INSTALL_EDGEBOX_API="true"
INSTALL_EDGEBOX_WS="true"
INSTALL_EDGEBOX_APPS="true"
INSTALL_EDGEBOX_LOGGER="true"
INSTALL_EDGEBOX_UPDATER="true"
CREATE_USER="true"
ADD_MOTD="true"
AUTO_START="true"
INSTALL_PATH="/home/system/components"
EDGEBOX_SYSTEM_PW="edgebox"
EDGEBOX_CLUSTER_HOST=""
# Parse arguments
arguments=${@:-}
if [[ "${arguments}" = *"--verbose"* ]]
then
VERBOSE_MODE="true"
fi
if [[ "${arguments}" = *"--skip-prompt"* ]]
then
SKIP_PROMPT="true"
fi
if [[ "${arguments}" = *"--no-install-avahi"* ]]
then
INSTALL_AVAHI="false"
fi
if [[ "${arguments}" = *"--no-install-yq"* ]]
then
INSTALL_YQ="false"
fi
if [[ "${arguments}" = *"--no-install-docker"* ]]
then
INSTALL_DOCKER="false"
fi
if [[ "${arguments}" = *"--no-install-compose"* ]]
then
INSTALL_DOCKER_COMPOSE="false"
fi
if [[ "${arguments}" = *"--no-install-cloudflared"* ]]
then
INSTALL_CLOUDFLARED="false"
fi
if [[ "${arguments}" = *"--no-install-sshx"* ]]
then
INSTALL_SSHX="false"
fi
if [[ "${arguments}" = *"--no-install-edgeboxctl"* ]]
then
INSTALL_EDGEBOXCTL="false"
fi
if [[ "${arguments}" = *"--no-install-edgebox-api"* ]]
then
INSTALL_EDGEBOX_API="false"
fi
if [[ "${arguments}" = *"--no-install-edgebox-ws"* ]]
then
INSTALL_EDGEBOX_WS="false"
fi
if [[ "${arguments}" = *"--no-install-edgebox-apps"* ]]
then
INSTALL_EDGEBOX_APPS="false"
fi
if [[ "${arguments}" = *"--no-install-edgebox-logger"* ]]
then
INSTALL_EDGEBOX_LOGGER="false"
fi
if [[ "${arguments}" = *"--no-install-edgebox-updater"* ]]
then
INSTALL_EDGEBOX_UPDATER="false"
fi
if [[ "${arguments}" = *"--no-create-user"* ]]
then
CREATE_USER="false"
fi
if [[ "${arguments}" = *"--no-auto-start"* ]]
then
AUTO_START="false"
fi
if [[ "${arguments}" = *"--no-add-motd"* ]]
then
ADD_MOTD="false"
fi
if [[ "${arguments}" = *"--no-update-apt"* ]]
then
UPDATE_APT="false"
fi
if [[ "${arguments}" = *"--no-install-deps"* ]]
then
INSTALL_APT_DEPS="false"
INSTALL_AVAHI="false"
INSTALL_YQ="false"
INSTALL_DOCKER="false"
INSTALL_DOCKER_COMPOSE="false"
INSTALL_CLOUDFLARED="false"
INSTALL_SSHX="false"
fi
if [[ "${arguments}" = *"--no-install-components"* ]]
then
INSTALL_EDGEBOXCTL="false"
INSTALL_EDGEBOX_API="false"
INSTALL_EDGEBOX_WS="false"
INSTALL_EDGEBOX_APPS="false"
INSTALL_EDGEBOX_LOGGER="false"
INSTALL_EDGEBOX_UPDATER="false"
fi
if [[ "${arguments}" = *"--version"* ]]
then
VERSION="$(echo "${arguments}" | sed 's/.*--version \([^ ]*\).*/\1/')"
fi
if [[ "${arguments}" = *"--install-path"* ]]
then
INSTALL_PATH="$(echo "${arguments}" | sed 's/.*--install-path \([^ ]*\).*/\1/')"
fi
if [[ "${arguments}" = *"--system-password"* ]]
then
EDGEBOX_SYSTEM_PW="$(echo "${arguments}" | sed 's/.*--system-password \([^ ]*\).*/\1/')"
export EDGEBOX_SYSTEM_PW
fi
if [[ "${arguments}" = *"--cluster-host"* ]]
then
EDGEBOX_CLUSTER_HOST="$(echo "${arguments}" | sed 's/.*--cluster-host \([^ ]*\).*/\1/')"
export EDGEBOX_CLUSTER_HOST
fi
# Get current system architecture (and normalize to POSIX standard)
ARCH=$(uname -m)
if [ "$ARCH" = "aarch64" ]; then
export ARCH="arm64"
fi
if [ "$ARCH" = "x86_64" ]; then
export ARCH="amd64"
fi
if [ "$ARCH" = "armv7l" ]; then
# Unsupported architecture. Error out.
echo "Unsupported architecture: $ARCH"
exit 1
fi
create_user() {
# Create user system and add to sudoers, set password to EDGEBOX_SYSTEM_PW
useradd -m -s /bin/bash system || true
echo "system:$(printenv EDGEBOX_SYSTEM_PW)" | chpasswd
usermod -aG sudo system
# Set root password as EDGEBOX_SYSTEM_PW
echo "root:$(printenv EDGEBOX_SYSTEM_PW)" | chpasswd
# Allow SSH access without public key
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
# Allow root ssh login
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
systemctl restart ssh
}
update_apt() {
sudo apt-get update --yes
}
install_apt_deps() {
sudo apt-get install --yes python3-pip golang jq apache2-utils restic golang samba
}
install_avahi() {
sudo apt-get install --yes avahi-daemon avahi-utils libnss-mdns
}
install_docker() {
sudo apt-get install --yes docker.io
# pip3 -v install docker==6.1.3
}
install_docker_compose() {
sudo apt-get install --yes docker-compose
# pip3 -v install docker-compose
}
install_yq() {
declare -A yq_sha256
yq_sha256["arm64"]="8879e61c0b3b70908160535ea358ec67989ac4435435510e1fcb2eda5d74a0e9"
yq_sha256["amd64"]="c93a696e13d3076e473c3a43c06fdb98fafd30dc2f43bc771c4917531961c760"
yq_version="v4.24.5"
system_arch=$(dpkg --print-architecture)
yq_binary="yq_linux_${system_arch}"
yq_temp_file="/tmp/yq"
curl -L "https://github.com/mikefarah/yq/releases/download/${yq_version}/${yq_binary}" -o "${yq_temp_file}"
if [[ "$(sha256sum "${yq_temp_file}" | awk '{ print $1 }')" == "${yq_sha256[$system_arch]}" ]]; then
sudo mv "${yq_temp_file}" /usr/bin/yq
sudo chmod +x /usr/bin/yq
echo "yq installed successfully..."
else
echo "yq install failed. sha256sum mismatch"
exit 1
fi
}
install_cloudflared() {
wget -q https://github.com/cloudflare/cloudflared/releases/download/2023.3.1/cloudflared-linux-$(printenv ARCH).deb
sudo dpkg -i cloudflared-linux-$(printenv ARCH).deb
}
install_sshx() {
curl -sSf https://sshx.io/get | sh
}
checkout_latest_component_version() {
latest_version=$(git tag -l | sort -V | tail -1)
git checkout $latest_version
}
install_edgeboxctl() {
cd $INSTALL_PATH
git clone https://github.com/edgebox-iot/edgeboxctl.git || true
# Setup cloud env and build edgeboxctl
cd edgeboxctl
checkout_latest_component_version
# Check if the file /home/ubuntu/cloud.env exists. If it does, copy it to /home/system/components/api
if [ -f /home/ubuntu/cloud.env ]; then
cp /home/ubuntu/cloud.env /home/system/components/api/cloud.env
make install-cloud
else
# Get curent system architecture
ARCH=$(uname -m)
if [ "$ARCH" = "aarch64" ]; then
make install-arm64
fi
if [ "$ARCH" = "armv7l" ]; then
make install-armhf
fi
if [ "$ARCH" = "x86_64" ]; then
make install-amd64
fi
fi
}
install_edgebox_api() {
cd $INSTALL_PATH
git clone https://github.com/edgebox-iot/api.git || true
cd api
checkout_latest_component_version
if [ -n "${EDGEBOX_CLUSTER_HOST}" ]; then
# build add cluster host to api conf
# Configure Dashboard Host
touch myedgeapp.env
echo "INTERNET_URL=$EDGEBOX_CLUSTER_HOST" >> myedgeapp.env
fi
cd ..
}
install_edgebox_ws() {
cd $INSTALL_PATH
git clone https://github.com/edgebox-iot/ws.git || true
# Prep ws permissions
cd ws
checkout_latest_component_version
chmod 757 ws
mkdir -p appdata
chmod -R 777 appdata
}
install_edgebox_apps() {
cd $INSTALL_PATH
git clone https://github.com/edgebox-iot/apps.git || true
cd apps
checkout_latest_component_version
cd ..
}
install_edgebox_logger() {
cd $INSTALL_PATH
git clone https://github.com/edgebox-iot/logger.git || true
cd logger
checkout_latest_component_version
make install
cd ..
}
install_edgebox_updater() {
cd $INSTALL_PATH
git clone https://github.com/edgebox-iot/updater.git || true
cd updater
checkout_latest_component_version
cd ..
}
start_services() {
# Reload deamon, enable, and start services
systemctl daemon-reload
systemctl enable edgeboxctl
systemctl start edgeboxctl
systemctl enable logger
systemctl start logger
cd $INSTALL_PATH
cd ws
./ws -b
}
add_motd() {
# Create motd file
cat << EOF > /etc/motd
#######
#############
######## # #######
#### ####### ##### ##### ## ##
#################### #### ##### ##### #### ##### ##### ## ##
#################### ## ## ## # ## ##### ## # ## ## ###
#### ######## ##### ##### #### ##### #### ##### ### ## ##
####### # ######## ###
#############
########
You're connected to the Edgebox system via terminal.
This provides administrator capabilities and total system access.
If you're developing for Edgebox, please refer to https://docs.edgebox.io
This software comes with ABSOLUTELY NO WARRANTY,
to the extent permitted by applicable law.
EOF
# add a line to print it on /root/.bashrc
# Shoudl be automatic for Debian, but if not, just uncomment this line
# echo "cat /etc/motd" >> /root/.bashrc
}
main() {
cat << EOF
#######
#############
######## # #######
#### ####### ##### ##### ## ##
#################### #### ##### ##### #### ##### ##### ## ##
#################### ## ## ## # ## ##### ## # ## ## ###
#### ######## ##### ##### #### ##### #### ##### ### ## ##
####### # ######## ###
#############
########
EOF
echo "Edgebox is about to be installed in \"${INSTALL_PATH}\". 🚀"
# Check if the user wants to skip the prompt
if [[ "${SKIP_PROMPT}" = "false" ]]
then
echo "If you want like to install in another location, you can specify a custom one with:"
echo
echo " curl -L install.edgebox.io | bash -s -- --install-path /some/path"
echo
echo "Waiting for 10 seconds... 🕒"
echo
echo "You may press Ctrl+C now to abort the install."
echo
sleep 10
fi
if [[ "${CREATE_USER}" = "true" ]]
then
echo "-> 👤 Creating User..."
sleep 3
create_user
fi
echo "-> 📁 Creating Installation Path..."
sleep 3
# Create INSTALL_PATH directory if it doesn't exist
mkdir -p $INSTALL_PATH || true
if [[ "${UPDATE_APT}" = "true" ]]
then
echo "-> 🌳 Updating Operating System Packages..."
sleep 3
update_apt
fi
if [[ "${INSTALL_APT_DEPS}" = "true" ]]
then
echo "-> 🧰 Installing APT Dependencies..."
sleep 3
install_apt_deps
fi
if [[ "${INSTALL_AVAHI}" = "true" ]]
then
echo "-> 🔗 Installing mDNS..."
sleep 3
install_avahi
fi
if [[ "${INSTALL_YQ}" = "true" ]]
then
echo "-> 🧰 Installing YQ..."
sleep 3
install_yq
fi
if [[ "${INSTALL_DOCKER}" = "true" ]]
then
echo "-> 🐳 Installing Docker..."
sleep 3
install_docker
fi
if [[ "${INSTALL_DOCKER_COMPOSE}" = "true" ]]
then
echo "-> 🐳 Installing Docker Compose..."
sleep 3
install_docker_compose
fi
if [[ "${INSTALL_CLOUDFLARED}" = "true" ]]
then
echo "-> 🌐 Installing Cloudflared..."
sleep 3
install_cloudflared
fi
if [[ "${INSTALL_SSHX}" = "true" ]]
then
echo "-> 🔗 Installing SSHX..."
sleep 3
install_sshx
fi
if [[ "${INSTALL_EDGEBOX_API}" = "true" ]]
then
echo "-> 💨 Installing Edgebox API / Dashboard..."
sleep 3
install_edgebox_api
fi
if [[ "${INSTALL_EDGEBOXCTL}" = "true" ]]
then
echo "-> 📦 Installing Edgebox Service..."
sleep 3
install_edgeboxctl
fi
if [[ "${INSTALL_EDGEBOX_WS}" = "true" ]]
then
echo "-> 🕸️ Installing Edgebox Web Services..."
sleep 3
install_edgebox_ws
fi
if [[ "${INSTALL_EDGEBOX_APPS}" = "true" ]]
then
echo "-> 📱 Installing Edgebox Apps Repository..."
sleep 3
install_edgebox_apps
fi
if [[ "${INSTALL_EDGEBOX_LOGGER}" = "true" ]]
then
echo "-> 🪵 Installing Edgebox Logger..."
sleep 3
install_edgebox_logger
fi
if [[ "${INSTALL_EDGEBOX_UPDATER}" = "true" ]]
then
echo "-> 👇 Installing Edgebox Updater..."
sleep 3
install_edgebox_updater
fi
if [[ "${ADD_MOTD}" = "true" ]]
then
echo "-> 📟 Adding Console Welcome Message..."
add_motd
fi
if [[ "${AUTO_START}" = "true" ]]
then
echo "-> 🏁 Starting Services... This can take a couple of minutes."
sleep 3
start_services
fi
echo "Edgebox has been successfully installed! 🎉"
echo "You can now access the Dashboard by visiting: http://edgebox.local"
echo "If you have any questions or need help, please visit https://docs.edgebox.io"
echo
echo "Thank you for using Edgebox! 🚀"
}
main