Skip to content

Commit e569081

Browse files
committed
[run_before_squashfs.sh] change mirrorlist generation with some fallback to not fail
1 parent 3f3b68a commit e569081

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

run_before_squashfs.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,40 @@ echo "--> content of /root/packages:"
7171
ls "/root/packages/"
7272
echo "end of content of /root/packages. <---"
7373
74-
echo "---> generating actual ranked mirrorlist to fetch packages for offline install / back up original to repace later---> "
74+
echo "---> generating actual ranked mirrorlist to fetch packages for offline install---> "
75+
echo "---> back up original to replace later---> "
7576
cp "/etc/pacman.d/mirrorlist" "/etc/pacman.d/mirrorlist.later"
7677
mkdir -p "/etc/pacman.d/"
77-
reflector --country "$(curl -s https://ipapi.co/country_name/)" --protocol https --sort rate --latest 10 --save /etc/pacman.d/mirrorlist
78+
echo "---> generate mirrorlist safely ---> "
79+
get_country() {
80+
for url in \
81+
"https://ipapi.co/country_code" \
82+
"https://ifconfig.co/country-iso" \
83+
"https://ipinfo.io/country"; do
84+
85+
code="$(curl -fs "$url" 2>/dev/null | grep -oE '^[A-Z]{2}$')"
86+
[[ -n "$code" ]] && echo "$code" && return
87+
done
88+
}
89+
90+
COUNTRY="$(get_country)"
91+
92+
if [[ -n "$COUNTRY" ]]; then
93+
reflector \
94+
--country "$COUNTRY" \
95+
--protocol "https" \
96+
--sort "rate" \
97+
--latest "10" \
98+
--save "/etc/pacman.d/mirrorlist"
99+
else
100+
reflector \
101+
--protocol "https" \
102+
--sort "rate" \
103+
--latest "20" \
104+
--save "/etc/pacman.d/mirrorlist"
105+
fi
106+
107+
echo "---> generate mirrorlist done ---> "
78108
79109
pacman -Sy
80110
pacman -U --noconfirm --needed -- "/root/packages/"*".pkg.tar.zst"

0 commit comments

Comments
 (0)