mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-02-02 17:47:13 +08:00
commit
71b06bb366
40
chsrc.c
40
chsrc.c
|
@ -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
22
chsrc.h
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user