2024-07-24 00:56:26 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
declare version=$(cat /etc/os-release | grep VERSION_CODENAME | awk -F '=' '{print $2}')
|
|
|
|
|
2024-07-24 12:50:44 +08:00
|
|
|
declare -A sources_dick
|
|
|
|
sources_dick['中国科技技术大学(默认)']='http://mirrors.ustc.edu.cn'
|
|
|
|
sources_dick['清华大学']='https://mirrors.tuna.tsinghua.edu.cn'
|
|
|
|
sources_dick['阿里云']='https://mirrors.aliyun.com'
|
2024-07-24 13:25:35 +08:00
|
|
|
sources_dick['网易云']='https://mirrors.163.com'
|
2024-07-24 00:56:26 +08:00
|
|
|
|
2024-07-24 12:50:44 +08:00
|
|
|
declare -a pcik_array
|
|
|
|
declare pick=0
|
2024-07-24 00:56:26 +08:00
|
|
|
echo "========Sources========"
|
2024-07-24 12:50:44 +08:00
|
|
|
for i in "${!sources_dick[@]}";
|
|
|
|
do
|
|
|
|
pick=$(( pick+1 ))
|
|
|
|
pcik_array[$pick]=$i
|
|
|
|
echo "${pick}.${i}"
|
|
|
|
done
|
2024-07-24 00:56:26 +08:00
|
|
|
echo "========Sources========"
|
2024-07-24 12:50:44 +08:00
|
|
|
read -p "请输入:" pick
|
2024-07-24 00:56:26 +08:00
|
|
|
|
|
|
|
|
2024-07-25 21:56:21 +08:00
|
|
|
if [[ -z $pick ]];then
|
2024-07-24 12:50:44 +08:00
|
|
|
declare url='http://mirrors.ustc.edu.cn'
|
2024-09-22 21:37:45 +08:00
|
|
|
elif [[ ${pick} =~ [1-${#sources_dick[@]}] ]];then
|
2024-07-24 12:50:44 +08:00
|
|
|
pick=${pcik_array[$pick]}
|
|
|
|
declare url=${sources_dick[$pick]}
|
2024-09-22 21:42:17 +08:00
|
|
|
else
|
|
|
|
echo "输入错误"
|
|
|
|
exit
|
2024-07-24 00:56:26 +08:00
|
|
|
fi
|
|
|
|
|
2024-07-24 12:50:44 +08:00
|
|
|
|
|
|
|
|
2024-07-24 00:56:26 +08:00
|
|
|
case "$version" in
|
|
|
|
'bookworm')
|
2024-07-25 21:56:21 +08:00
|
|
|
cat > "/etc/apt/sources.list" << EOF
|
|
|
|
deb ${url}/debian/ bookworm main contrib non-free non-free-firmware
|
|
|
|
deb ${url}/debian/ bookworm-updates main contrib non-free non-free-firmware
|
|
|
|
deb ${url}/debian/ bookworm-backports main contrib non-free non-free-firmware
|
|
|
|
EOF
|
2024-09-21 14:17:49 +08:00
|
|
|
sudo apt update -y
|
|
|
|
sudo apt-get update -y
|
2024-07-24 00:56:26 +08:00
|
|
|
;;
|
2024-07-25 21:56:21 +08:00
|
|
|
*)
|
2024-09-21 18:07:23 +08:00
|
|
|
echo "暂不支持该系统一键换源"
|
2024-07-25 21:56:21 +08:00
|
|
|
exit
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo "换源成功"
|