-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·2117 lines (1889 loc) · 83.8 KB
/
install.sh
File metadata and controls
executable file
·2117 lines (1889 loc) · 83.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
#!/usr/bin/env bash
# This file is part of PhotonFrame - VideoKit.
# Copyright (c) 2024–2025 David <…>
# Licensed under the MIT License. See LICENSE in the project root for details.
# -----------------------------------------------------------------------------
# install.sh - PhotonFrame - VideoKit + Real-ESRGAN/RealCUGAN + (optional) BasicVSR++
# - Language prompt (en/de) at start
# - OS/GPU detection -> auto backend selection (torch|ncnn) with CPU/GPU pref
# - Model downloads chosen per OS/Hardware (PyTorch or NCNN), always via the
# robust download ladder (resume, retries, fallbacks) to work on bad links
# - BasicVSR++ (Torch) optional; installs mmengine/mmcv/mmagic + tries weights
# - At the end: writes ~/.config/PhotonFrameVideoKit/config.ini with detected choices
# - Safe: does NOT touch system GPU drivers; favors offline/cached installs
# -----------------------------------------------------------------------------
set -Eeuo pipefail
set -o errtrace
trap 'rc=$?; echo -e "\e[31m[install]\e[0m Error at line $LINENO: \"$BASH_COMMAND\" (rc=$rc)"; exit $rc' ERR
[[ "${DEBUG_INSTALL:-0}" = "1" ]] && set -x
export PYTHONWARNINGS="ignore::DeprecationWarning"
export MKL_INTERFACE_LAYER="${MKL_INTERFACE_LAYER:-}"
export CONDA_MKL_INTERFACE_LAYER_BACKUP="${CONDA_MKL_INTERFACE_LAYER_BACKUP:-}"
ENV_NAME="PhotonFrameVideoKit"
PYTHON_VERSION="${PYTHON_VERSION:-3.10.*}" # conda will pick a recent 3.10.x
VIDEO_CMD="video"
GREEN='\e[1;36m'; CEND='\e[0m'
# ───────────────────────────── Language handling ────────────────────────────
VM_LANG="en"
IMPACT_OPT_IN="${IMPACT_OPT_IN:-}"
declare -A INSTALL_I18N_DE=(
["Language set to %s."]="Sprache gesetzt auf %s."
["Prefer GPU acceleration if available?"]="GPU-Beschleunigung bevorzugen, falls verfuegbar?"
["User prefers GPU (if available)."]="Nutzer bevorzugt GPU (falls verfuegbar)."
["User prefers CPU."]="Nutzer bevorzugt CPU."
["Install AI features (Real-ESRGAN, RealCUGAN, PyTorch, CUDA, ...)?"]="KI-Funktionen installieren (Real-ESRGAN, RealCUGAN, PyTorch, CUDA, ...)?"
["Install CodeFormer (face restoration, NON-COMMERCIAL S-Lab License 1.0)?"]="CodeFormer installieren (Gesichtsrestauration, nicht-kommerzielle S-Lab-Lizenz 1.0)?"
["CodeFormer requires the NON-COMMERCIAL S-Lab License 1.0. Do not use it commercially."]="CodeFormer unterliegt der nicht-kommerziellen S-Lab-Lizenz 1.0. Keine kommerzielle Nutzung."
["CodeFormer installation enabled."]="CodeFormer-Installation aktiviert."
["CodeFormer installation skipped (non-commercial license)."]="CodeFormer-Installation ausgelassen (nicht-kommerzielle Lizenz)."
["Skipping CodeFormer (non-commercial license)."]="CodeFormer wird aufgrund der nicht-kommerziellen Lizenz ausgelassen."
["CodeFormer is not installed - skipping weight download."]="CodeFormer ist nicht installiert - Gewichte werden ausgelassen."
["Download Impact font (Impact 2.35) now? This requires accepting the Microsoft Core Fonts EULA."]="Impact-Schrift (Impact 2.35) jetzt herunterladen? Dafuer muss die Microsoft-Core-Fonts-EULA akzeptiert werden."
["Impact font download skipped. GIF captions will use fallback fonts."]="Impact-Schrift-Download uebersprungen. GIF-Texte verwenden Ersatzschrift."
["cabextract missing - please install it manually to extract Microsoft Core Fonts."]="cabextract fehlt - bitte manuell installieren, um die Microsoft-Core-Fonts zu extrahieren."
["No supported package manager for cabextract detected - please install it manually."]="Kein unterstuetzter Paketmanager fuer cabextract erkannt - bitte manuell installieren."
["cabextract is required but could not be installed automatically."]="cabextract wird benoetigt, konnte aber nicht automatisch installiert werden."
["Homebrew not found – please install cabextract manually (https://www.cabextract.org.uk/)."]="Homebrew nicht gefunden – bitte cabextract manuell installieren (https://www.cabextract.org.uk/)."
["Impact installer download failed (%s)."]="Impact-Installer konnte nicht geladen werden (%s)."
["cabextract could not extract impact.ttf - please check manually."]="cabextract konnte impact.ttf nicht extrahieren - bitte manuell pruefen."
["impact.ttf missing in archive - installation skipped."]="impact.ttf wurde nicht gefunden - Installation uebersprungen."
["Impact font already present: %s"]="Impact-Schrift bereits vorhanden: %s"
["Impact font installed: %s"]="Impact-Schrift installiert: %s"
["cabextract missing - Impact cannot be installed automatically. Please install the font manually."]="cabextract fehlt - Impact kann nicht automatisch installiert werden. Bitte Schrift manuell installieren."
["No supported Linux package manager detected – please install ExifTool manually."]="Kein unterstuetzter Linux-Paketmanager erkannt – bitte ExifTool manuell installieren."
["Installing ExifTool inside Conda env: %s"]="Installiere ExifTool im Conda-Env: %s"
["ExifTool (Conda) OK: %s"]="ExifTool (Conda) OK: %s"
["Conda installation of ExifTool failed - trying system package."]="Conda-Installation von ExifTool fehlgeschlagen - Systempaket wird versucht."
["Homebrew not found - install Homebrew or use the official ExifTool pkg."]="Homebrew nicht gefunden - bitte Homebrew installieren oder das offizielle ExifTool-Paket verwenden."
["ExifTool already present: %s"]="ExifTool bereits vorhanden: %s"
["ExifTool installed: %s"]="ExifTool installiert: %s"
["ExifTool could not be installed."]="ExifTool konnte nicht installiert werden."
["Windows users: please open an elevated PowerShell and run 'choco install exiftool' or 'scoop install exiftool'."]="Windows: bitte PowerShell mit Administratorrechten oeffnen und 'choco install exiftool' oder 'scoop install exiftool' ausfuehren."
["Hint: your realesrgan-ncnn-vulkan wrapper does not pass a -m path."]="Hinweis: Dein realesrgan-ncnn-vulkan-Wrapper uebergibt keinen -m Pfad."
["You can add it like this: exec \".../realesrgan-ncnn-vulkan\" -m \"\$MODELS_DIR\" \"\$@\""]="Du kannst ihn so ergaenzen: exec \".../realesrgan-ncnn-vulkan\" -m \"\$MODELS_DIR\" \"\$@\""
["Environment exports written for face models."]="Umgebungsvariablen fuer Face-Modelle gesetzt."
["GFPGAN weights mirrored to %s (including v1.3 symlink)."]="GFPGAN-Gewichte nach %s kopiert (inkl. v1.3-Symlink)."
["CodeFormer weight mirrored to %s."]="CodeFormer-Gewicht nach %s kopiert."
["[impact] The Impact typeface is part of Microsoft's Core fonts for the Web."]="[impact] Die Impact-Schrift gehoert zu Microsofts Core Fonts fuer das Web."
["[impact] To comply with the EULA we only download the original impact32.exe from SourceForge after explicit consent."]="[impact] Zur Einhaltung der EULA laden wir impact32.exe nur nach ausdruecklicher Zustimmung von SourceForge."
["[impact] License text: https://sourceforge.net/projects/corefonts/files/ (Microsoft Core Fonts EULA)."]="[impact] Lizenztext: https://sourceforge.net/projects/corefonts/files/ (Microsoft-Core-Fonts-EULA)."
["Downloading Impact installer -> %s"]="Impact-Installer wird geladen -> %s"
["Extracting impact.ttf from impact32.exe via cabextract..."]="impact.ttf wird via cabextract aus impact32.exe extrahiert..."
["CodeFormer weight missing."]="CodeFormer-Gewicht fehlt."
["GFPGANv1.4 missing."]="GFPGANv1.4 fehlt."
["Skipping Impact/Corefonts download because VIDEO_NO_PROPRIETARY_FONTS=1."]="Impact/Corefonts-Download uebersprungen, da VIDEO_NO_PROPRIETARY_FONTS=1."
["[y/n] (default %s):"]="[j/n] (Standard %s):"
["config.ini copied from src.tar.gz -> %s"]="config.ini aus src.tar.gz uebernommen -> %s"
["Existing config.ini kept or none found in archive."]="Bestehende config.ini beibehalten oder keine im Archiv gefunden."
["Wrote THIRD_PARTY_LICENSES.md to %s"]="THIRD_PARTY_LICENSES.md nach %s geschrieben"
["Third-party license summary updated."]="Drittanbieter-Lizenzuebersicht aktualisiert."
)
loc() {
local key="$1"
if [[ "$VM_LANG" == "de" ]]; then
printf "%s" "${INSTALL_I18N_DE[$key]:-$key}"
else
printf "%s" "$key"
fi
}
loc_printf() {
local fmt
fmt="$(loc "$1")"
shift
printf "$fmt" "$@"
}
log() { echo -e "\e[32m[install]\e[0m $(loc "$*")"; }
warn() { echo -e "\e[33m[install]\e[0m $(loc "$*")" >&2; }
err() { echo -e "\e[31m[install]\e[0m $(loc "$*")" >&2; exit 1; }
# ───────────────────────────── Language prompt (EN/DE) ──────────────────────
ask_language() {
local ans
echo -ne "${GREEN}Select language for PhotonFrame - VideoKit / Sprache fuer PhotonFrame - VideoKit waehlen [1] English / [2] Deutsch (default: 1): ${CEND}"
read -r ans || ans=""
case "${ans:-1}" in
2) VM_LANG="de" ;;
*) VM_LANG="en" ;;
esac
log "$(loc_printf "Language set to %s." "${VM_LANG}")"
}
# ───────────────────────────── OS-/GPU detection ────────────────────────────
detect_os_name() {
local s="$(uname -s | tr '[:upper:]' '[:lower:]')"
if [[ "$s" == *linux* ]]; then echo "linux"
elif [[ "$s" == *darwin* ]]; then echo "mac"
elif [[ "$s" == *mingw* || "$s" == *msys* || "$s" == *cygwin* ]]; then echo "windows"
else echo "linux"; fi
}
detect_gpu_backend() {
# echo "<has_gpu> <backend_guess>"
if command -v nvidia-smi &>/dev/null; then
echo "true cuda"; return
fi
if [[ "$(detect_os_name)" == "mac" ]]; then
echo "true mps"; return
fi
echo "false none"
}
PREFER_GPU=true
INSTALL_CODEFORMER=true
ask_prefer_gpu() {
if ask_question "Prefer GPU acceleration if available?" "y"; then
PREFER_GPU=true
log "User prefers GPU (if available)."
else
PREFER_GPU=false
log "User prefers CPU."
fi
}
# ───────────────── Impact: Hinweis + frühe Abfrage (EULA) ────────────────────
prompt_impact_opt_in() {
# bereits entschieden oder via VIDEO_NO_PROPRIETARY_FONTS erzwungen?
if [[ "${VIDEO_NO_PROPRIETARY_FONTS:-0}" = "1" ]]; then
log "Skipping Impact/Corefonts download because VIDEO_NO_PROPRIETARY_FONTS=1."
IMPACT_OPT_IN="no"
return 0
fi
if [[ -n "${IMPACT_OPT_IN:-}" ]]; then
return 0
fi
log "[impact] The Impact typeface is part of Microsoft's Core fonts for the Web."
log "[impact] To comply with the EULA we only download the original impact32.exe from SourceForge after explicit consent."
log "[impact] License text: https://sourceforge.net/projects/corefonts/files/ (Microsoft Core Fonts EULA)."
if ask_question "Download Impact font (Impact 2.35) now? This requires accepting the Microsoft Core Fonts EULA." "n"; then
IMPACT_OPT_IN="yes"
else
IMPACT_OPT_IN="no"
warn "Impact font download skipped. GIF captions will use fallback fonts."
fi
}
# ───────────────────── Safety: block system GPU driver installs ─────────────
BLOCKED_APT_REGEX='^(nvidia-|cuda)'
apt_install_safe() {
local pkgs=()
for p in "$@"; do
if [[ "$p" =~ $BLOCKED_APT_REGEX ]]; then
err "Safety block: refusing apt install '$p' (would change NVIDIA/CUDA drivers)."
fi
pkgs+=("$p")
done
apt_with_retries install -y "${pkgs[@]}"
}
# ─────────────────────────── Networking / download ──────────────────────────
ask_question() {
local prompt="$1" default reply display_default
default="${2:-y}"
display_default="$default"
# Sprache: Default-Buchstaben anpassen (y -> j)
if [[ "${VM_LANG:-en}" == "de" ]]; then
case "${default,,}" in
y|j) display_default="j" ;;
n) display_default="n" ;;
esac
fi
while true; do
echo -en "$GREEN$(loc "$prompt") $(loc_printf "[y/n] (default %s):" "$display_default") ${CEND}"
read -r reply || reply=""
reply="${reply:-$default}"
case "$reply" in [YyJj]*) return 0 ;; [Nn]*) return 1 ;; esac
done
}
is_case_insensitive_fs() {
# Detect case-insensitive mounts (e.g., Windows/NTFS via WSL drvfs)
local dir="${1:-.}" probe mountpoint options
probe="$dir"
while [[ ! -d "$probe" && "$probe" != "/" ]]; do
probe="$(dirname "$probe")"
done
mountpoint="$(stat -c %m "$probe" 2>/dev/null || stat -f %m "$probe" 2>/dev/null || true)"
if [[ -n "$mountpoint" ]]; then
while IFS=' ' read -r _ target _ opts _; do
if [[ "$target" == "$mountpoint" ]]; then
options="$opts"
break
fi
done </proc/mounts 2>/dev/null || true
if [[ "$options" == *"case=off"* || "$options" == *"ignore_case=1"* ]]; then
return 0
fi
fi
local lower="$probe/.case_test_$$.lower" upper="$probe/.case_test_$$.LOWER"
rm -f "$lower" "$upper"
if touch "$lower" 2>/dev/null && touch "$upper" 2>/dev/null; then
local inode_lower inode_upper
inode_lower=$(stat -c %i "$lower" 2>/dev/null || stat -f %i "$lower" 2>/dev/null || echo "")
inode_upper=$(stat -c %i "$upper" 2>/dev/null || stat -f %i "$upper" 2>/dev/null || echo "")
rm -f "$lower" "$upper"
[[ -n "$inode_lower" && "$inode_lower" == "$inode_upper" ]] && return 0
return 1
fi
rm -f "$lower" "$upper"
return 1
}
get_site_packages() {
python - <<'PY'
import sysconfig
print(sysconfig.get_paths()["purelib"])
PY
}
wait_for_net() {
local tries="${1:-999999}" delay="${2:-20}"
local urls=("https://conda.anaconda.org/conda-forge" "https://pypi.org/simple" "https://github.com" "https://download.pytorch.org")
local ok=0 t=1
while (( t<=tries )); do
for u in "${urls[@]}"; do
if curl -sI --connect-timeout 10 --max-time 20 "$u" >/dev/null; then ok=1; break; fi
done
(( ok==1 )) && return 0
warn "No internet (attempt $t/$tries). Waiting ${delay}s..."
sleep "$delay"; ((t++))
done
return 1
}
# Accept 2xx **und** 3xx, da wir -L / Redirects nutzen
http_ok() {
local url="$1"
local code
code="$(curl -sIL -o /dev/null -w '%{http_code}' -H 'User-Agent: curl/8' "$url" || echo 000)"
[[ "$code" =~ ^(20[0-9]|30[0-9])$ ]]
}
conda_accept_tos() {
# Accept Anaconda repo ToS non-interactively (newer conda requires this)
if conda help tos >/dev/null 2>&1; then
local channels=(
"https://repo.anaconda.com/pkgs/main"
"https://repo.anaconda.com/pkgs/r"
)
for ch in "${channels[@]}"; do
if conda tos accept --yes --override-channels --channel "$ch" >/dev/null 2>&1; then
log "Accepted Anaconda ToS for $ch."
else
warn "Could not auto-accept Anaconda ToS for $ch. If installs fail, run: conda tos accept --override-channels --channel \"$ch\""
fi
done
fi
}
ensure_aria2c() {
if ! command -v aria2c &>/dev/null; then
if command -v apt-get &>/dev/null; then
log "Installing aria2..."
sudo apt-get update -qq || true
apt_install_safe aria2 || warn "aria2 install failed"
elif command -v pacman &>/dev/null; then
sudo pacman -Sy --noconfirm aria2 || warn "aria2 install failed"
elif command -v dnf &>/dev/null; then
sudo dnf install -y aria2 || warn "aria2 install failed"
elif command -v brew &>/dev/null; then
brew install aria2 || warn "aria2 install failed"
else
warn "No supported package manager for aria2 - please install manually."
fi
fi
}
ensure_unzip() {
if ! command -v unzip &>/dev/null; then
if command -v apt-get &>/dev/null; then
sudo apt-get update -qq || true
apt_install_safe unzip || true
elif command -v pacman &>/dev/null; then
sudo pacman -Sy --noconfirm unzip || true
elif command -v dnf &>/dev/null; then
sudo dnf install -y unzip || true
elif command -v zypper &>/dev/null; then
sudo zypper --non-interactive in unzip || true
fi
fi
}
# ───────────────────────── Impact font (Microsoft Core Fonts) ───────────────
impact_font_target_dir() {
local os="${1:-$(detect_os_name)}"
case "$os" in
mac) echo "$HOME/Library/Application Support/PhotonFrameVideoKit/fonts" ;;
windows)
local base="${LOCALAPPDATA:-$HOME/.local/share}"
echo "$base/PhotonFrameVideoKit/fonts"
;;
*)
local xdg="${XDG_DATA_HOME:-$HOME/.local/share}"
echo "$xdg/PhotonFrameVideoKit/fonts"
;;
esac
}
impact_font_path() {
local os="${1:-$(detect_os_name)}"
local dir
dir="$(impact_font_target_dir "$os")"
printf '%s/impact.ttf\n' "$dir"
}
impact_font_installed() {
local os="${1:-$(detect_os_name)}"
local dest
dest="$(impact_font_path "$os")"
[[ -f "$dest" ]]
}
ensure_cabextract() {
if command -v cabextract >/dev/null 2>&1; then
return 0
fi
local os="${1:-$(detect_os_name)}"
case "$os" in
linux)
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update -qq || true
apt_install_safe cabextract || true
elif command -v pacman >/dev/null 2>&1; then
sudo pacman -Sy --noconfirm cabextract || true
elif command -v dnf >/dev/null 2>&1; then
sudo dnf install -y cabextract || true
elif command -v zypper >/dev/null 2>&1; then
sudo zypper --non-interactive in cabextract || true
else
warn "No supported package manager for cabextract detected - please install it manually."
return 1
fi
;;
mac)
if command -v brew >/dev/null 2>&1; then
brew install cabextract || true
else
warn "Homebrew not found - please install cabextract manually (https://www.cabextract.org.uk/)."
return 1
fi
;;
*)
warn "cabextract is required but could not be installed automatically."
return 1
;;
esac
command -v cabextract >/dev/null 2>&1
}
install_impact_font() {
local os="${1:-$(detect_os_name)}"
local dest_dir dest impact_url tmp exe extracted
dest="$(impact_font_path "$os")"
dest_dir="$(impact_font_target_dir "$os")"
impact_url="https://downloads.sourceforge.net/corefonts/impact32.exe"
if impact_font_installed "$os"; then
log "$(loc_printf "Impact font already present: %s" "$dest")"
return 0
fi
if [[ "${VIDEO_NO_PROPRIETARY_FONTS:-0}" = "1" ]]; then
log "Skipping Impact/Corefonts download because VIDEO_NO_PROPRIETARY_FONTS=1."
return 0
fi
if [[ "${IMPACT_OPT_IN:-no}" != "yes" ]]; then
warn "Impact font download skipped. GIF captions will use fallback fonts."
return 0
fi
if ! ensure_cabextract "$os"; then
warn "cabextract missing - Impact cannot be installed automatically. Please install the font manually."
return 0
fi
tmp="$(mktemp -d "${TMPDIR:-/tmp}/impact-font.XXXXXX")"
exe="$tmp/impact32.exe"
log "$(loc_printf "Downloading Impact installer -> %s" "$exe")"
if ! download_with_retries "$impact_url" "$exe" 60 10; then
warn "$(loc_printf "Impact installer download failed (%s)." "$impact_url")"
rm -rf "$tmp"
return 0
fi
log "Extracting impact.ttf from impact32.exe via cabextract..."
if ! cabextract -F impact.ttf -d "$tmp" "$exe" >/dev/null 2>&1; then
warn "cabextract could not extract impact.ttf - please check manually."
rm -rf "$tmp"
return 0
fi
extracted="$tmp/impact.ttf"
if [ ! -f "$extracted" ]; then
warn "impact.ttf missing in archive - installation skipped."
rm -rf "$tmp"
return 0
fi
mkdir -p "$dest_dir"
install -m 0644 "$extracted" "$dest"
rm -rf "$tmp"
log "$(loc_printf "Impact font installed: %s" "$dest")"
if command -v fc-cache >/dev/null 2>&1; then
fc-cache -f "$dest_dir" >/dev/null 2>&1 || true
fi
}
write_third_party_licenses() {
local dest="$INSTALL_DIR/THIRD_PARTY_LICENSES.md"
local cf_status
if $INSTALL_CODEFORMER; then
cf_status="Installed because you accepted the S-Lab Non-Commercial License."
else
cf_status="Not installed (opt-out or feature disabled during setup)."
fi
cat > "$dest" <<EOF
# Third-Party Licenses
This document lists third-party projects and assets that the PhotonFrame - VideoKit installer downloads or references. Please review the upstream licenses before using the software.
## Microsoft Core Fonts - Impact
- Source: https://downloads.sourceforge.net/corefonts/
- License: Microsoft Core Fonts EULA (proprietary, non-redistributable except via original installer).
- Notes: impact32.exe is downloaded only after you accept the license during installation.
- PhotonFrame - VideoKit does not redistribute the Impact font. The installer only downloads the original impact32.exe from the official Core Fonts mirror after you accept the Microsoft EULA.
## Real-ESRGAN (PyTorch)
- Repository: https://github.com/xinntao/Real-ESRGAN
- License: BSD 3-Clause (see upstream LICENSE file).
## Real-ESRGAN NCNN / RealCUGAN NCNN
- Repository: https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan and https://github.com/nihui/realcugan-ncnn-vulkan
- License: See upstream repositories for the respective MIT/BSD style licenses.
## BasicSR
- Repository: https://github.com/XPixelGroup/BasicSR
- License: Apache License 2.0.
## facexlib
- Repository: https://github.com/xinntao/facexlib
- License: MIT License.
## GFPGAN
- Repository: https://github.com/TencentARC/GFPGAN
- License: Apache License 2.0.
## CodeFormer (optional)
- Repository: https://github.com/sczhou/CodeFormer
- License: S-Lab Non-Commercial License 1.0 (non-commercial use only).
- Status: $cf_status
## Additional dependencies
- PyTorch, torchvision, NCNN binaries, Conda packages, and other libraries remain under their respective upstream licenses. Please consult the downloaded repositories or package metadata for details.
## Notes
- All these components are cloned from their upstream repositories during installation. Please refer to the LICENSE file in each cloned repository for the full legal terms.
EOF
log "$(loc_printf "Wrote THIRD_PARTY_LICENSES.md to %s" "$dest")"
log "Third-party license summary updated."
}
download_with_retries() {
local url="$1" dest="$2" attempts="${3:-160}" base_sleep="${4:-10}"
mkdir -p "$(dirname "$dest")"
local i=1 ok=0 sleep_s="$base_sleep"
while (( i<=attempts )); do
wait_for_net 999999 10
if ! http_ok "$url"; then
warn "HTTP precheck failed (not 200) for $url (try $i/$attempts)"
else
if [[ "$url" == https://github.com/* ]]; then
if command -v curl >/dev/null; then
curl -L --fail --retry 80 --retry-delay 5 --retry-all-errors \
-H 'User-Agent: curl/8' \
-C - "$url" -o "$dest" && ok=1 || ok=0
elif command -v aria2c >/dev/null; then
aria2c --console-log-level=warn --summary-interval=0 \
-c -x4 -s4 --min-split-size=5M \
--file-allocation=none --auto-file-renaming=false \
--user-agent='curl/8' \
-o "$(basename "$dest")" -d "$(dirname "$dest")" "$url" && ok=1 || ok=0
fi
else
if command -v aria2c >/dev/null; then
aria2c --console-log-level=warn --summary-interval=0 \
-c -x16 -s16 -k1M --file-allocation=none \
--auto-file-renaming=false --max-tries=0 --retry-wait=5 \
-o "$(basename "$dest")" -d "$(dirname "$dest")" "$url" && ok=1 || ok=0
fi
if [[ $ok -eq 0 ]] && command -v curl >/dev/null; then
curl -L --fail --retry 200 --retry-delay 5 --retry-all-errors \
-C - "$url" -o "$dest" && ok=1 || ok=0
fi
if [[ $ok -eq 0 ]] && command -v wget >/dev/null; then
wget -c --tries=0 --timeout=60 "$url" -O "$dest" && ok=1 || ok=0
fi
fi
fi
if [[ $ok -eq 1 && -s "$dest" ]]; then
return 0
fi
warn "Download error: $url (attempt $i/$attempts). Backoff ${sleep_s}s..."
sleep "$sleep_s"
(( sleep_s < 180 )) && sleep_s=$(( sleep_s * 2 ))
((i++))
done
return 1
}
zip_valid() { local f="$1"; [[ -s "$f" ]] && unzip -tqq "$f" >/dev/null 2>&1; }
tar_valid() { [[ -s "$1" ]] && tar -tf "$1" >/dev/null 2>&1; }
file_min_ok() { local f="$1" min="${2:-1}"; [[ -s "$f" ]] && [[ $(stat -c%s "$f" 2>/dev/null || echo 0) -ge "$min" ]]; }
# ─────────────────────────── ExifTool installer (Conda-first) ───────────────
ensure_exiftool() {
# Schon vorhanden?
if command -v exiftool >/dev/null 2>&1; then
local ex_ver="$(exiftool -ver 2>/dev/null || echo ok)"
log "$(loc_printf "ExifTool already present: %s" "$ex_ver")"
return 0
fi
local OS_NAME_LOCAL="${1:-$(detect_os_name)}"
# 1) Prefer installing inside the active Conda env (isolated)
if command -v conda >/dev/null 2>&1 && [[ -n "${CONDA_PREFIX:-}" ]]; then
log "$(loc_printf "Installing ExifTool inside Conda env: %s" "$CONDA_PREFIX")"
if conda_retry 16 install -y -c conda-forge exiftool; then
if command -v exiftool >/dev/null 2>&1; then
local ex_ver="$(exiftool -ver 2>/dev/null || echo ok)"
log "$(loc_printf "ExifTool (Conda) OK: %s" "$ex_ver")"
return 0
fi
else
warn "Conda installation of ExifTool failed - trying system package."
fi
fi
# 2) Fallback: use OS package manager
case "$OS_NAME_LOCAL" in
linux)
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update -qq || true
# Ubuntu/Debian: package name varies by release ('exiftool' or 'libimage-exiftool-perl')
apt_install_safe exiftool || apt_install_safe libimage-exiftool-perl || true
elif command -v pacman >/dev/null 2>&1; then
sudo pacman -Sy --noconfirm perl-image-exiftool || true
elif command -v dnf >/dev/null 2>&1; then
sudo dnf install -y perl-Image-ExifTool || true
elif command -v zypper >/dev/null 2>&1; then
sudo zypper --non-interactive in exiftool || sudo zypper --non-interactive in perl-Image-ExifTool || true
else
warn "No supported Linux package manager detected - please install ExifTool manually."
fi
;;
mac)
if command -v brew >/dev/null 2>&1; then
brew install exiftool || true
else
warn "Homebrew not found - install Homebrew or use the official ExifTool pkg."
fi
;;
windows)
# This Bash installer does not support Windows directly; show PowerShell hint:
warn "Windows users: please open an elevated PowerShell and run 'choco install exiftool' or 'scoop install exiftool'."
;;
esac
if command -v exiftool >/dev/null 2>&1; then
local ex_ver="$(exiftool -ver 2>/dev/null || echo ok)"
log "$(loc_printf "ExifTool installed: %s" "$ex_ver")"
else
warn "ExifTool could not be installed."
fi
}
# ───────────────────────────── Pip/Conda helpers ────────────────────────────
apt_with_retries() { local attempts="${APT_RETRIES:-8}" i rc; for ((i=1;i<=attempts;i++)); do if sudo -n apt-get -o Acquire::Retries=8 "$@"; then return 0; fi; rc=$?; warn "apt-get failed (try $i/$attempts) - retrying..."; sleep $(( 5 * i )); done; return "$rc"; }
conda_retry() {
local attempts="${1:-24}"; shift
local i rc
for ((i=1;i<=attempts;i++)); do
wait_for_net 999999 10
if "$CMD_INSTALL" "$@" --repodata-fn repodata.json; then return 0; fi
rc=$?
warn "Conda failed (repodata.json) - try $i. Cleaning index cache & retry..."
"$CMD_INSTALL" clean -i -y >/dev/null 2>&1 || true
sleep $(( 5 * i ))
if "$CMD_INSTALL" "$@" --repodata-fn current_repodata.json; then return 0; fi
rc=$?
"$CMD_INSTALL" clean -i -y >/dev/null 2>&1 || true
sleep $(( 5 * i ))
done
return "$rc"
}
pip_download_and_offline_install_torch() {
# Args: torch_ver torchvision_ver tag
local tver="$1" vver="$2" tag="$3"
local idx_url
if [[ "$tag" == "cpu" ]]; then
idx_url="https://download.pytorch.org/whl/cpu"
else
idx_url="https://download.pytorch.org/whl/${tag}"
fi
local cache="$INSTALL_DIR/.torchcache/${tver}-${vver}-${tag}"
mkdir -p "$cache"
python -m pip uninstall -y torch torchvision >/dev/null 2>&1 || true
python -m pip uninstall -y "nvidia-*-cu12" "nvidia-cuda-*cu12" >/dev/null 2>&1 || true
wait_for_net 999999 10
log "Preloading Torch wheels (+deps) -> $cache (Index: $idx_url)..."
local tries=12 i=1 ok=0
while (( i<=tries )); do
PIP_DISABLE_PIP_VERSION_CHECK=1 PIP_DEFAULT_TIMEOUT=900 \
python -m pip download --progress-bar off \
--only-binary=:all: --prefer-binary \
--retries 100 --timeout 90 \
-i "$idx_url" \
-d "$cache" \
"torch==${tver}" "torchvision==${vver}" && ok=1 || ok=0
if (( ok==1 )); then break; fi
warn "pip download timeout/error (try $i/$tries) - retrying..."
sleep $(( 8 * i ))
((i++))
done
if (( ok==0 )); then warn "pip download failed (tag ${tag})."; return 2; fi
if ! ls "$cache"/torch-*.whl >/dev/null 2>&1; then warn "No torch wheel cached - abort (tag ${tag})."; return 2; fi
log "Offline installing from cache..."
PIP_DISABLE_PIP_VERSION_CHECK=1 \
python -m pip install -q --no-warn-script-location \
--no-index --find-links "$cache" \
"torch==${tver}" "torchvision==${vver}" || return 2
if torch_cuda_check_py; then log "PyTorch import OK (pip/offline, ${tag})."; return 0; else warn "PyTorch import/arch check failed (pip/offline, ${tag})."; return 2; fi
}
venv_pip_install_into_env_from_index() {
local target="$1"; shift
local tmp="$INSTALL_DIR/.pipvenv"
local cache="$INSTALL_DIR/.pipcache"
mkdir -p "$cache"
python -m venv "$tmp"
"$tmp/bin/python" -m ensurepip --upgrade
wait_for_net
PIP_DISABLE_PIP_VERSION_CHECK=1 PIP_NO_PYTHON_VERSION_WARNING=1 \
"$tmp/bin/pip" download --progress-bar off \
--retries 999 --timeout 90 --exists-action=w \
--no-deps --only-binary=:all: --prefer-binary \
-i https://pypi.org/simple \
-d "$cache" "$@" || {
echo "[install] notice: download failed - trying alternate index..."
wait_for_net
PIP_DISABLE_PIP_VERSION_CHECK=1 PIP_NO_PYTHON_VERSION_WARNING=1 \
"$tmp/bin/pip" download --progress-bar off \
--retries 999 --timeout 90 --exists-action=w \
--no-deps --only-binary=:all: --prefer-binary \
-i https://pypi.python.org/simple \
-d "$cache" "$@" || exit 1
}
PIP_DISABLE_PIP_VERSION_CHECK=1 PIP_NO_PYTHON_VERSION_WARNING=1 \
"$tmp/bin/pip" install -q \
--no-deps --no-warn-script-location --no-index --find-links "$cache" \
--target "$target" "$@"
rm -rf "$tmp"
}
clone_or_update_repo_with_retries() {
local repo_url="$1" target_dir="$2" max_attempts=200 delay=15 attempt=1 status=1
while (( attempt<=max_attempts )); do
wait_for_net 999999 15
if [[ -d "$target_dir/.git" ]]; then
log "Attempt $attempt: updating $target_dir..."
(
cd "$target_dir"
git fetch --all -q
# Default-Branch sauber ermitteln (origin/HEAD -> 'main' Fallback)
local def
def=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's|^origin/||' || echo main)
git reset -q --hard "origin/$def"
git pull -q --rebase
) && status=0 || status=$?
else
log "Attempt $attempt: cloning $repo_url -> $target_dir..."
rm -rf "$target_dir"
git clone --depth 1 "$repo_url" "$target_dir" && status=0 || status=$?
fi
if [[ $status -eq 0 && -d "$target_dir" ]]; then
log "Repo ready."
return 0
fi
warn "git failed (attempt $attempt). Waiting ${delay}s..."
((attempt++)); sleep "$delay"
done
err "Could not clone/update repo."
}
ensure_term_image_stack() {
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update -qq || true
apt_install_safe chafa xdg-utils || true
if command -v snap >/dev/null 2>&1; then
if ! command -v viu >/dev/null 2>&1; then sudo snap install viu --classic || true; fi
fi
elif command -v brew >/dev/null 2>&1; then
brew install chafa || true
# xdg-utils ist auf macOS optional; Brew bietet ein Paket, aber wir warnen nur bei Fehlschlag
brew install xdg-utils || warn "xdg-utils (optional) konnte nicht via Homebrew installiert werden."
elif command -v pacman >/dev/null 2>&1; then sudo pacman -Sy --noconfirm chafa xdg-utils || true
elif command -v dnf >/dev/null 2>&1; then sudo dnf install -y chafa xdg-utils || true
elif command -v zypper >/dev/null 2>&1; then sudo zypper --non-interactive in chafa xdg-utils || true
else warn "No known package manager - please install chafa/xdg-utils manually (optional: viu)."
fi
if command -v chafa >/dev/null 2>&1; then log "chafa available: $(chafa --version 2>/dev/null | head -n1 || echo ok)"; else warn "chafa not installed - image preview fallbacks limited."; fi
}
ensure_capture_stack() {
if command -v apt-get >/dev/null; then
sudo apt-get update -qq || true
apt_install_safe v4l-utils alsa-utils pulseaudio-utils || true
elif command -v brew >/dev/null 2>&1; then
# macOS: v4l/alsa/pulseaudio sind nicht relevant; nur Hinweis ausgeben
warn "Capture stack (v4l/alsa/pulseaudio) wird auf macOS uebersprungen."
elif command -v pacman >/dev/null; then sudo pacman -Sy --noconfirm v4l-utils alsa-utils pulseaudio || true
elif command -v dnf >/dev/null; then sudo dnf install -y v4l-utils alsa-utils pulseaudio-utils || true
elif command -v zypper >/dev/null; then sudo zypper --non-interactive in v4l-utils alsa-utils pulseaudio-utils || true
else warn "Please install v4l-utils/alsa-utils/pulseaudio-utils manually."
fi
}
ffmpeg_has_vidstab() { "$1" -hide_banner -filters 2>/dev/null | grep -qE 'vidstab(transform|detect)'; }
torch_cuda_check_py() {
python - <<'PY'
import sys
try:
import torch
ok = torch.cuda.is_available()
if not ok:
print("cuda_available:", ok)
sys.exit(2)
name = torch.cuda.get_device_name(0)
cc = torch.cuda.get_device_capability(0)
arch = f"sm_{cc[0]}{cc[1]}"
try:
supported = set(getattr(torch.cuda, "get_arch_list")())
except Exception:
supported = set()
print("cuda_available:", ok, "name:", name, "cc:", cc, "supported_arches:", sorted(supported))
if supported and arch not in supported:
print("ARCH_MISSING:", arch)
sys.exit(2)
sys.exit(0)
except Exception as e:
print("IMPORT_ERROR:", repr(e))
sys.exit(2)
PY
}
# GitHub API helpers (for release assets)
gh_api() { local path="$1" out="$2"; local ua='curl/8'; local auth=(); [[ -n "${GITHUB_TOKEN:-}" ]] && auth=(-H "Authorization: Bearer $GITHUB_TOKEN"); curl -fsSL -H 'Accept: application/vnd.github+json' -H "User-Agent: $ua" "${auth[@]}" "https://api.github.com${path}" -o "$out"; }
gh_candidates_assets() {
local repo="$1" pattern="$2" include_pre="${3:-1}"
local tmp="$(mktemp)"
gh_api "/repos/${repo}/releases/latest" "$tmp" && \
python - "$tmp" "$pattern" "$include_pre" <<'PY'
import json, re, sys
path, pat, allow_pre = sys.argv[1], sys.argv[2], sys.argv[3] == "1"
try: data=json.load(open(path,'r',encoding='utf-8'))
except: data={}
rels=[data] if isinstance(data,dict) else []
rx=re.compile(pat,re.I)
for r in rels:
if not r or r.get("draft"): continue
if (not allow_pre) and r.get("prerelease"): continue
for a in r.get("assets",[]):
n=a.get("name",""); u=a.get("browser_download_url","")
if rx.search(n) and u: print(u)
PY
gh_api "/repos/${repo}/releases?per_page=20" "$tmp" && \
python - "$tmp" "$pattern" "$include_pre" <<'PY'
import json, re, sys
path, pat, allow_pre = sys.argv[1], sys.argv[2], sys.argv[3] == "1"
try: data=json.load(open(path,'r',encoding='utf-8'))
except: data=[]
rx=re.compile(pat,re.I)
for r in data:
if r.get("draft"): continue
if (not allow_pre) and r.get("prerelease"): continue
for a in r.get("assets",[]):
n=a.get("name",""); u=a.get("browser_download_url","")
if rx.search(n) and u: print(u)
PY
rm -f "$tmp"
}
gh_fetch_asset() {
local repo="$1" regex="$2" out="$3" vtype="${4:-file}" min="${5:-1}"; shift 5
local fallback=("$@")
local candidates=()
while IFS= read -r u; do candidates+=("$u"); done < <(gh_candidates_assets "$repo" "$regex" 1 || true)
if [[ -n "${GH_OVERRIDE_URL:-}" ]]; then candidates=("$GH_OVERRIDE_URL" "${candidates[@]}"); fi
candidates+=("${fallback[@]}")
local tmp="$out.__dl__" ok=0
rm -f "$tmp"
for url in "${candidates[@]}"; do
[[ -z "$url" ]] && continue
if http_ok "$url" && download_with_retries "$url" "$tmp" 160 10; then
case "$vtype" in
zip) zip_valid "$tmp" || { warn "ZIP invalid: $url"; continue; } ;;
tar) tar_valid "$tmp" || { warn "TAR invalid: $url"; continue; } ;;
file) file_min_ok "$tmp" "$min" || { warn "File too small: $url"; continue; } ;;
*) file_min_ok "$tmp" "$min" || { warn "Unknown vtype->file-check: $url"; continue; } ;;
esac
mv -f "$tmp" "$out"; ok=1; break
else warn "Download/precheck failed: $url"; fi
done
rm -f "$tmp"; [[ $ok -eq 1 ]]
}
download_realesrgan_weights_selected() {
local WDIR="$INSTALL_DIR/real-esrgan/weights"
mkdir -p "$WDIR"
# Only keep the desired four models:
gh_fetch_asset "xinntao/Real-ESRGAN" "^realesr-general-x4v3\\.pth$" "$WDIR/realesr-general-x4v3.pth" "file" 50000000 \
"https://github.com/xinntao/Real-ESRGAN/releases/download/v0.3.0/realesr-general-x4v3.pth" || warn "realesr-general-x4v3.pth fehlte."
gh_fetch_asset "xinntao/Real-ESRGAN" "^RealESRGAN_x4plus\\.pth$" "$WDIR/RealESRGAN_x4plus.pth" "file" 50000000 \
"https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/RealESRGAN_x4plus.pth" || warn "RealESRGAN_x4plus.pth fehlte."
gh_fetch_asset "xinntao/Real-ESRGAN" "^RealESRGAN_x2plus\\.pth$" "$WDIR/RealESRGAN_x2plus.pth" "file" 30000000 \
"https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/RealESRGAN_x2plus.pth" || warn "RealESRGAN_x2plus.pth fehlte."
gh_fetch_asset "xinntao/Real-ESRGAN" "^RealESRGAN_x4plus_anime_6B\\.pth$" "$WDIR/RealESRGAN_x4plus_anime_6B.pth" "file" 30000000 \
"https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/RealESRGAN_x4plus_anime_6B.pth" || warn "RealESRGAN_x4plus_anime_6B.pth fehlte."
}
# ───────────────── Vulkan loader & NCNN binaries (OS-aware) ─────────────────
install_vulkan_loader() {
local OS_NAME="${1:-$(detect_os_name)}"
if [[ "$OS_NAME" == "linux" ]]; then
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update -qq || true
apt_install_safe libvulkan1 vulkan-tools || true
elif command -v pacman >/dev/null 2>&1; then sudo pacman -Sy --noconfirm vulkan-icd-loader vulkan-tools || true
elif command -v dnf >/dev/null 2>&1; then sudo dnf install -y vulkan-loader vulkan-tools || true
elif command -v zypper >/dev/null 2>&1; then sudo zypper --non-interactive in libvulkan1 vulkan-tools || true
else warn "Please install Vulkan loader manually."
fi
else
log "Skipping Vulkan loader install for $OS_NAME (NCNN bundles often include libs)."
fi
}
_install_ncnn_zip_generic() {
local repo="$1" outdir="$2" binname="$3" os_pat="$4"
local dest_dir="$outdir"
local bin="$dest_dir/$binname"
mkdir -p "$dest_dir"
ensure_unzip
local zip_out="$INSTALL_DIR/.cache/${binname}.zip"
mkdir -p "$(dirname "$zip_out")"
# Kandidaten aus GitHub Releases
local candidates=()
while IFS= read -r u; do candidates+=("$u"); done < <(
gh_candidates_assets "$repo" "(${os_pat}).*\\.(zip)$" 1 || true
)
# Fallbacks
if [[ "$repo" == "xinntao/Real-ESRGAN-ncnn-vulkan" ]]; then
candidates+=(
"https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan/releases/download/v0.2.0/realesrgan-ncnn-vulkan-v0.2.0-ubuntu.zip"
"https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-ubuntu.zip"
)
elif [[ "$repo" == "nihui/realesrgan-ncnn-vulkan" ]]; then
candidates+=(
"https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan/releases/download/v0.2.0/realesrgan-ncnn-vulkan-v0.2.0-ubuntu.zip"
"https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-ubuntu.zip"
)
elif [[ "$repo" == "nihui/realcugan-ncnn-vulkan" ]]; then
candidates+=(
"https://github.com/nihui/realcugan-ncnn-vulkan/releases/download/20220728/realcugan-ncnn-vulkan-20220728-ubuntu.zip"
)
fi
local ok=0
for url in "${candidates[@]}"; do
[[ -z "$url" ]] && continue
log "Trying ${binname} from: $url"
rm -f "$zip_out"
if http_ok "$url" && download_with_retries "$url" "$zip_out" 160 10 && zip_valid "$zip_out"; then
# Entpacken
# Extract into a temporary directory to inspect structure safely
local tmp_unpack="$dest_dir/__unpack__"
rm -rf "$tmp_unpack"
mkdir -p "$tmp_unpack"
(cd "$tmp_unpack" && unzip -oq "$zip_out") || true
# Binary finden (aus dem entpackten Baum)
local cand
cand="$(find "$tmp_unpack" -type f -name "$binname" -perm -111 | head -n1 || true)"
# Models konsolidieren:
# - Alle "models" **und** "models-*" sammeln
# - Unterordner **bewahren** (kein Flatten!)
local models_root="$dest_dir/models"
mkdir -p "$models_root"
# 1) Bereits vorhandenes 'models' (falls vorhanden) -> in Root mergen
while IFS= read -r m; do
[[ -z "$m" ]] && continue
rsync -a "$m"/ "$models_root"/ 2>/dev/null || { cp -a "$m"/. "$models_root"/ 2>/dev/null || true; }
done < <(find "$tmp_unpack" -type d -name models 2>/dev/null || true)
# 2) Alle 'models-*' -> als Unterordner unter $models_root/<basename>
while IFS= read -r m; do
[[ -z "$m" ]] && continue
local base; base="$(basename "$m")"
mkdir -p "$models_root/$base"
rsync -a "$m"/ "$models_root/$base"/ 2>/dev/null || { cp -a "$m"/. "$models_root/$base"/ 2>/dev/null || true; }
done < <(find "$tmp_unpack" -type d -name 'models-*' 2>/dev/null || true)
# Binary platzieren
if [[ -n "$cand" ]]; then
mkdir -p "$(dirname "$bin")"
if [[ "$cand" != "$bin" ]]; then
if ! mv -f "$cand" "$bin" 2>/dev/null; then
install -m 0755 "$cand" "$bin"
fi
else
log "Binary already at target: $bin"
fi
chmod +x "$bin" 2>/dev/null || true
ok=1
else
warn "Binary not found in zip - next candidate..."
fi
# Cleanup
rm -rf "$tmp_unpack"
[[ $ok -eq 1 ]] && break
else
warn "Zip invalid or download failed - next candidate..."