diff --git a/chsrc.c b/chsrc.c index 51b77dd..5e6b038 100644 --- a/chsrc.c +++ b/chsrc.c @@ -869,14 +869,14 @@ os_ubuntu_setsrc (char* option) if(strncmp(arch, "x86_64", 6)==0) { cmd = xy_strjoin(3, - "sed -E -i \'s@https?://.*/ubuntu@", + "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' /etc/apt/sources.list"); } else { cmd = xy_strjoin(3, - "sed -E -i \'s@https?://.*/ubuntu-ports@", + "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' /etc/apt/sources.list"); } @@ -919,12 +919,13 @@ os_debian_setsrc (char* option) xy_info ("chsrc: 如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并 需要您 安装"); xy_info ("chsrc: sudo apt install apt-transport-https ca-certificates"); - char* backup = "cp -f /etc/apt/sources.list /etc/apt/sources.list.bak --backup='t'"; + char* backup = "cp /etc/apt/sources.list /etc/apt/sources.list.bak --backup='t'"; chsrc_runcmd(backup); - char * cmd = xy_strjoin(3,"chsrc: 备份文件名: /etc/apt/.*)http[:|\\.|\\/|a-z|A-Z]*\\/debian\\/@\\1", - source.url, - "@\'< /etc/apt/sources.list.bak | cat > /etc/apt/sources.list"); + char* cmd = xy_strjoin(3, + "sed -E -i \'s@https?://.*/debian/?@", + source.url, + "@g\' /etc/apt/sources.list"); chsrc_runcmd(cmd); @@ -961,16 +962,15 @@ os_deepin_setsrc (char* option) source_info source = os_deepin_sources[index]; chsrc_say_selection(&source); - char* backup = "cp -f /etc/apt/sources.list /etc/apt/sources.list.bak --backup='t'"; + char* backup = "cp /etc/apt/sources.list /etc/apt/sources.list.bak --backup='t'"; chsrc_runcmd(backup); xy_info ("chsrc: 备份文件名: /etc/apt/sources.list.bak"); - char* cmd; - cmd = xy_strjoin(3, - "sed -E \'s@(^[^#]* .*)http[:|\\.|\\/|a-z|A-Z]*\\/deepin\\/@\\1", - source.url, - "@\'< /etc/apt/sources.list.bak | cat > /etc/apt/sources.list"); + char* cmd = xy_strjoin(3, + "sed -E -i \'s@https?://.*/deepin/?@", + source.url, + "@g\' /etc/apt/sources.list"); chsrc_logcmd(cmd); system(cmd); // char* rm = "rm -rf /etc/apt/source.list.bak"; @@ -1002,10 +1002,10 @@ os_fedora_setsrc (char* option) xy_warn ("chsrc: fedora 29 及以下版本暂不支持"); - char* backup = "cp -f /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/fedora.repo.bak --backup='t'"; + char* backup = "cp /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/fedora.repo.bak --backup='t'"; chsrc_runcmd(backup); - backup = "cp -f /etc/yum.repos.d/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo.bak"; + backup = "cp /etc/yum.repos.d/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo.bak"; chsrc_runcmd(backup); xy_info ("chsrc: 备份文件名:1. /etc/yum.repos.d/fedora.repo.bak"); @@ -1120,14 +1120,15 @@ os_kali_setsrc(char* option) source_info source = os_kali_sources[index]; chsrc_say_selection(&source); - char* backup = "cp -f /etc/apt/sources.list /etc/apt/sources.list.bak --backup='t'"; + char* backup = "cp /etc/apt/sources.list /etc/apt/sources.list.bak --backup='t'"; chsrc_runcmd(backup); xy_info ("chsrc: 备份文件名: /etc/apt/sources.list.bak"); - char* cmd = xy_strjoin(3, "sed -i \'s@(^[^#]* .*)http[:|\\.|\\/|a-z|A-Z]*\\/kali\\/@\\1", - source.url, - "@g\' /etc/apt/sources.list"); + char* cmd = xy_strjoin(3, + "sed -E -i \'s@https?://.*/kali/?@", + source.url, + "@g\' /etc/apt/sources.list"); chsrc_runcmd(cmd); // char* rm = "rm -rf /etc/apt/source.list.bak"; @@ -1283,7 +1284,7 @@ os_gentoo_setsrc(char* option) chsrc_runcmd(backup); xy_info ("chsrc: 备份文件名: /etc/portage/repos.conf/gentoo.conf.bak"); - char* cmd = xy_strjoin(3,"sed -i \"s#rsync[:|\\.|\\/|a-z|A-Z]*/gentoo-portage#rsync://", + char* cmd = xy_strjoin(3,"sed -i \"s#rsync://.*/gentoo-portage#rsync://", source.url, "gentoo-portage#g"); chsrc_runcmd(cmd); diff --git a/sources.h b/sources.h index 48cd313..776ac5c 100644 --- a/sources.h +++ b/sources.h @@ -370,13 +370,13 @@ os_ubuntu_sources[] = { * TODO: 1. 源并不完整,且未经测试是否有效 */ os_deepin_sources[] = { - {&Ali, "https://mirrors.aliyun.com/deepin/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/deepin/"}, - {&Ustc, "https://mirrors.ustc.edu.cn/deepin/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/deepin/"}, - {&Tencent, "https://mirrors.tencent.com/deepin/"}, - {&Netease, "https://mirrors.163.com/deepin/"}, - {&Sohu, "https://mirrors.sohu.com/deepin/"} + {&Ali, "https://mirrors.aliyun.com/deepin"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/deepin"}, + {&Ustc, "https://mirrors.ustc.edu.cn/deepin"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/deepin"}, + {&Tencent, "https://mirrors.tencent.com/deepin"}, + {&Netease, "https://mirrors.163.com/deepin"}, + {&Sohu, "https://mirrors.sohu.com/deepin"} }, @@ -386,13 +386,13 @@ os_deepin_sources[] = { * TODO: 1. 源并不完整,且未经测试是否有效 */ os_debian_sources[] = { - {&Ali, "https://mirrors.aliyun.com/debian/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/debian/"}, - {&Ustc, "https://mirrors.ustc.edu.cn/debian/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/debian/"}, - {&Tencent, "https://mirrors.tencent.com/debian/"}, - {&Netease, "https://mirrors.163.com/debian/"}, - {&Sohu, "https://mirrors.sohu.com/debian/"} + {&Ali, "https://mirrors.aliyun.com/debian"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/debian"}, + {&Ustc, "https://mirrors.ustc.edu.cn/debian"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/debian"}, + {&Tencent, "https://mirrors.tencent.com/debian"}, + {&Netease, "https://mirrors.163.com/debian"}, + {&Sohu, "https://mirrors.sohu.com/debian"} }, @@ -403,13 +403,13 @@ os_debian_sources[] = { * TODO: 1. 源并不完整,且未经测试是否有效 */ os_fedora_sources[] = { - {&Ali, "https://mirrors.aliyun.com/fedora/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/fedora/"}, - {&Ustc, "https://mirrors.ustc.edu.cn/fedora/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/fedora/"}, - {&Tencent, "https://mirrors.tencent.com/fedora/"}, - {&Netease, "https://mirrors.163.com/fedora/"}, - {&Sohu, "https://mirrors.sohu.com/fedora/"} + {&Ali, "https://mirrors.aliyun.com/fedora"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/fedora"}, + {&Ustc, "https://mirrors.ustc.edu.cn/fedora"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/fedora"}, + {&Tencent, "https://mirrors.tencent.com/fedora"}, + {&Netease, "https://mirrors.163.com/fedora"}, + {&Sohu, "https://mirrors.sohu.com/fedora"} }, @@ -419,13 +419,13 @@ os_fedora_sources[] = { * TODO: 1. 源并不完整,且未经测试是否有效 */ os_kali_sources[] = { - {&Ali, "https://mirrors.aliyun.com/kali/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/kali/"}, - {&Ustc, "https://mirrors.ustc.edu.cn/kali/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/kali/"}, - {&Tencent, "https://mirrors.tencent.com/kali/"}, - {&Netease, "https://mirrors.163.com/kali/"}, - {&Sohu, "https://mirrors.sohu.com/kali/"} + {&Ali, "https://mirrors.aliyun.com/kali"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/kali"}, + {&Ustc, "https://mirrors.ustc.edu.cn/kali"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/kali"}, + {&Tencent, "https://mirrors.tencent.com/kali"}, + {&Netease, "https://mirrors.163.com/kali"}, + {&Sohu, "https://mirrors.sohu.com/kali"} }, @@ -470,13 +470,13 @@ os_gentoo_sources[] = { * TODO: 1. 源并不完整,且未经测试是否有效 */ os_opensuse_sources[] = { - {&Ali, "https://mirrors.aliyun.com/opensuse/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/opensuse/"}, - {&Ustc, "https://mirrors.ustc.edu.cn/opensuse/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/opensuse/"}, - {&Tencent, "https://mirrors.tencent.com/opensuse/"}, - {&Netease, "https://mirrors.163.com/opensuse/"}, - {&Sohu, "https://mirrors.sohu.com/opensuse/"} + {&Ali, "https://mirrors.aliyun.com/opensuse"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/opensuse"}, + {&Ustc, "https://mirrors.ustc.edu.cn/opensuse"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/opensuse"}, + {&Tencent, "https://mirrors.tencent.com/opensuse"}, + {&Netease, "https://mirrors.163.com/opensuse"}, + {&Sohu, "https://mirrors.sohu.com/opensuse"} }, @@ -487,13 +487,13 @@ os_opensuse_sources[] = { * TODO: 1. 源并不完整,且未经测试是否有效 */ os_msys2_sources[] = { - {&Ali, "https://mirrors.aliyun.com/msys2/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/msys2/"}, - {&Ustc, "https://mirrors.ustc.edu.cn/msys2/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/msys2/"}, - {&Tencent, "https://mirrors.tencent.com/msys2/"}, - {&Netease, "https://mirrors.163.com/msys2/"}, - {&Sohu, "https://mirrors.sohu.com/msys2/"} + {&Ali, "https://mirrors.aliyun.com/msys2"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/msys2"}, + {&Ustc, "https://mirrors.ustc.edu.cn/msys2"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/msys2"}, + {&Tencent, "https://mirrors.tencent.com/msys2"}, + {&Netease, "https://mirrors.163.com/msys2"}, + {&Sohu, "https://mirrors.sohu.com/msys2"} },