!1 Debian换源合并

Merge pull request !1 from hengG/feature-os-debian
This commit is contained in:
ccmywish 2023-09-02 06:31:32 +00:00 committed by Gitee
commit 71b06bb366
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 55 additions and 10 deletions

40
chsrc.c
View File

@ -572,22 +572,47 @@ os_ubuntu_setsrc (char* option)
system(backup); system(backup);
xy_info ("chsrc: 备份文件名: /etc/apt/sources.list.bak"); xy_info ("chsrc: 备份文件名: /etc/apt/sources.list.bak");
const char* current_url = xy_strch(source_url,'/',"\\/");
char* cmd = xy_strjoin(3, "sed -E \'s/(^[^#]* .*)http[:|\\.|\\/|a-z|A-Z]*\\/ubuntu\\//\\1", char* cmd = xy_strjoin(3, "sed -E \'s@(^[^#]* .*)http[:|\\.|\\/|a-z|A-Z]*\\/ubuntu\\/@\\1",
current_url, source_url,
"/\'< /etc/apt/sources.list.bak | cat > /etc/apt/sources.list"); "@\'< /etc/apt/sources.list.bak | cat > /etc/apt/sources.list");
system(cmd); system(cmd);
free(cmd); free(cmd);
char* rm = "rm -rf /etc/apt/source.list.bak"; char* rm = "rm -rf /etc/apt/source.list.bak";
system(rm); system(rm);
// free(rm);
xy_info ("chsrc: 为 ubuntu 命令换源"); xy_info ("chsrc: 为 ubuntu 命令换源");
xy_success (xy_2strjoin("chsrc: 感谢镜像提供方:", source_name)); xy_success (xy_2strjoin("chsrc: 感谢镜像提供方:", source_name));
} }
void
os_debian_setsrc (char* option)
{
int selected = 0;
for (int i=0;i<sizeof(os_ubuntu_sources);i++) {
// 循环测速
}
const char* source_name = os_ubuntu_sources[selected].mirror->name;
const char* source_abbr = os_ubuntu_sources[selected].mirror->abbr;
const char* source_url = os_ubuntu_sources[selected].url;
char* backup = "cp -rf /etc/apt/sources.list /etc/apt/sources.list.bak";
system(backup);
xy_info ("chsrc: 备份文件名: /etc/apt/sources.list.bak");
char* cmd = xy_strjoin(3, "sed -E \'s@(^[^#]* .*)http[:|\\.|\\/|a-z|A-Z]*\\/debian\\/@\\1",
source_url,
"@\'< /etc/apt/sources.list.bak | cat > /etc/apt/sources.list");
system(cmd);
free(cmd);
char* rm = "rm -rf /etc/apt/source.list.bak";
system(rm);
xy_info ("chsrc: 为 ubuntu 命令换源");
xy_success (xy_2strjoin("chsrc: 感谢镜像提供方:", source_name));
}
#define setsrc_fn(func) (const char const*)func #define setsrc_fn(func) (const char const*)func
@ -613,10 +638,11 @@ static const char const
}, },
*os_ubuntu [] = {"ubuntu", NULL, setsrc_fn(os_ubuntu_setsrc)}, *os_ubuntu [] = {"ubuntu", NULL, setsrc_fn(os_ubuntu_setsrc),NULL,sources_ptr(os_ubuntu_sources)},
*os_debian [] = {"debian", NULL, setsrc_fn(os_debian_setsrc),NULL,sources_ptr(os_debian_sources)},
**os_systems[] = **os_systems[] =
{ {
os_ubuntu os_ubuntu,os_debian
}, },

22
chsrc.h
View File

@ -239,7 +239,11 @@ pl_php_sources[] = {
/**
* 2023-09-01
*
* TODO: 1.
*/
static source_info static source_info
os_ubuntu_sources[] = { os_ubuntu_sources[] = {
{&Ali, "https://mirrors.aliyun.com/ubuntu/"}, {&Ali, "https://mirrors.aliyun.com/ubuntu/"},
@ -249,8 +253,22 @@ os_ubuntu_sources[] = {
{&Tencent, "https://mirrors.tencent.com/ubuntu/"}, {&Tencent, "https://mirrors.tencent.com/ubuntu/"},
{&Netease, "https://mirrors.163.com/ubuntu/"}, {&Netease, "https://mirrors.163.com/ubuntu/"},
{&Sohu, "https://mirrors.sohu.com/ubuntu/"}, {&Sohu, "https://mirrors.sohu.com/ubuntu/"},
}; },
/**
* 2023-09-01
*
* TODO: 1.
*/
os_debian_sources[] = {
{&Ali, "https://mirrors.aliyun.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/"},
{&Netease, "https://mirrors.163.com/ubuntu/"},
{&Sohu, "https://mirrors.sohu.com/ubuntu/"},
};
/* 函数签名 */ /* 函数签名 */
bool does_the_program_exist (char* check_cmd, char* progname); bool does_the_program_exist (char* check_cmd, char* progname);

View File

@ -99,7 +99,8 @@ xy_log (int level, const char* str)
/** /**
* * str中所有的src字符替换成dest,
*
*/ */
static char* static char*
xy_strch (const char* str, char src,const char* dest) xy_strch (const char* str, char src,const char* dest)