Skip to content

Commit 6a627bb

Browse files
committed
Add Statically.io CDN as middle-tier fallback
- Add CDN fallback between GitHub and local backup - Update curl_to_dir() in lib.sh to try cdn.statically.io - Update fetch_lib.sh with CDN fallback - Update nextcloud_update.sh initial source with CDN fallback - Statically.io caches main branch for 1 day (helps with rate limits) - Fallback order: GitHub → Statically CDN → Local backup
1 parent 41e42e6 commit 6a627bb

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

lib.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,16 @@ fi
627627
then
628628
if ! curl -sfL "$1"/"$2" -o "$3"/"$2"
629629
then
630+
# Try Statically.io CDN if this is a GitHub URL
631+
if [[ "$1" == *"raw.githubusercontent.com"* ]]
632+
then
633+
local cdn_url="${1/raw.githubusercontent.com/cdn.statically.io\/gh}"
634+
cdn_url="${cdn_url//\/nextcloud\/vm\//\/nextcloud\/vm\/main\/}"
635+
if curl -sfL "$cdn_url"/"$2" -o "$3"/"$2"
636+
then
637+
return 0
638+
fi
639+
fi
630640
# Try local backup
631641
try_local_backup "$1" "$2" "$3"
632642
fi
@@ -636,6 +646,17 @@ fi
636646
do
637647
if [ "$retries" -ge 10 ]
638648
then
649+
# Try Statically.io CDN if this is a GitHub URL
650+
if [[ "$1" == *"raw.githubusercontent.com"* ]]
651+
then
652+
local cdn_url="${1/raw.githubusercontent.com/cdn.statically.io\/gh}"
653+
cdn_url="${cdn_url//\/nextcloud\/vm\//\/nextcloud\/vm\/main\/}"
654+
if curl -sfL "$cdn_url"/"$2" -o "$3"/"$2"
655+
then
656+
print_text_in_color "$IGreen" "✓ Used Statically.io CDN"
657+
break
658+
fi
659+
fi
639660
# Exhausted retries, try local backup
640661
if try_local_backup "$1" "$2" "$3"
641662
then

nextcloud_update.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,23 @@
1111
true
1212
SCRIPT_NAME="Nextcloud Update Script"
1313
# shellcheck source=lib.sh
14-
source <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/main/lib.sh)
14+
if ! source <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/main/lib.sh)
15+
then
16+
# Try Statically.io CDN
17+
if source <(curl -sL https://cdn.statically.io/gh/nextcloud/vm/main/lib.sh)
18+
then
19+
echo "✓ Used Statically.io CDN"
20+
# Try local backup
21+
elif [ -f /var/scripts/vm-repo-backup/lib.sh ]
22+
then
23+
echo "⚠ GitHub unavailable, using local backup: lib.sh"
24+
# shellcheck source=lib.sh
25+
source /var/scripts/vm-repo-backup/lib.sh
26+
else
27+
echo "Failed to download lib.sh from all sources. Exiting."
28+
exit 1
29+
fi
30+
fi
1531

1632
# Get all needed variables from the library
1733
ncdb

static/fetch_lib.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ if ! [ -f /var/scripts/lib.sh ]
2222
then
2323
if ! curl -sfL https://raw.githubusercontent.com/nextcloud/vm/main/lib.sh -o /var/scripts/lib.sh
2424
then
25+
# Try Statically.io CDN
26+
if curl -sfL https://cdn.statically.io/gh/nextcloud/vm/main/lib.sh -o /var/scripts/lib.sh
27+
then
28+
print_text_in_color "$IGreen" "✓ Used Statically.io CDN"
2529
# Try local backup
26-
if [ -f /var/scripts/vm-repo-backup/lib.sh ]
30+
elif [ -f /var/scripts/vm-repo-backup/lib.sh ]
2731
then
2832
print_text_in_color "$IYellow" "⚠ GitHub unavailable, using local backup: lib.sh"
2933
cp /var/scripts/vm-repo-backup/lib.sh /var/scripts/lib.sh
@@ -37,8 +41,12 @@ elif ! [ -f /var/scripts/nextcloud-startup-script.sh ]
3741
then
3842
if ! curl -sfL https://raw.githubusercontent.com/nextcloud/vm/main/lib.sh -o /var/scripts/lib.sh
3943
then
44+
# Try Statically.io CDN
45+
if curl -sfL https://cdn.statically.io/gh/nextcloud/vm/main/lib.sh -o /var/scripts/lib.sh
46+
then
47+
print_text_in_color "$IGreen" "✓ Used Statically.io CDN"
4048
# Try local backup
41-
if [ -f /var/scripts/vm-repo-backup/lib.sh ]
49+
elif [ -f /var/scripts/vm-repo-backup/lib.sh ]
4250
then
4351
print_text_in_color "$IYellow" "⚠ GitHub unavailable, using local backup: lib.sh"
4452
cp /var/scripts/vm-repo-backup/lib.sh /var/scripts/lib.sh

0 commit comments

Comments
 (0)