-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.sh
More file actions
1789 lines (1566 loc) · 55.8 KB
/
installer.sh
File metadata and controls
1789 lines (1566 loc) · 55.8 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
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
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
###############################################################################################################
### FUNCTIONS ##
###############################################################################################################
# -------------------- MESSAGE SYSTEM -------------------- #
msg() {
local type="$1"
local message="$2"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "$timestamp [$type] $message" >> /logs/script.log
case "$type" in
success) echo -e "\e[32m$message\e[0m" ;;
error) echo -e "\e[31m$message\e[0m" ;;
warning) echo -e "\e[33m$message\e[0m" ;;
info) echo -e "\e[34m$message\e[0m" ;;
*) echo "$message" ;;
esac
}
# -------------------- PRINT MENU -------------------- #
print_menu() {
clear
cat << "EOF"
╔══════════════════════════════════════════════════════════════════════╗
║ | | | | / _ \ ║
║ | |_| |/ /_\ \ ║
║ | _ || _ | ║
║ | | | || | | | ║
║ _____ \_| |_/\_| |_/ _ _ ║
║ |_ _| | | | || | ║
║ | | _ __ ___ | |_ __ _ | || | ___ _ __ ║
║ | | | '_ \ / __|| __|/ _` || || | / _ \| '__| ║
║ _| |_| | | |\__ \| |_| (_| || || || __/| | ║
║ \___/|_| |_||___/ \__|\__,_||_||_| \___||_| ║
╚══════════════════════════════════════════════════════════════════════╝
EOF
}
# -------------------- STARTUP -------------------- #
startup() {
### CHECK SUDO
if [[ $EUID -ne 0 ]]; then
msg error "Please run this script with sudo or as root."
exit 1
fi
### Generate Files
if [[ ! -d /logs ]]; then
mkdir -p /logs
fi
sudo apt install -y net-tools
if [[ ! -e "/opt/.net.txt" ]]; then
config_network
else
source /opt/.net.txt
fi
### UPDATE SYSTEM
while true; do
clear
msg info "Would you like to update the system? (y/n)"
read -r update_response
case $update_response in
y|Y)
clear
msg info "Updating system..."
sudo apt-get update -y
sudo apt-get upgrade -y
print_menu
msg success "System Updated\n"
break
;;
n|N)
print_menu
msg warning "Skipping system update...\n"
break
;;
*)
msg error "Invalid input. Please enter y or n."
;;
esac
done
}
# -------------------- SHUTDOWN -------------------- #
shutdown() {
msg info "Cleaning up..."
sudo apt-get autoclean
sudo apt-get clean
sudo apt-get autoremove
while true; do
msg info "Would you like to reboot now? (y/n)"
read -r reboot_response
case $reboot_response in
y|Y)
msg info "Rebooting..."
sudo reboot
;;
n|N)
msg info "Exiting without rebooting."
exit # Exit both the case and the outer select loop
;;
*)
msg error "Invalid input. Please enter y or n."
;;
esac
done
}
# -------------------- CONFIGURE NETWORK -------------------- #
config_network() {
clear
interfaces=$(ip -o link show | awk -F': ' '{print $2}')
echo "---------- Configure Network Settings ----------"
echo -e "\nNetwork Info:"
ip -o addr show
# Print out the interfaces and prompt the user to select one
echo -e "\n\nAvailable network interfaces:"
echo "$interfaces"
echo -e "\nPlease select an interface: "
read selected_interface
# Validate user input
if ! [[ $interfaces =~ $selected_interface ]]; then
echo "Invalid selection. Exiting."
exit 1
fi
ip_address=$(ip -o -4 addr list $selected_interface | awk '{print $4}')
gateway=$(ip route | grep default | grep $selected_interface | awk '{print $3}')
IFS='.' read -r -a octets <<< "${ip_address%%/*}" # Remove the /24 and split by '.'
subnet="${octets[0]}.${octets[1]}.${octets[2]}.0/24"
# Write the details to a file
echo "Interface: $selected_interface"
echo "IP Address: $ip_address"
echo "Gateway: $gateway"
echo "Subnet: $subnet"
new_ip="0.0.0.0"
while [[ $new_ip == "0.0.0.0" ]]; do
# Prompt the user for a new IP address
echo -e "\nWe will set a static IP for this system to make it easier to access."
echo -e "Please enter a new IP address (e.g., $ip_address): "
read new_ip
if ! [[ $new_ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\/[0-9]+$ ]]; then
echo "Invalid IP address format. Please try again."
new_ip="0.0.0.0"
fi
done
# Create a Netplan configuration file
cat <<EOL | sudo tee /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
$selected_interface:
dhcp4: no
addresses:
- $new_ip
gateway4: $gateway
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
EOL
# Apply the new network configuration
sudo netplan apply
# Verify the new settings
echo -e "\nNew Network Configuration:"
while true; do
clear
msg info "Do you have an external domain? (y/n)"
read -r domain_response
case $domain_response in
y|Y)
echo -e "Please enter your domain (e.g., example.com): "
read domain
break
;;
n|N)
domain = "example.com"
break
;;
*)
msg error "Invalid input. Please enter y or n."
;;
esac
done
new_ip=${new_ip%%/*} ## Remove subnet ID from IP
# Write the details to a file
echo "selected_interface=$selected_interface" > /opt/.net.txt
echo "new_ip=$new_ip" >> /opt/.net.txt
echo "gateway=$gateway" >> /opt/.net.txt
echo "subnet=$subnet" >> /opt/.net.txt
echo "domain=$domain" >> /opt/.net.txt
}
###############################################################################################################
### INSTALLERS ##
###############################################################################################################
# -------------------- HOME ASSISTANT INSTALL -------------------- #
install_homeassistant() {
check_docker
clear
msg info "Installing Home Assistant..."
if ! grep -q "homeassistant:" /opt/docker-compose.yaml; then
# Entry does not exist, add it
cat <<EOL >> /opt/docker-compose.yaml
homeassistant:
container_name: homeassistant
image: "homeassistant/home-assistant"
volumes:
- /opt/homeassistant/config:/config
- /home/homeassistant/Videos:/media
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
ports:
- "8123:8123"
restart: always
privileged: true
networks:
- homenet
labels:
traefik.enable: true
traefik.docker.network: "opt_homenet"
## Internal
traefik.http.services.homeassistantlocal.loadbalancer.server.port: 8123
traefik.http.routers.homeassistantlocal.service: homeassistantlocal
traefik.http.routers.homeassistantlocal.entrypoints: web, websecure
traefik.http.routers.homeassistantlocal.tls: true
traefik.http.routers.homeassistantlocal.rule: Host(\`home.local\`)
## External
traefik.http.services.homeassistantweb.loadbalancer.server.port: 8123
traefik.http.routers.homeassistantweb.service: homeassistantweb
traefik.http.routers.homeassistantweb.entrypoints: web, websecure
traefik.http.routers.homeassistantweb.rule: Host(\`home.$domain\`)
traefik.http.routers.homeassistantweb.tls: true
traefik.http.routers.homeassistantweb.tls.certresolver: production
EOL
msg success "Home Assistant configuration added to docker-compose.yaml"
else
msg warning "Home Assistant entry already exists in docker-compose.yaml"
fi
docker-compose -f /opt/docker-compose.yaml up -d --remove-orphans
if docker ps | grep -q "homeassistant"; then
print_menu
msg success "Home Assistant successfully installed and running"
ping -c 1 -W 1 home.local > /dev/null 2>&1
if [ $? -eq 0 ]; then
msg info "Local Network - http://home.local"
else
msg info "Local Network - http://$new_ip:8123"
fi
msg info "This PC - http://127.0.0.1:8123\n"
else
print_menu
msg error "Home Assistant container failed to start\n"
fi
}
# -------------------- NODE RED INSTALL -------------------- #
install_nodered() {
check_docker
clear
msg info "Installing Node-RED..."
if ! grep -q "nodered:" /opt/docker-compose.yaml; then
# Entry does not exist, add it
cat <<EOL >> /opt/docker-compose.yaml
nodered:
container_name: nodered
image: "nodered/node-red"
volumes:
- /opt/node-red/config:/data
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
ports:
- "1880:1880"
user: 1000:1000
restart: always
networks:
- homenet
labels:
traefik.enable: true
traefik.docker.network: "opt_homenet"
## Internal
traefik.http.services.noderedlocal.loadbalancer.server.port: 1880
traefik.http.routers.noderedlocal.service: noderedlocal
traefik.http.routers.noderedlocal.entrypoints: web, websecure
traefik.http.routers.noderedlocal.tls: true
traefik.http.routers.noderedlocal.rule: Host(\`nodered.local\`)
## External
traefik.http.services.noderedweb.loadbalancer.server.port: 1880
traefik.http.routers.noderedweb.service: noderedweb
traefik.http.routers.noderedweb.entrypoints: web, websecure
traefik.http.routers.noderedweb.rule: Host(\`nodered.$domain\`)
traefik.http.routers.noderedweb.tls: true
traefik.http.routers.noderedweb.tls.certresolver: production
EOL
msg success "Node-RED configuration added to docker-compose.yaml"
else
msg warning "Node-RED entry already exists in docker-compose.yaml"
fi
docker-compose -f /opt/docker-compose.yaml up -d --remove-orphans
# Set same user as Node Red to allow permissions on shared volume.
sudo chown -R 1000:1000 /opt/node-red/config
if docker ps | grep -q "nodered"; then
prep_nodered
print_menu
msg success "Node-RED successfully installed and running"
ping -c 1 -W 1 nodered.local > /dev/null 2>&1
if [ $? -eq 0 ]; then
msg info "Local Network - http://nodered.local"
else
msg info "Local Network - http://$new_ip:1880"
fi
msg info "This PC - http://127.0.0.1:1880\n"
else
print_menu
msg error "Node-RED container failed to start\n"
fi
}
prep_nodered(){
docker exec -it nodered npm install node-red-contrib-home-assistant-websocket
docker restart nodered
}
# -------------------- MOSQUITTO INSTALL -------------------- #
install_mosquitto() {
check_docker
clear
msg info "Installing Mosquitto MQTT..."
if ! grep -q "mosquitto:" /opt/docker-compose.yaml; then
cat << EOL >> /opt/docker-compose.yaml
mosquitto:
container_name: mosquitto
image: "eclipse-mosquitto"
restart: always
ports:
- "1883:1883"
- "9001:9001"
volumes:
- /opt/mosquitto:/mosquitto
networks:
- homenet
EOL
msg success "Mosquitto configuration added to docker-compose.yaml"
else
msg warning "Mosquitto entry already exists in docker-compose.yaml"
fi
if [[ ! -s /opt/mosquitto/config/mosquitto.conf ]]; then
sudo mkdir -p /opt/mosquitto
sudo mkdir -p /opt/mosquitto/config
sudo touch /opt/mosquitto/config/mosquitto.conf
cat << EOL >> /opt/mosquitto/config/mosquitto.conf
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
listener 1883
## Authentication ##
allow_anonymous true
EOL
else
msg info "Configuration file already exists, skipping..."
fi
docker-compose -f /opt/docker-compose.yaml up -d --remove-orphans
if docker ps | grep -q "mosquitto"; then
print_menu
msg success "Mosquitto successfully installed and running"
else
print_menu
msg error "Mosquitto container failed to start\n"
fi
}
# -------------------- KUMA UPTIME INSTALL -------------------- #
install_kuma() {
check_docker
clear
msg info "Installing Kuma Uptime..."
if ! grep -q "kuma:" /opt/docker-compose.yaml; then
cat << EOL >> /opt/docker-compose.yaml
kuma:
image: louislam/uptime-kuma
container_name: kuma
volumes:
- /opt/kuma:/app/data
ports:
- "3001:3001"
networks:
- homenet
restart: always
labels:
traefik.enable: true
traefik.docker.network: "opt_homenet"
## Internal
traefik.http.services.kumalocal.loadbalancer.server.port: 3001
traefik.http.routers.kumalocal.service: kumalocal
traefik.http.routers.kumalocal.entrypoints: web, websecure
traefik.http.routers.kumalocal.tls: true
traefik.http.routers.kumalocal.rule: Host(\`kuma.local\`)
## External
traefik.http.services.kumaweb.loadbalancer.server.port: 3001
traefik.http.routers.kumaweb.service: kumaweb
traefik.http.routers.kumaweb.entrypoints: web, websecure
traefik.http.routers.kumaweb.rule: Host(\`kuma.$domain\`)
traefik.http.routers.kumaweb.tls: true
traefik.http.routers.kumaweb.tls.certresolver: production
EOL
msg success "Kuma configuration added to docker-compose.yaml"
else
msg warning "Kuma entry already exists in docker-compose.yaml"
fi
docker-compose -f /opt/docker-compose.yaml up -d --remove-orphans
if docker ps | grep -q "kuma"; then
print_menu
msg success "Kuma successfully installed and running"
ping -c 1 -W 1 kuma.local > /dev/null 2>&1
if [ $? -eq 0 ]; then
msg info "Local Network - http://kuma.local"
else
msg info "Local Network - http://$new_ip:3001"
fi
msg info "This PC - http://127.0.0.1:3001\n"
else
print_menu
msg error "Kuma container failed to start\n"
fi
}
# -------------------- LOGITCH MEDIA SERVER INSTALL -------------------- #
install_lms() {
check_docker
clear
msg info "Installing Logitech Media Server..."
if ! grep -q "lms:" /opt/docker-compose.yaml; then
# Entry does not exist, add it
cat <<EOL >> /opt/docker-compose.yaml
lms:
container_name: lms
image: lmscommunity/logitechmediaserver
volumes:
- /opt/lms/config:/config
- /home/$(whoami)/Music:/music:ro
- /home/$(whoami)/Music/playlists:/playlist
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
# devices:
# - /dev/snd # For Adding USB Sound Card for Line-In Audio Input
ports:
- 9000:9000/tcp
- 9090:9090/tcp
- 3483:3483/tcp
- 3483:3483/udp
restart: unless-stopped
networks:
- homenet
labels:
traefik.enable: true
traefik.docker.network: "opt_homenet"
## Internal
traefik.http.services.lmslocal.loadbalancer.server.port: 9000
traefik.http.routers.lmslocal.service: lmslocal
traefik.http.routers.lmslocal.entrypoints: web, websecure
traefik.http.routers.lmslocal.tls: true
traefik.http.routers.lmslocal.rule: Host(\`music.local\`)
## External
traefik.http.services.lmsweb.loadbalancer.server.port: 9000
traefik.http.routers.lmsweb.service: lmsweb
traefik.http.routers.lmsweb.entrypoints: web, websecure
traefik.http.routers.lmsweb.rule: Host(\`music.$domain\`)
traefik.http.routers.lmsweb.tls: true
traefik.http.routers.lmsweb.tls.certresolver: production
EOL
msg success "Logitech Media Server configuration added to docker-compose.yaml"
else
msg warning "Logitech Media Server entry already exists in docker-compose.yaml"
fi
docker-compose -f /opt/docker-compose.yaml up -d --remove-orphans
if docker ps | grep -q "logitechmediaserver"; then
print_menu
msg success "Logitech Media Server successfully installed and running"
ping -c 1 -W 1 music.local > /dev/null 2>&1
if [ $? -eq 0 ]; then
msg info "Local Network - http://music.local"
else
msg info "Local Network - http://$new_ip:9000"
fi
msg info "This PC - http://127.0.0.1:9000\n"
else
print_menu
msg error "Logitech Media Server container failed to start\n"
fi
}
# -------------------- MUSIC ASSISTANT INSTALL -------------------- #
install_music_assistant() {
check_docker
clear
msg info "Installing Music Assistant..."
if ! grep -q "music-assistant:" /opt/docker-compose.yaml; then
# Entry does not exist, add it
cat <<EOL >> /opt/docker-compose.yaml
music-assistant:
container_name: music-assistant
image: ghcr.io/music-assistant/server:latest
volumes:
- /opt/music-assistant/config:/config
- /home/$(whoami)/Music:/music:ro
ports:
- 8095:8095/tcp
restart: unless-stopped
networks:
- homenet
labels:
traefik.enable: true
traefik.docker.network: "opt_homenet"
## Internal
traefik.http.services.malocal.loadbalancer.server.port: 8095
traefik.http.routers.malocal.service: malocal
traefik.http.routers.malocal.entrypoints: web, websecure
traefik.http.routers.malocal.tls: true
traefik.http.routers.malocal.rule: Host(\`music.local\`)
## External
traefik.http.services.maweb.loadbalancer.server.port: 8095
traefik.http.routers.maweb.service: maweb
traefik.http.routers.maweb.entrypoints: web, websecure
traefik.http.routers.maweb.rule: Host(\`music.$domain\`)
traefik.http.routers.maweb.tls: true
traefik.http.routers.maweb.tls.certresolver: production
EOL
msg success "Music Assistant configuration added to docker-compose.yaml"
else
msg warning "Music Assistant entry already exists in docker-compose.yaml"
fi
docker-compose -f /opt/docker-compose.yaml up -d --remove-orphans
if docker ps | grep -q "music-assistant"; then
print_menu
msg success "Music Assistant successfully installed and running"
msg info "Access Music Assistant at http://$(hostname -I | awk '{print $1}'):8095"
else
print_menu
msg error "Music Assistant container failed to start\n"
fi
}
# -------------------- FIRGATE INSTALL -------------------- #
install_frigate() {
check_docker
clear
msg info "Installing Frigate NVR..."
if ! grep -q "frigate:" /opt/docker-compose.yaml; then
# Entry does not exist, add it
cat <<EOL >> /opt/docker-compose.yaml
frigate:
container_name: frigate
image: ghcr.io/blakeblackshear/frigate:stable
shm_size: "64mb" # NEEDS TO BE UPDATED BASED ON CAMERAS - Each Camera = (<width> * <height> * 1.5 * 9 + 270480) / 1048576)
# devices:
# - /dev/bus/usb:/dev/bus/usb # Passes the USB Coral, NEEDS TO BE UPDATED FOR USER HARDWARE
# - /dev/apex_0:/dev/apex_0 # Passes a PCIe Coral Driver Instructions: https://coral.ai/docs/m2/get-started/#2a-on-linux
# - /dev/dri/renderD128 # Intel hwaccel, NEEDS TO BE UPDATED FOR USER HARDWARE
volumes:
- /opt/frigate/config:/config
- /home/frigate/Videos:/media/frigate
- type: tmpfs # Optional: Uses 1GB of RAM, reduces SSD/SD Card wear
target: /tmp/cache
tmpfs:
size: 1000000000
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
ports:
- "5000:5000"
- "8554:8554" # RTSP Feeds
- "8555:8555/tcp" # WebRTC over TCP
- "8555:8555/udp" # WebRTC over UDP
environment:
FRIGATE_RTSP_PASSWORD: "password"
privileged: true
restart: unless-stopped
networks:
- homenet
labels:
traefik.enable: true
traefik.docker.network: "opt_homenet"
## Internal
traefik.http.services.frigatelocal.loadbalancer.server.port: 5000
traefik.http.routers.frigatelocal.service: frigatelocal
traefik.http.routers.frigatelocal.entrypoints: web, websecure
traefik.http.routers.frigatelocal.tls: true
traefik.http.routers.frigatelocal.rule: Host(\`nvr.local\`)
## External
traefik.http.services.frigateweb.loadbalancer.server.port: 5000
traefik.http.routers.frigateweb.service: frigateweb
traefik.http.routers.frigateweb.entrypoints: web, websecure
traefik.http.routers.frigateweb.rule: Host(\`nvr.$domain\`)
traefik.http.routers.frigateweb.tls: true
traefik.http.routers.frigateweb.tls.certresolver: production
EOL
msg success "Frigate NVR configuration added to docker-compose.yaml"
else
msg warning "Frigate NVR entry already exists in docker-compose.yaml"
fi
docker-compose -f /opt/docker-compose.yaml up -d --remove-orphans
if docker ps | grep -q "frigate"; then
print_menu
msg success "Frigate NVR successfully installed and running"
ping -c 1 -W 1 nvr.local > /dev/null 2>&1
if [ $? -eq 0 ]; then
msg info "Local Network - http://nvr.local"
else
msg info "Local Network - http://$new_ip:5000"
fi
msg info "This PC - http://127.0.0.1:5000\n"
else
print_menu
msg error "Frigate NVR container failed to start\n"
fi
}
# -------------------- CLOUDFLARED INSTALL -------------------- #
install_cloudflared() {
clear
msg info "Installing Cloudflared..."
sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared jammy main' | sudo tee /etc/apt/sources.list.d/cloudflared.list
sudo apt-get update && sudo apt-get install cloudflared
clear
msg success "Cloudflared downloaded successfully\n"
# Get the home directory of the user who invoked sudo
USER_HOME=$(getent passwd $SUDO_USER | cut -d: -f6)
# Execute cloudflared login as the original user
sudo -u $SUDO_USER bash -c "cloudflared login"
clear
msg success "Login Successful\n"
# Prompt for Tunnel Name
while [[ -z $TUNNEL_NAME ]]; do
msg info "Enter the tunnel name: "
read TUNNEL_NAME
done
# Create a tunnel and capture the Tunnel UUID
TUNNEL_UUID=$(sudo -u $SUDO_USER bash -c "cloudflared tunnel create $TUNNEL_NAME" | awk '/Created tunnel/{print $NF}')
# Check if Tunnel UUID was captured
if [[ -z $TUNNEL_UUID ]]; then
msg error "Failed to obtain Tunnel UUID. Exiting."
exit 1
fi
# Create & Route Sub Domain
sudo -u $SUDO_USER bash -c "cloudflared tunnel route dns $TUNNEL_NAME $TUNNEL_NAME"
# Define the path to the credentials file using the Tunnel UUID
CREDENTIALS_FILE_PATH="$USER_HOME/.cloudflared/$TUNNEL_UUID.json"
# Create the config.yml file with the necessary parameters as the original user
sudo -u $SUDO_USER bash -c "cat <<EOL > $USER_HOME/.cloudflared/config.yml
url: localhost:80
tunnel: $TUNNEL_UUID
credentials-file: $CREDENTIALS_FILE_PATH
EOL"
clear
sudo -u $SUDO_USER bash -c "cloudflared tunnel --config $USER_HOME/.cloudflared/config.yml run" > /dev/null 2>&1 &
if sudo -u $SUDO_USER crontab -l | grep -q "cloudflared tunnel"; then
msg info "Command is already in crontab"
else
# Add the command to crontab to run it at reboot for the original user
sudo -u $SUDO_USER bash -c "(crontab -l 2>/dev/null; echo \"@reboot cloudflared tunnel --config $USER_HOME/.cloudflared/config.yml run\") | crontab -"
msg success "Cloudflare added to startup"
fi
if pgrep -f "cloudflared tunnel" > /dev/null; then
print_menu
msg success "Cloudflared successfully installed and running\n"
else
print_menu
msg error "Cloudflared container failed to start\n"
fi
}
# -------------------- APACHE INSTALL -------------------- #
install_apache() {
check_docker
clear
msg info "Installing Apache Web Server..."
if ! grep -q "apache:" /opt/docker-compose.yaml; then
# Entry does not exist, add it
cat <<EOL >> /opt/docker-compose.yaml
apache:
image: httpd:latest
container_name: apache
ports:
- '880:880'
volumes:
- /opt/apache/website:/usr/local/apache2/htdocs
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
networks:
- homenet
labels:
traefik.enable: true
traefik.docker.network: "opt_homenet"
## Internal
traefik.http.services.apachelocal.loadbalancer.server.port: 80
traefik.http.routers.apachelocal.service: apachelocal
traefik.http.routers.apachelocal.entrypoints: web, websecure
traefik.http.routers.apachelocal.tls: true
traefik.http.routers.apachelocal.rule: Host(\`web.local\`)
## External
traefik.http.services.apacheweb.loadbalancer.server.port: 80
traefik.http.routers.apacheweb.service: apacheweb
traefik.http.routers.apacheweb.entrypoints: web, websecure
traefik.http.routers.apacheweb.rule: Host(\`web.$domain\`)
traefik.http.routers.apacheweb.tls: true
traefik.http.routers.apacheweb.tls.certresolver: production
EOL
msg success "Apache configuration added to docker-compose.yaml"
else
msg warning "Apache entry already exists in docker-compose.yaml"
fi
docker-compose -f /opt/docker-compose.yaml up -d --remove-orphans
if docker ps | grep -q "apache"; then
print_menu
msg success "Apache Web Server successfully installed and running"
ping -c 1 -W 1 web.local > /dev/null 2>&1
if [ $? -eq 0 ]; then
msg info "Local Network - http://web.local"
else
msg info "Local Network - http://$new_ip:880"
fi
msg info "This PC - http://127.0.0.1:880\n"
else
print_menu
msg error "Apache Web Server failed to start\n"
fi
}
# -------------------- DUCKDNS INSTALL -------------------- #
install_duckdns() {
check_docker
clear
msg info "Installing DuckDNS..."
if ! grep -q "duckdns:" /opt/docker-compose.yaml; then
echo "http://duckdns.org"
# Prompt the user to enter a name for the device
msg info "Enter Subdomain: (_____.duckdns.com)"
read -r subdomain
# Prompt the user to enter a name for the device
msg info "Enter Token: "
read -r token
cat << EOL >> /opt/docker-compose.yaml
duckdns:
container_name: duckdns
image: "linuxserver/duckdns"
environment:
- PUID=999
- PGID=999
- SUBDOMAINS=$subdomain
- TOKEN=$token
volumes:
- /opt/duckdns:/config
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
restart: unless-stopped
networks:
- homenet
EOL
msg success "DuckDNS configuration added to docker-compose.yaml"
else
msg warning "DuckDNS entry already exists in docker-compose.yaml"
fi
docker-compose -f /opt/docker-compose.yaml up -d --remove-orphans
if docker ps | grep -q "duckdns"; then
print_menu
msg success "DuckDNS successfully installed and running\n"
else
print_menu
msg error "DuckDNS container failed to start\n"
fi
}
# -------------------- WIREGUARD INSTALL -------------------- #
install_wireguard() {
check_docker
clear
msg info "Installing WireGuard..."
if ! grep -q "wireguard:" /opt/docker-compose.yaml; then
cat << EOL >> /opt/docker-compose.yaml
wireguard:
container_name: wireguard
image: "linuxserver/wireguard"
cap_add:
- NET_ADMIN
- SYS_MODULE
environment:
- PUID=998
- PGID=998
volumes:
- /opt/wireguard:/config
- /lib/modules:/lib/modules:ro
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
ports:
- "51820:51820/udp"
sysctls:
- net.ipv4.conf.all.src_valid_mark=1
restart: unless-stopped
networks:
- homenet
EOL
msg success "WireGuard configuration added to docker-compose.yaml"
else
msg warning "WireGuard entry already exists in docker-compose.yaml"
fi
docker-compose -f /opt/docker-compose.yaml up -d --remove-orphans
if docker ps | grep -q "wireguard"; then
print_menu
msg success "WireGuard successfully installed and running\n"
else
print_menu
msg error "WireGuard container failed to start\n"
fi
}
# -------------------- TRAEFIK INSTALL -------------------- #
install_traefik() {
check_docker
clear
msg info "Installing Traefik..."
### Set Config File
# Prompt the user to enter a name for the device
msg info "\nEnter E-mail for SSL Certificates: "
read -r email
if [[ ! -s /opt/traefik/traefik.yaml ]]; then
sudo mkdir -p /opt/traefik
sudo touch /opt/traefik/traefik.yaml
cat << EOL >> /opt/traefik/traefik.yaml
## General
global:
checkNewVersion: false
sendAnonymousUsage: false
## Dashboard (Don't enable in production)
# api:
# dashboard: true
# insecure: true
## Ports
entryPoints:
web:
address: :80
http:
redirections:
entryPoint:
to: websecure
scheme: https
websecure:
address: :443
## SSL Certs
certificatesResolvers:
production:
acme:
email: $email
storage: /etc/traefik/certs/acme.json
caServer: "https://acme-v02.api.letsencrypt.org/directory"
httpChallenge:
entryPoint: web
## TLS Stores
tls:
stores:
default:
defaultCertificate:
certFile: /etc/traefik/certs/certificate.crt
keyFile: /etc/traefik/certs/private.key
## Docker Setup
providers:
docker:
# -- (Optional) Enable this, if you want to expose all containers automatically
exposedByDefault: false
EOL
else
msg info "Configuration file already exists, skipping..."
fi
### Install Container
if ! grep -q "traefik:" /opt/docker-compose.yaml; then
cat << EOL >> /opt/docker-compose.yaml
traefik:
container_name: traefik
image: "traefik"
ports:
- "80:80"
- "443:443"
- "8080:8080" # Dashboard (Disable in Production)
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /opt/traefik:/etc/traefik
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
networks:
- homenet
EOL
msg success "Traefik configuration added to docker-compose.yaml"
else
msg warning "Traefik entry already exists in docker-compose.yaml"
fi
docker-compose -f /opt/docker-compose.yaml up -d