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'
|
|
|
|
|
2020-11-23 02:00:49 +00:00
|
|
|
if ! in_china; then
|
|
|
|
echo 'Skip mirrors configuration'
|
|
|
|
return
|
|
|
|
fi
|
2020-11-21 18:07:26 +00:00
|
|
|
|
|
|
|
# setup package mirror for CHINA
|
|
|
|
case "$PM" in
|
|
|
|
apt)
|
|
|
|
# backup original sources.list
|
2020-11-23 02:00:49 +00:00
|
|
|
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
|
2020-11-23 02:00:49 +00:00
|
|
|
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
|
|
|
|
;;
|
|
|
|
pacman)
|
|
|
|
COUNTRY=China
|
2020-11-23 02:00:49 +00:00
|
|
|
if [ ! -f /etc/pacman.d/mirrorlist.bak ]; then
|
2020-11-21 18:07:26 +00:00
|
|
|
sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
|
2020-11-23 02:00:49 +00:00
|
|
|
fi
|
2020-11-21 18:07:26 +00:00
|
|
|
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 }
|
|
|
|
' /etc/pacman.d/mirrorlist.bak | sudo tee /etc/pacman.d/mirrorlist >/dev/null
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
|