From ed5b0981bdc0151b9d4c1ab219827c2286fc8c95 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Fri, 16 Aug 2024 02:07:38 +0800 Subject: [PATCH] Split armbian out --- include/source.h | 16 -------- src/chsrc.c | 37 +----------------- src/recipe/catalog.c | 1 - src/recipe/os/apt-family/armbian.c | 61 ++++++++++++++++++++++++++++++ src/recipe/os/apt-family/common.h | 6 +++ 5 files changed, 68 insertions(+), 53 deletions(-) create mode 100644 src/recipe/os/apt-family/armbian.c diff --git a/include/source.h b/include/source.h index a0b711c..e03441a 100644 --- a/include/source.h +++ b/include/source.h @@ -290,21 +290,6 @@ os_raspberrypi_sources[] = { }, -/** - * @time 2024-06-20 更新 - */ -os_armbian_sources[] = { - {&Upstream, NULL}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/armbian"}, - {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/armbian"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/armbian"}, - {&Sustech, "https://mirrors.sustech.edu.cn/armbian"}, - {&Ustc, "https://mirrors.ustc.edu.cn/armbian"}, - {&Nju, "https://mirrors.nju.edu.cn/armbian"}, - {&Ali, "https://mirrors.aliyun.com/armbian"}, -}, - - /** * @time 2023-09-06 更新 @@ -477,7 +462,6 @@ def_sources_n(os_msys2); def_sources_n(os_rocky); def_sources_n(os_alma); def_sources_n(os_linuxlite); def_sources_n(os_raspberrypi); -def_sources_n(os_armbian); def_sources_n(os_ros); diff --git a/src/chsrc.c b/src/chsrc.c index 4176de7..0149f4b 100644 --- a/src/chsrc.c +++ b/src/chsrc.c @@ -104,6 +104,7 @@ os_mint_setsrc (char *option) #include "recipe/os/apt-family/debian.c" #include "recipe/os/apt-family/ubuntu.c" #include "recipe/os/apt-family/trisquel.c" +#include "recipe/os/apt-family/armbian.c" void os_raspberrypi_getsrc (char *option) @@ -131,42 +132,6 @@ os_raspberrypi_setsrc (char *option) } -#define OS_Armbian_SOURCELIST "/etc/apt/sources.list.d/armbian.list" -void -os_armbian_getsrc (char *option) -{ - if (chsrc_check_file (OS_Armbian_SOURCELIST)) - { - chsrc_view_file (OS_Armbian_SOURCELIST); - return; - } - - chsrc_error2 ("缺少源配置文件!路径:" OS_Armbian_SOURCELIST); -} - -/** - * 参考: https://mirrors.tuna.tsinghua.edu.cn/help/armbian - */ -void -os_armbian_setsrc (char *option) -{ - chsrc_ensure_root (); - - SourceInfo source; - chsrc_yield_source (os_armbian); - chsrc_confirm_source (&source); - - chsrc_backup (OS_Armbian_SOURCELIST); - - char *cmd = xy_strjoin (3, "sed -E -i 's@https?[^ ]*armbian/?[^ ]*@", source.url, - "@g' " OS_Armbian_SOURCELIST); - - chsrc_run (cmd, RunOpt_Default); - chsrc_run ("apt update", RunOpt_No_Last_New_Line); - chsrc_say_lastly (&source, ChsrcTypeAuto); -} -#undef OS_Armbian_SOURCELIST - void diff --git a/src/recipe/catalog.c b/src/recipe/catalog.c index 797aa0f..a044c15 100644 --- a/src/recipe/catalog.c +++ b/src/recipe/catalog.c @@ -43,7 +43,6 @@ def_target(os_mint); def_target(os_kali); def_target(os_linuxlite); def_target(os_deepin); def_target(os_openkylin); def_target(os_raspberrypi); -def_target(os_armbian); def_target_noget(os_fedora); def_target_noget(os_rocky); def_target_noget(os_alma); diff --git a/src/recipe/os/apt-family/armbian.c b/src/recipe/os/apt-family/armbian.c new file mode 100644 index 0000000..7f48f89 --- /dev/null +++ b/src/recipe/os/apt-family/armbian.c @@ -0,0 +1,61 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * File Authors : Shengwei Chen <414685209@qq.com> + * Contributors : Aoran Zeng + * Created On : <2024-06-14> + * Last Modified : <2024-08-16> + * ------------------------------------------------------------*/ + +/** + * @time 2024-06-20 更新 + */ +static SourceInfo +os_armbian_sources[] = { + {&Upstream, NULL}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/armbian"}, + {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/armbian"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/armbian"}, + {&Sustech, "https://mirrors.sustech.edu.cn/armbian"}, + {&Ustc, "https://mirrors.ustc.edu.cn/armbian"}, + {&Nju, "https://mirrors.nju.edu.cn/armbian"}, + {&Ali, "https://mirrors.aliyun.com/armbian"}, +}; +def_sources_n(os_armbian); + +void +os_armbian_getsrc (char *option) +{ + if (chsrc_check_file (OS_Armbian_SourceList)) + { + chsrc_view_file (OS_Armbian_SourceList); + return; + } + + chsrc_error2 ("缺少源配置文件!路径:" OS_Armbian_SourceList); +} + +/** + * 参考: https://mirrors.tuna.tsinghua.edu.cn/help/armbian + */ +void +os_armbian_setsrc (char *option) +{ + chsrc_ensure_root (); + + SourceInfo source; + chsrc_yield_source (os_armbian); + chsrc_confirm_source (&source); + + chsrc_backup (OS_Armbian_SourceList); + + char *cmd = xy_strjoin (3, "sed -E -i 's@https?[^ ]*armbian/?[^ ]*@", source.url, + "@g' " OS_Armbian_SourceList); + + chsrc_run (cmd, RunOpt_Default); + chsrc_run ("apt update", RunOpt_No_Last_New_Line); + chsrc_say_lastly (&source, ChsrcTypeAuto); +} +#undef OS_Armbian_SourceList + +def_target(os_armbian); diff --git a/src/recipe/os/apt-family/common.h b/src/recipe/os/apt-family/common.h index 59c9698..335454f 100644 --- a/src/recipe/os/apt-family/common.h +++ b/src/recipe/os/apt-family/common.h @@ -25,6 +25,12 @@ #define OS_Is_Debian_Literally 1 #define OS_Is_Ubuntu 2 + +#define OS_Armbian_SourceList "/etc/apt/sources.list.d/armbian.list" + + + + /** * 当不存在该文件时,我们只能拼凑一个假的出来,但该函数目前只适用于 Ubuntu 和 Debian * 因为其它的 Debian 变体可能不使用 OS_Apt_SourceList,也可能并不适用 `VERSION_CODENAME`