linuxtool/Config/sources.sh

87 lines
2.4 KiB
Bash
Raw Normal View History

#!/bin/bash
declare version=$(cat /etc/os-release | grep VERSION_CODENAME | awk -F '=' '{print $2}')
2024-09-22 22:39:08 +08:00
declare system=$(cat /etc/os-release | grep "^ID" | awk -F '=' '{print $2}')
declare status=0
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'
declare -a pcik_array
declare pick=0
2024-09-26 16:20:14 +08:00
echo "========$(basename $0 .sh)========"
for i in "${!sources_dick[@]}";
do
pick=$(( pick+1 ))
pcik_array[$pick]=$i
echo "${pick}.${i}"
done
read -p "请输入:" pick
if [[ -z $pick ]];then
declare url='http://mirrors.ustc.edu.cn'
2024-09-22 21:37:45 +08:00
elif [[ ${pick} =~ [1-${#sources_dick[@]}] ]];then
pick=${pcik_array[$pick]}
declare url=${sources_dick[$pick]}
2024-09-22 21:42:17 +08:00
else
echo "输入错误"
exit
fi
case "$version" in
'bookworm')
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-23 17:59:28 +08:00
apt update -y
apt-get update -y
2024-09-22 22:39:08 +08:00
status=1
;;
2024-09-22 23:27:12 +08:00
'bullseye')
cat > "/etc/apt/sources.list" << EOF
deb ${url}/debian/ bullseye main contrib non-free
deb ${url}/debian/ bullseye-updates main contrib non-free
deb ${url}/debian/ bullseye-backports main contrib non-free
EOF
2024-09-23 17:59:28 +08:00
apt update -y
apt-get update -y
2024-09-22 23:27:12 +08:00
status=1
;;
2024-09-22 22:39:08 +08:00
esac
case "$system" in
'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 = ${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
status=1
;;
'ubuntu')
cat > "/etc/apt/sources.list" << EOF
deb ${url}/ubuntu/ ${version} main restricted universe multiverse
deb ${url}/ubuntu/ ${version}-security main restricted universe multiverse
deb ${url}/ubuntu/ ${version}-updates main restricted universe multiverse
deb ${url}/ubuntu/ ${version}-backports main restricted universe multiverse
EOF
2024-09-23 17:59:28 +08:00
apt update -y
apt-get update -y
2024-09-22 22:39:08 +08:00
status=1
;;
esac
2024-09-22 22:39:08 +08:00
if [[ $status == 0 ]]; then
echo "暂不支持该系统一键换源"
exit
fi
echo "换源成功"