mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-02-02 14:10:45 +08:00
Split apt-family
This commit is contained in:
parent
645f073b9f
commit
d12e626f69
|
@ -154,29 +154,11 @@ pl_dotnet_sources[] = {
|
|||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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"}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @time 2023-09-29 更新
|
||||
* @note 实际上镜像站里的内容和Ubuntu的不太一样
|
||||
*/
|
||||
static SourceInfo
|
||||
os_mint_sources[] = {
|
||||
{&Upstream, NULL},
|
||||
{&MirrorZ, "https://mirrors.cernet.edu.cn/linuxmint/"},
|
||||
|
@ -201,21 +183,6 @@ os_deepin_sources[] = {
|
|||
},
|
||||
|
||||
|
||||
/**
|
||||
* @time 2024-06-12 更新
|
||||
*/
|
||||
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"}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @time 2023-09-02 更新
|
||||
|
@ -503,8 +470,8 @@ wr_tex_sources[] = {
|
|||
def_sources_n(pl_clojure);
|
||||
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_mint);
|
||||
def_sources_n(os_fedora);
|
||||
def_sources_n(os_kali);
|
||||
def_sources_n(os_msys2);
|
||||
def_sources_n(os_rocky); def_sources_n(os_alma);
|
||||
|
|
306
src/chsrc.c
306
src/chsrc.c
|
@ -71,203 +71,6 @@ pl_clojure_setsrc (char *option)
|
|||
|
||||
|
||||
|
||||
#define ETC_APT_SOURCELIST "/etc/apt/sources.list"
|
||||
#define ETC_OSRELEASE "/etc/os-release"
|
||||
|
||||
#define Debian_debian 1
|
||||
#define Debian_deriv_ubuntu 2
|
||||
|
||||
/**
|
||||
* 当不存在该文件时,我们只能拼凑一个假的出来,但该函数目前只适用于 Ubuntu 和 Debian
|
||||
* 因为其它的 Debian 变体可能不使用 ETC_APT_SOURCELIST,也可能并不适用 `VERSION_CODENAME`
|
||||
*
|
||||
* @return 文件是否存在
|
||||
*/
|
||||
bool
|
||||
ensure_apt_sourcelist (int debian_type)
|
||||
{
|
||||
bool exist = chsrc_check_file (ETC_APT_SOURCELIST);
|
||||
|
||||
if (exist)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
chsrc_note2 ("将生成新的源配置文件");
|
||||
}
|
||||
|
||||
// 反向引用需要escape一下
|
||||
char *codename = xy_run ("sed -nr 's/VERSION_CODENAME=(.*)/\\1/p' " ETC_OSRELEASE, 0, NULL);
|
||||
codename = xy_str_delete_suffix (codename, "\n");
|
||||
|
||||
char *version_id = xy_run ("sed -nr 's/VERSION_ID=(.*)/\\1/p' " ETC_OSRELEASE, 0, NULL);
|
||||
version_id = xy_str_delete_suffix (codename, "\n");
|
||||
double version = atof (version_id);
|
||||
|
||||
char *makeup = NULL;
|
||||
|
||||
if (debian_type == Debian_deriv_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 (ETC_APT_SOURCELIST, "w");
|
||||
fwrite (makeup, strlen (makeup), 1, f);
|
||||
fclose (f);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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 ETC_APT_DEB822_Debian_Sources "/etc/apt/sources.list.d/debian.sources"
|
||||
#define ETC_APT_DEB822_Ubuntu_Sources "/etc/apt/sources.list.d/ubuntu.sources"
|
||||
|
||||
void
|
||||
os_ubuntu_getsrc (char *option)
|
||||
{
|
||||
if (chsrc_check_file (ETC_APT_DEB822_Ubuntu_Sources))
|
||||
{
|
||||
chsrc_view_file (ETC_APT_DEB822_Ubuntu_Sources);
|
||||
return;
|
||||
}
|
||||
|
||||
if (chsrc_check_file (ETC_APT_SOURCELIST))
|
||||
{
|
||||
chsrc_view_file (ETC_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 (ETC_APT_DEB822_Ubuntu_Sources);
|
||||
|
||||
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\' " ETC_APT_DEB822_Ubuntu_Sources);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " ETC_APT_DEB822_Ubuntu_Sources);
|
||||
}
|
||||
|
||||
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 (ETC_APT_DEB822_Ubuntu_Sources))
|
||||
{
|
||||
chsrc_note2 ("将基于新格式换源");
|
||||
os_ubuntu_setsrc_for_deb822 (option);
|
||||
return;
|
||||
}
|
||||
|
||||
bool sourcelist_exist = ensure_apt_sourcelist (Debian_deriv_ubuntu);
|
||||
|
||||
SourceInfo source;
|
||||
chsrc_yield_source (os_ubuntu);
|
||||
chsrc_confirm_source (&source);
|
||||
|
||||
// 不存在的时候,用的是我们生成的无效文件,不要备份
|
||||
if (sourcelist_exist)
|
||||
{
|
||||
chsrc_backup (ETC_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\' " ETC_APT_SOURCELIST);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " ETC_APT_SOURCELIST);
|
||||
}
|
||||
|
||||
chsrc_run (cmd, RunOpt_Default);
|
||||
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
||||
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
os_mint_getsrc (char *option)
|
||||
{
|
||||
|
@ -297,92 +100,10 @@ os_mint_setsrc (char *option)
|
|||
chsrc_warn2 ("完成后请不要再使用 mintsources(自带的图形化软件源设置工具)进行任何操作,因为在操作后,无论是否有按“确定”,mintsources 均会覆写我们刚才换源的内容");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
os_debian_getsrc (char *option)
|
||||
{
|
||||
if (chsrc_check_file (ETC_APT_DEB822_Debian_Sources))
|
||||
{
|
||||
chsrc_view_file (ETC_APT_DEB822_Debian_Sources);
|
||||
return;
|
||||
}
|
||||
|
||||
if (chsrc_check_file (ETC_APT_SOURCELIST))
|
||||
{
|
||||
chsrc_view_file (ETC_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 (ETC_APT_DEB822_Debian_Sources);
|
||||
|
||||
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/debian/?@", source.url, "@g' " ETC_APT_DEB822_Debian_Sources);
|
||||
chsrc_run (cmd, RunOpt_Default);
|
||||
|
||||
// debian-security 源和其他源不一样
|
||||
cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/debian-security/?@", source.url, "-security@g' " ETC_APT_DEB822_Debian_Sources);
|
||||
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 (ETC_APT_DEB822_Debian_Sources))
|
||||
{
|
||||
chsrc_note2 ("将基于新格式换源");
|
||||
os_debian_setsrc_for_deb822 (option);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Docker环境下,Debian镜像可能不存在该文件
|
||||
bool sourcelist_exist = ensure_apt_sourcelist (Debian_debian);
|
||||
|
||||
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 (ETC_APT_SOURCELIST);
|
||||
}
|
||||
|
||||
char *cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/debian/?@", source.url, "@g\' " ETC_APT_SOURCELIST);
|
||||
|
||||
chsrc_run (cmd, RunOpt_Default);
|
||||
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
||||
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
||||
}
|
||||
|
||||
|
||||
#include "recipe/os/apt-family/common.h"
|
||||
#include "recipe/os/apt-family/debian.c"
|
||||
#include "recipe/os/apt-family/ubuntu.c"
|
||||
#include "recipe/os/apt-family/trisquel.c"
|
||||
|
||||
void
|
||||
os_raspberrypi_getsrc (char *option)
|
||||
|
@ -451,7 +172,7 @@ os_armbian_setsrc (char *option)
|
|||
void
|
||||
os_deepin_getsrc(char *option)
|
||||
{
|
||||
chsrc_view_file (ETC_APT_SOURCELIST);
|
||||
chsrc_view_file (OS_Apt_SourceList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -466,7 +187,7 @@ os_deepin_setsrc (char *option)
|
|||
chsrc_yield_source (os_deepin);
|
||||
chsrc_confirm_source (&source);
|
||||
|
||||
chsrc_backup (ETC_APT_SOURCELIST);
|
||||
chsrc_backup (OS_Apt_SourceList);
|
||||
|
||||
char *cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/deepin/?@",
|
||||
source.url,
|
||||
|
@ -523,7 +244,7 @@ os_fedora_setsrc (char *option)
|
|||
void
|
||||
os_kali_getsrc (char *option)
|
||||
{
|
||||
chsrc_view_file (ETC_APT_SOURCELIST);
|
||||
chsrc_view_file (OS_Apt_SourceList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -538,7 +259,7 @@ os_kali_setsrc (char *option)
|
|||
chsrc_yield_source (os_kali);
|
||||
chsrc_confirm_source (&source);
|
||||
|
||||
chsrc_backup (ETC_APT_SOURCELIST);
|
||||
chsrc_backup (OS_Apt_SourceList);
|
||||
|
||||
char *cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/kali/?@",
|
||||
source.url,
|
||||
|
@ -647,13 +368,12 @@ os_manjaro_setsrc (char *option)
|
|||
chsrc_say_lastly (NULL, ChsrcTypeAuto);
|
||||
}
|
||||
|
||||
#include "recipe/os/trisquel.c"
|
||||
|
||||
|
||||
void
|
||||
os_linuxlite_getsrc (char *option)
|
||||
{
|
||||
chsrc_view_file (ETC_APT_SOURCELIST);
|
||||
chsrc_view_file (OS_Apt_SourceList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -668,7 +388,7 @@ os_linuxlite_setsrc (char *option)
|
|||
chsrc_yield_source (os_linuxlite);
|
||||
chsrc_confirm_source (&source);
|
||||
|
||||
chsrc_backup (ETC_APT_SOURCELIST);
|
||||
chsrc_backup (OS_Apt_SourceList);
|
||||
|
||||
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/.*/?@", source.url, "@g' /etc/apt/sources.list");
|
||||
|
||||
|
@ -731,7 +451,7 @@ os_anolis_setsrc (char *option)
|
|||
void
|
||||
os_openkylin_getsrc (char *option)
|
||||
{
|
||||
chsrc_view_file (ETC_APT_SOURCELIST);
|
||||
chsrc_view_file (OS_Apt_SourceList);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -743,9 +463,9 @@ os_openkylin_setsrc (char *option)
|
|||
chsrc_yield_source (os_openkylin);
|
||||
chsrc_confirm_source (&source);
|
||||
|
||||
chsrc_backup (ETC_APT_SOURCELIST);
|
||||
chsrc_backup (OS_Apt_SourceList);
|
||||
|
||||
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/openkylin/?@", source.url, "@g'" ETC_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);
|
||||
|
|
|
@ -39,7 +39,7 @@ static const char
|
|||
};
|
||||
|
||||
|
||||
def_target(os_ubuntu); def_target(os_mint); def_target(os_debian); def_target(os_kali);
|
||||
def_target(os_mint); def_target(os_kali);
|
||||
def_target(os_linuxlite);
|
||||
def_target(os_deepin); def_target(os_openkylin);
|
||||
def_target(os_raspberrypi);
|
||||
|
|
112
src/recipe/os/apt-family/common.h
Normal file
112
src/recipe/os/apt-family/common.h
Normal file
|
@ -0,0 +1,112 @@
|
|||
/** ------------------------------------------------------------
|
||||
* 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>
|
||||
* ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @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 OS_Apt_SourceList "/etc/apt/sources.list"
|
||||
|
||||
#define ETC_os_release "/etc/os-release"
|
||||
|
||||
#define OS_Is_Debian_Literally 1
|
||||
#define OS_Is_Ubuntu 2
|
||||
|
||||
/**
|
||||
* 当不存在该文件时,我们只能拼凑一个假的出来,但该函数目前只适用于 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-family/debian.c
Normal file
112
src/recipe/os/apt-family/debian.c
Normal 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);
|
|
@ -5,6 +5,8 @@
|
|||
* Contributors : Nil Null <nil@null.org>
|
||||
* Created On : <2023-09-29>
|
||||
* Last Modified : <2024-08-16>
|
||||
*
|
||||
* Trisquel基于Ubuntu开发,不含任何专有软件及专有固件,内核使用 Linux-libre
|
||||
* ------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
|
@ -24,7 +26,7 @@ def_sources_n(os_trisquel);
|
|||
void
|
||||
os_trisquel_getsrc (char *option)
|
||||
{
|
||||
chsrc_view_file (ETC_APT_SOURCELIST);
|
||||
chsrc_view_file (OS_Apt_SourceList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,7 +41,7 @@ os_trisquel_setsrc (char *option)
|
|||
chsrc_yield_source (os_trisquel);
|
||||
chsrc_confirm_source (&source);
|
||||
|
||||
chsrc_backup (ETC_APT_SOURCELIST);
|
||||
chsrc_backup (OS_Apt_SourceList);
|
||||
|
||||
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/trisquel/?@", source.url, "@g' /etc/apt/sources.list");
|
||||
|
121
src/recipe/os/apt-family/ubuntu.c
Normal file
121
src/recipe/os/apt-family/ubuntu.c
Normal 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);
|
Loading…
Reference in New Issue
Block a user