dotfiles/cli/mirrors.sh

82 lines
2.8 KiB
Bash
Raw Normal View History

2020-11-21 18:07:26 +00:00
#!/bin/sh
set -e
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
log 'Setting up mirror list'
if ! in_china; then
echo 'Skip mirrors configuration'
return
fi
2020-11-21 18:07:26 +00:00
2022-05-15 03:34:22 +00:00
pacman_china_mirror() {
MIRRORLIST=${1:-/etc/pacman.d/mirrorlist}
MIRRORLIST_BAK=$MIRRORLIST.bak
COUNTRY=${2:-China}
if [ ! -f "$MIRRORLIST_BAK" ]; then
sudo cp "$MIRRORLIST" "$MIRRORLIST_BAK"
fi
awk '
{
if (NR < 7) {
print
} else if ($0 == "## '$COUNTRY'") {
print
matched = 1
} else if (matched == 1) {
print
matched = 0
} else {
buffer = buffer "\n" $0
}
}
END { print buffer }
' "$MIRRORLIST_BAK" | sudo tee "$MIRRORLIST" >/dev/null
}
2022-05-29 16:00:30 +00:00
case "$PM" in
*apt*)
2020-11-21 18:07:26 +00:00
# backup original sources.list
if [ ! -f /etc/apt/sources.list.bak ]; then
2020-11-21 18:07:26 +00:00
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
fi
2020-11-21 18:07:26 +00:00
# replace with aliyun mirror
awk '$0 ~ /^deb/ {$2="https://mirrors.aliyun.com/ubuntu/"; print}' /etc/apt/sources.list.bak \
| sudo tee /etc/apt/sources.list
;;
2022-05-29 16:00:30 +00:00
esac
# setup package mirror for CHINA
case "$UNAMEA" in
2022-05-15 03:34:22 +00:00
*artix*)
# enable arch repo
2022-08-10 16:12:43 +00:00
sudo pacman -S --needed --noconfirm artix-archlinux-support archlinux-keyring
2022-05-15 03:34:22 +00:00
if ! grep -qF "mirrorlist-arch" /etc/pacman.conf; then
echo "# Arch" >> sudo tee -a /etc/pacman
echo "[extra]" >> sudo tee -a /etc/pacman
echo "Include = /etc/pacman.d/mirrorlist-arch" >> sudo tee -a /etc/pacman
echo "" >> sudo tee -a /etc/pacman
echo "[community]" >> sudo tee -a /etc/pacman
echo "Include = /etc/pacman.d/mirrorlist-arch" >> sudo tee -a /etc/pacman
echo "" >> sudo tee -a /etc/pacman
echo "[multilib]" >> sudo tee -a /etc/pacman
echo "Include = /etc/pacman.d/mirrorlist-arch" >> sudo tee -a /etc/pacman
2022-08-10 16:12:43 +00:00
echo "" >> sudo tee -a /etc/pacman
echo '[universe]' >> sudo tee -a /etc/pacman
echo 'Server = https://universe.artixlinux.org/$arch' >> sudo tee -a /etc/pacman
echo 'Server = https://mirror1.artixlinux.org/universe/$arch' >> sudo tee -a /etc/pacman
echo 'Server = https://mirror.pascalpuffke.de/artix-universe/$arch' >> sudo tee -a /etc/pacman
echo 'Server = https://artixlinux.qontinuum.space/artixlinux/universe/os/$arch' >> sudo tee -a /etc/pacman
echo 'Server = https://mirror1.cl.netactuate.com/artix/universe/$arch' >> sudo tee -a /etc/pacman
echo 'Server = https://ftp.crifo.org/artix-universe/' >> sudo tee -a /etc/pacman
fi
2022-05-15 03:34:22 +00:00
pacman_china_mirror /etc/pacman.d/mirrorlist Asia
pacman_china_mirror /etc/pacman.d/mirrorlist-arch
sudo pacman -Sy
2022-05-29 16:00:30 +00:00
;;
2020-11-21 18:07:26 +00:00
esac