From 91711185b0b6bf9bfb7851dafd07e0ba7e485292 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Sun, 24 Sep 2023 20:01:46 +0800 Subject: [PATCH] Add support for `alpine` Gitee close #I80262 --- chsrc.c | 35 +++++++++++++++++++++++++++++++++++ sources.h | 18 +++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/chsrc.c b/chsrc.c index 9b3db98..998f5f9 100644 --- a/chsrc.c +++ b/chsrc.c @@ -1308,6 +1308,38 @@ os_rocky_setsrc (char* option) +/** + * 参考: https://help.mirrors.cernet.edu.cn/alpine/ + */ +void +os_alpine_setsrc (char* option) +{ + // ensure_root(); // HELP: 不确定是否需要root + + int index = 0; + + if (NULL!=option) { + index = lets_find_mirror(os_alpine, option); + } else { + index = lets_test_speed(os_alpine); + } + + source_info source = os_alpine_sources[index]; + chsrc_say_selection(&source); + + char* cmd = xy_strjoin(3, + "sed -i 's#https\\?://dl-cdn.alpinelinux.org/alpine#", source.url, "#g' /etc/apk/repositories" + ); + chsrc_runcmd(cmd); + + cmd = "apk update"; + chsrc_runcmd(cmd); + + chsrc_say_thanks(&source); +} + + + /** * HELP: 未经测试 */ @@ -1938,6 +1970,7 @@ target_info os_manjaro_target = {os_manjaro_setsrc, NULL, NULL, 0}, os_gentoo_target = {os_gentoo_setsrc, NULL, os_gentoo_sources, os_gentoo_sources_n}, os_rocky_target = {os_rocky_setsrc, NULL, os_rocky_sources, os_rocky_sources_n}, + os_alpine_target = {os_alpine_setsrc, NULL, os_alpine_sources, os_alpine_sources_n}, os_freebsd_target = {os_freebsd_setsrc, NULL, os_freebsd_sources, os_freebsd_sources_n}, os_netbsd_target = {os_netbsd_setsrc, NULL, os_netbsd_sources, os_netbsd_sources_n}, os_openbsd_target = {os_openbsd_setsrc, NULL, os_openbsd_sources, os_openbsd_sources_n}, @@ -1955,6 +1988,7 @@ static const char *os_manjaro [] = {"manjaro", NULL, targetinfo(&os_manjaro_target)}, *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_freebsd [] = {"freebsd", NULL, targetinfo(&os_freebsd_target)}, *os_netbsd [] = {"netbsd", NULL, targetinfo(&os_netbsd_target)}, *os_openbsd [] = {"openbsd", NULL, targetinfo(&os_openbsd_target)}, @@ -1966,6 +2000,7 @@ static const char os_ubuntu, os_debian, os_fedora, os_opensuse, os_kali, os_arch, os_manjaro, os_gentoo, os_rocky, + os_alpine, os_freebsd, os_netbsd, os_openbsd, os_msys2, os_deepin, os_openeuler, os_openkylin, diff --git a/sources.h b/sources.h index 5ae3115..05a6891 100644 --- a/sources.h +++ b/sources.h @@ -445,6 +445,21 @@ os_rocky_sources[] = { +/** + * 2023-09-24 更新 + */ +os_alpine_sources[] = { + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/alpine"}, + {&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/alpine"}, + {&Sustech, "https://mirrors.sustech.edu.cn/alpine"}, + {&Zju, "https://mirrors.zju.edu.cn/alpine"}, + {&Lzuoss, "https://mirror.lzu.edu.cn/alpine"}, + {&Ali, "https://mirrors.aliyun.com/alpine"}, + {&Tencent, "https://mirrors.cloud.tencent.com/alpine"} +}, + + + /** * 2023-09-02 更新 * @@ -689,7 +704,8 @@ 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_rocky); +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_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);