Modify sed to more simple,including ubuntu,deepin,fedora,debian,kali,gentoo

This commit is contained in:
Heng Guo 2023-09-26 16:40:12 +08:00
parent 29c54e0498
commit 9d600b26c8
2 changed files with 62 additions and 61 deletions

39
chsrc.c
View File

@ -869,14 +869,14 @@ os_ubuntu_setsrc (char* option)
if(strncmp(arch, "x86_64", 6)==0) if(strncmp(arch, "x86_64", 6)==0)
{ {
cmd = xy_strjoin(3, cmd = xy_strjoin(3,
"sed -E -i \'s@https?://.*/ubuntu@", "sed -E -i \'s@https?://.*/ubuntu/?@",
source.url, source.url,
"@g\' /etc/apt/sources.list"); "@g\' /etc/apt/sources.list");
} }
else { else {
cmd = xy_strjoin(3, cmd = xy_strjoin(3,
"sed -E -i \'s@https?://.*/ubuntu-ports@", "sed -E -i \'s@https?://.*/ubuntu-ports/?@",
source.url, source.url,
"-ports@g\' /etc/apt/sources.list"); "-ports@g\' /etc/apt/sources.list");
} }
@ -919,12 +919,13 @@ os_debian_setsrc (char* option)
xy_info ("chsrc: 如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并 需要您 安装"); xy_info ("chsrc: 如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并 需要您 安装");
xy_info ("chsrc: sudo apt install apt-transport-https ca-certificates"); 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); chsrc_runcmd(backup);
char * cmd = xy_strjoin(3,"chsrc: 备份文件名: /etc/apt/.*)http[:|\\.|\\/|a-z|A-Z]*\\/debian\\/@\\1", char* cmd = xy_strjoin(3,
source.url, "sed -E -i \'s@https?://.*/debian/?@",
"@\'< /etc/apt/sources.list.bak | cat > /etc/apt/sources.list"); source.url,
"@g\' /etc/apt/sources.list");
chsrc_runcmd(cmd); chsrc_runcmd(cmd);
@ -961,16 +962,15 @@ os_deepin_setsrc (char* option)
source_info source = os_deepin_sources[index]; source_info source = os_deepin_sources[index];
chsrc_say_selection(&source); 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); chsrc_runcmd(backup);
xy_info ("chsrc: 备份文件名: /etc/apt/sources.list.bak"); xy_info ("chsrc: 备份文件名: /etc/apt/sources.list.bak");
char* cmd; char* cmd = xy_strjoin(3,
cmd = xy_strjoin(3, "sed -E -i \'s@https?://.*/deepin/?@",
"sed -E \'s@(^[^#]* .*)http[:|\\.|\\/|a-z|A-Z]*\\/deepin\\/@\\1", source.url,
source.url, "@g\' /etc/apt/sources.list");
"@\'< /etc/apt/sources.list.bak | cat > /etc/apt/sources.list");
chsrc_logcmd(cmd); chsrc_logcmd(cmd);
system(cmd); system(cmd);
// char* rm = "rm -rf /etc/apt/source.list.bak"; // char* rm = "rm -rf /etc/apt/source.list.bak";
@ -1002,10 +1002,10 @@ os_fedora_setsrc (char* option)
xy_warn ("chsrc: fedora 29 及以下版本暂不支持"); 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); 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); chsrc_runcmd(backup);
xy_info ("chsrc: 备份文件名:1. /etc/yum.repos.d/fedora.repo.bak"); 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]; source_info source = os_kali_sources[index];
chsrc_say_selection(&source); 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); chsrc_runcmd(backup);
xy_info ("chsrc: 备份文件名: /etc/apt/sources.list.bak"); xy_info ("chsrc: 备份文件名: /etc/apt/sources.list.bak");
char* cmd = xy_strjoin(3, "sed -i \'s@(^[^#]* .*)http[:|\\.|\\/|a-z|A-Z]*\\/kali\\/@\\1", char* cmd = xy_strjoin(3,
source.url, "sed -E -i \'s@https?://.*/kali/?@",
"@g\' /etc/apt/sources.list"); source.url,
"@g\' /etc/apt/sources.list");
chsrc_runcmd(cmd); chsrc_runcmd(cmd);
// char* rm = "rm -rf /etc/apt/source.list.bak"; // char* rm = "rm -rf /etc/apt/source.list.bak";
@ -1283,7 +1284,7 @@ os_gentoo_setsrc(char* option)
chsrc_runcmd(backup); chsrc_runcmd(backup);
xy_info ("chsrc: 备份文件名: /etc/portage/repos.conf/gentoo.conf.bak"); 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, source.url,
"gentoo-portage#g"); "gentoo-portage#g");
chsrc_runcmd(cmd); chsrc_runcmd(cmd);

View File

@ -370,13 +370,13 @@ os_ubuntu_sources[] = {
* TODO: 1. * TODO: 1.
*/ */
os_deepin_sources[] = { os_deepin_sources[] = {
{&Ali, "https://mirrors.aliyun.com/deepin/"}, {&Ali, "https://mirrors.aliyun.com/deepin"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/deepin/"}, {&Bfsu, "https://mirrors.bfsu.edu.cn/deepin"},
{&Ustc, "https://mirrors.ustc.edu.cn/deepin/"}, {&Ustc, "https://mirrors.ustc.edu.cn/deepin"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/deepin/"}, {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/deepin"},
{&Tencent, "https://mirrors.tencent.com/deepin/"}, {&Tencent, "https://mirrors.tencent.com/deepin"},
{&Netease, "https://mirrors.163.com/deepin/"}, {&Netease, "https://mirrors.163.com/deepin"},
{&Sohu, "https://mirrors.sohu.com/deepin/"} {&Sohu, "https://mirrors.sohu.com/deepin"}
}, },
@ -386,13 +386,13 @@ os_deepin_sources[] = {
* TODO: 1. * TODO: 1.
*/ */
os_debian_sources[] = { os_debian_sources[] = {
{&Ali, "https://mirrors.aliyun.com/debian/"}, {&Ali, "https://mirrors.aliyun.com/debian"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/debian/"}, {&Bfsu, "https://mirrors.bfsu.edu.cn/debian"},
{&Ustc, "https://mirrors.ustc.edu.cn/debian/"}, {&Ustc, "https://mirrors.ustc.edu.cn/debian"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/debian/"}, {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/debian"},
{&Tencent, "https://mirrors.tencent.com/debian/"}, {&Tencent, "https://mirrors.tencent.com/debian"},
{&Netease, "https://mirrors.163.com/debian/"}, {&Netease, "https://mirrors.163.com/debian"},
{&Sohu, "https://mirrors.sohu.com/debian/"} {&Sohu, "https://mirrors.sohu.com/debian"}
}, },
@ -403,13 +403,13 @@ os_debian_sources[] = {
* TODO: 1. * TODO: 1.
*/ */
os_fedora_sources[] = { os_fedora_sources[] = {
{&Ali, "https://mirrors.aliyun.com/fedora/"}, {&Ali, "https://mirrors.aliyun.com/fedora"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/fedora/"}, {&Bfsu, "https://mirrors.bfsu.edu.cn/fedora"},
{&Ustc, "https://mirrors.ustc.edu.cn/fedora/"}, {&Ustc, "https://mirrors.ustc.edu.cn/fedora"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/fedora/"}, {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/fedora"},
{&Tencent, "https://mirrors.tencent.com/fedora/"}, {&Tencent, "https://mirrors.tencent.com/fedora"},
{&Netease, "https://mirrors.163.com/fedora/"}, {&Netease, "https://mirrors.163.com/fedora"},
{&Sohu, "https://mirrors.sohu.com/fedora/"} {&Sohu, "https://mirrors.sohu.com/fedora"}
}, },
@ -419,13 +419,13 @@ os_fedora_sources[] = {
* TODO: 1. * TODO: 1.
*/ */
os_kali_sources[] = { os_kali_sources[] = {
{&Ali, "https://mirrors.aliyun.com/kali/"}, {&Ali, "https://mirrors.aliyun.com/kali"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/kali/"}, {&Bfsu, "https://mirrors.bfsu.edu.cn/kali"},
{&Ustc, "https://mirrors.ustc.edu.cn/kali/"}, {&Ustc, "https://mirrors.ustc.edu.cn/kali"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/kali/"}, {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/kali"},
{&Tencent, "https://mirrors.tencent.com/kali/"}, {&Tencent, "https://mirrors.tencent.com/kali"},
{&Netease, "https://mirrors.163.com/kali/"}, {&Netease, "https://mirrors.163.com/kali"},
{&Sohu, "https://mirrors.sohu.com/kali/"} {&Sohu, "https://mirrors.sohu.com/kali"}
}, },
@ -470,13 +470,13 @@ os_gentoo_sources[] = {
* TODO: 1. * TODO: 1.
*/ */
os_opensuse_sources[] = { os_opensuse_sources[] = {
{&Ali, "https://mirrors.aliyun.com/opensuse/"}, {&Ali, "https://mirrors.aliyun.com/opensuse"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/opensuse/"}, {&Bfsu, "https://mirrors.bfsu.edu.cn/opensuse"},
{&Ustc, "https://mirrors.ustc.edu.cn/opensuse/"}, {&Ustc, "https://mirrors.ustc.edu.cn/opensuse"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/opensuse/"}, {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/opensuse"},
{&Tencent, "https://mirrors.tencent.com/opensuse/"}, {&Tencent, "https://mirrors.tencent.com/opensuse"},
{&Netease, "https://mirrors.163.com/opensuse/"}, {&Netease, "https://mirrors.163.com/opensuse"},
{&Sohu, "https://mirrors.sohu.com/opensuse/"} {&Sohu, "https://mirrors.sohu.com/opensuse"}
}, },
@ -487,13 +487,13 @@ os_opensuse_sources[] = {
* TODO: 1. * TODO: 1.
*/ */
os_msys2_sources[] = { os_msys2_sources[] = {
{&Ali, "https://mirrors.aliyun.com/msys2/"}, {&Ali, "https://mirrors.aliyun.com/msys2"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/msys2/"}, {&Bfsu, "https://mirrors.bfsu.edu.cn/msys2"},
{&Ustc, "https://mirrors.ustc.edu.cn/msys2/"}, {&Ustc, "https://mirrors.ustc.edu.cn/msys2"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/msys2/"}, {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/msys2"},
{&Tencent, "https://mirrors.tencent.com/msys2/"}, {&Tencent, "https://mirrors.tencent.com/msys2"},
{&Netease, "https://mirrors.163.com/msys2/"}, {&Netease, "https://mirrors.163.com/msys2"},
{&Sohu, "https://mirrors.sohu.com/msys2/"} {&Sohu, "https://mirrors.sohu.com/msys2"}
}, },