Split arch out

This commit is contained in:
Aoran Zeng 2024-08-16 01:08:51 +08:00
parent 49c5c0163d
commit 8c4a7969fd
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
4 changed files with 135 additions and 123 deletions

View File

@ -250,38 +250,6 @@ os_kali_sources[] = {
},
/**
* @time 2024-07-03
* @note / ARM情况下 arm
*/
os_arch_sources[] = {
{&Upstream, NULL},
{&Ali, "https://mirrors.aliyun.com/archlinux"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/archlinux"},
{&Ustc, "https://mirrors.ustc.edu.cn/archlinux"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/archlinux"},
{&Tencent, "https://mirrors.tencent.com/archlinux"},
{&Huawei, "https://mirrors.huaweicloud.com/archlinux"}, // 不支持 archlinuxcn
{&Netease, "https://mirrors.163.com/archlinux"}, // archlinuxcn 的URL和其他镜像站不同
// {&Sohu, "https://mirrors.sohu.com/archlinux"} // 不支持 archlinuxcn
},
/**
* @time 2024-07-03
* @note GitHub:@zheng7fu2 archlinuxcn
*/
os_archlinuxcn_sources[] = {
{&Upstream, "https://repo.archlinuxcn.org/"},
{&Ali, "https://mirrors.aliyun.com/archlinuxcn/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/archlinuxcn/"},
{&Ustc, "https://mirrors.ustc.edu.cn/archlinuxcn/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/"},
{&Tencent, "https://mirrors.cloud.tencent.com/archlinuxcn/"},
{&Netease, "https://mirrors.163.com/archlinux-cn/"}
},
/**
* @time 2024-06-12
@ -601,7 +569,6 @@ def_sources_n(pl_dotnet);
def_sources_n(os_ubuntu); def_sources_n(os_mint);
def_sources_n(os_debian); def_sources_n(os_fedora);
def_sources_n(os_kali); def_sources_n(os_opensuse);
def_sources_n(os_arch); def_sources_n(os_archlinuxcn);
def_sources_n(os_msys2);
def_sources_n(os_rocky); def_sources_n(os_alma);

View File

@ -635,95 +635,7 @@ os_msys2_setsrc (char *option)
#define OS_Pacman_MirrorList "/etc/pacman.d/mirrorlist"
void
os_arch_getsrc (char *option)
{
chsrc_view_file (OS_Pacman_MirrorList);
}
/**
* :
* 1. https://mirrors.tuna.tsinghua.edu.cn/help/archlinux/
* 2. https://mirrors.tuna.tsinghua.edu.cn/help/archlinuxarm/
*/
void
os_arch_setsrc (char *option)
{
chsrc_ensure_root ();
SourceInfo source;
chsrc_yield_source (os_arch);
chsrc_confirm_source (&source);
chsrc_backup (OS_Pacman_MirrorList);
bool is_x86 = false;
char *to_write = NULL;
char *arch = chsrc_get_cpuarch ();
if (strncmp(arch, "x86_64", 6)==0)
{
is_x86 = true;
to_write = xy_strjoin (3, "Server = ", source.url, "/$repo/os/$arch");
}
else
{
is_x86 = false;
to_write = xy_strjoin (3, "Server = ", source.url, "arm/$arch/$repo");
}
// 越前面的优先级越高
chsrc_prepend_to_file (to_write, OS_Pacman_MirrorList);
if (is_x86)
{
chsrc_run ("pacman -Syyu", RunOpt_No_Last_New_Line);
}
else
{
chsrc_run ("pacman -Syy", RunOpt_No_Last_New_Line);
}
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
void
os_archlinuxcn_getsrc (char *option)
{
chsrc_view_file (OS_Pacman_MirrorList);
}
/**
* https://mirrors.tuna.tsinghua.edu.cn/help/archlinuxcn/
*/
void
os_archlinuxcn_setsrc (char *option)
{
chsrc_ensure_root ();
SourceInfo source;
chsrc_yield_source (os_archlinuxcn);
chsrc_confirm_source (&source);
chsrc_backup (OS_Pacman_MirrorList);
bool arch_flag = false;
char *arch = chsrc_get_cpuarch ();
char *towrite = xy_strjoin (3, "[archlinuxcn]\nServer = ", source.url, "$arch");
// 越前面的优先级越高
chsrc_prepend_to_file (towrite, OS_Pacman_MirrorList);
chsrc_run ("pacman-key --lsign-key \"farseerfc@archlinux.org\"", RunOpt_Dont_Abort_On_Failure);
chsrc_run ("pacman -Sy archlinuxcn-keyring", RunOpt_Default);
chsrc_run ("pacman -Syy", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
#undef OS_Pacman_MirrorList
#include "recipe/os/arch.c"
#include "recipe/os/gentoo.c"
/**

View File

@ -45,7 +45,6 @@ def_target(os_netbsd); def_target(os_openbsd);
def_target(os_deepin); def_target(os_openkylin);
def_target(os_raspberrypi);
def_target(os_armbian);
def_target(os_arch); def_target(os_archlinuxcn);
def_target_noget(os_fedora);
def_target_noget(os_opensuse);
def_target_noget(os_rocky);

134
src/recipe/os/arch.c Normal file
View File

@ -0,0 +1,134 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* | Heng Guo <2085471348@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-05>
* Last Modified : <2024-08-16>
* ------------------------------------------------------------*/
/**
* @time 2024-07-03
* @note / ARM情况下 arm
*/
static SourceInfo
os_arch_sources[] = {
{&Upstream, NULL},
{&Ali, "https://mirrors.aliyun.com/archlinux"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/archlinux"},
{&Ustc, "https://mirrors.ustc.edu.cn/archlinux"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/archlinux"},
{&Tencent, "https://mirrors.tencent.com/archlinux"},
{&Huawei, "https://mirrors.huaweicloud.com/archlinux"}, // 不支持 archlinuxcn
{&Netease, "https://mirrors.163.com/archlinux"}, // archlinuxcn 的URL和其他镜像站不同
// {&Sohu, "https://mirrors.sohu.com/archlinux"} // 不支持 archlinuxcn
},
/**
* @time 2024-07-03
* @note GitHub:@zheng7fu2 archlinuxcn
*/
os_archlinuxcn_sources[] = {
{&Upstream, "https://repo.archlinuxcn.org/"},
{&Ali, "https://mirrors.aliyun.com/archlinuxcn/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/archlinuxcn/"},
{&Ustc, "https://mirrors.ustc.edu.cn/archlinuxcn/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/"},
{&Tencent, "https://mirrors.cloud.tencent.com/archlinuxcn/"},
{&Netease, "https://mirrors.163.com/archlinux-cn/"}
};
def_sources_n(os_arch);
def_sources_n(os_archlinuxcn);
#define OS_Pacman_MirrorList "/etc/pacman.d/mirrorlist"
void
os_arch_getsrc (char *option)
{
chsrc_view_file (OS_Pacman_MirrorList);
}
/**
* :
* 1. https://mirrors.tuna.tsinghua.edu.cn/help/archlinux/
* 2. https://mirrors.tuna.tsinghua.edu.cn/help/archlinuxarm/
*/
void
os_arch_setsrc (char *option)
{
chsrc_ensure_root ();
SourceInfo source;
chsrc_yield_source (os_arch);
chsrc_confirm_source (&source);
chsrc_backup (OS_Pacman_MirrorList);
bool is_x86 = false;
char *to_write = NULL;
char *arch = chsrc_get_cpuarch ();
if (strncmp(arch, "x86_64", 6)==0)
{
is_x86 = true;
to_write = xy_strjoin (3, "Server = ", source.url, "/$repo/os/$arch");
}
else
{
is_x86 = false;
to_write = xy_strjoin (3, "Server = ", source.url, "arm/$arch/$repo");
}
// 越前面的优先级越高
chsrc_prepend_to_file (to_write, OS_Pacman_MirrorList);
if (is_x86)
{
chsrc_run ("pacman -Syyu", RunOpt_No_Last_New_Line);
}
else
{
chsrc_run ("pacman -Syy", RunOpt_No_Last_New_Line);
}
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
void
os_archlinuxcn_getsrc (char *option)
{
chsrc_view_file (OS_Pacman_MirrorList);
}
/**
* https://mirrors.tuna.tsinghua.edu.cn/help/archlinuxcn/
*/
void
os_archlinuxcn_setsrc (char *option)
{
chsrc_ensure_root ();
SourceInfo source;
chsrc_yield_source (os_archlinuxcn);
chsrc_confirm_source (&source);
chsrc_backup (OS_Pacman_MirrorList);
bool arch_flag = false;
char *arch = chsrc_get_cpuarch ();
char *towrite = xy_strjoin (3, "[archlinuxcn]\nServer = ", source.url, "$arch");
// 越前面的优先级越高
chsrc_prepend_to_file (towrite, OS_Pacman_MirrorList);
chsrc_run ("pacman-key --lsign-key \"farseerfc@archlinux.org\"", RunOpt_Dont_Abort_On_Failure);
chsrc_run ("pacman -Sy archlinuxcn-keyring", RunOpt_Default);
chsrc_run ("pacman -Syy", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
#undef OS_Pacman_MirrorList
def_target(os_arch);
def_target(os_archlinuxcn);