mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-02-02 12:28:31 +08:00
Add feature os_debian.
This commit is contained in:
parent
89890f9d82
commit
afa2d9cb64
40
chsrc.c
40
chsrc.c
|
@ -572,22 +572,47 @@ os_ubuntu_setsrc (char* option)
|
|||
system(backup);
|
||||
|
||||
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",
|
||||
current_url,
|
||||
"/\'< /etc/apt/sources.list.bak | cat > /etc/apt/sources.list");
|
||||
char* cmd = xy_strjoin(3, "sed -E \'s@(^[^#]* .*)http[:|\\.|\\/|a-z|A-Z]*\\/ubuntu\\/@\\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);
|
||||
// free(rm);
|
||||
|
||||
xy_info ("chsrc: 为 ubuntu 命令换源");
|
||||
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
|
||||
|
@ -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_ubuntu
|
||||
os_ubuntu,os_debian
|
||||
},
|
||||
|
||||
|
||||
|
|
22
chsrc.h
22
chsrc.h
|
@ -239,7 +239,11 @@ pl_php_sources[] = {
|
|||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 2023-09-01 更新
|
||||
*
|
||||
* TODO: 1. 源并不完整,且未经测试是否有效
|
||||
*/
|
||||
static source_info
|
||||
os_ubuntu_sources[] = {
|
||||
{&Ali, "https://mirrors.aliyun.com/ubuntu/"},
|
||||
|
@ -249,8 +253,22 @@ os_ubuntu_sources[] = {
|
|||
{&Tencent, "https://mirrors.tencent.com/ubuntu/"},
|
||||
{&Netease, "https://mirrors.163.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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user