-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-docker.sh
More file actions
executable file
·746 lines (609 loc) · 24.8 KB
/
init-docker.sh
File metadata and controls
executable file
·746 lines (609 loc) · 24.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
#!/bin/bash
# Docker Web Template - Initialization Script
# This script sets up Docker, Docker Compose, and configures a containerized web environment
#======================================
# Color Definitions for Beautiful CLI
#======================================
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
BOLD='\033[1m'
#======================================
# Helper Functions
#======================================
print_header() {
echo -e "\n${CYAN}╔════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║${WHITE}${BOLD} Docker Web Template - Initialization Script ${NC}${CYAN}║${NC}"
echo -e "${CYAN}╚════════════════════════════════════════════════════════════════╝${NC}\n"
}
print_step() {
echo -e "${BLUE}▶${NC} ${BOLD}$1${NC}"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_info() {
echo -e "${CYAN}ℹ${NC} $1"
}
print_section() {
echo -e "\n${MAGENTA}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${MAGENTA} $1${NC}"
echo -e "${MAGENTA}═══════════════════════════════════════════════════════════════${NC}\n"
}
#======================================
# System Detection Functions
#======================================
detect_os() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
VERSION=$VERSION_ID
else
print_error "Cannot detect OS. /etc/os-release not found."
exit 1
fi
}
check_sudo() {
SUDO_CMD=""
if [ "$EUID" -ne 0 ]; then
if command -v sudo &> /dev/null; then
SUDO_CMD="sudo"
print_info "Running with sudo privileges"
else
print_error "This script requires root privileges, but sudo is not available."
exit 1
fi
else
print_info "Running as root"
fi
}
#======================================
# Docker Installation Functions
#======================================
check_docker() {
if command -v docker &> /dev/null; then
DOCKER_VERSION=$(docker --version | cut -d' ' -f3 | cut -d',' -f1)
print_success "Docker is already installed (version $DOCKER_VERSION)"
return 0
else
print_warning "Docker is not installed"
return 1
fi
}
install_docker_ubuntu() {
print_step "Installing Docker on Ubuntu..."
$SUDO_CMD apt update
$SUDO_CMD apt-get install -yy ca-certificates curl gnupg lsb-release
$SUDO_CMD mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | $SUDO_CMD gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | $SUDO_CMD tee /etc/apt/sources.list.d/docker.list > /dev/null
$SUDO_CMD apt update
$SUDO_CMD apt-get install -yy docker-ce docker-ce-cli containerd.io docker-compose-plugin
# Add current user to docker group
$SUDO_CMD groupadd docker 2>/dev/null || true
$SUDO_CMD usermod -aG docker $USER
# Install docker-compose standalone
$SUDO_CMD curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$SUDO_CMD chmod +x /usr/local/bin/docker-compose
$SUDO_CMD ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose
print_success "Docker installed successfully on Ubuntu"
}
install_docker_debian() {
print_step "Installing Docker on Debian..."
$SUDO_CMD apt update
$SUDO_CMD apt install -yy ca-certificates curl gnupg lsb-release
$SUDO_CMD mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | $SUDO_CMD gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | $SUDO_CMD tee /etc/apt/sources.list.d/docker.list > /dev/null
$SUDO_CMD apt update
$SUDO_CMD apt-get install -yy docker-ce docker-ce-cli containerd.io docker-compose-plugin
# Add current user to docker group
$SUDO_CMD groupadd docker 2>/dev/null || true
$SUDO_CMD usermod -aG docker $USER
# Install docker-compose standalone
$SUDO_CMD curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$SUDO_CMD chmod +x /usr/local/bin/docker-compose
$SUDO_CMD ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose
print_success "Docker installed successfully on Debian"
}
install_docker() {
detect_os
case $OS in
ubuntu)
install_docker_ubuntu
;;
debian)
install_docker_debian
;;
*)
print_error "Unsupported OS: $OS. This script supports Ubuntu and Debian only."
exit 1
;;
esac
}
#======================================
# Environment Setup Functions
#======================================
setup_dockers_folder() {
print_step "Setting up dockers folder..."
DOCKERS_DIR="$HOME/dockers"
if [ ! -d "$DOCKERS_DIR" ]; then
mkdir -p "$DOCKERS_DIR"
print_success "Created dockers folder at $DOCKERS_DIR"
else
print_info "Dockers folder already exists at $DOCKERS_DIR"
fi
# Create .env file if it doesn't exist
if [ ! -f "$DOCKERS_DIR/.env" ]; then
cp .env.example "$DOCKERS_DIR/.env"
print_success "Created .env file from template"
print_warning "Please edit $DOCKERS_DIR/.env with your configuration"
else
print_info ".env file already exists"
fi
}
setup_docker_network() {
print_step "Checking Docker network..."
NETWORK_NAME="t2_proxy"
# Check if network exists
if docker network ls | grep -q "$NETWORK_NAME"; then
print_success "Docker network '$NETWORK_NAME' already exists"
else
print_warning "Docker network '$NETWORK_NAME' not found"
# Ask for subnet
echo -e "${CYAN}Please enter the subnet for the network (e.g., 192.168.90.0/24):${NC}"
read -p "> " SUBNET
if [ -z "$SUBNET" ]; then
print_error "Subnet cannot be empty"
exit 1
fi
# Create network
docker network create --subnet="$SUBNET" "$NETWORK_NAME"
print_success "Created Docker network '$NETWORK_NAME' with subnet $SUBNET"
fi
}
setup_traefik() {
print_step "Setting up Traefik..."
DOCKERS_DIR="$HOME/dockers"
TRAEFIK_DIR="$DOCKERS_DIR/traefik"
# Create traefik directory
mkdir -p "$TRAEFIK_DIR"
# Copy traefik configuration files
cp -r traefik/* "$TRAEFIK_DIR/"
print_success "Copied Traefik configuration files"
# Create acme.json with proper permissions
touch "$TRAEFIK_DIR/acme.json"
chmod 600 "$TRAEFIK_DIR/acme.json"
print_success "Created acme.json with proper permissions (600)"
}
#======================================
# Plugin Management Functions
#======================================
load_plugins_config() {
local plugins_file="./plugins.conf"
declare -g -A PLUGIN_REPOS
declare -g -A PLUGIN_MODULES
declare -g -A PLUGIN_DESCRIPTIONS
declare -g -a PLUGIN_NAMES
if [ ! -f "$plugins_file" ]; then
print_warning "plugins.conf not found. Plugin installation will be skipped."
return 1
fi
# Read plugins configuration
while IFS='|' read -r name repo module desc; do
# Skip comments and empty lines
[[ "$name" =~ ^#.*$ ]] || [ -z "$name" ] && continue
PLUGIN_NAMES+=("$name")
PLUGIN_REPOS["$name"]="$repo"
PLUGIN_MODULES["$name"]="$module"
PLUGIN_DESCRIPTIONS["$name"]="$desc"
done < "$plugins_file"
return 0
}
select_plugins() {
print_section "Plugin Selection"
if ! load_plugins_config; then
return 0
fi
if [ ${#PLUGIN_NAMES[@]} -eq 0 ]; then
print_warning "No plugins configured in plugins.conf"
return 0
fi
print_info "Available Traefik plugins:"
echo ""
local i=1
for plugin in "${PLUGIN_NAMES[@]}"; do
echo -e " ${YELLOW}[$i]${NC} ${BOLD}$plugin${NC}"
echo -e " ${PLUGIN_DESCRIPTIONS[$plugin]}"
((i++))
done
echo -e "\n${CYAN}Enter the numbers of plugins you want to install (space-separated, e.g., '1 3 5'):${NC}"
echo -e "${CYAN}Press Enter without input to skip plugin installation${NC}"
read -p "> " CHOICES
declare -a SELECTED_PLUGINS
# Parse choices
if [ -n "$CHOICES" ]; then
for choice in $CHOICES; do
if [ "$choice" -ge 1 ] && [ "$choice" -le "${#PLUGIN_NAMES[@]}" ]; then
local idx=$((choice - 1))
SELECTED_PLUGINS+=("${PLUGIN_NAMES[$idx]}")
fi
done
fi
# Return selected plugins
echo "${SELECTED_PLUGINS[@]}"
}
clone_plugin_repos() {
local plugins_array=($1)
if [ ${#plugins_array[@]} -eq 0 ]; then
return 0
fi
print_step "Cloning plugin repositories..."
DOCKERS_DIR="$HOME/dockers"
PLUGINS_DIR="$DOCKERS_DIR/traefik/plugins"
# Create plugins directory
mkdir -p "$PLUGINS_DIR"
for plugin in "${plugins_array[@]}"; do
local repo="${PLUGIN_REPOS[$plugin]}"
local plugin_dir="$PLUGINS_DIR/traefik-${plugin}-plugin"
if [ -d "$plugin_dir" ]; then
print_info "Plugin '$plugin' already cloned, skipping..."
else
print_step "Cloning $plugin from $repo"
if git clone "$repo" "$plugin_dir" 2>/dev/null; then
print_success "Cloned $plugin successfully"
else
print_error "Failed to clone $plugin from $repo"
fi
fi
done
}
add_plugin_volumes() {
local plugins_array=($1)
local compose_file="$2"
if [ ${#plugins_array[@]} -eq 0 ]; then
return 0
fi
print_step "Adding plugin volumes to docker-compose.yml..."
# Find the line number where traefik volumes end (before labels section)
# We'll add plugin volumes after the existing traefik volumes
for plugin in "${plugins_array[@]}"; do
local module="${PLUGIN_MODULES[$plugin]}"
local plugin_dir="./traefik/plugins/traefik-${plugin}-plugin"
local volume_line=" - $plugin_dir:/plugins-local/src/$module"
# Check if volume already exists
if grep -q "$volume_line" "$compose_file"; then
print_info "Volume for plugin '$plugin' already exists in docker-compose.yml"
else
# Add the volume line after the last volume entry and before labels
sed -i "/traefik\/acme.json:\/acme.json/a\\$volume_line" "$compose_file"
print_success "Added volume for plugin '$plugin'"
fi
done
}
update_traefik_config_plugins() {
local plugins_array=($1)
local traefik_config="$2"
if [ ${#plugins_array[@]} -eq 0 ]; then
return 0
fi
print_step "Updating traefik.yml with plugin configuration..."
# Check if experimental section already exists
if grep -q "^experimental:" "$traefik_config"; then
print_info "Experimental section already exists in traefik.yml"
# Check if localPlugins subsection exists
if ! grep -q " localPlugins:" "$traefik_config"; then
# Add localPlugins section
sed -i "/^experimental:/a\\ localPlugins:" "$traefik_config"
fi
else
# Add experimental section at the end of file
echo "" >> "$traefik_config"
echo "experimental:" >> "$traefik_config"
echo " localPlugins:" >> "$traefik_config"
fi
# Add each plugin configuration
for plugin in "${plugins_array[@]}"; do
local module="${PLUGIN_MODULES[$plugin]}"
# Check if plugin already configured
if grep -q " $plugin:" "$traefik_config"; then
print_info "Plugin '$plugin' already configured in traefik.yml"
else
# Add plugin configuration
sed -i "/ localPlugins:/a\\ $plugin:\n moduleName: $module" "$traefik_config"
print_success "Added configuration for plugin '$plugin'"
fi
done
}
check_existing_configuration() {
DOCKERS_DIR="$HOME/dockers"
# Check if configuration exists
if [ -d "$DOCKERS_DIR" ] && [ -f "$DOCKERS_DIR/docker-compose.yml" ] && [ -f "$DOCKERS_DIR/.env" ]; then
return 0 # Configuration exists
else
return 1 # Configuration doesn't exist
fi
}
#======================================
# Service Template Functions
#======================================
select_services() {
print_section "Service Selection"
print_info "Available services:"
TEMPLATES_DIR="./templates"
declare -a SERVICES
declare -a SELECTED_SERVICES
# List all template files
local i=1
for template in "$TEMPLATES_DIR"/*.yml; do
if [ -f "$template" ]; then
SERVICE_NAME=$(basename "$template" .yml)
SERVICES[$i]="$SERVICE_NAME"
echo -e " ${YELLOW}[$i]${NC} $SERVICE_NAME"
((i++))
fi
done
echo -e "\n${CYAN}Enter the numbers of services you want to install (space-separated, e.g., '1 3 5'):${NC}"
echo -e "${CYAN}Press Enter without input to skip additional services${NC}"
read -p "> " CHOICES
# Parse choices
if [ -n "$CHOICES" ]; then
for choice in $CHOICES; do
if [ "$choice" -ge 1 ] && [ "$choice" -lt "$i" ]; then
SELECTED_SERVICES+=("${SERVICES[$choice]}")
fi
done
fi
# Return selected services
echo "${SELECTED_SERVICES[@]}"
}
build_docker_compose() {
print_step "Building docker-compose.yml..."
DOCKERS_DIR="$HOME/dockers"
COMPOSE_FILE="$DOCKERS_DIR/docker-compose.yml"
TEMPLATES_DIR="./templates"
# Start with base docker-compose (Traefik)
cat > "$COMPOSE_FILE" << 'EOF'
version: '3.8'
services:
traefik:
image: traefik:v2.10
container_name: traefik
restart: unless-stopped
security_opt:
- no-new-privileges:true
networks:
- t2_proxy
ports:
- "80:80"
- "443:443"
environment:
- CF_API_EMAIL=${CF_API_EMAIL}
- CF_DNS_API_TOKEN=${CF_DNS_API_TOKEN}
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik/traefik.yml:/traefik.yml:ro
- ./traefik/dynamic.yml:/dynamic.yml:ro
- ./traefik/acme.json:/acme.json
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.entrypoints=http"
- "traefik.http.routers.traefik.rule=Host(`traefik.${DOMAIN:-localhost}`)"
- "traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_DASHBOARD_AUTH}"
- "traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https"
- "traefik.http.middlewares.sslheader.headers.customrequestheaders.X-Forwarded-Proto=https"
- "traefik.http.routers.traefik.middlewares=traefik-https-redirect"
- "traefik.http.routers.traefik-secure.entrypoints=https"
- "traefik.http.routers.traefik-secure.rule=Host(`traefik.${DOMAIN:-localhost}`)"
- "traefik.http.routers.traefik-secure.middlewares=traefik-auth"
- "traefik.http.routers.traefik-secure.tls=true"
- "traefik.http.routers.traefik-secure.tls.certresolver=cloudflare"
- "traefik.http.routers.traefik-secure.tls.domains[0].main=${DOMAIN:-localhost}"
- "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.${DOMAIN:-localhost}"
- "traefik.http.routers.traefik-secure.service=api@internal"
EOF
# Add selected services
local services_array=($1)
for service in "${services_array[@]}"; do
if [ -f "$TEMPLATES_DIR/$service.yml" ]; then
print_info "Adding $service to docker-compose.yml"
# Append service template (skip version line if present)
grep -v "^version:" "$TEMPLATES_DIR/$service.yml" | sed '/^$/d' >> "$COMPOSE_FILE"
echo "" >> "$COMPOSE_FILE"
fi
done
# Add networks section
cat >> "$COMPOSE_FILE" << 'EOF'
networks:
t2_proxy:
external: true
EOF
print_success "docker-compose.yml created successfully at $COMPOSE_FILE"
}
#======================================
# Main Execution
#======================================
add_to_existing_configuration() {
print_section "Add to Existing Configuration"
DOCKERS_DIR="$HOME/dockers"
echo -e "${CYAN}What would you like to add?${NC}"
echo -e " ${YELLOW}[1]${NC} Add new plugins"
echo -e " ${YELLOW}[2]${NC} Add new services"
echo -e " ${YELLOW}[3]${NC} Add both plugins and services"
echo -e " ${YELLOW}[4]${NC} Exit"
read -p "> " ADD_CHOICE
case $ADD_CHOICE in
1)
# Add plugins only
SELECTED_PLUGINS=$(select_plugins)
if [ -n "$SELECTED_PLUGINS" ]; then
clone_plugin_repos "$SELECTED_PLUGINS"
add_plugin_volumes "$SELECTED_PLUGINS" "$DOCKERS_DIR/docker-compose.yml"
update_traefik_config_plugins "$SELECTED_PLUGINS" "$DOCKERS_DIR/traefik/traefik.yml"
print_success "Plugins added successfully!"
print_warning "Remember to restart Traefik: cd $DOCKERS_DIR && docker-compose restart traefik"
fi
;;
2)
# Add services only
SELECTED=$(select_services)
if [ -n "$SELECTED" ]; then
# Backup existing docker-compose.yml
cp "$DOCKERS_DIR/docker-compose.yml" "$DOCKERS_DIR/docker-compose.yml.backup"
# Append new services (remove networks section first, we'll re-add it)
sed -i '/^networks:/,$d' "$DOCKERS_DIR/docker-compose.yml"
local services_array=($SELECTED)
for service in "${services_array[@]}"; do
if [ -f "./templates/$service.yml" ]; then
print_info "Adding $service to docker-compose.yml"
grep -v "^version:" "./templates/$service.yml" | sed '/^$/d' >> "$DOCKERS_DIR/docker-compose.yml"
echo "" >> "$DOCKERS_DIR/docker-compose.yml"
fi
done
# Re-add networks section
cat >> "$DOCKERS_DIR/docker-compose.yml" << 'EOF'
networks:
t2_proxy:
external: true
EOF
print_success "Services added successfully!"
print_info "Backup created at: $DOCKERS_DIR/docker-compose.yml.backup"
fi
;;
3)
# Add both
SELECTED_PLUGINS=$(select_plugins)
SELECTED=$(select_services)
if [ -n "$SELECTED_PLUGINS" ]; then
clone_plugin_repos "$SELECTED_PLUGINS"
add_plugin_volumes "$SELECTED_PLUGINS" "$DOCKERS_DIR/docker-compose.yml"
update_traefik_config_plugins "$SELECTED_PLUGINS" "$DOCKERS_DIR/traefik/traefik.yml"
fi
if [ -n "$SELECTED" ]; then
cp "$DOCKERS_DIR/docker-compose.yml" "$DOCKERS_DIR/docker-compose.yml.backup"
sed -i '/^networks:/,$d' "$DOCKERS_DIR/docker-compose.yml"
local services_array=($SELECTED)
for service in "${services_array[@]}"; do
if [ -f "./templates/$service.yml" ]; then
print_info "Adding $service to docker-compose.yml"
grep -v "^version:" "./templates/$service.yml" | sed '/^$/d' >> "$DOCKERS_DIR/docker-compose.yml"
echo "" >> "$DOCKERS_DIR/docker-compose.yml"
fi
done
cat >> "$DOCKERS_DIR/docker-compose.yml" << 'EOF'
networks:
t2_proxy:
external: true
EOF
fi
if [ -n "$SELECTED_PLUGINS" ] || [ -n "$SELECTED" ]; then
print_success "Configuration updated successfully!"
if [ -n "$SELECTED_PLUGINS" ]; then
print_warning "Remember to restart Traefik: cd $DOCKERS_DIR && docker-compose restart traefik"
fi
fi
;;
4)
print_info "Exiting..."
exit 0
;;
*)
print_error "Invalid choice"
exit 1
;;
esac
}
main() {
print_header
# Check if configuration already exists
if check_existing_configuration; then
print_info "Existing Docker configuration detected at $HOME/dockers"
echo -e "${CYAN}Do you want to add new plugins or services? (y/n):${NC}"
read -p "> " ADD_MORE
if [[ "$ADD_MORE" =~ ^[Yy]$ ]]; then
add_to_existing_configuration
else
print_info "Exiting without changes"
fi
echo -e "\n${CYAN}╔════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║${WHITE}${BOLD} Thank you for using Docker Web Template! ${NC}${CYAN}║${NC}"
echo -e "${CYAN}╚════════════════════════════════════════════════════════════════╝${NC}\n"
exit 0
fi
# Fresh installation flow
# Step 1: System Detection
print_section "Step 1: System Detection"
detect_os
print_success "Detected OS: $OS $VERSION"
check_sudo
# Step 2: Docker Installation Check
print_section "Step 2: Docker Installation"
if ! check_docker; then
echo -e "${CYAN}Do you want to install Docker? (y/n):${NC}"
read -p "> " INSTALL_DOCKER
if [[ "$INSTALL_DOCKER" =~ ^[Yy]$ ]]; then
install_docker
print_warning "You may need to log out and log back in for Docker group permissions to take effect"
else
print_error "Docker is required to continue. Exiting."
exit 1
fi
fi
# Step 3: Environment Setup
print_section "Step 3: Environment Setup"
setup_dockers_folder
# Step 4: Docker Network
print_section "Step 4: Docker Network Configuration"
setup_docker_network
# Step 5: Traefik Setup
print_section "Step 5: Traefik Configuration"
setup_traefik
# Step 6: Plugin Selection
SELECTED_PLUGINS=$(select_plugins)
# Step 7: Service Selection
SELECTED=$(select_services)
# Step 8: Build Docker Compose
print_section "Step 7: Building Configuration"
build_docker_compose "$SELECTED"
# Step 9: Clone Plugin Repositories
if [ -n "$SELECTED_PLUGINS" ]; then
print_section "Step 8: Installing Plugins"
clone_plugin_repos "$SELECTED_PLUGINS"
DOCKERS_DIR="$HOME/dockers"
add_plugin_volumes "$SELECTED_PLUGINS" "$DOCKERS_DIR/docker-compose.yml"
update_traefik_config_plugins "$SELECTED_PLUGINS" "$DOCKERS_DIR/traefik/traefik.yml"
fi
# Final Summary
print_section "Installation Complete!"
print_success "Docker environment has been configured successfully"
print_info "Configuration directory: $HOME/dockers"
print_info "Next steps:"
echo -e " ${YELLOW}1.${NC} Edit $HOME/dockers/.env with your domain and credentials"
echo -e " ${YELLOW}2.${NC} Navigate to $HOME/dockers"
echo -e " ${YELLOW}3.${NC} Run: ${BOLD}docker-compose up -d${NC}"
if [ -n "$SELECTED" ]; then
echo -e "\n${GREEN}Selected services:${NC} $SELECTED"
fi
if [ -n "$SELECTED_PLUGINS" ]; then
echo -e "${GREEN}Installed plugins:${NC} $SELECTED_PLUGINS"
fi
echo -e "\n${CYAN}╔════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║${WHITE}${BOLD} Thank you for using Docker Web Template! ${NC}${CYAN}║${NC}"
echo -e "${CYAN}╚════════════════════════════════════════════════════════════════╝${NC}\n"
}
# Run main function
main