Qualify os family name

This commit is contained in:
Aoran Zeng
2024-08-17 09:52:10 +08:00
parent 0f97a00f68
commit 2753a4c3d7
22 changed files with 21 additions and 21 deletions

View File

@@ -0,0 +1,59 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Heng Guo <2085471348@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-29>
* Last Modified : <2024-08-16>
*
* Kali Linux 基于 Debian Testing branch
* ------------------------------------------------------------*/
/**
* @time 2024-06-12 更新
*/
static SourceInfo
os_kali_sources[] = {
{&Upstream, NULL},
{&Ali, "https://mirrors.aliyun.com/kali"},
{&Volcengine, "https://mirrors.volces.com/kali"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/kali"},
{&Ustc, "https://mirrors.ustc.edu.cn/kali"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/kali"},
{&Tencent, "https://mirrors.tencent.com/kali"},
{&Huawei, "https://mirrors.huaweicloud.com/kali"},
{&Netease, "https://mirrors.163.com/kali"},
{&Sohu, "https://mirrors.sohu.com/kali"}
};
def_sources_n(os_kali);
void
os_kali_getsrc (char *option)
{
chsrc_view_file (OS_Apt_SourceList);
}
/**
* HELP: 未经测试
*/
void
os_kali_setsrc (char *option)
{
chsrc_ensure_root ();
SourceInfo source;
chsrc_yield_source (os_kali);
chsrc_confirm_source (&source);
chsrc_backup (OS_Apt_SourceList);
char *cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/kali/?@",
source.url,
"@g\' " OS_Apt_SourceList);
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
def_target(os_kali);

View File

@@ -0,0 +1,47 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-29>
* Last Modified : <2024-08-16>
* ------------------------------------------------------------*/
/**
* @time 2023-09-29 更新
*/
static SourceInfo
os_linuxlite_sources[] = {
{&Upstream, NULL},
{&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/linuxliteos/"}
};
def_sources_n(os_linuxlite);
void
os_linuxlite_getsrc (char *option)
{
chsrc_view_file (OS_Apt_SourceList);
}
/**
* 参考: https://help.mirrors.cernet.edu.cn/linuxliteos/
*/
void
os_linuxlite_setsrc (char *option)
{
chsrc_ensure_root ();
SourceInfo source;
chsrc_yield_source (os_linuxlite);
chsrc_confirm_source (&source);
chsrc_backup (OS_Apt_SourceList);
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/.*/?@", source.url, "@g' " OS_Apt_SourceList);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeAuto);
}
def_target(os_linuxlite);

View File

@@ -0,0 +1,53 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-29>
* Last Modified : <2024-08-16>
* ------------------------------------------------------------*/
/**
* @time 2023-09-29 更新
* @note 实际上镜像站里的内容和Ubuntu的不太一样
*/
static SourceInfo
os_linuxmint_sources[] = {
{&Upstream, NULL},
{&MirrorZ, "https://mirrors.cernet.edu.cn/linuxmint/"},
{&Ali, "http://mirrors.aliyun.com/linuxmint-packages/"},
{&Netease, "https://mirrors.163.com/linuxmint/packages/"},
};
def_sources_n(os_linuxmint);
void
os_linuxmint_getsrc (char *option)
{
chsrc_view_file (OS_LinuxMint_SourceList);
}
/**
* 参考: https://help.mirrors.cernet.edu.cn/linuxmint/
*/
void
os_linuxmint_setsrc (char *option)
{
chsrc_ensure_root ();
SourceInfo source;
chsrc_yield_source (os_linuxmint);
chsrc_confirm_source (&source);
chsrc_backup (OS_LinuxMint_SourceList);
char* cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/.*/?@", source.url,
"@g' " OS_LinuxMint_SourceList);
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeAuto);
chsrc_warn2 ("完成后请不要再使用 mintsources自带的图形化软件源设置工具进行任何操作因为在操作后无论是否有按“确定”mintsources 均会覆写我们刚才换源的内容");
}
def_target(os_linuxmint);

View File

@@ -0,0 +1,61 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Shengwei Chen <414685209@qq.com>
* Contributors : Aoran Zeng <ccmywish@qq.com>
* 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);

124
src/recipe/os/APT/common.h Normal file
View File

@@ -0,0 +1,124 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2024-06-14>
* Last Modified : <2024-08-16>
* ------------------------------------------------------------*/
#define OS_Apt_SourceList "/etc/apt/sources.list"
#define OS_Apt_SourceList_D "/etc/apt/sources.list.d/"
/**
* @note 从 Debian 12 开始Debain 的软件源配置文件变更为 DEB822 格式,
* 路径为: /etc/apt/sources.list.d/debian.sources"
*
* @note 从 Ubuntu 24.04 开始Ubuntu 的软件源配置文件变更为 DEB822 格式,
* 路径为: /etc/apt/sources.list.d/ubuntu.sources
*/
#define OS_Debian_SourceList_DEB822 "/etc/apt/sources.list.d/debian.sources"
#define OS_Ubuntu_SourceList_DEB822 "/etc/apt/sources.list.d/ubuntu.sources"
#define ETC_os_release "/etc/os-release"
#define OS_Is_Debian_Literally 1
#define OS_Is_Ubuntu 2
// independent
#define OS_ROS_SourceList OS_Apt_SourceList_D "ros-latest.list"
// Ubuntu based
#define OS_LinuxMint_SourceList OS_Apt_SourceList_D "official-package-repositories.list"
// Debian based
#define OS_Armbian_SourceList OS_Apt_SourceList_D "armbian.list"
#define OS_RaspberryPi_SourceList OS_Apt_SourceList_D "raspi.list"
/**
* 当不存在该文件时,我们只能拼凑一个假的出来,但该函数目前只适用于 Ubuntu 和 Debian
* 因为其它的 Debian 变体可能不使用 OS_Apt_SourceList也可能并不适用 `VERSION_CODENAME`
*
* @return 文件是否存在
*/
bool
ensure_apt_sourcelist (int debian_type)
{
bool exist = chsrc_check_file (OS_Apt_SourceList);
if (exist)
{
return true;
}
else
{
chsrc_note2 ("将生成新的源配置文件");
}
// 反向引用需要escape一下
char *codename = xy_run ("sed -nr 's/VERSION_CODENAME=(.*)/\\1/p' " ETC_os_release, 0, NULL);
codename = xy_str_delete_suffix (codename, "\n");
char *version_id = xy_run ("sed -nr 's/VERSION_ID=(.*)/\\1/p' " ETC_os_release, 0, NULL);
version_id = xy_str_delete_suffix (codename, "\n");
double version = atof (version_id);
char *makeup = NULL;
if (debian_type == OS_Is_Ubuntu)
{
makeup = xy_strjoin (9,
"# Generated by chsrc " Chsrc_Version "\n\n"
"deb " Chsrc_Maintain_URL "/ubuntu ", codename, " main restricted universe multiverse\n"
"deb " Chsrc_Maintain_URL "/ubuntu ", codename, "-updates main restricted universe multiverse\n"
"deb " Chsrc_Maintain_URL "/ubuntu ", codename, "-backports main restricted universe multiverse\n"
"deb " Chsrc_Maintain_URL "/ubuntu ", codename, "-security main restricted universe multiverse\n");
}
else
{
if (version >= 12)
{
// https://wiki.debian.org/SourcesList
// https://mirrors.tuna.tsinghua.edu.cn/help/debian/
// 从 Debian 12 开始,开始有一项 non-free-firmware
makeup = xy_strjoin (9,
"# Generated by chsrc " Chsrc_Version "\n\n"
"deb " Chsrc_Maintain_URL "/debian ", codename, " main contrib non-free non-free-firmware\n"
"deb " Chsrc_Maintain_URL "/debian ", codename, "-updates main contrib non-free non-free-firmware\n"
"deb " Chsrc_Maintain_URL "/debian ", codename, "-backports main contrib non-free non-free-firmware\n"
"deb " Chsrc_Maintain_URL "/debian-security ", codename, "-security main contrib non-free non-free-firmware\n");
// 上述 debian-security 这种写法是和 Debian 10不同的所以我们只能支持 Debian 11+
}
else if (version >= 11)
{
makeup = xy_strjoin (9,
"# Generated by chsrc " Chsrc_Version "(" Chsrc_Maintain_URL ")\n\n"
"deb " Chsrc_Maintain_URL "/debian ", codename, " main contrib non-free\n"
"deb " Chsrc_Maintain_URL "/debian ", codename, "-updates main contrib non-free\n"
"deb " Chsrc_Maintain_URL "/debian ", codename, "-backports main contrib non-free\n"
"deb " Chsrc_Maintain_URL "/debian-security ", codename, "-security main contrib non-free\n");
}
else if (version >= 10)
{
makeup = xy_strjoin (9,
"# Generated by chsrc " Chsrc_Version "(" Chsrc_Maintain_URL ")\n\n"
"deb " Chsrc_Maintain_URL "/debian ", codename, " main contrib non-free\n"
"deb " Chsrc_Maintain_URL "/debian ", codename, "-updates main contrib non-free\n"
"deb " Chsrc_Maintain_URL "/debian ", codename, "-backports main contrib non-free\n"
"deb " Chsrc_Maintain_URL "/debian-security ", codename, "/updates main contrib non-free\n");
// 上述 debian-security 这种写法是和 Debian 11 不同的
}
else
{
chsrc_error ("您的Debian版本过低(<10),暂不支持换源");
exit (Exit_Unsupported);
}
}
FILE *f = fopen (OS_Apt_SourceList, "w");
fwrite (makeup, strlen (makeup), 1, f);
fclose (f);
return false;
}

112
src/recipe/os/APT/debian.c Normal file
View File

@@ -0,0 +1,112 @@
/** ------------------------------------------------------------
* 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-02>
* Last Modified : <2024-08-16>
* ------------------------------------------------------------*/
/**
* @time 2024-06-12 更新
*/
static SourceInfo
os_debian_sources[] = {
{&Upstream, NULL},
{&Ali, "https://mirrors.aliyun.com/debian"},
{&Volcengine, "https://mirrors.volces.com/debian"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/debian"},
{&Ustc, "https://mirrors.ustc.edu.cn/debian"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/debian"},
{&Tencent, "https://mirrors.tencent.com/debian"},
{&Netease, "https://mirrors.163.com/debian"},
{&Sohu, "https://mirrors.sohu.com/debian"}
};
def_sources_n(os_debian);
void
os_debian_getsrc (char *option)
{
if (chsrc_check_file (OS_Debian_SourceList_DEB822))
{
chsrc_view_file (OS_Debian_SourceList_DEB822);
return;
}
if (chsrc_check_file (OS_Apt_SourceList))
{
chsrc_view_file (OS_Apt_SourceList);
return;
}
chsrc_error2 ("缺少源配置文件!但仍可直接通过 chsrc set debian 来添加使用新的源");
return;
}
void
os_debian_setsrc_for_deb822 (char *option)
{
SourceInfo source;
chsrc_yield_source (os_debian);
chsrc_confirm_source (&source);
chsrc_note2 ("如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并需要您运行:");
puts ("apt install apt-transport-https ca-certificates");
chsrc_backup (OS_Debian_SourceList_DEB822);
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/debian/?@", source.url, "@g' " OS_Debian_SourceList_DEB822);
chsrc_run (cmd, RunOpt_Default);
// debian-security 源和其他源不一样
cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/debian-security/?@", source.url, "-security@g' " OS_Debian_SourceList_DEB822);
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeAuto);
}
/**
* Debian 10 Buster 以上版本默认支持 HTTPS 源。如果遇到无法拉取 HTTPS 源的情况,请先使用 HTTP 源并安装
* apt install apt-transport-https ca-certificates
*/
void
os_debian_setsrc (char *option)
{
chsrc_ensure_root ();
if (chsrc_check_file (OS_Debian_SourceList_DEB822))
{
chsrc_note2 ("将基于新格式换源");
os_debian_setsrc_for_deb822 (option);
return;
}
// Docker环境下Debian镜像可能不存在该文件
bool sourcelist_exist = ensure_apt_sourcelist (OS_Is_Debian_Literally);
SourceInfo source;
chsrc_yield_source (os_debian);
chsrc_confirm_source (&source);
chsrc_note2 ("如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并需要您运行:");
puts ("apt install apt-transport-https ca-certificates");
// 不存在的时候,用的是我们生成的无效文件,不要备份
if (sourcelist_exist)
{
chsrc_backup (OS_Apt_SourceList);
}
char *cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/debian/?@", source.url, "@g\' " OS_Apt_SourceList);
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeAuto);
}
def_target(os_debian);

View File

@@ -0,0 +1,59 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Heng Guo <2085471348@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-26>
* Last Modified : <2024-08-16>
*
* 名称为小写deepin而非Deepin
* ------------------------------------------------------------*/
/**
* @time 2023-09-06 更新
* @note 源并不完整,且未经测试是否有效
*/
static SourceInfo
os_deepin_sources[] = {
{&Upstream, NULL},
{&Ali, "https://mirrors.aliyun.com/deepin"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/deepin"},
{&Ustc, "https://mirrors.ustc.edu.cn/deepin"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/deepin"},
{&Tencent, "https://mirrors.tencent.com/deepin"},
{&Netease, "https://mirrors.163.com/deepin"},
{&Sohu, "https://mirrors.sohu.com/deepin"}
};
def_sources_n(os_deepin);
void
os_deepin_getsrc(char *option)
{
chsrc_view_file (OS_Apt_SourceList);
}
/**
* HELP: 未经测试
*/
void
os_deepin_setsrc (char *option)
{
chsrc_ensure_root();
SourceInfo source;
chsrc_yield_source (os_deepin);
chsrc_confirm_source (&source);
chsrc_backup (OS_Apt_SourceList);
char *cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/deepin/?@",
source.url,
"@g\' " OS_Apt_SourceList);
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
def_target(os_deepin);

View File

@@ -0,0 +1,47 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Heng Guo <2085471348@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-06>
* Last Modified : <2024-08-16>
*
* openKylin直接基于Linux内核开发属于和Debian、openSUSE、Fedora、Arch
* 同一级别的、根社区发布的系统
* -------------------------------------------------------------
/**
* @time 2023-09-29 更新
*/
static SourceInfo
os_openkylin_sources[] = {
{&Upstream, "https://archive.openkylin.top/openkylin/"},
{&Ali, "https://mirrors.aliyun.com/openkylin/"},
{&Netease, "https://mirrors.163.com/openkylin/"},
};
def_sources_n(os_openkylin);
void
os_openkylin_getsrc (char *option)
{
chsrc_view_file (OS_Apt_SourceList);
}
void
os_openkylin_setsrc (char *option)
{
chsrc_ensure_root();
SourceInfo source;
chsrc_yield_source (os_openkylin);
chsrc_confirm_source (&source);
chsrc_backup (OS_Apt_SourceList);
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/openkylin/?@", source.url, "@g'" OS_Apt_SourceList);
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
def_target(os_openkylin);

View File

@@ -0,0 +1,52 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-29>
* Last Modified : <2024-08-16>
*
* Raspberry Pi OS 树莓派操作系统,以前称为 Raspbian
* ------------------------------------------------------------*/
/**
* @time 2023-09-29 更新
*/
static SourceInfo
os_raspberrypi_sources[] = {
{&Upstream, NULL},
{&MirrorZ, "https://help.mirrors.cernet.edu.cn/raspberrypi/"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/raspberrypi/"},
{&Ustc, "https://mirrors.ustc.edu.cn/raspberrypi/"},
{&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/raspberrypi/"},
{&Sustech, "https://mirrors.sustech.edu.cn/raspberrypi/"}
};
def_sources_n(os_raspberrypi);
void
os_raspberrypi_getsrc (char *option)
{
chsrc_view_file (OS_RaspberryPi_SourceList);
}
void
os_raspberrypi_setsrc (char *option)
{
chsrc_ensure_root(); // HELP: 不确定是否需要
SourceInfo source;
chsrc_yield_source (os_raspberrypi);
chsrc_confirm_source (&source);
chsrc_backup (OS_RaspberryPi_SourceList);
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/.*/?@", source.url,
"@g' " OS_RaspberryPi_SourceList);
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
def_target(os_raspberrypi);

54
src/recipe/os/APT/ros.c Normal file
View File

@@ -0,0 +1,54 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Heng Guo <2085471348@qq.com>
* Contributors : Aoran Zeng <ccmywish@qq.com>
* Created On : <2023-09-03>
* Last Modified : <2024-08-16>
* ------------------------------------------------------------*/
/**
* @time 2024-04-18 更新
* @note 未经测试是否有效
*/
static SourceInfo
os_ros_sources[] = {
{&Upstream, NULL},
{&Ali, "https://mirrors.aliyun.com"},
{&Bfsu, "https://mirrors.bfsu.edu.cn"},
{&Ustc, "https://mirrors.ustc.edu.cn"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn"},
{&Tencent, "https://mirrors.tencent.com"},
{&Huawei, "https://mirrors.huaweicloud.com"},
{&Netease, "https://mirrors.163.com"},
{&Sohu, "https://mirrors.sohu.com"}
};
def_sources_n(os_ros);
/**
* 参考:
* https://mirrors.tuna.tsinghua.edu.cn/help/ros/
*/
void
os_ros_setsrc (char *option)
{
chsrc_ensure_root (OS_ROS_SourceList);
SourceInfo source;
chsrc_yield_source (os_ros);
chsrc_confirm_source (&source);
chsrc_backup (OS_ROS_SourceList);
char *cmd = NULL;
cmd = xy_strjoin(3, "sed -E -i \'s@https?://.*/ros/ubuntu/?@", source.url, "@/ros/ubuntug\' " OS_ROS_SourceList);
chsrc_run(cmd, RunOpt_Default);
cmd = "apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654";
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
def_target_s(os_ros);

View File

@@ -0,0 +1,53 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org>
* Created On : <2023-09-29>
* Last Modified : <2024-08-16>
*
* Trisquel基于Ubuntu开发不含任何专有软件及专有固件内核使用 Linux-libre
* ------------------------------------------------------------*/
/**
* @time 2023-09-29 更新
*/
static SourceInfo
os_trisquel_sources[] = {
{&Upstream, NULL},
{&Ali, "https://mirrors.aliyun.com/trisquel/"},
{&MirrorZ, "https://mirrors.cernet.edu.cn/trisquel/"},
{&Nju, "https://mirror.nju.edu.cn/trisquel/"},
{&Ustc, "https://mirrors.ustc.edu.cn/trisquel/"}
};
def_sources_n(os_trisquel);
void
os_trisquel_getsrc (char *option)
{
chsrc_view_file (OS_Apt_SourceList);
}
/**
* 参考: https://help.mirrors.cernet.edu.cn/trisquel/
*/
void
os_trisquel_setsrc (char *option)
{
chsrc_ensure_root ();
SourceInfo source;
chsrc_yield_source (os_trisquel);
chsrc_confirm_source (&source);
chsrc_backup (OS_Apt_SourceList);
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/trisquel/?@", source.url, "@g' /etc/apt/sources.list");
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
def_target(os_trisquel);

121
src/recipe/os/APT/ubuntu.c Normal file
View File

@@ -0,0 +1,121 @@
/** ------------------------------------------------------------
* 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-08-30>
* Last Modified : <2024-08-16>
* ------------------------------------------------------------*/
/**
* @time 2024-06-12 更新
*/
static SourceInfo
os_ubuntu_sources[] = {
{&Upstream, NULL},
{&Ali, "https://mirrors.aliyun.com/ubuntu"},
{&Volcengine, "https://mirrors.volces.com/ubuntu"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/ubuntu"},
{&Ustc, "https://mirrors.ustc.edu.cn/ubuntu"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/ubuntu"},
{&Tencent, "https://mirrors.tencent.com/ubuntu"},
{&Huawei, "https://mirrors.huaweicloud.com/ubuntu"},
{&Netease, "https://mirrors.163.com/ubuntu"},
{&Sohu, "https://mirrors.sohu.com/ubuntu"}
};
def_sources_n(os_ubuntu);
void
os_ubuntu_getsrc (char *option)
{
if (chsrc_check_file (OS_Ubuntu_SourceList_DEB822))
{
chsrc_view_file (OS_Ubuntu_SourceList_DEB822);
return;
}
if (chsrc_check_file (OS_Apt_SourceList))
{
chsrc_view_file (OS_Apt_SourceList);
return;
}
chsrc_error2 ("缺少源配置文件!但仍可直接通过 chsrc set ubuntu 来添加使用新的源");
return;
}
/**
* 此函数基本和 os_ubuntu_setsrc() 一致
*/
void
os_ubuntu_setsrc_for_deb822 (char *option)
{
SourceInfo source;
chsrc_yield_source (os_ubuntu);
chsrc_confirm_source (&source);
chsrc_backup (OS_Ubuntu_SourceList_DEB822);
char *arch = chsrc_get_cpuarch ();
char *cmd = NULL;
if (strncmp (arch, "x86_64", 6)==0)
{
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " OS_Ubuntu_SourceList_DEB822);
}
else
{
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " OS_Ubuntu_SourceList_DEB822);
}
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeAuto);
}
/**
* @note 不同架构下换源不一样
*/
void
os_ubuntu_setsrc (char *option)
{
chsrc_ensure_root ();
if (chsrc_check_file (OS_Ubuntu_SourceList_DEB822))
{
chsrc_note2 ("将基于新格式换源");
os_ubuntu_setsrc_for_deb822 (option);
return;
}
bool sourcelist_exist = ensure_apt_sourcelist (OS_Is_Ubuntu);
SourceInfo source;
chsrc_yield_source (os_ubuntu);
chsrc_confirm_source (&source);
// 不存在的时候,用的是我们生成的无效文件,不要备份
if (sourcelist_exist)
{
chsrc_backup (OS_Apt_SourceList);
}
char *arch = chsrc_get_cpuarch ();
char *cmd = NULL;
if (0==strncmp (arch, "x86_64", 6))
{
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " OS_Apt_SourceList);
}
else
{
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " OS_Apt_SourceList);
}
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeAuto);
}
def_target(os_ubuntu);