吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1685|回复: 15
收起左侧

[其他原创] Ubuntu/Debian多版本自动识别一键换源脚本+一键安装谷歌浏览器和远程软件

[复制链接]
qinyuhui 发表于 2023-8-3 14:56
本帖最后由 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)

QQ截图20230803162938.png

直接使用上面命令即可运行脚本或者自行复制下面内容到服务器内执行

简单弄了个脚本方便自己使用现分享出来,可能也许脚本并不完美或者有问题用不了的自行修改

[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)

QQ截图20230803162347.png



免费评分

参与人数 5吾爱币 +10 热心值 +4 收起 理由
Rolmax + 1 热心回复!
FastLunchGOA + 1 + 1 谢谢@Thanks!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
heisefuyun + 1 + 1 我很赞同!
baguaiguai + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| qinyuhui 发表于 2023-8-3 16:08
200206083139 发表于 2023-8-3 15:57
老哥有没有centos的脚本呀

CentOS 7 阿里源、163、腾讯一键脚本

bash <(curl -sL https://giie.cn/sh/Centos-7.sh)

或者使用下面的
备份
cd /etc/yum.repos.d/
mkdir repo_bak
mv *.repo repo_bak/

下载新的CentOS-Base.repo 到/etc/yum.repos.d/

wget http://mirrors.aliyun.com/repo/Centos-7.repo

yum clean all
yum makecache
tslace 发表于 2023-8-3 15:44
在用ubuntu server 22.04,安装时都设置过阿里云了,不知道为啥装依赖时还是会因为网络问题连接超时,只能在安装指令后面指定源才可以。。。。
不知道楼主的脚本管用不管用,可以实现一劳永逸。。。
540151542 发表于 2023-8-3 15:36
Ljz31707 发表于 2023-8-3 15:47
可以尝试尝试
200206083139 发表于 2023-8-3 15:57
老哥有没有centos的脚本呀
Pojawa 发表于 2023-8-3 16:18
之前都没想过把换源操作写成脚本 不过一次性的东西也确实不太想写
dreamrise 发表于 2023-8-3 16:20
有没有其他各种的,比如pip,npm,等等。
 楼主| qinyuhui 发表于 2023-8-3 16:32
dreamrise 发表于 2023-8-3 16:20
有没有其他各种的,比如pip,npm,等等。

那没有呢
200206083139 发表于 2023-8-4 08:47
qinyuhui 发表于 2023-8-3 16:08
CentOS 7 阿里源、163、腾讯一键脚本

bash

谢谢老哥我去试试去
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-2 21:12

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表