From 5e2f74562c8b765fa6f05ade660a3e34a4da57f8 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Sun, 24 Sep 2023 20:32:33 +0800 Subject: [PATCH] Add support for `voidlinux` Gitee close #I83XTF --- README.md | 1 + chsrc.c | 176 +++++++++++++++++++++++-------------- sources.h | 254 ++++++++++++++++++++++++++++++------------------------ 3 files changed, 255 insertions(+), 176 deletions(-) diff --git a/README.md b/README.md index 7040630..9f78881 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,7 @@ sudo chsrc set kali sudo chsrc set gentoo sudo chsrc set alpine sudo chsrc set rocky +sudo chsrc set void sudo chsrc set freebsd sudo chsrc set openbsd diff --git a/chsrc.c b/chsrc.c index 998f5f9..20335e2 100644 --- a/chsrc.c +++ b/chsrc.c @@ -1040,6 +1040,69 @@ os_fedora_setsrc (char* option) +/** + * HELP: 未经测试 + */ +void +os_opensuse_setsrc (char* option) +{ + ensure_root(); // HELP: 不知道是否需要确保root权限 + int index = 0; + + if (NULL!=option) { + index = lets_find_mirror(os_opensuse, option); + } else { + index = lets_test_speed(os_opensuse); + } + + source_info source = os_opensuse_sources[index]; + chsrc_say_selection(&source); + + char* source_nselect = "zypper mr -da"; + chsrc_runcmd(source_nselect); + + char* cmd1 = xy_strjoin(3, + "zypper ar -cfg '", + source.url, + "/opensuse/distribution/leap/$releasever/repo/oss/' mirror-oss"); + char* cmd2 = xy_strjoin(3, + "zypper ar -cfg '", + source.url, + "/opensuse/distribution/leap/$releasever/repo/non-oss/' mirror-non-oss"); + char* cmd3 = xy_strjoin(3, + "zypper ar -cfg '", + source.url, + "/opensuse/distribution/leap/$releasever/oss/' mirror-update"); + char* cmd4 = xy_strjoin(3, + "zypper ar -cfg '", + source.url, + "/opensuse/distribution/leap/$releasever/non-oss/' mirror-update-non-oss"); + char* cmd5 = xy_strjoin(3, + "zypper ar -cfg '", + source.url, + "/opensuse/distribution/leap/$releasever/sle/' mirror-sle-update"); + char* cmd6 = xy_strjoin(3, + "zypper ar -cfg '", + source.url, + "/opensuse/distribution/leap/$releasever/backports/' mirror-backports-update"); + + chsrc_runcmd(cmd1); + chsrc_runcmd(cmd2); + chsrc_runcmd(cmd3); + chsrc_runcmd(cmd4); + + xy_info("chsrc: leap 15.3用户还需 要添加sle和backports源"); + xy_info("chsrc: 另外请确保系统在更新后仅启用了六个软件源,可以使用 zypper lr 检查软件源状态"); + xy_info("chsrc: 并使用 zypper mr -d 禁用多余的软件源"); + + chsrc_runcmd(cmd5); + chsrc_runcmd(cmd6); + // char* rm = "rm -f /etc/apt/source.list.bak"; + // chsrc_runcmd(rm); + chsrc_say_thanks(&source); +} + + /** * HELP: 未经测试 */ @@ -1340,6 +1403,54 @@ os_alpine_setsrc (char* option) +void +os_void_getsrc (char* option) +{ + char* cmd = "xbps-query -L"; + chsrc_runcmd(cmd); +} + +/** + * 参考: https://help.mirrors.cernet.edu.cn/voidlinux/ + */ +void +os_void_setsrc (char* option) +{ + // ensure_root(); // HELP: 不确定是否需要root + + int index = 0; + + if (NULL!=option) { + index = lets_find_mirror(os_void, option); + } else { + index = lets_test_speed(os_void); + } + + source_info source = os_void_sources[index]; + chsrc_say_selection(&source); + + char* cmd = "mkdir -p /etc/xbps.d"; + chsrc_runcmd(cmd); + + cmd = "cp /usr/share/xbps.d/*-repository-*.conf /etc/xbps.d/"; + chsrc_runcmd(cmd); + + cmd = xy_strjoin(3, + "sed -i 's|https://repo-default.voidlinux.org|", source.url, "|g' /etc/xbps.d/*-repository-*.conf" + ); + chsrc_runcmd(cmd); + + cmd = xy_strjoin(3, + "sed -i 's|https://alpha.de.repo.voidlinux.org|", source.url, "|g' /etc/xbps.d/*-repository-*.conf" + ); + + xy_warn("chsrc: 若报错可尝试使用以下命令"); + puts(cmd); + chsrc_say_thanks(&source); +} + + + /** * HELP: 未经测试 */ @@ -1554,69 +1665,6 @@ os_freebsd_setsrc (char* option) -/** - * HELP: 未经测试 - */ -void -os_opensuse_setsrc (char* option) -{ - ensure_root(); // HELP: 不知道是否需要确保root权限 - int index = 0; - - if (NULL!=option) { - index = lets_find_mirror(os_opensuse, option); - } else { - index = lets_test_speed(os_opensuse); - } - - source_info source = os_opensuse_sources[index]; - chsrc_say_selection(&source); - - char* source_nselect = "zypper mr -da"; - chsrc_runcmd(source_nselect); - - char* cmd1 = xy_strjoin(3, - "zypper ar -cfg '", - source.url, - "/opensuse/distribution/leap/$releasever/repo/oss/' mirror-oss"); - char* cmd2 = xy_strjoin(3, - "zypper ar -cfg '", - source.url, - "/opensuse/distribution/leap/$releasever/repo/non-oss/' mirror-non-oss"); - char* cmd3 = xy_strjoin(3, - "zypper ar -cfg '", - source.url, - "/opensuse/distribution/leap/$releasever/oss/' mirror-update"); - char* cmd4 = xy_strjoin(3, - "zypper ar -cfg '", - source.url, - "/opensuse/distribution/leap/$releasever/non-oss/' mirror-update-non-oss"); - char* cmd5 = xy_strjoin(3, - "zypper ar -cfg '", - source.url, - "/opensuse/distribution/leap/$releasever/sle/' mirror-sle-update"); - char* cmd6 = xy_strjoin(3, - "zypper ar -cfg '", - source.url, - "/opensuse/distribution/leap/$releasever/backports/' mirror-backports-update"); - - chsrc_runcmd(cmd1); - chsrc_runcmd(cmd2); - chsrc_runcmd(cmd3); - chsrc_runcmd(cmd4); - - xy_info("chsrc: leap 15.3用户还需 要添加sle和backports源"); - xy_info("chsrc: 另外请确保系统在更新后仅启用了六个软件源,可以使用 zypper lr 检查软件源状态"); - xy_info("chsrc: 并使用 zypper mr -d 禁用多余的软件源"); - - chsrc_runcmd(cmd5); - chsrc_runcmd(cmd6); - // char* rm = "rm -f /etc/apt/source.list.bak"; - // chsrc_runcmd(rm); - chsrc_say_thanks(&source); -} - - @@ -1960,6 +2008,7 @@ static const char def_target_info(os_ubuntu); def_target_info(os_debian); def_target_info(os_deepin); +def_target_info(os_void); target_info os_fedora_target = {os_fedora_setsrc, NULL, os_fedora_sources, os_fedora_sources_n}, @@ -1989,6 +2038,7 @@ static const char *os_gentoo [] = {"gentoo", NULL, targetinfo(&os_gentoo_target)}, *os_rocky [] = {"rocky", "rockylinux", NULL, targetinfo(&os_rocky_target)}, *os_alpine [] = {"alpine", NULL, targetinfo(&os_alpine_target)}, +*os_void [] = {"void", "voidlinux", NULL, targetinfo(&os_void_target)}, *os_freebsd [] = {"freebsd", NULL, targetinfo(&os_freebsd_target)}, *os_netbsd [] = {"netbsd", NULL, targetinfo(&os_netbsd_target)}, *os_openbsd [] = {"openbsd", NULL, targetinfo(&os_openbsd_target)}, diff --git a/sources.h b/sources.h index 05a6891..1a14931 100644 --- a/sources.h +++ b/sources.h @@ -430,6 +430,74 @@ os_kali_sources[] = { +/** + * 2023-09-05 更新 + * + * TODO: 1. 源并不完整,且未经测试是否有效 + */ +os_arch_sources[] = { + {&Ali, "https://mirrors.aliyun.com/"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/"}, + {&Ustc, "https://mirrors.ustc.edu.cn/"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/"}, + {&Tencent, "https://mirrors.tencent.com/"}, + {&Netease, "https://mirrors.163.com/"}, + {&Sohu, "https://mirrors.sohu.com/"} +}, + + + +/** + * 2023-09-05 更新 + * + * TODO: 1. 源并不完整,且未经测试是否有效 + */ +os_gentoo_sources[] = { + {&Ali, "mirrors.aliyun.com"}, + {&Bfsu, "mirrors.bfsu.edu.cn"}, + {&Ustc, "mirrors.ustc.edu.cn"}, + {&Tuna, "mirrors.tuna.tsinghua.edu.cn"}, + {&Tencent, "mirrors.tencent.com"}, + {&Netease, "mirrors.163.com"}, + {&Sohu, "mirrors.sohu.com"} +}, + + + +/** + * 2023-09-17 更新 + * + * 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/"} +}, + + + +/** + * 2023-09-02 更新 + * + * 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/"} +}, + + + /** * 2023-09-24 更新 */ @@ -461,111 +529,15 @@ os_alpine_sources[] = { /** - * 2023-09-02 更新 - * - * TODO: 1. 源并不完整,且未经测试是否有效 + * 2023-09-24 更新 */ -os_openbsd_sources[] = { - {&Ali, "https://mirrors.aliyun.com/OpenBSD/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/OpenBSD/"}, - {&Ustc, "https://mirrors.ustc.edu.cn/OpenBSD/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/OpenBSD/"}, - {&Tencent, "https://mirrors.tencent.com/OpenBSD/"}, - {&Netease, "https://mirrors.163.com/OpenBSD/"}, - {&Sohu, "https://mirrors.sohu.com/OpenBSD/"} +os_void_sources[] = { + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/voidlinux"}, + {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/voidlinux"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/voidlinux"} }, -/** - * 2023-09-02 更新 - * - * 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/"} -}, - - -/** - * 2023-09-05 更新 - * - * TODO: 1. 源并不完整,且未经测试是否有效 - */ -os_arch_sources[] = { - {&Ali, "https://mirrors.aliyun.com/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/"}, - {&Ustc, "https://mirrors.ustc.edu.cn/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/"}, - {&Tencent, "https://mirrors.tencent.com/"}, - {&Netease, "https://mirrors.163.com/"}, - {&Sohu, "https://mirrors.sohu.com/"} -}, - -/** - * 2023-09-05 更新 - * - * TODO: 1. 源并不完整,且未经测试是否有效 - */ -os_gentoo_sources[] = { - {&Ali, "mirrors.aliyun.com"}, - {&Bfsu, "mirrors.bfsu.edu.cn"}, - {&Ustc, "mirrors.ustc.edu.cn"}, - {&Tuna, "mirrors.tuna.tsinghua.edu.cn"}, - {&Tencent, "mirrors.tencent.com"}, - {&Netease, "mirrors.163.com"}, - {&Sohu, "mirrors.sohu.com"} -}, - -/** - * 2023-09-05 更新 - * - * TODO: 1. 源并不完整,且未经测试是否有效 - */ -os_netbsd_sources[] = { - {&Ali, "https://mirrors.aliyun.com/pkgsrc/packages/NetBSD/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/pkgsrc/packages/NetBSD/"}, - {&Ustc, "https://mirrors.ustc.edu.cn/pkgsrc/packages/NetBSD/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/pkgsrc/packages/NetBSD/"}, - {&Tencent, "https://mirrors.tencent.com/pkgsrc/packages/NetBSD/"}, - {&Netease, "https://mirrors.163.com/pkgsrc/packages/NetBSD/"}, - {&Sohu, "https://mirrors.sohu.com/pkgsrc/packages/NetBSD/"} -}, - -/** - * 2023-09-06 更新 - * - * TODO: 1. 源并不完整,且未经测试是否有效 - */ -os_openeuler_sources[] = { - {&Ali, "https://mirrors.aliyun.com/openeuler/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/openeuler/"}, - {&Ustc, "https://mirrors.ustc.edu.cn/openeuler/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/openeuler/"}, - {&Tencent, "https://mirrors.tencent.com/openeuler/"}, - {&Netease, "https://mirrors.163.com/openeuler/"}, - {&Sohu, "https://mirrors.sohu.com/openeuler/"} -}, - -/** - * 2023-09-06 更新 - * - * TODO: 1. 源并不完整,且未经测试是否有效 - */ -os_openkylin_sources[] = { - {&Ali, "https://mirrors.aliyun.com/openkylin/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/openkylin/"}, - {&Ustc, "https://mirrors.ustc.edu.cn/openkylin/"}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/openkylin/"}, - {&Tencent, "https://mirrors.tencent.com/openkylin/"}, - {&Netease, "https://mirrors.163.com/openkylin/"}, - {&Sohu, "https://mirrors.sohu.com/openkylin/"} -}, /** * 2023-09-17 更新 @@ -582,22 +554,78 @@ os_freebsd_sources[] = { {&Sohu, "mirrors.sohu.com"} }, + + /** - * 2023-09-17 更新 + * 2023-09-05 更新 * * 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/"} +os_netbsd_sources[] = { + {&Ali, "https://mirrors.aliyun.com/pkgsrc/packages/NetBSD/"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/pkgsrc/packages/NetBSD/"}, + {&Ustc, "https://mirrors.ustc.edu.cn/pkgsrc/packages/NetBSD/"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/pkgsrc/packages/NetBSD/"}, + {&Tencent, "https://mirrors.tencent.com/pkgsrc/packages/NetBSD/"}, + {&Netease, "https://mirrors.163.com/pkgsrc/packages/NetBSD/"}, + {&Sohu, "https://mirrors.sohu.com/pkgsrc/packages/NetBSD/"} +}, + + +/** + * 2023-09-02 更新 + * + * TODO: 1. 源并不完整,且未经测试是否有效 + */ +os_openbsd_sources[] = { + {&Ali, "https://mirrors.aliyun.com/OpenBSD/"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/OpenBSD/"}, + {&Ustc, "https://mirrors.ustc.edu.cn/OpenBSD/"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/OpenBSD/"}, + {&Tencent, "https://mirrors.tencent.com/OpenBSD/"}, + {&Netease, "https://mirrors.163.com/OpenBSD/"}, + {&Sohu, "https://mirrors.sohu.com/OpenBSD/"} +}, + + + +/** + * 2023-09-06 更新 + * + * TODO: 1. 源并不完整,且未经测试是否有效 + */ +os_openeuler_sources[] = { + {&Ali, "https://mirrors.aliyun.com/openeuler/"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/openeuler/"}, + {&Ustc, "https://mirrors.ustc.edu.cn/openeuler/"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/openeuler/"}, + {&Tencent, "https://mirrors.tencent.com/openeuler/"}, + {&Netease, "https://mirrors.163.com/openeuler/"}, + {&Sohu, "https://mirrors.sohu.com/openeuler/"} +}, + + + +/** + * 2023-09-06 更新 + * + * TODO: 1. 源并不完整,且未经测试是否有效 + */ +os_openkylin_sources[] = { + {&Ali, "https://mirrors.aliyun.com/openkylin/"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/openkylin/"}, + {&Ustc, "https://mirrors.ustc.edu.cn/openkylin/"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/openkylin/"}, + {&Tencent, "https://mirrors.tencent.com/openkylin/"}, + {&Netease, "https://mirrors.163.com/openkylin/"}, + {&Sohu, "https://mirrors.sohu.com/openkylin/"} }; + + + + /** * 2023-09-10 更新 * @@ -704,9 +732,9 @@ def_target_sources_n(pl_r); def_target_sources_n(pl_julia); def_target_sources_n(os_ubuntu); def_target_sources_n(os_debian); def_target_sources_n(os_fedora); def_target_sources_n(os_kali); def_target_sources_n(os_opensuse); -def_target_sources_n(os_arch); def_target_sources_n(os_gentoo); def_target_sources_n(os_alpine); -def_target_sources_n(os_rocky); -def_target_sources_n(os_msys2); +def_target_sources_n(os_arch); def_target_sources_n(os_msys2); def_target_sources_n(os_gentoo); +def_target_sources_n(os_alpine); def_target_sources_n(os_rocky); def_target_sources_n(os_void); + def_target_sources_n(os_freebsd); def_target_sources_n(os_netbsd); def_target_sources_n(os_openbsd); def_target_sources_n(os_deepin); def_target_sources_n(os_openeuler); def_target_sources_n(os_openkylin);