mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-02-02 16:10:45 +08:00
parent
a910733b42
commit
7439f522e2
68
src/chsrc.c
68
src/chsrc.c
|
@ -843,20 +843,24 @@ pl_julia_setsrc (char *option)
|
||||||
#define ETC_APT_SOURCELIST "/etc/apt/sources.list"
|
#define ETC_APT_SOURCELIST "/etc/apt/sources.list"
|
||||||
#define ETC_OSRELEASE "/etc/os-release"
|
#define ETC_OSRELEASE "/etc/os-release"
|
||||||
|
|
||||||
|
#define Debian_debian 1
|
||||||
|
#define Debian_deriv_ubuntu 2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当不存在该文件时,我们只能拼凑一个假的出来,但该函数目前只适用于 Ubuntu
|
* 当不存在该文件时,我们只能拼凑一个假的出来,但该函数目前只适用于 Ubuntu 和 Debian
|
||||||
* 因为其它的 Debian 变体可能不使用 ETC_APT_SOURCELIST,也可能并不适用 `VERSION_CODENAME`
|
* 因为其它的 Debian 变体可能不使用 ETC_APT_SOURCELIST,也可能并不适用 `VERSION_CODENAME`
|
||||||
|
*
|
||||||
|
* @return 文件是否存在
|
||||||
*/
|
*/
|
||||||
void
|
bool
|
||||||
makeup_etc_apt_sourcelist ()
|
ensure_apt_sourcelist (int debian_type)
|
||||||
{
|
{
|
||||||
bool exist = xy_file_exist (ETC_APT_SOURCELIST);
|
bool exist = xy_file_exist (ETC_APT_SOURCELIST);
|
||||||
|
|
||||||
if (exist)
|
if (exist)
|
||||||
{
|
{
|
||||||
chsrc_infolog_remarkably (ETC_APT_SOURCELIST " 存在");
|
chsrc_infolog_remarkably (ETC_APT_SOURCELIST " 存在");
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -866,16 +870,32 @@ makeup_etc_apt_sourcelist ()
|
||||||
char *codename = xy_run ("sed -nr 's/VERSION_CODENAME=(.*)/\1/p' " ETC_OSRELEASE, 0, NULL);
|
char *codename = xy_run ("sed -nr 's/VERSION_CODENAME=(.*)/\1/p' " ETC_OSRELEASE, 0, NULL);
|
||||||
codename = xy_str_delete_suffix (codename, "\n");
|
codename = xy_str_delete_suffix (codename, "\n");
|
||||||
|
|
||||||
char *makeup = xy_strjoin (9,
|
char *makeup = NULL;
|
||||||
"# Generated by " Chsrc_Version "\n"
|
|
||||||
"deb " Chsrc_Maintain_URL, codename, " main restricted universe multiverse\n"
|
if (debian_type == Debian_deriv_ubuntu)
|
||||||
"deb " Chsrc_Maintain_URL, codename, "-updates main restricted universe multiverse\n"
|
{
|
||||||
"deb " Chsrc_Maintain_URL, codename, "-backports main restricted universe multiverse\n"
|
makeup = xy_strjoin (9,
|
||||||
"deb " Chsrc_Maintain_URL, codename, "-security main restricted universe multiverse\n");
|
"# Generated by chsrc" Chsrc_Version "\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
|
||||||
|
{
|
||||||
|
// https://wiki.debian.org/SourcesList
|
||||||
|
makeup = xy_strjoin (9,
|
||||||
|
"# Generated by chsrc" Chsrc_Version "\n"
|
||||||
|
"deb " Chsrc_Maintain_URL "/debian", codename, " main contrib non-free\n"
|
||||||
|
"deb " Chsrc_Maintain_URL "/debian", codename, "-security 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");
|
||||||
|
}
|
||||||
|
|
||||||
FILE *f = fopen (ETC_APT_SOURCELIST, "w");
|
FILE *f = fopen (ETC_APT_SOURCELIST, "w");
|
||||||
fwrite (makeup, strlen(makeup), 1, f);
|
fwrite (makeup, strlen (makeup), 1, f);
|
||||||
fclose (f);
|
fclose (f);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -894,24 +914,28 @@ os_ubuntu_setsrc (char *option)
|
||||||
{
|
{
|
||||||
chsrc_ensure_root ();
|
chsrc_ensure_root ();
|
||||||
|
|
||||||
makeup_etc_apt_sourcelist ();
|
bool sourcelist_exist = ensure_apt_sourcelist (Debian_deriv_ubuntu);
|
||||||
|
|
||||||
int index = use_specific_mirror_or_auto_select (option, os_ubuntu);
|
int index = use_specific_mirror_or_auto_select (option, os_ubuntu);
|
||||||
|
|
||||||
SourceInfo source = os_ubuntu_sources[index];
|
SourceInfo source = os_ubuntu_sources[index];
|
||||||
chsrc_confirm_selection (&source);
|
chsrc_confirm_selection (&source);
|
||||||
|
|
||||||
chsrc_backup (ETC_APT_SOURCELIST);
|
// 不存在的时候,用的是我们生成的无效文件,不要备份
|
||||||
|
if (sourcelist_exist)
|
||||||
|
{
|
||||||
|
chsrc_backup (ETC_APT_SOURCELIST);
|
||||||
|
}
|
||||||
|
|
||||||
char *arch = xy_run ("arch", 0, NULL);
|
char *arch = xy_run ("arch", 0, NULL);
|
||||||
char *cmd = NULL;
|
char *cmd = NULL;
|
||||||
if (strncmp (arch, "x86_64", 6)==0)
|
if (strncmp (arch, "x86_64", 6)==0)
|
||||||
{
|
{
|
||||||
cmd = xy_strjoin (3, "sed -E -i \'s@^https?://.*$@", source.url, "@g\' " ETC_APT_SOURCELIST);
|
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " ETC_APT_SOURCELIST);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cmd = xy_strjoin (3, "sed -E -i \'s@^https?://.*$@", source.url, "-ports@g\' " ETC_APT_SOURCELIST);
|
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " ETC_APT_SOURCELIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
chsrc_run (cmd);
|
chsrc_run (cmd);
|
||||||
|
@ -968,6 +992,9 @@ os_debian_setsrc (char *option)
|
||||||
{
|
{
|
||||||
chsrc_ensure_root ();
|
chsrc_ensure_root ();
|
||||||
|
|
||||||
|
// Docker环境下,Debian镜像可能不存在该文件
|
||||||
|
bool sourcelist_exist = ensure_apt_sourcelist (Debian_debian);
|
||||||
|
|
||||||
int index = use_specific_mirror_or_auto_select (option, os_debian);
|
int index = use_specific_mirror_or_auto_select (option, os_debian);
|
||||||
|
|
||||||
SourceInfo source = os_debian_sources[index];
|
SourceInfo source = os_debian_sources[index];
|
||||||
|
@ -976,12 +1003,13 @@ os_debian_setsrc (char *option)
|
||||||
chsrc_note_remarkably ("如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并需要您运行:");
|
chsrc_note_remarkably ("如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并需要您运行:");
|
||||||
puts ("apt install apt-transport-https ca-certificates");
|
puts ("apt install apt-transport-https ca-certificates");
|
||||||
|
|
||||||
chsrc_backup (ETC_APT_SOURCELIST);
|
// 不存在的时候,用的是我们生成的无效文件,不要备份
|
||||||
|
if (sourcelist_exist)
|
||||||
|
{
|
||||||
|
chsrc_backup (ETC_APT_SOURCELIST);
|
||||||
|
}
|
||||||
|
|
||||||
char *cmd = xy_strjoin(3,
|
char *cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/debian/?@", source.url, "@g\' " ETC_APT_SOURCELIST);
|
||||||
"sed -E -i \'s@https?://.*/debian/?@",
|
|
||||||
source.url,
|
|
||||||
"@g\' /etc/apt/sources.list");
|
|
||||||
|
|
||||||
chsrc_run (cmd);
|
chsrc_run (cmd);
|
||||||
chsrc_run ("apt update");
|
chsrc_run ("apt update");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user