From eb41991060e399dab51faa689f152c9f59798527 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Thu, 8 Aug 2024 18:30:28 +0800 Subject: [PATCH] Support `OpenWRT` [Gitee #IAAAKD] --- src/chsrc.c | 21 ++++++++++----- src/recipe/os/openwrt.c | 57 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 src/recipe/os/openwrt.c diff --git a/src/chsrc.c b/src/chsrc.c index b681ac7..c3ce5b6 100644 --- a/src/chsrc.c +++ b/src/chsrc.c @@ -1693,6 +1693,10 @@ os_linuxlite_setsrc (char *option) +#include "./recipe/os/openwrt.c" + + + /** * HELP: 未经测试 */ @@ -2428,23 +2432,28 @@ static const char *os_solus [] = {"solus", NULL, t(&os_solus_target)}, *os_trisquel [] = {"trisquel", NULL, t(&os_trisquel_target)}, *os_linuxlite [] = {"lite", "linuxlite", NULL, t(&os_linuxlite_target)}, +*os_ros [] = {"ros", "ros2", NULL, t(&os_ros_target)}, + *os_raspberrypi[] = {"raspi", "raspberrypi",NULL, t(&os_raspberrypi_target)}, *os_armbian [] = {"armbian", NULL, t(&os_armbian_target)}, +*os_openwrt [] = {"openwrt", "opkg", "LEDE", NULL, t(&os_openwrt_target)}, + +*os_openkylin [] = {"kylin", "openkylin", NULL, t(&os_openkylin_target)}, +*os_openeuler [] = {"euler", "openeuler", NULL, t(&os_openeuler_target)}, +*os_deepin [] = {"deepin", NULL, t(&os_deepin_target)}, +*os_anolis [] = {"anolis", "openanolis", NULL, t(&os_anolis_target)}, + *os_freebsd [] = {"freebsd", NULL, t(&os_freebsd_target)}, *os_netbsd [] = {"netbsd", NULL, t(&os_netbsd_target)}, *os_openbsd [] = {"openbsd", NULL, t(&os_openbsd_target)}, -*os_deepin [] = {"deepin", NULL, t(&os_deepin_target)}, -*os_openeuler [] = {"euler", "openeuler", NULL, t(&os_openeuler_target)}, -*os_anolis [] = {"anolis", "openanolis", NULL, t(&os_anolis_target)}, -*os_openkylin [] = {"kylin", "openkylin", NULL, t(&os_openkylin_target)}, -*os_ros [] = {"ros", "ros2", NULL, t(&os_ros_target)}, + **os_systems[] = { os_ubuntu, os_mint, os_debian, os_fedora, os_opensuse, os_kali, os_arch, os_archlinuxcn, os_manjaro, os_gentoo, os_rocky, os_alma, os_alpine, os_void, os_solus, os_ros, - os_trisquel, os_linuxlite, os_raspberrypi, os_armbian, + os_trisquel, os_linuxlite, os_raspberrypi, os_armbian, os_openwrt, os_deepin, os_openeuler, os_anolis, os_openkylin, os_msys2, os_freebsd, os_netbsd, os_openbsd, diff --git a/src/recipe/os/openwrt.c b/src/recipe/os/openwrt.c new file mode 100644 index 0000000..e565bb6 --- /dev/null +++ b/src/recipe/os/openwrt.c @@ -0,0 +1,57 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * Contributors : Aoran Zeng + * Created on : <2024-08-08> + * Last modified : <2024-08-08> + * ------------------------------------------------------------*/ + +/** + * 2024-08-08 更新 + */ +static SourceInfo +os_openwrt_sources[] = { + {&Upstream, NULL}, + {&MirrorZ, "https://mirrors.cernet.edu.cn/openwrt"}, + {&Ali, "https://mirrors.aliyun.com/openwrt"}, + {&Tencent, "https://mirrors.cloud.tencent.com/openwrt"}, + {&Tuna, "https://mirror.tuna.tsinghua.edu.cn/openwrt"}, + {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/openwrt"}, + {&Ustc, "https://mirrors.ustc.edu.cn/openwrt"}, + {&Pku, "https://mirrors.pku.edu.cn/openwrt"}, + {&Sustech, "https://mirrors.sustech.edu.cn/openwrt"}, +}; + +def_sources_n(os_openwrt); + + +#define OS_OpenWRT_SourceConfig "/etc/opkg/distfeeds.conf" + +void +os_openwrt_getsrc (char *option) +{ + chsrc_view_file (OS_OpenWRT_SourceConfig); +} + +/** + * 参考: https://mirror.tuna.tsinghua.edu.cn/help/openwrt/ + */ +void +os_openwrt_setsrc (char *option) +{ + chsrc_ensure_root (); + + SourceInfo source; + chsrc_yield_source (os_openwrt); + chsrc_confirm_source (&source); + + chsrc_backup (OS_OpenWRT_SourceConfig); + + char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*downloads.openwrt.org@", source.url, "@g' " OS_OpenWRT_SourceConfig); + + chsrc_run ("apt update", RunOpt_No_Last_New_Line); + chsrc_say_lastly (&source, ChsrcTypeAuto); +} + + +def_target(os_openwrt);