-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·1407 lines (1198 loc) · 49 KB
/
install.sh
File metadata and controls
executable file
·1407 lines (1198 loc) · 49 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
################################################################################
# disk2iso v1.3.0 - Installation Script
# Filepath: install.sh
#
# Beschreibung:
# Wizard-basierte Installation von disk2iso
# - Installations-Wizard mit dialog
# - Optionale systemd Service-Konfiguration
#
# Version: 1.3.0
# Datum: 07.02.2026
################################################################################
set -e
# Ermittle Script-Verzeichnis (auch wenn via sudo ausgeführt)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Farben für Output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Standard-Installationspfade
INSTALL_DIR="/opt/disk2iso"
SERVICE_FILE="/etc/systemd/system/disk2iso.service"
BIN_LINK="/usr/local/bin/disk2iso"
# Wizard-Zustandsvariablen
# Services werden immer installiert (nicht mehr optional)
SERVICE_OUTPUT_DIR="/media/iso"
# Versions- und Update-Variablen
NEW_VERSION="1.2.0" # Wird aus VERSION-Datei gelesen
INSTALLED_VERSION=""
IS_REPAIR=false
IS_UPDATE=false
# ============================================================================
# UTILITY FUNCTIONS
# ============================================================================
################################################################################
# AUSGABEVERZEICHNIS - Helper Funktion
################################################################################
# Erstelle Ausgabeverzeichnis mit korrekten Berechtigungen
create_output_directory() {
local output_dir="$1"
[[ -z "$output_dir" ]] && return 1
# Erstelle Basis-Verzeichnisstruktur
# Hinweis: audio/, dvd/, bd/ werden zur Laufzeit von optionalen Modulen erstellt
mkdir -p "$output_dir"/{.log,.temp/mountpoints,data} || return 1
# Setze Berechtigungen
chmod 755 "$output_dir"
chmod 755 "$output_dir"/data 2>/dev/null
chmod 777 "$output_dir"/.log 2>/dev/null
chmod 777 "$output_dir"/.temp 2>/dev/null
chmod 777 "$output_dir"/.temp/mountpoints 2>/dev/null
return 0
}
print_header() {
echo -e "\n${BLUE}========================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}========================================${NC}\n"
}
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 "${BLUE}ℹ${NC} $1"
}
# Whiptail-Wrapper für bessere UX
use_dialog() {
command -v dialog >/dev/null 2>&1
}
ask_yes_no() {
local question="$1"
local default="${2:-n}"
if use_dialog; then
if [[ "$default" == "n" ]]; then
dialog --title "disk2iso Installation" --defaultno --yesno "$question" 10 60
else
dialog --title "disk2iso Installation" --yesno "$question" 10 60
fi
return $?
else
# Fallback auf klassische Eingabe
local answer
if [[ "$default" == "y" ]]; then
read -p "$question [J/n]: " answer
answer=${answer:-j}
else
read -p "$question [j/N]: " answer
answer=${answer:-n}
fi
[[ "$answer" =~ ^[jJyY]$ ]]
fi
}
show_info() {
local title="$1"
local message="$2"
if use_dialog; then
dialog --title "$title" --msgbox "$message" 20 70
else
echo -e "\n${BLUE}$title${NC}"
echo "$message"
read -p "Drücken Sie Enter zum Fortfahren..."
fi
}
# ============================================================================
# CONFIG MERGE FUNCTION
# ============================================================================
# Intelligentes Merge von alter und neuer Konfiguration
# Parameter: $1 = Pfad zur alten Config, $2 = Pfad zur neuen Config (Template)
merge_config() {
local old_config="$1"
local new_config="$2"
if [[ ! -f "$old_config" ]]; then
print_info "Keine alte Konfiguration gefunden - nutze neue Template"
return 0
fi
if [[ ! -f "$new_config" ]]; then
print_error "Neue Config-Template nicht gefunden: $new_config"
return 1
fi
print_info "Merge Konfigurationen: alt → neu"
# Extrahiere alle Einstellungen aus alter Config (ignoriere Kommentare/Leerzeilen)
local temp_values="/tmp/disk2iso-config-values-$$.tmp"
grep -E '^[A-Z_]+=' "$old_config" | grep -v '^#' > "$temp_values" 2>/dev/null || true
# Aktualisiere neue Config mit alten Werten
while IFS='=' read -r key value; do
[[ -z "$key" ]] && continue
# Prüfe ob Key in neuer Config existiert
if grep -q "^${key}=" "$new_config"; then
# Ersetze Wert in neuer Config (behalte Quotes-Style)
sed -i "s|^${key}=.*|${key}=${value}|" "$new_config"
print_info " ✓ Übernehme: $key"
else
print_warning " ⚠ Überspringe veralteten Parameter: $key"
fi
done < "$temp_values"
rm -f "$temp_values"
# Zeige neue Einstellungen an
print_info "Neue Einstellungen in dieser Version:"
local new_keys=$(grep -E '^[A-Z_]+=' "$new_config" | cut -d'=' -f1)
local found_new=false
for key in $new_keys; do
if ! grep -q "^${key}=" "$old_config" 2>/dev/null; then
local value=$(grep "^${key}=" "$new_config" | cut -d'=' -f2-)
print_info " + $key=$value"
found_new=true
fi
done
[[ "$found_new" == "false" ]] && print_info " (keine neuen Einstellungen)"
return 0
}
# ============================================================================
# SYSTEM CHECKS
# ============================================================================
check_root() {
if [[ $EUID -ne 0 ]]; then
print_error "Dieses Script muss als root ausgeführt werden"
echo "Bitte verwenden Sie: sudo $0"
exit 1
fi
}
check_debian() {
if [[ ! -f /etc/debian_version ]]; then
print_warning "Dieses Script wurde für Debian entwickelt"
if ! ask_yes_no "Trotzdem fortfahren?"; then
exit 1
fi
else
print_success "Debian System erkannt: $(cat /etc/debian_version)"
fi
}
# Prüfe auf bestehende Installation
check_existing_installation() {
if [[ ! -d "$INSTALL_DIR" ]]; then
return 0 # Keine Installation vorhanden
fi
# Bestehende Installation gefunden
local version="unbekannt"
if [[ -f "$INSTALL_DIR/VERSION" ]]; then
version=$(cat "$INSTALL_DIR/VERSION" 2>/dev/null || echo "unbekannt")
elif [[ -f "$INSTALL_DIR/services/disk2iso/daemon.sh" ]]; then
# Fallback für alte Installationen ohne VERSION-Datei
version=$(grep -m1 "^# disk2iso v" "$INSTALL_DIR/services/disk2iso/daemon.sh" 2>/dev/null | awk '{print $3}' | tr -d 'v' || echo "unbekannt")
fi
INSTALLED_VERSION="$version"
# Lese neue Version aus SOURCE
if [[ -f "$SCRIPT_DIR/VERSION" ]]; then
NEW_VERSION=$(cat "$SCRIPT_DIR/VERSION" 2>/dev/null || echo "1.2.0")
fi
# Bestimme Aktion basierend auf Version
local action_mode=""
if [[ "$version" == "$NEW_VERSION" ]]; then
action_mode="REPARATUR"
else
action_mode="UPDATE"
fi
if use_dialog; then
local info=""
local action_label=""
local menu_title=""
if [[ "$action_mode" == "REPARATUR" ]]; then
menu_title="Eine bestehende disk2iso Installation wurde gefunden!
Installierter Pfad: $INSTALL_DIR
Installierte Version: ${version}
Neue Version: ${NEW_VERSION}
➜ GLEICHE VERSION ERKANNT"
action_label="Reparatur"
else
menu_title="Eine bestehende disk2iso Installation wurde gefunden!
Installierter Pfad: $INSTALL_DIR
Installierte Version: ${version}
Neue Version: ${NEW_VERSION}
➜ UPDATE VERFÜGBAR"
action_label="Update"
fi
local choice
choice=$(dialog --title "Bestehende Installation gefunden" \
--menu "$menu_title" 22 75 2 \
"1" "$action_label (Empfohlen)" \
"2" "Neuinstallation" \
2>&1 >/dev/tty)
local exit_code=$?
# Abbruch bei ESC oder Cancel
if [[ $exit_code -ne 0 ]]; then
return 0
fi
if [[ "$choice" == "1" ]]; then
# UPDATE/REPARATUR gewählt
if [[ "$action_mode" == "REPARATUR" ]]; then
IS_REPAIR=true
IS_UPDATE=false
else
IS_REPAIR=false
IS_UPDATE=true
fi
return 1
else
# NEUINSTALLATION gewählt
if dialog --title "Neuinstallation bestätigen" \
--defaultno \
--yesno "WARNUNG: Alle Einstellungen gehen verloren!\n\nSind Sie sicher, dass Sie eine komplette Neuinstallation durchführen möchten?\n\nDies kann NICHT rückgängig gemacht werden!" \
14 60; then
print_info "Führe Deinstallation durch..."
if [[ -f "$INSTALL_DIR/uninstall.sh" ]]; then
"$INSTALL_DIR/uninstall.sh" --silent
else
# Fallback: Manuelle Deinstallation
systemctl stop disk2iso 2>/dev/null || true
systemctl disable disk2iso 2>/dev/null || true
systemctl stop disk2iso-web 2>/dev/null || true
systemctl disable disk2iso-web 2>/dev/null || true
rm -rf "$INSTALL_DIR"
rm -f "$SERVICE_FILE"
rm -f "/etc/systemd/system/disk2iso-web.service"
rm -f "$BIN_LINK"
systemctl daemon-reload
fi
print_success "Deinstallation abgeschlossen"
return 0 # Fortfahren mit kompletter Installation
else
print_info "Installation abgebrochen"
clear
exit 0
fi
fi
else
# Text-basierter Dialog
print_warning "Bestehende Installation gefunden: $INSTALL_DIR"
if [[ -n "$version" ]]; then
echo " Version: $version"
fi
echo ""
echo "Optionen:"
echo " 1) Update (Einstellungen beibehalten)"
echo " 2) Neuinstallation (Einstellungen löschen)"
echo " 3) Abbrechen"
echo ""
read -p "Auswahl [1]: " choice
choice=${choice:-1}
case $choice in
1)
return 1 # UPDATE
;;
2)
read -p "WARNUNG: Alle Einstellungen gehen verloren! Fortfahren? [j/N]: " confirm
if [[ "$confirm" =~ ^[jJyY]$ ]]; then
if [[ -f "$INSTALL_DIR/uninstall.sh" ]]; then
"$INSTALL_DIR/uninstall.sh" --silent
else
rm -rf "$INSTALL_DIR"
rm -f "$SERVICE_FILE"
rm -f "/etc/systemd/system/disk2iso-web.service"
rm -f "$BIN_LINK"
fi
return 0 # NEUINSTALLATION
else
clear
exit 0
fi
;;
*)
clear
exit 0
;;
esac
fi
}
# Führe Reparatur durch (nur Programmdateien, keine config.sh-Änderung)
perform_repair() {
print_header "REPARATUR INSTALLATION v$INSTALLED_VERSION"
# Sichere aktuelle Konfiguration
local config_backup="/tmp/disk2iso-config-backup-$(date +%s).sh"
if [[ -f "$INSTALL_DIR/conf/disk2iso.conf" ]]; then
cp "$INSTALL_DIR/conf/disk2iso.conf" "$config_backup"
print_info "Konfiguration gesichert: $config_backup"
fi
# Stoppe laufende Services
local service_was_active=false
local web_service_was_active=false
if systemctl is-active --quiet disk2iso; then
systemctl stop disk2iso
service_was_active=true
print_info "Service disk2iso gestoppt"
fi
if systemctl is-active --quiet disk2iso-web; then
systemctl stop disk2iso-web
web_service_was_active=true
print_info "Service disk2iso-web gestoppt"
fi
# Fortschrittsanzeige
(
echo "10" ; sleep 0.5
echo "# Kopiere VERSION-Datei..."
if [[ -f "$SCRIPT_DIR/VERSION" ]]; then
cp -f "$SCRIPT_DIR/VERSION" "$INSTALL_DIR/"
fi
echo "30" ; sleep 0.3
echo "50" ; sleep 0.3
echo "# Kopiere Bibliotheken..."
cp -rf "$SCRIPT_DIR/lib" "$INSTALL_DIR/" 2>/dev/null
chmod +x "$INSTALL_DIR"/lib/*.sh 2>/dev/null
echo "60" ; sleep 0.3
echo "# Kopiere Konfiguration..."
mkdir -p "$INSTALL_DIR/conf" 2>/dev/null
cp -f "$SCRIPT_DIR/conf/disk2iso.conf" "$INSTALL_DIR/conf/" 2>/dev/null
cp -f "$SCRIPT_DIR/conf/"*.ini "$INSTALL_DIR/conf/" 2>/dev/null || true
echo "70" ; sleep 0.3
echo "# Merge Konfigurationen..."
if [[ -f "$config_backup" ]]; then
merge_config "$config_backup" "$INSTALL_DIR/conf/disk2iso.conf" >/dev/null 2>&1
rm -f "$config_backup" 2>/dev/null
fi
echo "85" ; sleep 0.3
echo "# Kopiere Dokumentation..."
if [[ -d "$SCRIPT_DIR/doc" ]]; then
cp -rf "$SCRIPT_DIR/doc" "$INSTALL_DIR/" 2>/dev/null
fi
if [[ -d "$SCRIPT_DIR/lang" ]]; then
cp -rf "$SCRIPT_DIR/lang" "$INSTALL_DIR/" 2>/dev/null
fi
if [[ -f "$SCRIPT_DIR/LICENSE" ]]; then
cp -f "$SCRIPT_DIR/LICENSE" "$INSTALL_DIR/" 2>/dev/null
fi
echo "90" ; sleep 0.3
echo "# Erstelle Dokumentations-Symlink..."
if [[ -d "$INSTALL_DIR/doc" ]]; then
mkdir -p "$INSTALL_DIR/services/disk2iso-web/static" 2>/dev/null
ln -sf "../../../doc" "$INSTALL_DIR/services/disk2iso-web/static/docs" 2>/dev/null || true
fi
echo "100"
echo "# Reparatur abgeschlossen!"
sleep 0.5
) | dialog --title "Reparatur läuft" --gauge "Starte Reparatur..." 10 70 0
# Prüfe fehlende Komponenten und biete Installation an
local missing_components=false
local install_service_now=false
local install_web_now=false
# Prüfe disk2iso.service
if [[ ! -f "$SERVICE_FILE" ]]; then
if use_dialog; then
if dialog --title "Fehlende Komponente erkannt" \
--yesno "Der disk2iso Service ist nicht installiert.\n\nMöchten Sie ihn jetzt einrichten?\n\nDies ermöglicht automatisches Starten beim Booten." \
12 70; then
install_service_now=true
missing_components=true
fi
fi
fi
# Prüfe Web-Server (Python venv)
if [[ ! -d "$INSTALL_DIR/venv" ]] || [[ ! -f "$INSTALL_DIR/venv/bin/flask" ]]; then
if use_dialog; then
if dialog --title "Optionale Komponente" \
--yesno "Web-Server ist nicht installiert.\n\nWeb-Server bietet:\n• Status-Überwachung im Browser\n• Archiv-Verwaltung und Übersicht\n• Log-Viewer mit Live-Updates\n• Responsive Design\n\nMöchten Sie den Web-Server jetzt installieren?" \
14 70; then
install_web_now=true
missing_components=true
fi
else
print_info "Web-Server ist nicht installiert"
if ask_yes_no "Web-Server jetzt installieren?" "n"; then
install_web_now=true
missing_components=true
fi
fi
fi
# Service jetzt installieren wenn gewünscht
if [[ "$install_service_now" == "true" ]]; then
# Frage Ausgabeverzeichnis
local output_dir="/media/iso"
if use_dialog; then
output_dir=$(dialog --title "Ausgabeverzeichnis" \
--inputbox "Ausgabeverzeichnis für ISOs:" \
10 60 "/media/iso" 3>&1 1>&2 2>&3) || output_dir="/media/iso"
fi
# Erstelle Service-Datei
cat > "$SERVICE_FILE" <<EOF
[Unit]
Description=disk2iso - Automatische ISO Erstellung von optischen Medien
After=multi-user.target
Wants=systemd-udevd.service
After=systemd-udevd.service
[Service]
Type=simple
User=root
Group=root
ExecStart=$INSTALL_DIR/services/disk2iso/daemon.sh -o $output_dir
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
EOF
# Aktualisiere config.sh
if [[ -f "$INSTALL_DIR/conf/disk2iso.conf" ]]; then
sed -i "s|DEFAULT_OUTPUT_DIR=.*|DEFAULT_OUTPUT_DIR=\"$output_dir\"|" "$INSTALL_DIR/conf/disk2iso.conf"
fi
# Erstelle Ausgabeverzeichnis mit Unterordnern
create_output_directory "$output_dir"
print_success "Ausgabeverzeichnis erstellt: $output_dir"
systemctl daemon-reload
systemctl enable disk2iso.service >/dev/null 2>&1
systemctl start disk2iso.service >/dev/null 2>&1
print_success "Service disk2iso installiert und gestartet"
else
# Service existiert bereits → Stelle sicher dass Ausgabeverzeichnis existiert
if [[ -f "$SERVICE_FILE" ]]; then
# Lese Ausgabeverzeichnis aus Service-Datei
local output_dir=$(grep "ExecStart=" "$SERVICE_FILE" | sed -n 's/.*-o \([^ ]*\).*/\1/p')
if [[ -z "$output_dir" ]]; then
# Fallback: Lese aus config.sh
output_dir=$(grep "DEFAULT_OUTPUT_DIR=" "$INSTALL_DIR/conf/disk2iso.conf" 2>/dev/null | cut -d'"' -f2)
fi
# Erstelle Verzeichnis falls es nicht existiert
if [[ -n "$output_dir" ]] && [[ ! -d "$output_dir" ]]; then
create_output_directory "$output_dir"
print_success "Ausgabeverzeichnis erstellt: $output_dir"
fi
fi
# Starte Services neu (falls vorher aktiv)
if [[ "$service_was_active" == "true" ]]; then
systemctl start disk2iso
print_success "Service disk2iso neu gestartet"
fi
if [[ "$web_service_was_active" == "true" ]]; then
systemctl start disk2iso-web
print_success "Service disk2iso-web neu gestartet"
fi
fi
# Web-Server jetzt installieren wenn gewünscht
if [[ "$install_web_now" == "true" ]]; then
INSTALL_WEB_SERVER=true
# Führe Web-Server Installation aus (direkt inline für Repair-Modus)
{
echo "0"
echo "XXX"
echo "Prüfe Python-Abhängigkeiten..."
echo "XXX"
# Installiere Python3 falls nötig
if ! command -v python3 >/dev/null 2>&1; then
echo "20"
echo "XXX"
echo "Installiere Python3 und pip..."
echo "XXX"
apt-get update >/dev/null 2>&1
apt-get install -y python3 python3-pip python3-venv >/dev/null 2>&1
fi
# Stelle sicher dass python3-venv installiert ist (Debian/Ubuntu brauchen separates Paket)
if ! dpkg -l | grep -q python3.*-venv; then
echo "25"
echo "XXX"
echo "Installiere python3-venv..."
echo "XXX"
apt-get install -y python3-venv >/dev/null 2>&1
fi
# Erstelle Virtual Environment
echo "40"
echo "XXX"
echo "Erstelle Python Virtual Environment..."
echo "XXX"
python3 -m venv "$INSTALL_DIR/venv" >/dev/null 2>&1
# Installiere Flask
echo "60"
echo "XXX"
echo "Installiere Flask..."
echo "XXX"
"$INSTALL_DIR/venv/bin/pip" install --quiet --upgrade pip >/dev/null 2>&1
"$INSTALL_DIR/venv/bin/pip" install --quiet flask >/dev/null 2>&1
# Erstelle Verzeichnisstruktur
echo "80"
echo "XXX"
echo "Erstelle Verzeichnisstruktur..."
echo "XXX"
mkdir -p "$INSTALL_DIR/services/disk2iso-web/templates"
mkdir -p "$INSTALL_DIR/services/disk2iso-web/static/css"
mkdir -p "$INSTALL_DIR/services/disk2iso-web/static/js"
mkdir -p "$INSTALL_DIR/services/disk2iso-web/logs"
chmod -R 755 "$INSTALL_DIR/services" 2>/dev/null || true
chmod -R 755 "$INSTALL_DIR/venv" 2>/dev/null || true
# Erstelle requirements.txt
cat > "$INSTALL_DIR/services/disk2iso-web/requirements.txt" <<'EOFREQ'
# disk2iso Web-Server Dependencies
flask>=2.0.0
EOFREQ
echo "100"
echo "XXX"
echo "Web-Server installiert!"
echo "XXX"
sleep 0.5
} | dialog --title "Web-Server Installation" \
--gauge "Installiere Web-Server-Komponenten..." 8 70 0
print_success "Web-Server installiert (Python/Flask)"
print_info "Hinweis: Flask app.py noch nicht vorhanden (Phase 2)"
fi
# Zeige Reparatur-Zusammenfassung
if use_dialog; then
dialog --title "Reparatur Abgeschlossen" --msgbox \
"disk2iso wurde erfolgreich repariert!\n\nAlle Einstellungen wurden beibehalten.\nServices wurden neu gestartet (falls aktiviert).\n\nPfad: $INSTALL_DIR\nVersion: $NEW_VERSION" \
14 70
else
print_header "REPARATUR ABGESCHLOSSEN"
print_success "disk2iso wurde repariert"
print_info "Alle Einstellungen wurden beibehalten"
echo ""
fi
clear
exit 0
}
# Führe Update durch (behält config.sh)
perform_update() {
print_header "UPDATE INSTALLATION $INSTALLED_VERSION → $NEW_VERSION"
# Sichere aktuelle Konfiguration
local config_backup="/tmp/disk2iso-config-backup-$(date +%s).sh"
if [[ -f "$INSTALL_DIR/conf/disk2iso.conf" ]]; then
cp "$INSTALL_DIR/conf/disk2iso.conf" "$config_backup"
print_info "Konfiguration gesichert: $config_backup"
fi
# Prüfe aktuellen Status
local service_enabled=false
local service_active=false
local web_service_enabled=false
local web_service_active=false
if systemctl is-enabled --quiet disk2iso 2>/dev/null; then
service_enabled=true
fi
if systemctl is-active --quiet disk2iso 2>/dev/null; then
service_active=true
fi
if systemctl is-enabled --quiet disk2iso-web 2>/dev/null; then
web_service_enabled=true
fi
if systemctl is-active --quiet disk2iso-web 2>/dev/null; then
web_service_active=true
fi
# Frage ob Benutzer Einstellungen ändern möchte
local reconfigure=false
if use_dialog; then
if dialog --title "Update-Optionen" \
--defaultno \
--yesno "Möchten Sie die Einstellungen während des Updates überprüfen/ändern?\n\nAktueller Status:\n - disk2iso Service: $([ "$service_enabled" == "true" ] && echo "aktiviert" || echo "deaktiviert")\n - disk2iso-web Service: $([ "$web_service_enabled" == "true" ] && echo "aktiviert" || echo "deaktiviert")\n\nJA: Einstellungen während Update anpassen\nNEIN: Nur Dateien aktualisieren (empfohlen)" \
16 70; then
reconfigure=true
fi
fi
# Stoppe laufende Services
if [[ "$service_active" == "true" ]]; then
systemctl stop disk2iso
print_info "Service disk2iso gestoppt"
fi
if [[ "$web_service_active" == "true" ]]; then
systemctl stop disk2iso-web
print_info "Service disk2iso-web gestoppt"
fi
# Fortschrittsanzeige während Installation
(
echo "5" ; sleep 0.5
echo "# Kopiere VERSION-Datei..."
if [[ -f "$SCRIPT_DIR/VERSION" ]]; then
cp -f "$SCRIPT_DIR/VERSION" "$INSTALL_DIR/"
fi
echo "15" ; sleep 0.3
echo "30" ; sleep 0.3
echo "# Aktualisiere Bibliotheken..."
cp -rf "$SCRIPT_DIR/lib" "$INSTALL_DIR/" 2>/dev/null
chmod +x "$INSTALL_DIR"/lib/*.sh 2>/dev/null
echo "40" ; sleep 0.3
echo "# Kopiere neue Konfiguration..."
mkdir -p "$INSTALL_DIR/conf" 2>/dev/null
cp -f "$SCRIPT_DIR/conf/disk2iso.conf" "$INSTALL_DIR/conf/" 2>/dev/null
cp -f "$SCRIPT_DIR/conf/"*.ini "$INSTALL_DIR/conf/" 2>/dev/null || true
echo "50" ; sleep 0.3
echo "# Merge Konfigurationen..."
if [[ -f "$config_backup" ]]; then
merge_config "$config_backup" "$INSTALL_DIR/conf/disk2iso.conf" >/dev/null 2>&1
fi
echo "65" ; sleep 0.3
echo "# Aktualisiere Dokumentation..."
if [[ -d "$SCRIPT_DIR/doc" ]]; then
cp -rf "$SCRIPT_DIR/doc" "$INSTALL_DIR/" 2>/dev/null
fi
echo "75" ; sleep 0.3
echo "# Aktualisiere Sprachdateien..."
if [[ -d "$SCRIPT_DIR/lang" ]]; then
cp -rf "$SCRIPT_DIR/lang" "$INSTALL_DIR/" 2>/dev/null
fi
if [[ -f "$SCRIPT_DIR/LICENSE" ]]; then
cp -f "$SCRIPT_DIR/LICENSE" "$INSTALL_DIR/" 2>/dev/null
fi
echo "80" ; sleep 0.3
echo "# Erstelle Dokumentations-Symlink..."
if [[ -d "$INSTALL_DIR/doc" ]]; then
mkdir -p "$INSTALL_DIR/services/disk2iso-web/static" 2>/dev/null
ln -sf "../../../doc" "$INSTALL_DIR/services/disk2iso-web/static/docs" 2>/dev/null || true
fi
echo "85" ; sleep 0.3
echo "# Aktualisiere Service-Dateien..."
if [[ -d "$SCRIPT_DIR/services" ]]; then
cp -rf "$SCRIPT_DIR/services" "$INSTALL_DIR/" 2>/dev/null
fi
echo "90" ; sleep 0.3
echo "# Kopiere Update-Skripte..."
cp -f "$SCRIPT_DIR/install.sh" "$INSTALL_DIR/" 2>/dev/null
chmod +x "$INSTALL_DIR/install.sh" 2>/dev/null
if [[ -f "$SCRIPT_DIR/uninstall.sh" ]]; then
cp -f "$SCRIPT_DIR/uninstall.sh" "$INSTALL_DIR/" 2>/dev/null
chmod +x "$INSTALL_DIR/uninstall.sh" 2>/dev/null
fi
echo "95"
echo "# Räume auf..."
rm -f "$config_backup"
echo "100"
echo "# Update abgeschlossen!"
sleep 0.5
) | dialog --title "Update wird durchgeführt" --gauge "Starte Update von v$INSTALLED_VERSION auf v$NEW_VERSION..." 10 70 0
# Optional: Einstellungen anpassen
if [[ "$reconfigure" == "true" ]]; then
if use_dialog; then
# Service-Status ändern?
if dialog --title "Service-Konfiguration" \
--yesno "disk2iso Service aktuell: $([ "$service_enabled" == "true" ] && echo "aktiviert" || echo "deaktiviert")\n\nMöchten Sie den Service-Status ändern?" \
10 70; then
if dialog --title "Service aktivieren" \
--yesno "disk2iso Service aktivieren und starten?" \
8 50; then
systemctl enable disk2iso 2>/dev/null || true
systemctl start disk2iso 2>/dev/null || true
service_enabled=true
service_active=true
print_success "Service disk2iso aktiviert und gestartet"
else
systemctl disable disk2iso 2>/dev/null || true
service_enabled=false
service_active=false
print_info "Service disk2iso deaktiviert"
fi
fi
fi
else
# Starte Services mit altem Status neu
if [[ "$service_enabled" == "true" ]] && [[ "$service_active" == "true" ]]; then
systemctl start disk2iso
print_success "Service disk2iso neu gestartet"
fi
if [[ "$web_service_enabled" == "true" ]] && [[ "$web_service_active" == "true" ]]; then
systemctl start disk2iso-web
print_success "Service disk2iso-web neu gestartet"
fi
fi
# Prüfe fehlende Komponenten nach Update
local missing_components=false
local install_service_now=false
# Prüfe disk2iso.service
if [[ ! -f "$SERVICE_FILE" ]]; then
if use_dialog; then
if dialog --title "Fehlende Komponente erkannt" \
--yesno "Der disk2iso Service ist nicht installiert.\n\nMöchten Sie ihn jetzt einrichten?\n\nDies ermöglicht automatisches Starten beim Booten." \
12 70; then
install_service_now=true
missing_components=true
fi
fi
fi
# Prüfe Web-Server (Python venv)
if [[ ! -d "$INSTALL_DIR/venv" ]] || [[ ! -f "$INSTALL_DIR/venv/bin/flask" ]]; then
if use_dialog; then
if dialog --title "Optionale Komponente" \
--yesno "Web-Server ist nicht installiert.\n\nWeb-Server bietet:\n• Status-Überwachung im Browser\n• Archiv-Verwaltung und Übersicht\n• Log-Viewer mit Live-Updates\n• Responsive Design\n\nMöchten Sie den Web-Server jetzt installieren?" \
14 70; then
install_web_now=true
missing_components=true
fi
else
print_info "Web-Server ist nicht installiert"
if ask_yes_no "Web-Server jetzt installieren?" "n"; then
install_web_now=true
missing_components=true
fi
fi
fi
# Service jetzt installieren wenn gewünscht
if [[ "$install_service_now" == "true" ]]; then
# Frage Ausgabeverzeichnis
local output_dir="/media/iso"
if use_dialog; then
output_dir=$(dialog --title "Ausgabeverzeichnis" \
--inputbox "Ausgabeverzeichnis für ISOs:" \
10 60 "/media/iso" 3>&1 1>&2 2>&3) || output_dir="/media/iso"
fi
# Erstelle Service-Datei
cat > "$SERVICE_FILE" <<EOF
[Unit]
Description=disk2iso - Automatische ISO Erstellung von optischen Medien
After=multi-user.target
Wants=systemd-udevd.service
After=systemd-udevd.service
[Service]
Type=simple
User=root
Group=root
ExecStart=$INSTALL_DIR/services/disk2iso/daemon.sh -o $output_dir
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
EOF
# Aktualisiere config.sh
if [[ -f "$INSTALL_DIR/conf/disk2iso.conf" ]]; then
sed -i "s|DEFAULT_OUTPUT_DIR=.*|DEFAULT_OUTPUT_DIR=\"$output_dir\"|" "$INSTALL_DIR/conf/disk2iso.conf"
fi
# Erstelle Ausgabeverzeichnis mit Unterordnern
create_output_directory "$output_dir"
print_success "Ausgabeverzeichnis erstellt: $output_dir"
systemctl daemon-reload
systemctl enable disk2iso.service >/dev/null 2>&1
systemctl start disk2iso.service >/dev/null 2>&1
service_enabled=true
service_active=true
print_success "Service disk2iso installiert und gestartet"
else
# Service existiert bereits → Stelle sicher dass Ausgabeverzeichnis existiert
if [[ -f "$SERVICE_FILE" ]]; then
# Lese Ausgabeverzeichnis aus Service-Datei
local output_dir=$(grep "ExecStart=" "$SERVICE_FILE" | sed -n 's/.*-o \([^ ]*\).*/\1/p')
if [[ -z "$output_dir" ]]; then
# Fallback: Lese aus config.sh
output_dir=$(grep "DEFAULT_OUTPUT_DIR=" "$INSTALL_DIR/conf/disk2iso.conf" 2>/dev/null | cut -d'"' -f2)
fi
# Erstelle Verzeichnis falls es nicht existiert
if [[ -n "$output_dir" ]] && [[ ! -d "$output_dir" ]]; then
create_output_directory "$output_dir"
print_success "Ausgabeverzeichnis erstellt: $output_dir"
fi
fi
fi
# Web-Server jetzt installieren wenn gewünscht
if [[ "$install_web_now" == "true" ]]; then
INSTALL_WEB_SERVER=true
# Führe Web-Server Installation aus (direkt inline für Update-Modus)
{
echo "0"
echo "XXX"
echo "Prüfe Python-Abhängigkeiten..."
echo "XXX"
# Installiere Python3 falls nötig
if ! command -v python3 >/dev/null 2>&1; then
echo "20"
echo "XXX"
echo "Installiere Python3 und pip..."
echo "XXX"
apt-get update >/dev/null 2>&1
apt-get install -y python3 python3-pip python3-venv >/dev/null 2>&1
fi
# Stelle sicher dass python3-venv installiert ist (Debian/Ubuntu brauchen separates Paket)
if ! dpkg -l | grep -q python3.*-venv; then
echo "25"
echo "XXX"
echo "Installiere python3-venv..."
echo "XXX"
apt-get install -y python3-venv >/dev/null 2>&1
fi
# Erstelle Virtual Environment
echo "40"
echo "XXX"
echo "Erstelle Python Virtual Environment..."
echo "XXX"
python3 -m venv "$INSTALL_DIR/venv" >/dev/null 2>&1
# Installiere Flask
echo "60"
echo "XXX"
echo "Installiere Flask..."
echo "XXX"
"$INSTALL_DIR/venv/bin/pip" install --quiet --upgrade pip >/dev/null 2>&1
"$INSTALL_DIR/venv/bin/pip" install --quiet flask >/dev/null 2>&1
# Erstelle Verzeichnisstruktur
echo "80"
echo "XXX"
echo "Erstelle Verzeichnisstruktur..."
echo "XXX"
mkdir -p "$INSTALL_DIR/services/disk2iso-web/templates"
mkdir -p "$INSTALL_DIR/services/disk2iso-web/static/css"
mkdir -p "$INSTALL_DIR/services/disk2iso-web/static/js"
mkdir -p "$INSTALL_DIR/services/disk2iso-web/logs"
chmod -R 755 "$INSTALL_DIR/services" 2>/dev/null || true
chmod -R 755 "$INSTALL_DIR/venv" 2>/dev/null || true
# Erstelle requirements.txt
cat > "$INSTALL_DIR/services/disk2iso-web/requirements.txt" <<'EOFREQ'
# disk2iso Web-Server Dependencies
flask>=2.0.0
EOFREQ
echo "100"
echo "XXX"
echo "Web-Server installiert!"
echo "XXX"
sleep 0.5
} | dialog --title "Web-Server Installation" \
--gauge "Installiere Web-Server-Komponenten..." 8 70 0
print_success "Web-Server installiert (Python/Flask)"
print_info "Hinweis: Flask app.py noch nicht vorhanden (Phase 2)"
fi
# Zeige Update-Zusammenfassung
if use_dialog; then
local summary="disk2iso wurde erfolgreich aktualisiert!
Version: $INSTALLED_VERSION → $NEW_VERSION
Alle Einstellungen wurden beibehalten.
Service-Status:
- disk2iso: $([ "$service_enabled" == "true" ] && echo "aktiviert" || echo "deaktiviert") $([ "$service_active" == "true" ] && echo "(läuft)" || echo "(gestoppt)")
- disk2iso-web: $([ "$web_service_enabled" == "true" ] && echo "aktiviert" || echo "deaktiviert") $([ "$web_service_active" == "true" ] && echo "(läuft)" || echo "(gestoppt)")
Pfad: $INSTALL_DIR
Hinweis: Überprüfen Sie die Dokumentation für neue Features!"
dialog --title "Update Abgeschlossen" --msgbox "$summary" 20 70
else