linuxtool/Config/sources.sh

84 lines
2.7 KiB
Bash
Raw Normal View History

#!/bin/bash
declare os_version=$(cat /etc/os-release | grep VERSION_CODENAME | awk -F '=' '{print $2}')
declare os_id=$(cat /etc/os-release | grep "^ID" | awk -F '=' '{print $2}')
declare update_status=0
declare -A mirror_sources
mirror_sources['中国科技技术大学(默认)']='http://mirrors.ustc.edu.cn'
mirror_sources['清华大学']='https://mirrors.tuna.tsinghua.edu.cn'
mirror_sources['阿里云']='https://mirrors.aliyun.com'
mirror_sources['网易云']='https://mirrors.163.com'
declare -a selected_sources
declare source_choice=0
2024-09-26 16:20:14 +08:00
echo "========$(basename $0 .sh)========"
for i in "${!mirror_sources[@]}";
do
source_choice=$(( source_choice+1 ))
selected_sources[$source_choice]=$i
echo "${source_choice}.${i}"
done
read -p "请输入选择的源:" source_choice
if [[ -z $source_choice ]];then
declare selected_url='http://mirrors.ustc.edu.cn'
elif [[ ${source_choice} =~ [1-${#mirror_sources[@]}] ]];then
source_choice=${selected_sources[$source_choice]}
declare selected_url=${mirror_sources[$source_choice]}
2024-09-22 21:42:17 +08:00
else
echo "输入错误"
exit
fi
case "$os_version" in
'bookworm')
cat > "/etc/apt/sources.list" << EOF
deb ${selected_url}/debian/ bookworm main contrib non-free non-free-firmware
deb ${selected_url}/debian/ bookworm-updates main contrib non-free non-free-firmware
deb ${selected_url}/debian/ bookworm-backports main contrib non-free non-free-firmware
EOF
2024-09-23 17:59:28 +08:00
apt update -y
apt-get update -y
update_status=1
2024-09-22 22:39:08 +08:00
;;
2024-09-22 23:27:12 +08:00
'bullseye')
cat > "/etc/apt/sources.list" << EOF
deb ${selected_url}/debian/ bullseye main contrib non-free
deb ${selected_url}/debian/ bullseye-updates main contrib non-free
deb ${selected_url}/debian/ bullseye-backports main contrib non-free
2024-09-22 23:27:12 +08:00
EOF
2024-09-23 17:59:28 +08:00
apt update -y
apt-get update -y
update_status=1
2024-09-22 23:27:12 +08:00
;;
2024-09-22 22:39:08 +08:00
esac
case "$os_id" in
2024-09-22 22:39:08 +08:00
'arch')
2024-09-23 17:59:28 +08:00
pacman -Sy pacman-key --noconfirm
2024-09-22 22:39:08 +08:00
sed -i '/^Server.*/d' "/etc/pacman.conf"
echo "Server = ${selected_url}/archlinuxcn/\$arch"
2024-09-23 17:59:28 +08:00
pacman-key --lsign-key "farseerfc@archlinux.org"
2024-09-22 23:27:12 +08:00
pacman -Syyu
update_status=1
2024-09-22 23:27:12 +08:00
;;
'ubuntu')
cat > "/etc/apt/sources.list" << EOF
deb ${selected_url}/ubuntu/ ${os_version} main restricted universe multiverse
deb ${selected_url}/ubuntu/ ${os_version}-security main restricted universe multiverse
deb ${selected_url}/ubuntu/ ${os_version}-updates main restricted universe multiverse
deb ${selected_url}/ubuntu/ ${os_version}-backports main restricted universe multiverse
2024-09-22 23:27:12 +08:00
EOF
2024-09-23 17:59:28 +08:00
apt update -y
apt-get update -y
update_status=1
;;
esac
if [[ $update_status == 0 ]]; then
2024-09-22 22:39:08 +08:00
echo "暂不支持该系统一键换源"
exit
fi
echo "换源成功"