mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-01-22 18:56:15 +08:00
Merge hengG
This commit is contained in:
commit
ee55dce25f
57
chsrc.c
57
chsrc.c
|
@ -128,6 +128,35 @@ pl_ruby_chsrc (char* option)
|
|||
xy_success(xy_strjoin("chsrc: 感谢镜像提供方:", source_name));
|
||||
}
|
||||
|
||||
void
|
||||
os_ubuntu_chsrc (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* beifen = "cp -rf /etc/apt/sources.list /etc/apt/sources.list.bak";
|
||||
system(beifen);
|
||||
// free(beifen);
|
||||
puts("备份文件名: /etc/apt/sources.list.bak");
|
||||
const char* current_url = xy_strch(source_url,'/',"\\/");
|
||||
|
||||
char* cmd = xy_strjoin(xy_strjoin("sed -E \'s/(^[^#]* .*)http[:|\\.|\\/|a-z|A-Z]*\\/ubuntu\\//\\1",current_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);
|
||||
|
||||
puts("chsrc: 为'ubuntu'命令换源");
|
||||
puts(xy_strjoin("chsrc: 感谢镜像提供方:", source_name));
|
||||
}
|
||||
|
||||
#define chsrcfunc(func) (const char const*)func
|
||||
static const char const
|
||||
*pl_ruby[] = {"gem", "ruby", "rb", NULL, chsrcfunc(pl_ruby_chsrc) },
|
||||
|
@ -142,12 +171,19 @@ static const char const
|
|||
*pl_maven[] = {"maven", NULL},
|
||||
*pl_gradle[] = {"gradel",NULL},
|
||||
*pl_julia[] = {"julia", NULL},
|
||||
|
||||
*os_ubuntu[] = {"ubuntu", NULL, chsrcfunc(os_ubuntu_chsrc)},
|
||||
// Java暂时需要直接指定包管理器
|
||||
// pl_java
|
||||
**pl_packagers[] = {
|
||||
pl_ruby, pl_python, pl_nodejs, pl_perl, pl_php, pl_cran,
|
||||
pl_rust, pl_go, pl_dotnet, pl_maven, pl_gradle, pl_julia
|
||||
},
|
||||
**os_packagers[] = {
|
||||
os_ubuntu
|
||||
};
|
||||
// static const char const
|
||||
// *os_ubuntu[] = {"ubuntu", NULL, cmdfunc(os_ubuntu_chsrc)};
|
||||
#undef chsrcfunc
|
||||
|
||||
static const char const*
|
||||
|
@ -224,6 +260,27 @@ main (int argc, char const *argv[])
|
|||
int k = 0;
|
||||
const char* alias = packager[k];
|
||||
while (NULL!=alias) {
|
||||
printf("%s matched: %s\n",target, alias);
|
||||
if (0==strcmp(target, alias)) {
|
||||
// printf("matched: %s\n", alias);
|
||||
matched = 1; break;
|
||||
}
|
||||
k++;
|
||||
alias = packager[k];
|
||||
}
|
||||
if (matched) {
|
||||
do {
|
||||
k++; alias = packager[k];
|
||||
} while (NULL!=alias);
|
||||
call_cmd ((void*) packager[k+1], cmdarg);
|
||||
}
|
||||
}
|
||||
for (int i=0; i<Array_Size(os_packagers); i++) {
|
||||
const char const** packager = os_packagers[i];
|
||||
int k = 0;
|
||||
const char* alias = packager[k];
|
||||
while (NULL!=alias) {
|
||||
// printf("%s matched: %s\n",target, alias);
|
||||
if (0==strcmp(target, alias)) {
|
||||
// printf("matched: %s\n", alias);
|
||||
matched = 1; break;
|
||||
|
|
16
chsrc.h
16
chsrc.h
|
@ -29,12 +29,15 @@ mirror_info
|
|||
Bfsu = {"BFSU", "北京外国语大学开源软件镜像站"},
|
||||
Pku = {"PKU", "北京大学开源镜像站"},
|
||||
Bjtu = {"BJTU", "北京交通大学自由与开源软件镜像站"},
|
||||
Sustech = {"SUSTech", "南方科技大学开源软件镜像站"};
|
||||
Sustech = {"SUSTech", "南方科技大学开源软件镜像站"},
|
||||
Ustc = {"USTC", "中国科学技术大学开源镜像站"},
|
||||
|
||||
// 大型公司
|
||||
mirror_info
|
||||
Ali = {"Ali OPSX", "阿里巴巴开源镜像站"},
|
||||
Tencent = {"Tencent", "腾讯软件源"};
|
||||
Netease = {"Netease", "网易开源镜像站"},
|
||||
Sohu = {"SOHU", "搜狐开源镜像站"};
|
||||
|
||||
// 开源社区
|
||||
mirror_info
|
||||
|
@ -73,6 +76,17 @@ pl_python_sources[] = {
|
|||
};
|
||||
|
||||
|
||||
static source_info
|
||||
os_ubuntu_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/"},
|
||||
{&Wy, "https://mirrors.163.com/ubuntu/"},
|
||||
{&Sohu, "https://mirrors.sohu.com/ubuntu/"},
|
||||
};
|
||||
|
||||
|
||||
/* 函数签名 */
|
||||
bool does_the_program_exist (char* check_cmd, char* progname);
|
||||
|
|
33
helper.h
33
helper.h
|
@ -98,6 +98,39 @@ xy_log (int level, const char* str)
|
|||
#define xy_error(str) xy_log (XY_ERROR, str)
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* */
|
||||
static char*
|
||||
xy_strch (const char* str, char src,const char* dest)
|
||||
{
|
||||
size_t str_len = strlen(str);
|
||||
size_t dest_len = strlen(dest);
|
||||
size_t size = str_len*dest_len;
|
||||
char* ret = (char*)malloc(size);
|
||||
int i=0;
|
||||
int j=0;
|
||||
while(i<str_len) {
|
||||
if(str[i]==src) {
|
||||
int k=0;
|
||||
while(k<dest_len){
|
||||
ret[j++] = dest[k++];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
ret[j++] = str[i++];
|
||||
}
|
||||
}
|
||||
ret[j] = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
xy_success (const char* str1)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user