diff --git a/src/chsrc-main.c b/src/chsrc-main.c index 8b533c3..a3386b6 100644 --- a/src/chsrc-main.c +++ b/src/chsrc-main.c @@ -86,6 +86,47 @@ #include "recipe/lang/NuGet.c" #include "recipe/lang/Clojure.c" +#include "recipe/os/rawstr4c.h" +#include "recipe/os/APT/common.h" +// Debian-based +#include "recipe/os/APT/Debian.c" +#include "recipe/os/APT/Ubuntu.c" +#include "recipe/os/APT/Kali-Linux.c" +#include "recipe/os/APT/Raspberry-Pi-OS.c" +// Ubuntu-based +#include "recipe/os/APT/Linux-Mint.c" +#include "recipe/os/APT/Trisquel.c" +#include "recipe/os/APT/Linux-Lite.c" +// Debian-based and Ubuntu-based +#include "recipe/os/APT/Armbian.c" +// Independent +#include "recipe/os/APT/ROS.c" +#include "recipe/os/APT/Termux.c" +#include "recipe/os/APT/openKylin.c" +#include "recipe/os/APT/deepin.c" + +#include "recipe/os/YUM/common.h" +#include "recipe/os/YUM/Fedora-Linux.c" +#include "recipe/os/YUM/AlmaLinux.c" +#include "recipe/os/YUM/Rocky-Linux.c" +#include "recipe/os/YUM/openEuler.c" +#include "recipe/os/YUM/Anolis-OS.c" + +#include "recipe/os/pacman/Arch-Linux.c" +#include "recipe/os/pacman/Manjaro-Linux.c" +#include "recipe/os/pacman/MSYS2.c" + +#include "recipe/os/openSUSE.c" +#include "recipe/os/Alpine-Linux.c" +#include "recipe/os/Gentoo-Linux.c" +#include "recipe/os/Void-Linux.c" +#include "recipe/os/Solus.c" +#include "recipe/os/OpenWrt.c" + +#include "recipe/os/BSD/FreeBSD.c" +#include "recipe/os/BSD/NetBSD.c" +#include "recipe/os/BSD/OpenBSD.c" + #include "rawstr4c.h" diff --git a/src/recipe/os/APT/Armbian.c b/src/recipe/os/APT/Armbian.c index 8ad9238..547d2a1 100644 --- a/src/recipe/os/APT/Armbian.c +++ b/src/recipe/os/APT/Armbian.c @@ -64,7 +64,7 @@ os_armbian_setsrc (char *option) { chsrc_ensure_root (); - chsrc_yield_source_and_confirm (os_armbian); + use_this_source(os_armbian); chsrc_backup (OS_Armbian_SourceList); diff --git a/src/recipe/os/APT/Debian.c b/src/recipe/os/APT/Debian.c index c3de98f..18b8787 100644 --- a/src/recipe/os/APT/Debian.c +++ b/src/recipe/os/APT/Debian.c @@ -89,7 +89,7 @@ os_debian_does_old_sourcelist_use_cdrom (void) void os_debian_setsrc_for_deb822 (char *option) { - chsrc_yield_source_and_confirm (os_debian); + use_this_source(os_debian); chsrc_backup (OS_Debian_SourceList_DEB822); @@ -150,7 +150,7 @@ os_debian_setsrc (char *option) } } - chsrc_yield_source_and_confirm (os_debian); + use_this_source(os_debian); chsrc_alert2 ("如果遇到无法拉取 HTTPS 源的情况,请手动运行:"); say ("apt install apt-transport-https ca-certificates"); diff --git a/src/recipe/os/APT/Kali-Linux.c b/src/recipe/os/APT/Kali-Linux.c index 127edd6..28e2de9 100644 --- a/src/recipe/os/APT/Kali-Linux.c +++ b/src/recipe/os/APT/Kali-Linux.c @@ -51,7 +51,7 @@ os_kali_setsrc (char *option) { chsrc_ensure_root (); - chsrc_yield_source_and_confirm (os_kali); + use_this_source(os_kali); chsrc_backup (OS_Apt_SourceList); diff --git a/src/recipe/os/APT/Linux-Lite.c b/src/recipe/os/APT/Linux-Lite.c index 9032bbf..aa6f1ca 100644 --- a/src/recipe/os/APT/Linux-Lite.c +++ b/src/recipe/os/APT/Linux-Lite.c @@ -49,7 +49,7 @@ os_linuxlite_setsrc (char *option) { chsrc_ensure_root (); - chsrc_yield_source_and_confirm (os_linuxlite); + use_this_source(os_linuxlite); chsrc_backup (OS_Apt_SourceList); diff --git a/src/recipe/os/APT/Linux-Mint.c b/src/recipe/os/APT/Linux-Mint.c index fcb8859..9cfb803 100644 --- a/src/recipe/os/APT/Linux-Mint.c +++ b/src/recipe/os/APT/Linux-Mint.c @@ -61,7 +61,7 @@ os_linuxmint_setsrc (char *option) { chsrc_ensure_root (); - chsrc_yield_source_and_confirm (os_linuxmint); + use_this_source(os_linuxmint); chsrc_backup (OS_LinuxMint_SourceList); diff --git a/src/recipe/os/APT/ROS.c b/src/recipe/os/APT/ROS.c index e80737a..8e6bfb0 100644 --- a/src/recipe/os/APT/ROS.c +++ b/src/recipe/os/APT/ROS.c @@ -59,7 +59,7 @@ os_ros_setsrc (char *option) { chsrc_ensure_root (); - chsrc_yield_source_and_confirm (os_ros); + use_this_source(os_ros); chsrc_backup (OS_ROS_SourceList); diff --git a/src/recipe/os/APT/Raspberry-Pi-OS.c b/src/recipe/os/APT/Raspberry-Pi-OS.c index 95dfd57..2bb8d7d 100644 --- a/src/recipe/os/APT/Raspberry-Pi-OS.c +++ b/src/recipe/os/APT/Raspberry-Pi-OS.c @@ -53,7 +53,7 @@ os_raspberrypi_setsrc (char *option) { chsrc_ensure_root(); // HELP: 不确定是否需要 - chsrc_yield_source_and_confirm (os_raspberrypi); + use_this_source(os_raspberrypi); chsrc_backup (OS_RaspberryPi_SourceList); diff --git a/src/recipe/os/APT/Termux.c b/src/recipe/os/APT/Termux.c index 066f967..8d5f7d9 100644 --- a/src/recipe/os/APT/Termux.c +++ b/src/recipe/os/APT/Termux.c @@ -61,7 +61,7 @@ os_termux_setsrc (char *option) // chsrc_ensure_root (); Termux下禁止使用root - chsrc_yield_source_and_confirm (os_termux); + use_this_source(os_termux); char *cmd = xy_strjoin (3, "sed -i 's@^\\(deb.*stable main\\)$@#\\1\\ndeb ", source.url, "apt/termux-main stable main@' " OS_Termux_SourceList); diff --git a/src/recipe/os/APT/Trisquel.c b/src/recipe/os/APT/Trisquel.c index 5b98efd..941f177 100644 --- a/src/recipe/os/APT/Trisquel.c +++ b/src/recipe/os/APT/Trisquel.c @@ -53,7 +53,7 @@ os_trisquel_setsrc (char *option) { chsrc_ensure_root (); - chsrc_yield_source_and_confirm (os_trisquel); + use_this_source(os_trisquel); chsrc_backup (OS_Apt_SourceList); diff --git a/src/recipe/os/APT/Ubuntu.c b/src/recipe/os/APT/Ubuntu.c index ecba803..282b824 100644 --- a/src/recipe/os/APT/Ubuntu.c +++ b/src/recipe/os/APT/Ubuntu.c @@ -79,7 +79,7 @@ os_ubuntu_getsrc (char *option) void os_ubuntu_setsrc_for_deb822 (char *option) { - chsrc_yield_source_and_confirm (os_ubuntu); + use_this_source(os_ubuntu); chsrc_backup (OS_Ubuntu_SourceList_DEB822); @@ -122,7 +122,7 @@ os_ubuntu_setsrc (char *option) bool sourcelist_exist = ensure_debian_or_ubuntu_old_sourcelist (OS_Is_Ubuntu); - chsrc_yield_source_and_confirm (os_ubuntu); + use_this_source(os_ubuntu); /* 不存在的时候,用的是我们生成的无效文件,不要备份 */ if (sourcelist_exist) diff --git a/src/recipe/os/APT/deepin.c b/src/recipe/os/APT/deepin.c index 46add3b..ece5cc8 100644 --- a/src/recipe/os/APT/deepin.c +++ b/src/recipe/os/APT/deepin.c @@ -56,7 +56,7 @@ os_deepin_setsrc (char *option) { chsrc_ensure_root(); - chsrc_yield_source_and_confirm (os_deepin); + use_this_source(os_deepin); chsrc_backup (OS_Apt_SourceList); diff --git a/src/recipe/os/APT/openKylin.c b/src/recipe/os/APT/openKylin.c index a2b58c9..b06da7d 100644 --- a/src/recipe/os/APT/openKylin.c +++ b/src/recipe/os/APT/openKylin.c @@ -47,7 +47,7 @@ os_openkylin_setsrc (char *option) { chsrc_ensure_root(); - chsrc_yield_source_and_confirm (os_openkylin); + use_this_source(os_openkylin); chsrc_backup (OS_Apt_SourceList); diff --git a/src/recipe/os/Alpine-Linux.c b/src/recipe/os/Alpine-Linux.c index ab8db97..e945e43 100644 --- a/src/recipe/os/Alpine-Linux.c +++ b/src/recipe/os/Alpine-Linux.c @@ -57,8 +57,7 @@ os_alpine_setsrc (char *option) { // chsrc_ensure_root(); // HELP: 不确定是否需要root - use_this(os_alpine); - Source_t source = chsrc_yield_source_and_confirm (this, option); + use_this_source(os_alpine); char* cmd = xy_strjoin (3, "sed -i 's#https\\?://dl-cdn.alpinelinux.org/alpine#", source.url, "#g' /etc/apk/repositories" diff --git a/src/recipe/os/BSD/FreeBSD.c b/src/recipe/os/BSD/FreeBSD.c index f3547fe..ef0735d 100644 --- a/src/recipe/os/BSD/FreeBSD.c +++ b/src/recipe/os/BSD/FreeBSD.c @@ -23,8 +23,9 @@ os_freebsd_prelude () chef_forbid_english(this); chef_forbid_user_define(this); - chef_set_note ("2023-09-24: 以下三个USTC, NJU, Netease 均维护了 freebsd-pkg freebsd-ports\n2023-09-27: 请务必保持Nju前面有至少一个镜像,原因请查看 freebsd 的换源函数", NULL); + // 2023-09-24: 以下三个USTC, NJU, Netease 均维护了 freebsd-pkg freebsd-ports + // 2023-09-27: 请务必保持Nju前面有至少一个镜像,原因请查看 freebsd 的换源函数 def_sources_begin() {&upstream, NULL, DelegateToUpstream}, {&Ustc, "mirrors.ustc.edu.cn", DelegateToMirror}, @@ -47,10 +48,11 @@ os_freebsd_setsrc (char *option) // 据 @ykla,FreeBSD不自带sudo,但是我们依然要保证是root权限 chsrc_ensure_root (); - int index = use_specific_mirror_or_auto_select (option, os_freebsd); + use_this(os_freebsd); + int index = use_specific_mirror_or_auto_select (option, this); - Source_t source = os_freebsd_sources[index]; - chsrc_confirm_source(); + Source_t source = this->sources[index]; + chsrc_confirm_source(&source); chsrc_log2 ("1. 添加 freebsd-pkg 源 (二进制安装包)"); chsrc_ensure_dir ("/usr/local/etc/pkg/repos"); @@ -80,11 +82,11 @@ os_freebsd_setsrc (char *option) { if (xy_streql("nju",source.mirror->code)) { - source = os_freebsd_sources[index-1]; // 使用NJU的前一个源,即USTC源 + source = this->sources[index-1]; // 使用NJU的前一个源,即USTC源 } char *git_cmd = xy_strjoin (3, "git clone --depth 1 https://", source.url, "/freebsd-ports/ports.git /usr/ports"); chsrc_run (git_cmd, RunOpt_Default); - source = os_freebsd_sources[index]; // 恢复至选中的源 + source = this->sources[index]; // 恢复至选中的源 chsrc_alert2 ("下次更新请使用 git -C /usr/ports pull 而非使用 gitup"); } else diff --git a/src/recipe/os/BSD/NetBSD.c b/src/recipe/os/BSD/NetBSD.c index 22e9248..361c295 100644 --- a/src/recipe/os/BSD/NetBSD.c +++ b/src/recipe/os/BSD/NetBSD.c @@ -24,8 +24,6 @@ os_netbsd_prelude () chef_forbid_english(this); chef_forbid_user_define(this); - chef_set_note ("根据 @ykla: NetBSD 默认状态下没有 pkgsrc,用户可能安装了也可能没安装", NULL); - def_sources_begin() {&upstream, NULL, DelegateToUpstream}, {&MirrorZ, "https://mirrors.cernet.edu.cn/pkgsrc/packages/NetBSD/", DelegateToMirror}, @@ -62,7 +60,7 @@ os_netbsd_setsrc (char *option) { chsrc_ensure_root (); - chsrc_yield_source_and_confirm (os_netbsd); + use_this_source(os_netbsd); chsrc_backup ("/usr/pkg/etc/pkgin/repositories.conf"); diff --git a/src/recipe/os/BSD/OpenBSD.c b/src/recipe/os/BSD/OpenBSD.c index af81f3d..7920c22 100644 --- a/src/recipe/os/BSD/OpenBSD.c +++ b/src/recipe/os/BSD/OpenBSD.c @@ -59,7 +59,7 @@ os_openbsd_setsrc (char *option) { chsrc_ensure_root (); - chsrc_yield_source_and_confirm (os_openbsd); + use_this_source(os_openbsd); chsrc_backup ("/etc/installurl"); chsrc_overwrite_file (source.url, "/etc/installurl"); diff --git a/src/recipe/os/Gentoo-Linux.c b/src/recipe/os/Gentoo-Linux.c index b1d4a92..aaf4017 100644 --- a/src/recipe/os/Gentoo-Linux.c +++ b/src/recipe/os/Gentoo-Linux.c @@ -45,8 +45,7 @@ os_gentoo_setsrc (char *option) { chsrc_ensure_root (); - use_this(os_gentoo); - Source_t source = chsrc_yield_source_and_confirm (this, option); + use_this_source(os_gentoo); chsrc_backup ("/etc/portage/repos.conf/gentoo.conf"); diff --git a/src/recipe/os/OpenWrt.c b/src/recipe/os/OpenWrt.c index 89914a3..02a9982 100644 --- a/src/recipe/os/OpenWrt.c +++ b/src/recipe/os/OpenWrt.c @@ -61,8 +61,7 @@ os_openwrt_setsrc (char *option) { chsrc_ensure_root (); - use_this(os_openwrt); - Source_t source = chsrc_yield_source_and_confirm (this, option); + use_this_source(os_openwrt); chsrc_backup (OS_OpenWRT_SourceConfig); diff --git a/src/recipe/os/Solus.c b/src/recipe/os/Solus.c index 073c6b5..8459e96 100644 --- a/src/recipe/os/Solus.c +++ b/src/recipe/os/Solus.c @@ -43,8 +43,7 @@ os_solus_setsrc (char *option) { chsrc_ensure_root (); - use_this(os_solus); - Source_t source = chsrc_yield_source_and_confirm (this, option); + use_this_source(os_solus); char *cmd = xy_2strjoin ("eopkg add-repo Solus ", source.url); chsrc_run (cmd, RunOpt_Default); diff --git a/src/recipe/os/Void-Linux.c b/src/recipe/os/Void-Linux.c index 87dff3d..97e8450 100644 --- a/src/recipe/os/Void-Linux.c +++ b/src/recipe/os/Void-Linux.c @@ -52,8 +52,7 @@ os_voidlinux_setsrc (char *option) { chsrc_ensure_root (); - use_this(os_voidlinux); - Source_t source = chsrc_yield_source_and_confirm (this, option); + use_this_source(os_voidlinux); chsrc_ensure_dir ("/etc/xbps.d"); char *cmd = "cp /usr/share/xbps.d/*-repository-*.conf /etc/xbps.d/"; diff --git a/src/recipe/os/YUM/AlmaLinux.c b/src/recipe/os/YUM/AlmaLinux.c index 7e1e486..18ce656 100644 --- a/src/recipe/os/YUM/AlmaLinux.c +++ b/src/recipe/os/YUM/AlmaLinux.c @@ -46,8 +46,7 @@ os_almalinux_setsrc (char *option) { chsrc_ensure_root (); - use_this(os_almalinux); - Source_t source = chsrc_yield_source_and_confirm (this, option); + use_this_source(os_almalinux); char *cmd = xy_strjoin (3, "sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#\\s*baseurl=https://repo.almalinux.org/almalinux|baseurl=", source.url, "|g' -i.bak /etc/yum.repos.d/almalinux*.repo"); diff --git a/src/recipe/os/YUM/Anolis-OS.c b/src/recipe/os/YUM/Anolis-OS.c index 8808fbc..28dad15 100644 --- a/src/recipe/os/YUM/Anolis-OS.c +++ b/src/recipe/os/YUM/Anolis-OS.c @@ -41,8 +41,7 @@ os_anolis_setsrc (char *option) { chsrc_ensure_root (); - use_this(os_anolis); - Source_t source = chsrc_yield_source_and_confirm (this, option); + use_this_source(os_anolis); char *cmd = xy_strjoin (3, "sed -i.bak -E 's|https?://(mirrors\\.openanolis\\.cn/anolis)|", source.url, "|g' /etc/yum.repos.d/*.repo"); chsrc_run (cmd, RunOpt_Default); diff --git a/src/recipe/os/YUM/Fedora-Linux.c b/src/recipe/os/YUM/Fedora-Linux.c index f55859c..836e4fc 100644 --- a/src/recipe/os/YUM/Fedora-Linux.c +++ b/src/recipe/os/YUM/Fedora-Linux.c @@ -55,8 +55,7 @@ os_fedora_setsrc (char *option) { chsrc_ensure_root (); - use_this(os_fedora); - Source_t source = chsrc_yield_source_and_confirm (this, option); + use_this_source(os_fedora); chsrc_alert2 ("Fedora 38 及以下版本暂不支持"); diff --git a/src/recipe/os/YUM/Rocky-Linux.c b/src/recipe/os/YUM/Rocky-Linux.c index c1d7fcb..b7bb365 100644 --- a/src/recipe/os/YUM/Rocky-Linux.c +++ b/src/recipe/os/YUM/Rocky-Linux.c @@ -49,7 +49,7 @@ os_rockylinux_setsrc (char *option) { chsrc_ensure_root (); - chsrc_yield_source_and_confirm (os_rockylinux); + use_this_source(os_rockylinux); char *version_str = xy_run ("sed -nr 's/ROCKY_SUPPORT_PRODUCT_VERSION=\"(.*)\"/\\1/p' " ETC_OS_RELEASE, 0); double version = atof (version_str); diff --git a/src/recipe/os/YUM/openEuler.c b/src/recipe/os/YUM/openEuler.c index cc21bb9..f6b4e6c 100644 --- a/src/recipe/os/YUM/openEuler.c +++ b/src/recipe/os/YUM/openEuler.c @@ -66,8 +66,7 @@ os_openeuler_setsrc (char *option) { chsrc_ensure_root (); - use_this(os_openeuler); - Source_t source = chsrc_yield_source_and_confirm (this, option); + use_this_source(os_openeuler); chsrc_backup (OS_openEuler_SourceList); @@ -97,11 +96,3 @@ os_openeuler_resetsrc (char *option) { os_openeuler_setsrc (option); } - - -/** - * chsrc ls openeuler - */ -chef_allow_get(); -chef_allow_reset(); -def_target(os_openeuler); diff --git a/src/recipe/os/openSUSE.c b/src/recipe/os/openSUSE.c index 0167c44..d8586d4 100644 --- a/src/recipe/os/openSUSE.c +++ b/src/recipe/os/openSUSE.c @@ -46,8 +46,7 @@ os_opensuse_setsrc (char *option) { // chsrc_ensure_root (); - use_this(os_opensuse); - Source_t source = chsrc_yield_source_and_confirm (this, option); + use_this_source(os_opensuse); while (1) { chsrc_note2 ("请选择你的操作系统为:"); diff --git a/src/recipe/os/pacman/Arch-Linux.c b/src/recipe/os/pacman/Arch-Linux.c index 945b16a..f4f7dec 100644 --- a/src/recipe/os/pacman/Arch-Linux.c +++ b/src/recipe/os/pacman/Arch-Linux.c @@ -28,7 +28,9 @@ os_arch_prelude () chef_forbid_english(this); chef_forbid_user_define(this); - chef_set_note ("可额外使用 chsrc set archlinuxcn 来更换 Arch Linux CN Repository 源", "You can additionally use chsrc set archlinuxcn to change Arch Linux CN Repository source"); + chef_set_note (this, + "可额外使用 chsrc set archlinuxcn 来更换 Arch Linux CN Repository 源", + "You can additionally use chsrc set archlinuxcn to change Arch Linux CN Repository source"); /** * @note 不要给后面加 / ,因为ARM情况下,还要额外加一个 arm 后缀 @@ -68,7 +70,7 @@ os_arch_setsrc (char *option) { chsrc_ensure_root (); - chsrc_yield_source_and_confirm (os_arch); + use_this_source(os_arch); chsrc_backup (OS_Pacman_MirrorList); @@ -115,6 +117,7 @@ void os_archlinuxcn_prelude () { use_this(os_archlinuxcn); + chef_allow_gs(os_archlinuxcn); chef_set_created_on (this, "2023-09-05"); chef_set_last_updated (this, "2025-08-10"); @@ -126,14 +129,13 @@ os_archlinuxcn_prelude () chef_set_contributors (this, 1, "happy game", "happygame1024@gmail.com"); - chef_allow_get(); - chef_allow_set(); - chef_allow_local_mode (this, CanNot, NULL, NULL); chef_forbid_english(this); chef_forbid_user_define(this); - chef_set_note ("可额外使用 chsrc set arch 来更换 Arch Linux 源", "You can additionally use chsrc set arch to change Arch Linux source"); + chef_set_note (this, + "可额外使用 chsrc set arch 来更换 Arch Linux 源", + "You can additionally use chsrc set arch to change Arch Linux source"); def_sources_begin() @@ -167,7 +169,7 @@ os_archlinuxcn_setsrc (char *option) { chsrc_ensure_root (); - chsrc_yield_source_and_confirm (os_archlinuxcn); + use_this_source(os_archlinuxcn); chsrc_backup (OS_Pacman_ArchLinuxCN_MirrorList); diff --git a/src/recipe/os/pacman/MSYS2.c b/src/recipe/os/pacman/MSYS2.c index 4f05884..77560fe 100644 --- a/src/recipe/os/pacman/MSYS2.c +++ b/src/recipe/os/pacman/MSYS2.c @@ -46,7 +46,7 @@ os_msys2_prelude () void os_msys2_setsrc (char *option) { - chsrc_yield_source_and_confirm (os_msys2); + use_this_source(os_msys2); chsrc_backup ("/etc/pacman.d/mirrorlist.mingw32"); chsrc_backup ("/etc/pacman.d/mirrorlist.mingw64");