本帖最后由 qinyuhui 于 2023-8-3 17:44 编辑
使用脚本前请先安装curl
apt -y install curl
Ubuntu一键换源脚本ubuntu14/16/18/20/22,多版本自动识别,包含阿里源、网易源、腾讯源、清华源、华为源
bash <(curl -sL https://giie.cn/sh/ubuntu.sh)
直接使用上面命令即可运行脚本或者自行复制下面内容到服务器内执行
简单弄了个脚本方便自己使用现分享出来,可能也许脚本并不完美或者有问题用不了的自行修改
[PHP] 纯文本查看 复制代码 #!/bin/bash
# 备份原始软件源配置文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 国内软件源数组
declare -a repo_urls=(
"http://mirrors.aliyun.com/ubuntu/|阿里云"
"http://mirrors.163.com/ubuntu/|网易"
"https://mirrors.cloud.tencent.com/ubuntu/|腾讯"
"https://mirrors.tuna.tsinghua.edu.cn/ubuntu/|清华大学"
"https://mirrors.huaweicloud.com/repository/ubuntu/|华为云"
)
# 获取当前Ubuntu系统版本
ubuntu_version=$(lsb_release -r -s)
# 根据系统版本选择对应的软件源
case $ubuntu_version in
"14.04")
repo_index=3 # 清华源
;;
"16.04")
repo_index=3 # 清华源
;;
"18.04")
repo_index=3 # 清华源
;;
"20.04")
repo_index=4 # 华为源
;;
"22.04")
repo_index=4 # 华为源
;;
*)
repo_index=0 # 默认选择阿里云源
;;
esac
# 显示可用的软件源列表
echo "国内软件源列表:"
for ((i=0; i<${#repo_urls[@]}; i++)); do
url=$(echo ${repo_urls[$i]} | cut -d '|' -f 1)
name=$(echo ${repo_urls[$i]} | cut -d '|' -f 2)
echo "$i. $name ($url)"
done
# 提示用户选择一个源
read -p "请选择要使用的软件源的编号 (默认为 $repo_index): " user_repo_index
# 如果用户选择了有效的编号,则更新 repo_index
if [[ $user_repo_index =~ ^[0-9]+$ ]] && [ $user_repo_index -ge 0 ] && [ $user_repo_index -lt ${#repo_urls[@]} ]; then
repo_index=$user_repo_index
fi
# 检测源是否正常
repo_url=$(echo ${repo_urls[$repo_index]} | cut -d '|' -f 1)
if ping -c 1 $(echo $repo_url | awk -F/ '{print $3}') &> /dev/null; then
echo "源 $repo_url 可正常连接。"
else
echo "源 $repo_url 无法连接,请检查网络连接。"
# 尝试使用其他源进行更新
for ((i=0; i<${#repo_urls[@]}; i++)); do
alt_repo_url=$(echo ${repo_urls[$i]} | cut -d '|' -f 1)
if ping -c 1 $(echo $alt_repo_url | awk -F/ '{print $3}') &> /dev/null; then
echo "尝试使用备选源 $alt_repo_url 进行更新。"
repo_url=$alt_repo_url
break
fi
done
if [ -z "$repo_url" ]; then
echo "所有备选源均无法连接,请检查网络连接或稍后再试。"
exit 1
fi
fi
# 检查当前使用的源
current_source=$(grep -oP '(?<=^deb\s).+' /etc/apt/sources.list | awk '{print $2}' | cut -d '/' -f 3)
echo "当前使用的源:$current_source"
# 下载并替换为用户选择的软件源配置文件
sudo sed -i "s|http://[^ ]*|${repo_url}|g" /etc/apt/sources.list
# 清除缓存
sudo apt-get clean
# 更新软件包索引
sudo apt-get update
# 升级系统
sudo apt-get upgrade -y
# 清理残余文件
sudo apt-get autoremove -y
echo "软件源已经成功设置并更新完成。"
Debian一键换源脚本Debian 10/11/12多版本自动识别,脚本包含阿里源、网易源、腾讯源、清华源、华为源
bash <(curl -sL https://giie.cn/sh/Debian.sh)
直接使用上面命令即可运行脚本或者自行复制下面内容到服务器内执行
[PHP] 纯文本查看 复制代码 #!/bin/bash
# 备份原始软件源配置文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 国内软件源数组
declare -a repo_urls=(
"http://mirrors.aliyun.com/debian/|阿里云"
"http://mirrors.163.com/debian/|网易"
"https://mirrors.cloud.tencent.com/debian/|腾讯"
"https://mirrors.tuna.tsinghua.edu.cn/debian/|清华大学"
"https://mirrors.huaweicloud.com/repository/debian/|华为云"
)
# 获取当前Debian系统版本
debian_version=$(awk -F'[= "]' '/VERSION_CODENAME/{print $3}' /etc/os-release)
# 根据系统版本选择对应的软件源
case $debian_version in
"stretch")
repo_index=3 # 清华源
;;
"buster")
repo_index=3 # 清华源
;;
"bullseye")
repo_index=4 # 华为源
;;
*)
repo_index=0 # 默认选择阿里云源
;;
esac
# 显示可用的软件源列表
echo "国内软件源列表:"
for ((i=0; i<${#repo_urls[@]}; i++)); do
url=$(echo ${repo_urls[$i]} | cut -d '|' -f 1)
name=$(echo ${repo_urls[$i]} | cut -d '|' -f 2)
echo "$i. $name ($url)"
done
# 提示用户选择一个源
read -p "请选择要使用的软件源的编号 (默认为 $repo_index): " user_repo_index
# 如果用户选择了有效的编号,则更新 repo_index
if [[ $user_repo_index =~ ^[0-9]+$ ]] && [ $user_repo_index -ge 0 ] && [ $user_repo_index -lt ${#repo_urls[@]} ]; then
repo_index=$user_repo_index
fi
# 检测源是否正常
repo_url=$(echo ${repo_urls[$repo_index]} | cut -d '|' -f 1)
if ping -c 1 $(echo $repo_url | awk -F/ '{print $3}') &> /dev/null; then
echo "源 $repo_url 可正常连接。"
else
echo "源 $repo_url 无法连接,请检查网络连接。"
# 尝试使用其他源进行更新
for ((i=0; i<${#repo_urls[@]}; i++)); do
alt_repo_url=$(echo ${repo_urls[$i]} | cut -d '|' -f 1)
if ping -c 1 $(echo $alt_repo_url | awk -F/ '{print $3}') &> /dev/null; then
echo "尝试使用备选源 $alt_repo_url 进行更新。"
repo_url=$alt_repo_url
break
fi
done
if [ -z "$repo_url" ]; then
echo "所有备选源均无法连接,请检查网络连接或稍后再试。"
exit 1
fi
fi
# 检查当前使用的源
current_source=$(grep -oP '(?<=^deb\s).+' /etc/apt/sources.list | awk '{print $2}' | cut -d '/' -f 3)
echo "当前使用的源:$current_source"
# 下载并替换为用户选择的软件源配置文件
sudo sed -i "s|http://[^ ]*|${repo_url}|g" /etc/apt/sources.list
# 清除缓存
sudo apt-get clean
# 更新软件包索引
sudo apt-get update
# 升级系统
sudo apt-get upgrade -y
# 清理残余文件
sudo apt-get autoremove -y
echo "软件源已经成功设置并更新完成。"
如使用不了自行修复或者使用其他方法换源,本脚本并不一定适合你使用,也不保证百分百可用。
ubuntu/debian一键安装谷歌浏览器、向日癸、ToDesk、百度网盘
一样随便写的不保证所有版本都可以安装
使用脚本前请先安装curl
apt -y install curl
bash <(curl -sL https://giie.cn/sh/ruanjian.sh)
|