-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdockersetup.sh
490 lines (427 loc) · 17.1 KB
/
dockersetup.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
#!/bin/bash
# Function for printing colored section headings
print_colored_section_header() {
echo
echo -e "\e[1;34m#############################################\e[0m"
echo
echo -e "\e[1;34m $1\e[0m"
echo
echo -e "\e[1;34m#############################################\e[0m"
echo
}
# Function to execute commands with optional sudo
run_command() {
if [ -x "$(command -v sudo)" ]; then
sudo "$@"
else
"$@"
fi
}
# Detect the operating system
if [ -f "/etc/os-release" ]; then
. /etc/os-release
OS=$ID
else
echo "Error: Unable to detect the operating system."
exit 1
fi
color_echo() {
local color_code=$1
shift
echo -e "\e[1;${color_code}m$@\e[0m"
}
# Function to display installed services and ports
get_ip_address() {
# Use the command "hostname -I" to obtain the IP address
ip_address=$(hostname -I | awk '{print $1}')
echo "$ip_address"
}
displaydocker() {
colorred="\033[31m"
colorpowder_blue="\033[1;36m" #with bold
colorblue="\033[34m"
colornormal="\033[0m"
colorwhite="\033[97m"
colorlightgrey="\033[90m"
echo
printf " ${colorred} ## ${colorpowder_blue} .\n"
printf " ${colornormal}${colorred} ## ## ## ${colorpowder_blue} == ${colorpowder_blue} _____ ____ _____ _ ________ _____ \n"
printf " ${colornormal}${colorred}## ## ## ## ${colorpowder_blue}=== ${colorpowder_blue}| __ \ / __ \ / ____| |/ / ____| __ \ \n"
printf " /\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\\\___/ === ${colorpowder_blue}| | | | | | | | | ' /| |__ | |__) |\n"
printf " ${colorpowder_blue}{${colorblue} ${colorpowder_blue}/ ===- ${colorpowder_blue}| | | | | | | | | < | __| | _ / \n"
printf " \\\______${colorwhite} o ${colorpowder_blue} __/ | |__| | |__| | |____| . \| |____| | \ \ \n"
printf " \\\ \\\ __/ ${colorpowder_blue}|_____/ \____/ \_____|_|\_\______|_| \_\ \n"
printf " \\\____\\\______/ \n${colornormal}"
printf " ${colorred}Created by: sd-itlab\n"
printf "${colornormal}============================================================================="
echo
}
displayupdate() {
cat <<EOF
=============================================================================
_____ __ __ __ __ __
/ ___/__ _______/ /____ ____ ___ / / / /___ ____/ /___ _/ /____
\__ \/ / / / ___/ __/ _ \/ __ __ \ / / / / __ \/ __ / __ / __/ _ \
___/ / /_/ (__ ) /_/ __/ / / / / / / /_/ / /_/ / /_/ / /_/ / /_/ __/
/____/\__ /____/\__/\___/_/ /_/ /_/ \____/ ___/\____/\____/\__/\___/
/____/ /_/
Created by: sd-itlab
=============================================================================
EOF
}
################################################################################################################
############### System - Update ###############
################################################################################################################
sys_update() {
clear
displayupdate
run_command apt-get update
run_command apt-get upgrade -y
clear
displayupdate
echo
color_echo 32 " System has been updated and is now up-to-date."
echo
}
################################################################################################################
############### Docker - installation ###############
################################################################################################################
docker_setup() {
clear
displaydocker
echo
# Install dependencies
run_command apt-get install -y ca-certificates curl
# Create directory for keyrings
run_command install -m 0755 -d /etc/apt/keyrings
# Download Docker's GPG key
run_command curl -fsSL https://download.docker.com/linux/$OS/gpg -o /etc/apt/keyrings/docker.asc
# Adjust permissions for the GPG key
run_command chmod a+r /etc/apt/keyrings/docker.asc
# Add Docker repository to Apt sources
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/$OS \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
run_command tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update Apt repositories
run_command apt-get update
# Install Docker packages
run_command apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl stop docker
# Check if /etc/docker directory exists
if [ ! -d "/etc/docker" ]; then
mkdir /etc/docker
fi
# Check if /etc/docker/daemon.json exists
if [ ! -e "/etc/docker/daemon.json" ]; then
# Change docker directory for more space
cat <<EOL > /etc/docker/daemon.json
{
"data-root": "/home/docker"
}
EOL
fi
# Check if /home/docker directory exists
if [ ! -d "/home/docker" ]; then
mkdir /home/docker
fi
# Check if /var/lib/docker directory exists
if [ -d "/var/lib/docker" ]; then
cp -rp /var/lib/docker/* "/home/docker/"
rm -rf /var/lib/docker
fi
systemctl start docker
clear
displaydocker
echo
color_echo 32 " Installation of Docker and Docker-Compose completed."
color_echo 32 " Information: Default-Directory was changed to [/home/docker],"
color_echo 32 " for more storage capacity."
echo
}
################################################################################################################
############### Dockerapps - installation ###############
################################################################################################################
app_menu() {
# Function for installing apps
while true; do
clear
displaydocker
# Show menu options
echo
echo -e "\e[1;33m [\033[1;36m1\e[1;33m] Portainer\e[0m [Dashboard for docker containers]"
echo -e "\e[1;33m [\033[1;36m2\e[1;33m] Adguard Home\e[0m [Network-wide ad & tracker blocker]"
echo -e "\e[1;33m [\033[1;36m3\e[1;33m] Uptime Kuma\e[0m [Uptime-monitoring]"
echo -e "\e[1;33m [\033[1;36m4\e[1;33m] Watchtower\e[0m [Automatic updating of docker containers]"
echo -e "\e[1;33m [\033[1;36m5\e[1;33m] Grafana_Stack\e[0m [Data visualization]"
echo -e "\e[1;33m [\033[1;36m6\e[1;33m] Nginx-Proxy-Manager\e[0m [Reverse proxy with LetsEncrypt]"
echo -e "\e[1;33m [\033[1;36m7\e[1;33m] Homarr\e[0m [Dashboards for Favorites]"
echo
echo "============================================================================="
echo
# Query user input
read -p " Please select an option (1-8) or Quit (Q): " user_choice
# Process menu options
case $user_choice in
1) install_portainer ;;
2) install_adguard_home ;;
3) install_uptime_kuma ;;
4) install_watchtower ;;
5) install_grafana_stack ;;
6) install_npm ;;
7) install_homarr ;;
Q|q) return ;;
*) echo "Invalid option. Please select again." ;;
esac
done
}
################################################################################################################
############### Dockerapps ###############
################################################################################################################
# Function to install portainer
install_portainer() {
clear
displaydocker
echo
print_colored_section_header "Install Portainer..."
run_command docker volume create portainer_data
run_command docker run -d -p 9000:9000 --hostname=portainer --name=portainer --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce:sts
clear
displaydocker
echo
echo -e " Portainer can now be reached at the following address >"
echo -e " \e[32mhttp://$(get_ip_address):9000\e[0m"
echo
read -p " Press Enter to return to the menu."
}
# function to install Adguard Home
install_adguard_home() {
clear
displaydocker
echo
print_colored_section_header "Install Adguard Home..."
run_command docker volume create adguardhome_data
run_command docker run -d --hostname=adguardhome --name=adguardhome --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v adguardhome_data:/opt/adguardhome/conf \
-v adguardhome_data:/opt/adguardhome/work \
-p 53:53/tcp \
-p 53:53/udp \
-p 33000:3000/tcp \
-p 30080:80/tcp \
adguard/adguardhome:latest
clear
displaydocker
echo
echo -e " Adguard can now be reached at the following address > "
echo -e " For first setup use: \e[32mhttp://$(get_ip_address):33000\e[0m"
echo -e " After setup use: \e[32mhttp://$(get_ip_address):30080\e[0m"
echo
read -p " Press Enter to return to the menu."
}
# function to install Uptime Kuma
install_uptime_kuma() {
clear
displaydocker
echo
print_colored_section_header "Install Uptime Kuma..."
run_command docker volume create uptimekuma_data
run_command docker run -d --hostname=uptimekuma --name=uptimekuma --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v uptimekuma_data:/app/data \
-p 3001:3001 \
louislam/uptime-kuma:latest
clear
displaydocker
echo
echo -e " Uptime Kuma can now be reached at the following address >"
echo -e " \e[32mhttp://$(get_ip_address):3001\e[0m"
echo
read -p " Press Enter to return to the menu."
}
# function to install Watchtower
install_watchtower() {
clear
displaydocker
echo
print_colored_section_header "Install Watchtower..."
run_command docker run -d --hostname=watchtower --name=watchtower --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /etc/localtime:/etc/localtime:ro \
-e WATCHTOWER_NOTIFICATIONS=shoutrrr \
-e WATCHTOWER_NOTIFICATION_URL= \
-e WATCHTOWER_NOTIFICATIONS_LEVEL=info \
-e WATCHTOWER_MONITOR_ONLY=false \
-e WATCHTOWER_CLEANUP=true \
-e WATCHTOWER_INCLUDE_STOPPED=true \
-e WATCHTOWER_NO_STARTUP_MESSAGE=true \
-e PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
-e WATCHTOWER_SCHEDULE="0 0 0 * * *" \
-e WATCHTOWER_ROLLING_RESTART=true \
containrrr/watchtower:latest
clear
displaydocker
echo
echo -e " watchtower are now running"
echo
read -p " Press Enter to return to the menu."
}
# Function to install Grafana and Node-exporter
install_grafana_stack() {
clear
displaydocker
echo
print_colored_section_header "Install Grafana..."
echo
run_command mkdir -p /etc/prometheus/
cat <<EOL > /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 10s
static_configs:
- targets: ['localhost:9090']
- job_name: 'Localhost'
scrape_interval: 10s
static_configs:
- targets: ['node_exporter:9100']
EOL
run_command docker network create grafana_network
run_command docker volume create prometheus_data
run_command docker run -d --hostname=prometheus --name=g_prometheus --network=grafana_network --restart=unless-stopped \
-p 9090:9090 \
-v /etc/prometheus:/etc/prometheus \
-v prometheus_data:/prometheus \
prom/prometheus:latest
run_command docker volume create grafana_data
run_command docker run -d --hostname=grafana --name=g_grafana --network=grafana_network --restart=unless-stopped \
-p 3000:3000 \
-v grafana_data:/var/lib/grafana \
grafana/grafana:latest
run_command docker run -d --hostname=node_exporter --name=g_node_exporter --network=grafana_network --restart=unless-stopped \
--pid=host \
-v /:/host:ro,rslave \
quay.io/prometheus/node-exporter:v1.5.0 --path.rootfs=/host
clear
displaydocker
echo
print_colored_section_header "Install Grafana-Fritzbox..."
echo
read -p "Would you like to install the fritzbox-prometheus-exporter as well? (Y/N): " install_fritzbox_exporter
if [ "$install_fritzbox_exporter" == "y" ]; then
read -p "Enter the IP address of your Fritzbox: " fb_exporter_gateway_url
read -p "Enter the fritzbox user name (USERNAME) for fritzbox-prometheus-exporter: " fb_exporter_username
read -p "Enter the fritzbox password (PASSWORD) for fritzbox-prometheus-exporter: " fb_exporter_passwort
echo
run_command docker run -d --hostname=fritzbox_exporter --name=g_fritzbox_exporter --network=grafana_network --restart=unless-stopped \
-p 9042:9042 \
-e USERNAME=$fb_exporter_username \
-e PASSWORD=$fb_exporter_password \
-e GATEWAY_URL=http://$fb_exporter_gateway_url:49000 \
-e LISTEN_ADDRESS=0.0.0.0:9042 \
mineyannik/fritzbox_exporter:latest
fritzbox_exporter_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' fritzbox_exporter)
cat <<EOL >> /etc/prometheus/prometheus.yml
- job_name: 'fritzbox_exporter'
static_configs:
- targets: ['g_fritzbox_exporter:9042']
EOL
run_command docker restart prometheus
else
color_echo 31 "fritzbox-prometheus-exporter will be not installed"
fi
clear
displaydocker
echo
echo -e " Grafana can now be reached at the following address >"
echo -e " \e[32mhttp://$(get_ip_address):3000\e[0m"
echo
echo -e " Node-Exporter can now be reached at the following address >"
echo -e " \e[32mhttp://$(get_ip_address):9090\e[0m"
echo
read -p " Press Enter to return to the menu."
}
install_npm() {
clear
displaydocker
echo
print_colored_section_header "Install Nginx-Proxy-Manager"
run_command docker network create npm_network
run_command docker volume create npm_data
run_command docker run -d --hostname=npm --name=nginx-proxy-manager --network=npm_network --restart=always \
-v npm_data/data:/data \
-v npm_data/letsencrypt:/etc/letsencrypt \
-p 80:80 \
-p 443:443 \
-p 81:81 \
-e TZ=Europe/Berlin \
jc21/nginx-proxy-manager:latest
clear
displaydocker
echo
echo -e " Nginx Proxy Manager can now be reached at the following address >"
echo -e " \e[32mhttp://$(get_ip_address):81\e[0m"
echo
echo -e " Default email: \e[[email protected] \033[0m| Default password: \e[32mchangeme\e[0m"
echo
read -p " Press Enter to return to the menu."
}
install_homarr() {
clear
displaydocker
echo
print_colored_section_header "Install homarr"
run_command docker volume create homarr_configs
run_command docker volume create homarr_icons
run_command docker volume create homarr_data
run_command docker run -d --hostname=homarr --name=homarr --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v homarr_configs:/app/data/configs \
-v homarr_icons:/app/public/icons \
-v homarr_data:/data \
-p 7575:7575 \
linuxserver/heimdall:latest
clear
displaydocker
echo
echo -e " homarr can now be reached at the following address >"
echo -e " \e[32mhttp://$(get_ip_address):7575\e[0m"
echo
read -p " Press Enter to return to the menu."
}
################################################################################################################
############### Mainmenu ###############
################################################################################################################
while true; do
clear
displaydocker
# Process menu options
echo
echo -e "\e[1;33m [\033[1;36m1\e[1;33m] Perform system update\e[0m [Update the system]"
echo
echo -e "\e[1;33m [\033[1;36m2\e[1;33m] Install Docker\e[0m [Install Docker and Docker-Compose]"
echo
echo -e "\e[1;33m [\033[1;36m3\e[1;33m] Install Applications\e[0m [Install Docker-Apps]"
echo
echo
echo
echo "============================================================================="
echo
# Query user input
read -p " Please select an option (1-3) or Quit (Q): " choice
# Process menu options
case $choice in
1) sys_update ; read -p " Press Enter to return to the main menu." ;;
2) docker_setup ; read -p " Press Enter to return to the main menu." ;;
3) app_menu ;;
Q|q)
clear
exit
;;
*) ;;
esac
done