2023-09-09 16:49:06 +08:00
|
|
|
|
/** ------------------------------------------------------------
|
|
|
|
|
* File : chsrc.c
|
|
|
|
|
* License : GPLv3
|
|
|
|
|
* Authors : Aoran Zeng <ccmywish@qq.com>
|
|
|
|
|
* Created on : <2023-08-28>
|
2023-09-29 19:12:57 +08:00
|
|
|
|
* Last modified : <2023-09-29>
|
2023-09-09 16:49:06 +08:00
|
|
|
|
*
|
|
|
|
|
* chsrc:
|
|
|
|
|
*
|
|
|
|
|
* Change Source —— 命令行换源工具
|
|
|
|
|
*
|
|
|
|
|
* 该软件为自由软件,采用 GPLv3 许可证,请查阅 LICENSE.txt 文件
|
|
|
|
|
* ------------------------------------------------------------*/
|
2023-08-29 15:54:21 +08:00
|
|
|
|
|
2023-09-29 19:12:57 +08:00
|
|
|
|
#define Chsrc_Version "v0.1.2-20230929"
|
2023-09-21 14:34:16 +08:00
|
|
|
|
|
2023-08-29 23:07:48 +08:00
|
|
|
|
#include "chsrc.h"
|
2023-08-28 22:21:33 +08:00
|
|
|
|
|
2023-08-31 15:54:47 +08:00
|
|
|
|
void
|
2023-09-03 15:56:01 +08:00
|
|
|
|
pl_ruby_getsrc (char* option)
|
2023-08-31 15:54:47 +08:00
|
|
|
|
{
|
2023-09-27 19:31:23 +08:00
|
|
|
|
chsrc_run("gem sources");
|
|
|
|
|
chsrc_run("bundle config get mirror.https://rubygems.org");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pl_ruby_remove_gem_source (const char* source)
|
|
|
|
|
{
|
|
|
|
|
char* cmd = NULL;
|
|
|
|
|
if (xy_str_start_with(source, "http")){
|
|
|
|
|
cmd = xy_str_delete_suffix(source, "\n");
|
|
|
|
|
cmd = xy_2strjoin("gem sources -r ", cmd);
|
|
|
|
|
chsrc_run(cmd);
|
|
|
|
|
}
|
2023-09-03 15:56:01 +08:00
|
|
|
|
}
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-03 15:56:01 +08:00
|
|
|
|
/**
|
2023-09-26 18:11:38 +08:00
|
|
|
|
* Ruby换源,参考:https://gitee.com/RubyMetric/rbenv-cn
|
2023-09-03 15:56:01 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pl_ruby_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-03 17:57:45 +08:00
|
|
|
|
int index = 0;
|
2023-09-04 15:10:18 +08:00
|
|
|
|
char* check_cmd = xy_str_to_quietcmd("gem -v");
|
2023-09-10 21:40:21 +08:00
|
|
|
|
bool exist = does_the_program_exist (check_cmd, "gem");
|
|
|
|
|
if (!exist) {
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_error ("未找到 gem 命令,请检查是否存在");
|
2023-08-31 15:54:47 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
index = use_specific_mirror_or_auto_select (option, pl_ruby);
|
2023-09-03 20:49:55 +08:00
|
|
|
|
|
2023-09-03 17:57:45 +08:00
|
|
|
|
source_info source = pl_ruby_sources[index];
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_selection (&source);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-15 16:24:43 +08:00
|
|
|
|
char* cmd = NULL;
|
|
|
|
|
|
2023-09-27 19:31:23 +08:00
|
|
|
|
xy_getcmd ("gem sources -l", 0, pl_ruby_remove_gem_source);
|
2023-09-04 15:39:49 +08:00
|
|
|
|
|
|
|
|
|
cmd = xy_2strjoin("gem source -a ", source.url);
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-08-31 14:41:48 +08:00
|
|
|
|
|
2023-09-04 15:10:18 +08:00
|
|
|
|
check_cmd = xy_str_to_quietcmd("bundle -v");
|
2023-09-10 21:40:21 +08:00
|
|
|
|
exist = does_the_program_exist (check_cmd, "bundle");
|
|
|
|
|
if (!exist) {
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_error ("未找到 bundle 命令,请检查是否存在");
|
2023-08-31 14:41:48 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-04 15:10:18 +08:00
|
|
|
|
cmd = xy_2strjoin("bundle config 'mirror.https://rubygems.org' ", source.url);
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-08-31 14:41:48 +08:00
|
|
|
|
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-09-15 15:21:17 +08:00
|
|
|
|
puts("");
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_warn("维护者提醒您: Ruby的镜像源目前仅有腾讯和RubyChina实现正确");
|
|
|
|
|
chsrc_warn("而其它如Tuna,Bfsu,Ali目前都实现的有问题,请勿使用");
|
2023-08-31 14:41:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-03 15:56:01 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param[out] prog 返回 Python 的可用名,如果不可用,则返回 NULL
|
2023-08-28 22:21:33 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_python_check_cmd_ (char** prog)
|
2023-08-28 22:21:33 +08:00
|
|
|
|
{
|
2023-09-04 15:10:18 +08:00
|
|
|
|
*prog = NULL;
|
2023-08-30 17:10:23 +08:00
|
|
|
|
// 不要调用 python 自己,而是使用 python --version,避免Windows弹出Microsoft Store
|
2023-09-04 15:10:18 +08:00
|
|
|
|
char* check_cmd = xy_str_to_quietcmd("python --version");
|
2023-09-10 21:40:21 +08:00
|
|
|
|
bool exist = does_the_program_exist (check_cmd, "python");
|
2023-08-30 17:10:23 +08:00
|
|
|
|
|
2023-09-10 21:40:21 +08:00
|
|
|
|
if (!exist) {
|
2023-09-04 15:10:18 +08:00
|
|
|
|
check_cmd = xy_str_to_quietcmd("python3 --version");
|
2023-09-10 21:40:21 +08:00
|
|
|
|
exist = does_the_program_exist (check_cmd, "python3");
|
|
|
|
|
if (exist) *prog = "python3";
|
2023-08-30 17:10:23 +08:00
|
|
|
|
}
|
|
|
|
|
else {
|
2023-09-03 15:56:01 +08:00
|
|
|
|
*prog = "python";
|
2023-08-30 17:10:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 21:40:21 +08:00
|
|
|
|
if (!exist) {
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_error ("未找到 Python 相关命令,请检查是否存在");
|
2023-09-03 15:56:01 +08:00
|
|
|
|
exit(1);
|
2023-08-30 17:10:23 +08:00
|
|
|
|
}
|
2023-09-03 15:56:01 +08:00
|
|
|
|
}
|
2023-08-28 23:10:09 +08:00
|
|
|
|
|
2023-09-03 15:56:01 +08:00
|
|
|
|
void
|
|
|
|
|
pl_python_getsrc (char* option)
|
|
|
|
|
{
|
|
|
|
|
char* prog = NULL;
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_python_check_cmd_ (&prog);
|
2023-09-03 15:56:01 +08:00
|
|
|
|
char* cmd = xy_2strjoin(prog, " -m pip config get global.index-url");
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-03 15:56:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Python换源,参考:https://mirrors.tuna.tsinghua.edu.cn/help/pypi/
|
|
|
|
|
*
|
|
|
|
|
* 经测试,Windows上调用换源命令,会写入 C:\Users\RubyMetric\AppData\Roaming\pip\pip.ini
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pl_python_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-03 20:49:55 +08:00
|
|
|
|
int index = 0;
|
2023-09-03 15:56:01 +08:00
|
|
|
|
char* prog = NULL;
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_python_check_cmd_ (&prog);
|
2023-09-03 15:56:01 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
index = use_specific_mirror_or_auto_select (option, pl_python);
|
2023-08-30 11:33:23 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
source_info source = pl_python_sources[index];
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_selection(&source);
|
2023-08-28 22:21:33 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
char* cmd = xy_2strjoin(prog, xy_2strjoin(" -m pip config set global.index-url ", source.url));
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-08-28 22:21:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-03 14:48:53 +08:00
|
|
|
|
|
2023-09-03 15:56:01 +08:00
|
|
|
|
void
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_nodejs_check_cmd_ (bool* npm_exist, bool* yarn_exist)
|
2023-09-03 15:56:01 +08:00
|
|
|
|
{
|
2023-09-04 15:10:18 +08:00
|
|
|
|
char* check_cmd = xy_str_to_quietcmd("npm -v");
|
2023-09-09 17:21:59 +08:00
|
|
|
|
*npm_exist = does_the_program_exist (check_cmd, "npm");
|
|
|
|
|
|
|
|
|
|
check_cmd = xy_str_to_quietcmd("yarn -v");
|
|
|
|
|
*yarn_exist = does_the_program_exist (check_cmd, "yarn");
|
|
|
|
|
|
|
|
|
|
if (!*npm_exist && !*yarn_exist) {
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_error ("未找到 npm 或 yarn 命令,请检查是否存在其一");
|
2023-09-03 15:56:01 +08:00
|
|
|
|
exit(1);
|
2023-09-03 14:48:53 +08:00
|
|
|
|
}
|
2023-09-03 15:56:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
|
2023-09-03 15:56:01 +08:00
|
|
|
|
void
|
|
|
|
|
pl_nodejs_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-09 17:21:59 +08:00
|
|
|
|
bool npm_exist, yarn_exist;
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_nodejs_check_cmd_ (&npm_exist, &yarn_exist);
|
2023-09-09 17:21:59 +08:00
|
|
|
|
|
|
|
|
|
if (npm_exist)
|
|
|
|
|
{
|
|
|
|
|
char* cmd = "npm config get registry";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-09 17:21:59 +08:00
|
|
|
|
}
|
|
|
|
|
if (yarn_exist)
|
|
|
|
|
{
|
|
|
|
|
char* cmd = "yarn config get registry";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-09 17:21:59 +08:00
|
|
|
|
}
|
2023-09-03 14:48:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 22:21:33 +08:00
|
|
|
|
/**
|
2023-09-03 15:56:01 +08:00
|
|
|
|
* NodeJS换源,参考:https://npmmirror.com/
|
2023-08-28 22:21:33 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
2023-09-03 15:56:01 +08:00
|
|
|
|
pl_nodejs_setsrc (char* option)
|
2023-08-28 22:21:33 +08:00
|
|
|
|
{
|
2023-09-09 17:21:59 +08:00
|
|
|
|
bool npm_exist, yarn_exist;
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_nodejs_check_cmd_ (&npm_exist, &yarn_exist);
|
2023-08-28 23:10:09 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
int index = 0;
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
index = use_specific_mirror_or_auto_select (option, pl_nodejs);
|
2023-08-28 22:21:33 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
source_info source = pl_nodejs_sources[index];
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_selection (&source);
|
2023-08-28 22:21:33 +08:00
|
|
|
|
|
2023-09-09 17:21:59 +08:00
|
|
|
|
if (npm_exist)
|
|
|
|
|
{
|
|
|
|
|
char* cmd = xy_2strjoin("npm config set registry ", source.url);
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-09 17:21:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (yarn_exist)
|
|
|
|
|
{
|
|
|
|
|
char* cmd = xy_str_to_quietcmd(xy_2strjoin("yarn config set registry ", source.url));
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-09 17:21:59 +08:00
|
|
|
|
}
|
|
|
|
|
chsrc_say_thanks(&source);
|
2023-09-03 15:56:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_perl_check_cmd_ ()
|
2023-09-03 15:56:01 +08:00
|
|
|
|
{
|
2023-09-04 15:10:18 +08:00
|
|
|
|
char* check_cmd = xy_str_to_quietcmd("perl --version");
|
2023-09-10 21:40:21 +08:00
|
|
|
|
bool exist = does_the_program_exist (check_cmd, "perl");
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-10 21:40:21 +08:00
|
|
|
|
if (!exist) {
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_error ("未找到 perl 命令,请检查是否存在");
|
2023-09-03 15:56:01 +08:00
|
|
|
|
exit(1);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
}
|
2023-09-03 15:56:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pl_perl_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_perl_check_cmd_ ();
|
2023-09-04 19:19:30 +08:00
|
|
|
|
// @ccmywish: 注意,prettyprint 仅仅是一个内部实现,可能不稳定,如果需要更稳定的,
|
|
|
|
|
// 可以使用 CPAN::Shell->o('conf', 'urllist');
|
|
|
|
|
// 另外,上述两种方法无论哪种,都要首先load()
|
|
|
|
|
char* cmd = "perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->prettyprint('urllist')\" ";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-03 15:56:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perl换源,参考:https://help.mirrors.cernet.edu.cn/CPAN/
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pl_perl_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, pl_perl);
|
2023-09-03 15:56:01 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
source_info source = pl_perl_sources[index];
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_selection (&source);
|
2023-09-03 15:56:01 +08:00
|
|
|
|
|
|
|
|
|
char* cmd = xy_strjoin(3,
|
2023-09-04 19:19:30 +08:00
|
|
|
|
"perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->edit('urllist', 'unshift', '", source.url, "'); CPAN::HandleConfig->commit()\"");
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-04 19:19:30 +08:00
|
|
|
|
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_warn ("请您使用 perl -v 以及 cpan -v,若 Perl >= v5.36 或 CPAN >= 2.29,请额外手动调用下面的命令");
|
|
|
|
|
puts("perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->edit('pushy_https', 0);; CPAN::HandleConfig->commit()\"");
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-08-28 22:21:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 15:56:01 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-02 15:45:37 +08:00
|
|
|
|
void
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_php_check_cmd_()
|
2023-09-02 15:45:37 +08:00
|
|
|
|
{
|
2023-09-04 15:10:18 +08:00
|
|
|
|
char* check_cmd = xy_str_to_quietcmd("composer --version");
|
2023-09-10 21:40:21 +08:00
|
|
|
|
bool exist = does_the_program_exist (check_cmd, "composer");
|
2023-09-03 15:56:01 +08:00
|
|
|
|
|
2023-09-10 21:40:21 +08:00
|
|
|
|
if (!exist) {
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_error ("未找到 composer 命令,请检查是否存在");
|
2023-09-03 15:56:01 +08:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 22:11:52 +08:00
|
|
|
|
/**
|
|
|
|
|
* 已在Windows上测试通过,待其他平台PHP用户确认
|
2023-09-05 13:06:04 +08:00
|
|
|
|
*/
|
2023-09-03 15:56:01 +08:00
|
|
|
|
void
|
|
|
|
|
pl_php_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_php_check_cmd_ ();
|
2023-09-03 22:11:52 +08:00
|
|
|
|
char* cmd = "composer config -g repositories";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-03 15:56:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* PHP 换源,参考:https://developer.aliyun.com/composer
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pl_php_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_php_check_cmd_();
|
2023-09-03 15:56:01 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, pl_php);
|
2023-09-03 15:56:01 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
source_info source = pl_php_sources[index];
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_selection (&source);
|
2023-09-03 15:56:01 +08:00
|
|
|
|
|
2023-09-03 22:11:52 +08:00
|
|
|
|
char* cmd = xy_2strjoin("composer config -g repo.packagist composer ", source.url);
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-03 15:56:01 +08:00
|
|
|
|
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-09-02 15:45:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-27 14:49:00 +08:00
|
|
|
|
void
|
|
|
|
|
pl_lua_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-27 15:54:23 +08:00
|
|
|
|
chsrc_check_file ("~/.luarocks/config.lua");
|
2023-09-27 14:49:00 +08:00
|
|
|
|
chsrc_check_file ("~/.luarocks/upload_config.lua");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Lua 换源,参考:https://luarocks.cn/
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pl_lua_setsrc (char* option)
|
|
|
|
|
{
|
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, pl_lua);
|
|
|
|
|
|
|
|
|
|
source_info source = pl_lua_sources[index];
|
|
|
|
|
chsrc_say_selection (&source);
|
|
|
|
|
|
|
|
|
|
char* config = xy_strjoin(3, "rocks_servers = {\n"
|
|
|
|
|
" \"", source.url, "\"\n"
|
2023-09-27 15:04:36 +08:00
|
|
|
|
"}");
|
2023-09-27 14:49:00 +08:00
|
|
|
|
|
|
|
|
|
chsrc_info ("请手动修改 ~/.luarocks/config.lua 文件 (用于下载):");
|
|
|
|
|
puts(config);
|
|
|
|
|
|
|
|
|
|
char* upload_config = xy_strjoin(3, "key = \"<Your API Key>\"\n"
|
2023-09-27 15:04:36 +08:00
|
|
|
|
"server = \"", source.url, "\"");
|
2023-09-27 14:49:00 +08:00
|
|
|
|
|
|
|
|
|
chsrc_info ("请手动修改 ~/.luarocks/upload_config.lua 文件 (用于上传):");
|
|
|
|
|
puts(upload_config);
|
|
|
|
|
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
|
|
|
|
void
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_go_check_cmd_ ()
|
2023-08-31 15:54:47 +08:00
|
|
|
|
{
|
2023-09-04 15:10:18 +08:00
|
|
|
|
char* check_cmd = xy_str_to_quietcmd("go version");
|
2023-09-10 21:40:21 +08:00
|
|
|
|
bool exist = does_the_program_exist (check_cmd, "go");
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-10 21:40:21 +08:00
|
|
|
|
if (!exist) {
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_error ("未找到 go 相关命令,请检查是否存在");
|
2023-09-03 20:49:55 +08:00
|
|
|
|
exit(1);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
}
|
2023-09-03 20:49:55 +08:00
|
|
|
|
}
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
void
|
|
|
|
|
pl_go_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_go_check_cmd_ ();
|
2023-09-04 11:29:49 +08:00
|
|
|
|
char* cmd = "go env GOPROXY";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-03 20:49:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Go换源,参考:https://goproxy.cn/
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pl_go_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_go_check_cmd_();
|
2023-09-03 20:49:55 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, pl_go);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
source_info source = pl_go_sources[index];
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_selection (&source);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
|
|
|
|
char* cmd = "go env -w GO111MODULE=on";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
cmd = xy_strjoin(3, "go env -w GOPROXY=", source.url, ",direct");
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
void
|
|
|
|
|
pl_rust_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-27 18:47:49 +08:00
|
|
|
|
chsrc_check_file ("~/.cargo");
|
2023-09-03 20:49:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 15:54:47 +08:00
|
|
|
|
/**
|
2023-09-05 14:17:31 +08:00
|
|
|
|
* Rust 换源,参考:https://mirrors.tuna.tsinghua.edu.cn/help/crates.io-index/
|
2023-08-31 15:54:47 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
2023-08-31 22:57:09 +08:00
|
|
|
|
pl_rust_setsrc (char* option)
|
2023-08-31 15:54:47 +08:00
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, pl_rust);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
source_info source = pl_rust_sources[index];
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_selection(&source);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
|
|
|
|
const char* file = xy_strjoin (3,
|
|
|
|
|
"[source.crates-io]\n"
|
|
|
|
|
"replace-with = 'mirror'\n\n"
|
|
|
|
|
|
|
|
|
|
"[source.mirror]\n"
|
2023-09-05 14:17:31 +08:00
|
|
|
|
"registry = \"sparse+", source.url, "\"");
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-27 18:47:49 +08:00
|
|
|
|
chsrc_warn (xy_strjoin(3, "请您手动写入以下内容到 ", xy_uniform_path("~/.cargo"), " 文件中:"));
|
2023-09-05 14:17:31 +08:00
|
|
|
|
puts(file);
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
void
|
|
|
|
|
pl_dotnet_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_error ("暂时无法查看NuGet源,若有需求,请您提交issue");
|
2023-09-03 20:49:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 15:54:47 +08:00
|
|
|
|
/**
|
|
|
|
|
* NuGet 换源
|
|
|
|
|
*/
|
|
|
|
|
void
|
2023-08-31 22:57:09 +08:00
|
|
|
|
pl_dotnet_setsrc (char* option)
|
2023-08-31 15:54:47 +08:00
|
|
|
|
{
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_error ("暂时无法为NuGet换源,若有需求,请您提交issue");
|
2023-08-31 15:54:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-05 11:09:08 +08:00
|
|
|
|
void
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_java_check_cmd_(bool* maven_exist, bool* gradle_exist)
|
2023-09-05 11:09:08 +08:00
|
|
|
|
{
|
|
|
|
|
char* check_cmd = NULL;
|
|
|
|
|
check_cmd = xy_str_to_quietcmd("mvn --version");
|
|
|
|
|
*maven_exist = does_the_program_exist (check_cmd, "mvn");
|
|
|
|
|
|
|
|
|
|
check_cmd = xy_str_to_quietcmd("gradle --version");
|
|
|
|
|
*gradle_exist = does_the_program_exist (check_cmd, "gradle");
|
|
|
|
|
|
|
|
|
|
if (! *maven_exist && ! *gradle_exist) {
|
2023-09-27 18:31:45 +08:00
|
|
|
|
chsrc_error ("maven 与 gradle 命令均未找到,请检查是否存在其一");
|
2023-09-05 11:09:08 +08:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char*
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_java_find_maven_config_ ()
|
2023-09-05 11:09:08 +08:00
|
|
|
|
{
|
2023-09-27 19:31:23 +08:00
|
|
|
|
char* buf = xy_getcmd ("mvn -v", 2, NULL);
|
2023-09-05 11:09:08 +08:00
|
|
|
|
char* maven_home = xy_str_delete_prefix(buf, "Maven home: ");
|
|
|
|
|
maven_home = xy_str_strip(maven_home);
|
|
|
|
|
|
2023-09-27 18:31:45 +08:00
|
|
|
|
char* maven_config = xy_uniform_path(xy_2strjoin(maven_home, "/conf/settings.xml"));
|
2023-09-05 11:09:08 +08:00
|
|
|
|
return maven_config;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
void
|
|
|
|
|
pl_java_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-05 11:09:08 +08:00
|
|
|
|
bool maven_exist, gradle_exist;
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_java_check_cmd_ (&maven_exist, &gradle_exist);
|
|
|
|
|
char* maven_config = pl_java_find_maven_config_();
|
2023-09-05 11:09:08 +08:00
|
|
|
|
|
|
|
|
|
char* echo = xy_2strjoin("chsrc: 请查看 ", maven_config);
|
|
|
|
|
xy_info (echo);
|
2023-09-03 20:49:55 +08:00
|
|
|
|
}
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2023-09-05 11:09:08 +08:00
|
|
|
|
* Java 换源,参考:https://developer.aliyun.com/mirror/maven
|
2023-08-31 15:54:47 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
2023-08-31 22:57:09 +08:00
|
|
|
|
pl_java_setsrc (char* option)
|
2023-08-31 15:54:47 +08:00
|
|
|
|
{
|
2023-09-05 11:09:08 +08:00
|
|
|
|
bool maven_exist, gradle_exist;
|
2023-09-15 12:34:36 +08:00
|
|
|
|
pl_java_check_cmd_ (&maven_exist, &gradle_exist);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, pl_java);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
source_info source = pl_java_sources[index];
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_selection(&source);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
2023-09-05 11:09:08 +08:00
|
|
|
|
if (maven_exist) {
|
|
|
|
|
const char* file = xy_strjoin(7,
|
2023-08-31 15:54:47 +08:00
|
|
|
|
"<mirror>\n"
|
2023-09-05 11:09:08 +08:00
|
|
|
|
" <id>", source.mirror->code, "</id>\n"
|
2023-08-31 15:54:47 +08:00
|
|
|
|
" <mirrorOf>*</mirrorOf>\n"
|
2023-09-05 11:09:08 +08:00
|
|
|
|
" <name>", source.mirror->name, "</name>\n"
|
2023-09-03 20:49:55 +08:00
|
|
|
|
" <url>", source.url, "</url>\n"
|
2023-08-31 15:54:47 +08:00
|
|
|
|
"</mirror>");
|
|
|
|
|
|
2023-09-15 12:34:36 +08:00
|
|
|
|
char* maven_config = pl_java_find_maven_config_();
|
2023-09-05 11:09:08 +08:00
|
|
|
|
char* echo = xy_strjoin(3, "chsrc: 请在您的 maven 配置文件 ", maven_config, " 中添加:");
|
|
|
|
|
xy_info(echo);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
puts (file);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-05 11:09:08 +08:00
|
|
|
|
if (gradle_exist) {
|
|
|
|
|
if (maven_exist) puts("");
|
2023-08-31 15:54:47 +08:00
|
|
|
|
const char* file = xy_strjoin(3,
|
|
|
|
|
"allprojects {\n"
|
|
|
|
|
" repositories {\n"
|
2023-09-05 11:09:08 +08:00
|
|
|
|
" maven { url '", source.url, "' }\n"
|
|
|
|
|
" mavenLocal()\n"
|
|
|
|
|
" mavenCentral()\n"
|
2023-08-31 15:54:47 +08:00
|
|
|
|
" }\n"
|
|
|
|
|
"}");
|
|
|
|
|
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_info ("请在您的 build.gradle 中添加:");
|
2023-08-31 15:54:47 +08:00
|
|
|
|
puts (file);
|
|
|
|
|
}
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-08-31 15:54:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-04 20:27:37 +08:00
|
|
|
|
|
2023-09-10 18:44:34 +08:00
|
|
|
|
void
|
|
|
|
|
pl_clojure_setsrc(char* option)
|
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, pl_clojure);
|
2023-09-10 18:44:34 +08:00
|
|
|
|
|
|
|
|
|
source_info source = pl_clojure_sources[index];
|
|
|
|
|
chsrc_say_selection (&source);
|
|
|
|
|
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_warn("抱歉,Clojure换源较复杂,您可手动查阅并换源:");
|
2023-09-10 18:44:34 +08:00
|
|
|
|
puts(source.url);
|
|
|
|
|
chsrc_say_thanks (&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-10 13:59:53 +08:00
|
|
|
|
void
|
|
|
|
|
pl_dart_getsrc(char* option)
|
|
|
|
|
{
|
|
|
|
|
char* cmd = NULL;
|
|
|
|
|
if (xy_on_windows) {
|
2023-09-10 21:33:59 +08:00
|
|
|
|
cmd = "set PUB_HOSTED_URL & set FLUTTER_STORAGE_BASE_URL";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-10 13:59:53 +08:00
|
|
|
|
} else {
|
2023-09-10 21:33:59 +08:00
|
|
|
|
cmd = "echo $PUB_HOSTED_URL; echo $FLUTTER_STORAGE_BASE_URL";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-10 13:59:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Dart pub 换源,参考:https://mirrors.tuna.tsinghua.edu.cn/help/dart-pub/
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pl_dart_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, pl_dart);
|
2023-09-10 13:59:53 +08:00
|
|
|
|
|
|
|
|
|
source_info source = pl_dart_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-26 22:14:41 +08:00
|
|
|
|
char* towrite = NULL;
|
2023-09-10 13:59:53 +08:00
|
|
|
|
|
2023-09-10 21:31:16 +08:00
|
|
|
|
char* pub = xy_2strjoin(source.url, "dart-pub");
|
|
|
|
|
char* flutter = xy_2strjoin(source.url, "flutter");
|
|
|
|
|
|
2023-09-10 13:59:53 +08:00
|
|
|
|
if (xy_on_windows)
|
|
|
|
|
{
|
2023-09-10 21:31:16 +08:00
|
|
|
|
if (xy_file_exist(xy_win_powershell_profile))
|
|
|
|
|
{
|
2023-09-26 22:14:41 +08:00
|
|
|
|
towrite = xy_strjoin(4, "$env:PUB_HOSTED_URL = \"", pub, "\"");
|
|
|
|
|
chsrc_append_to_file (towrite, xy_win_powershell_profile);
|
|
|
|
|
|
|
|
|
|
towrite = xy_strjoin(4, "$env:FLUTTER_STORAGE_BASE_URL = \"", flutter, "\"");
|
|
|
|
|
chsrc_append_to_file (towrite, xy_win_powershell_profile);
|
2023-09-10 13:59:53 +08:00
|
|
|
|
}
|
2023-09-10 21:31:16 +08:00
|
|
|
|
|
|
|
|
|
if (xy_file_exist(xy_win_powershellv5_profile))
|
|
|
|
|
{
|
2023-09-26 22:14:41 +08:00
|
|
|
|
towrite = xy_strjoin(4, "$env:PUB_HOSTED_URL = \"", pub, "\"");
|
|
|
|
|
chsrc_append_to_file (towrite, xy_win_powershellv5_profile);
|
|
|
|
|
|
|
|
|
|
towrite = xy_strjoin(4, "$env:FLUTTER_STORAGE_BASE_URL = \"", flutter, "\"");
|
|
|
|
|
chsrc_append_to_file (towrite, xy_win_powershellv5_profile);
|
2023-09-10 13:59:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-10 21:31:16 +08:00
|
|
|
|
|
2023-09-10 13:59:53 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
2023-09-26 22:14:41 +08:00
|
|
|
|
towrite = xy_strjoin(3, "export PUB_HOSTED_URL=\"", pub, "\"");
|
|
|
|
|
chsrc_append_to_file (towrite, "~/.bashrc >> ~/.zshrc");
|
|
|
|
|
|
|
|
|
|
towrite = xy_strjoin(3, "export FLUTTER_STORAGE_BASE_URL=\"", flutter, "\"");
|
|
|
|
|
chsrc_append_to_file (towrite, "~/.bashrc >> ~/.zshrc");
|
2023-09-10 13:59:53 +08:00
|
|
|
|
}
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-10 19:35:13 +08:00
|
|
|
|
void
|
|
|
|
|
pl_haskell_setsrc(char* option)
|
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, pl_haskell);
|
2023-09-10 19:35:13 +08:00
|
|
|
|
|
|
|
|
|
source_info source = pl_haskell_sources[index];
|
|
|
|
|
chsrc_say_selection (&source);
|
|
|
|
|
|
|
|
|
|
char* file = xy_strjoin(3, "repository mirror\n"
|
|
|
|
|
" url: ", source.url,
|
|
|
|
|
"\n secure: True");
|
|
|
|
|
|
|
|
|
|
char* config = NULL;
|
|
|
|
|
if (xy_on_windows) {
|
2023-09-27 18:31:45 +08:00
|
|
|
|
config = xy_uniform_path ("~/AppData/Roaming/cabal/config");
|
2023-09-10 19:35:13 +08:00
|
|
|
|
} else {
|
2023-09-27 18:31:45 +08:00
|
|
|
|
config = "~/.cabal/config";
|
2023-09-10 19:35:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xy_info(xy_strjoin(3,"chsrc: 请向 ", config, " 中手动添加:"));
|
|
|
|
|
puts(file); puts("");
|
|
|
|
|
|
2023-09-27 18:31:45 +08:00
|
|
|
|
config = xy_uniform_path ("~/.stack/config.yaml");
|
2023-09-10 19:35:13 +08:00
|
|
|
|
file = xy_strjoin(3, "package-indices:\n"
|
|
|
|
|
" - download-prefix: ", source.url,
|
|
|
|
|
"\n hackage-security:\n"
|
|
|
|
|
" keyids:\n"
|
|
|
|
|
" - 0a5c7ea47cd1b15f01f5f51a33adda7e655bc0f0b0615baa8e271f4c3351e21d\n"
|
|
|
|
|
" - 1ea9ba32c526d1cc91ab5e5bd364ec5e9e8cb67179a471872f6e26f0ae773d42\n"
|
|
|
|
|
" - 280b10153a522681163658cb49f632cde3f38d768b736ddbc901d99a1a772833\n"
|
|
|
|
|
" - 2a96b1889dc221c17296fcc2bb34b908ca9734376f0f361660200935916ef201\n"
|
|
|
|
|
" - 2c6c3627bd6c982990239487f1abd02e08a02e6cf16edb105a8012d444d870c3\n"
|
|
|
|
|
" - 51f0161b906011b52c6613376b1ae937670da69322113a246a09f807c62f6921\n"
|
|
|
|
|
" - 772e9f4c7db33d251d5c6e357199c819e569d130857dc225549b40845ff0890d\n"
|
|
|
|
|
" - aa315286e6ad281ad61182235533c41e806e5a787e0b6d1e7eef3f09d137d2e9\n"
|
|
|
|
|
" - fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0\n"
|
|
|
|
|
" key-threshold: 3\n"
|
|
|
|
|
" ignore-expiry: no");
|
|
|
|
|
xy_info(xy_strjoin(3,"chsrc: 请向 ", config, " 中手动添加:"));
|
|
|
|
|
puts(file);
|
|
|
|
|
chsrc_say_thanks (&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-15 12:20:45 +08:00
|
|
|
|
void
|
|
|
|
|
pl_ocaml_check_cmd_()
|
|
|
|
|
{
|
|
|
|
|
char* check_cmd = xy_str_to_quietcmd("opam --version");
|
|
|
|
|
bool exist = does_the_program_exist (check_cmd, "opam");
|
|
|
|
|
|
|
|
|
|
if (!exist) {
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_error ("未找到 opam 命令,请检查是否存在");
|
2023-09-15 12:20:45 +08:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
pl_ocaml_getsrc(char* option)
|
|
|
|
|
{
|
|
|
|
|
pl_ocaml_check_cmd_();
|
|
|
|
|
char* cmd = "opam repo get-url default";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-15 12:20:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 参考: https://mirrors.sjtug.sjtu.edu.cn/docs/git/opam-repository.git
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pl_ocaml_setsrc(char* option)
|
|
|
|
|
{
|
|
|
|
|
pl_ocaml_check_cmd_();
|
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, pl_ocaml);
|
2023-09-15 12:20:45 +08:00
|
|
|
|
|
|
|
|
|
source_info source = pl_ocaml_sources[index];
|
|
|
|
|
chsrc_say_selection (&source);
|
|
|
|
|
|
2023-09-15 12:26:39 +08:00
|
|
|
|
char* cmd = xy_strjoin(3, "opam repo set-url default ",
|
|
|
|
|
source.url,
|
|
|
|
|
" --all --set-default");
|
2023-09-15 12:20:45 +08:00
|
|
|
|
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-15 12:20:45 +08:00
|
|
|
|
|
2023-09-26 21:09:16 +08:00
|
|
|
|
chsrc_info("如果是首次使用 opam ,请使用以下命令进行初始化");
|
2023-09-15 12:26:39 +08:00
|
|
|
|
puts(xy_2strjoin("opam init default ", source.url));
|
2023-09-15 12:20:45 +08:00
|
|
|
|
|
|
|
|
|
chsrc_say_thanks (&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
void
|
|
|
|
|
pl_r_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-04 21:42:05 +08:00
|
|
|
|
// 或参考:https://zhuanlan.zhihu.com/p/585036231
|
|
|
|
|
//
|
|
|
|
|
// options()$repos
|
|
|
|
|
// options()$BioC_mirror
|
|
|
|
|
//
|
2023-09-27 18:47:49 +08:00
|
|
|
|
if (xy_on_windows) {
|
|
|
|
|
chsrc_check_file ("~/Documents/.Rprofile");
|
2023-09-04 20:27:37 +08:00
|
|
|
|
} else {
|
2023-09-26 22:24:48 +08:00
|
|
|
|
chsrc_check_file ("~/.Rprofile");
|
2023-09-04 20:27:37 +08:00
|
|
|
|
}
|
2023-09-03 20:49:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* R 换源,参考:https://help.mirrors.cernet.edu.cn/CRAN/
|
2023-08-31 16:21:42 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
2023-08-31 22:57:09 +08:00
|
|
|
|
pl_r_setsrc (char* option)
|
2023-08-31 16:21:42 +08:00
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, pl_r);
|
2023-08-31 16:21:42 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
source_info source = pl_r_sources[index];
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_selection(&source);
|
2023-08-31 16:21:42 +08:00
|
|
|
|
|
2023-09-04 21:42:05 +08:00
|
|
|
|
char* bioconductor_url = xy_str_delete_suffix(xy_str_delete_suffix(source.url, "cran/"), "CRAN/");
|
|
|
|
|
bioconductor_url = xy_2strjoin(bioconductor_url, "bioconductor");
|
|
|
|
|
|
2023-09-26 22:14:41 +08:00
|
|
|
|
const char* towrite1 = xy_strjoin (3, "options(\"repos\" = c(CRAN=\"", source.url, "\"))" );
|
|
|
|
|
const char* towrite2 = xy_strjoin (3, "options(BioC_mirror=\"", bioconductor_url, "\")" );
|
2023-09-04 21:42:05 +08:00
|
|
|
|
|
|
|
|
|
// 或者我们调用 r.exe --slave -e 上面的内容
|
2023-08-31 16:21:42 +08:00
|
|
|
|
if (xy_on_windows)
|
2023-09-26 22:14:41 +08:00
|
|
|
|
{
|
2023-09-27 18:47:49 +08:00
|
|
|
|
chsrc_append_to_file (towrite1, "~/Documents/.Rprofile");
|
|
|
|
|
chsrc_append_to_file (towrite2, "~/Documents/.Rprofile");
|
2023-09-26 22:14:41 +08:00
|
|
|
|
}
|
2023-08-31 16:21:42 +08:00
|
|
|
|
else
|
2023-09-26 22:14:41 +08:00
|
|
|
|
{
|
|
|
|
|
chsrc_append_to_file (towrite1, "~/.Rprofile");
|
|
|
|
|
chsrc_append_to_file (towrite2, "~/.Rprofile");
|
|
|
|
|
}
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-08-31 16:21:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-05 09:28:42 +08:00
|
|
|
|
/**
|
|
|
|
|
* Julia的换源可以通过两种方式
|
|
|
|
|
* 1. 写入 startup.jl
|
|
|
|
|
* 2. 使用环境变量
|
|
|
|
|
*
|
|
|
|
|
* 我们采用第一种
|
|
|
|
|
*/
|
2023-09-03 20:49:55 +08:00
|
|
|
|
void
|
|
|
|
|
pl_julia_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-27 18:47:49 +08:00
|
|
|
|
chsrc_check_file ("~/.julia/config/startup.jl");
|
2023-09-03 20:49:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-09-05 09:28:42 +08:00
|
|
|
|
* Julia 换源,参考:
|
|
|
|
|
* 1. https://help.mirrors.cernet.edu.cn/julia/
|
|
|
|
|
* 2. https://docs.julialang.org/en/v1/manual/command-line-interface/#Startup-file
|
2023-08-31 16:21:42 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
2023-08-31 22:57:09 +08:00
|
|
|
|
pl_julia_setsrc (char* option)
|
2023-08-31 16:21:42 +08:00
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, pl_julia);
|
2023-08-31 16:21:42 +08:00
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
|
source_info source = pl_julia_sources[index];
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_selection(&source);
|
2023-08-31 16:21:42 +08:00
|
|
|
|
|
2023-09-26 22:49:28 +08:00
|
|
|
|
const char* towrite = xy_strjoin (3, "ENV[\"JULIA_PKG_SERVER\"] = \"", source.url, "\"");
|
2023-08-31 16:21:42 +08:00
|
|
|
|
|
2023-09-27 18:47:49 +08:00
|
|
|
|
chsrc_append_to_file (towrite, "~/.julia/config/startup.jl");
|
2023-09-04 15:39:49 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-08-31 16:21:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-10 18:44:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-17 11:33:30 +08:00
|
|
|
|
|
2023-09-29 20:15:32 +08:00
|
|
|
|
#define ETC_APT_SOURCELIST "/etc/apt/sources.list"
|
|
|
|
|
|
|
|
|
|
|
2023-09-17 11:33:30 +08:00
|
|
|
|
void
|
|
|
|
|
os_ubuntu_getsrc(char* option)
|
|
|
|
|
{
|
2023-09-29 20:17:59 +08:00
|
|
|
|
chsrc_check_file (ETC_APT_SOURCELIST);
|
2023-09-17 11:33:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 12:01:43 +08:00
|
|
|
|
/**
|
2023-09-05 18:58:08 +08:00
|
|
|
|
* @note 不同架构下换源不一样
|
2023-09-03 12:01:43 +08:00
|
|
|
|
*/
|
2023-08-30 20:05:03 +08:00
|
|
|
|
void
|
2023-08-31 22:57:09 +08:00
|
|
|
|
os_ubuntu_setsrc (char* option)
|
2023-08-30 14:24:26 +08:00
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-22 13:07:49 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_ubuntu);
|
2023-09-05 18:58:08 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_ubuntu_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
2023-08-30 20:05:03 +08:00
|
|
|
|
|
2023-09-29 20:17:59 +08:00
|
|
|
|
chsrc_backup (ETC_APT_SOURCELIST);
|
2023-08-30 14:24:26 +08:00
|
|
|
|
|
2023-09-27 19:31:23 +08:00
|
|
|
|
char* arch = xy_getcmd("arch", 0, NULL);
|
2023-09-27 11:35:30 +08:00
|
|
|
|
char* cmd = NULL;
|
2023-09-27 18:47:49 +08:00
|
|
|
|
if (strncmp(arch, "x86_64", 6)==0)
|
2023-09-05 16:32:56 +08:00
|
|
|
|
{
|
2023-09-26 22:37:59 +08:00
|
|
|
|
cmd = xy_strjoin(3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' /etc/apt/sources.list");
|
2023-09-05 16:32:56 +08:00
|
|
|
|
}
|
2023-09-05 18:58:08 +08:00
|
|
|
|
else {
|
2023-09-26 22:37:59 +08:00
|
|
|
|
cmd = xy_strjoin(3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url,
|
|
|
|
|
"-ports@g\' /etc/apt/sources.list");
|
2023-09-05 16:32:56 +08:00
|
|
|
|
}
|
2023-09-05 18:58:08 +08:00
|
|
|
|
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-27 19:54:28 +08:00
|
|
|
|
chsrc_run("sudo apt update");
|
2023-09-05 18:58:08 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-08-30 14:24:26 +08:00
|
|
|
|
}
|
2023-09-05 18:58:08 +08:00
|
|
|
|
|
2023-09-17 11:26:31 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-29 19:49:31 +08:00
|
|
|
|
void
|
|
|
|
|
os_mint_getsrc(char* option)
|
|
|
|
|
{
|
|
|
|
|
chsrc_check_file ("/etc/apt/sources.list.d/official-package-repositories.list");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/linuxmint/
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_mint_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-29 19:49:31 +08:00
|
|
|
|
|
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_mint);
|
|
|
|
|
|
|
|
|
|
source_info source = os_mint_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
|
|
|
|
chsrc_backup ("/etc/apt/sources.list.d/official-package-repositories.list");
|
|
|
|
|
|
2023-09-29 20:07:02 +08:00
|
|
|
|
char* cmd = xy_strjoin(3, "sed -E -i 's@https?://.*/.*/?@", source.url,
|
2023-09-29 19:49:31 +08:00
|
|
|
|
"@g' /etc/apt/sources.list.d/official-package-repositories.list");
|
|
|
|
|
|
|
|
|
|
chsrc_run(cmd);
|
|
|
|
|
chsrc_run("sudo apt update");
|
|
|
|
|
chsrc_say_thanks(&source);
|
2023-09-29 20:07:02 +08:00
|
|
|
|
chsrc_warn ("完成后请不要再使用 mintsources(自带的图形化软件源设置工具)进行任何操作,因为在操作后,无论是否有按“确定”,mintsources 均会覆写我们刚才换源的内容");
|
2023-09-29 19:49:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-17 11:33:30 +08:00
|
|
|
|
void
|
|
|
|
|
os_debian_getsrc(char* option)
|
|
|
|
|
{
|
2023-09-29 20:17:59 +08:00
|
|
|
|
chsrc_check_file (ETC_APT_SOURCELIST);
|
2023-09-17 11:33:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-06 16:39:29 +08:00
|
|
|
|
/**
|
2023-09-17 11:33:30 +08:00
|
|
|
|
* Debian Buster 以上版本默认支持 HTTPS 源。如果遇到无法拉取 HTTPS 源的情况,请先使用 HTTP 源并安装
|
|
|
|
|
* sudo apt install apt-transport-https ca-certificates
|
2023-09-06 16:39:29 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
2023-09-17 11:33:30 +08:00
|
|
|
|
os_debian_setsrc (char* option)
|
2023-09-06 16:39:29 +08:00
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-06 16:39:29 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_debian);
|
2023-09-06 16:39:29 +08:00
|
|
|
|
|
2023-09-17 11:33:30 +08:00
|
|
|
|
source_info source = os_debian_sources[index];
|
2023-09-06 16:39:29 +08:00
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
chsrc_info ("如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并需要您运行:");
|
|
|
|
|
puts ("sudo apt install apt-transport-https ca-certificates");
|
2023-09-17 11:33:30 +08:00
|
|
|
|
|
2023-09-29 20:17:59 +08:00
|
|
|
|
chsrc_backup (ETC_APT_SOURCELIST);
|
2023-09-06 16:39:29 +08:00
|
|
|
|
|
2023-09-26 16:40:12 +08:00
|
|
|
|
char* cmd = xy_strjoin(3,
|
|
|
|
|
"sed -E -i \'s@https?://.*/debian/?@",
|
|
|
|
|
source.url,
|
|
|
|
|
"@g\' /etc/apt/sources.list");
|
2023-09-17 11:33:30 +08:00
|
|
|
|
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-27 19:54:28 +08:00
|
|
|
|
chsrc_run("sudo apt update");
|
2023-09-06 16:39:29 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
2023-09-05 18:58:08 +08:00
|
|
|
|
|
2023-09-17 11:26:31 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-29 20:51:13 +08:00
|
|
|
|
void
|
|
|
|
|
os_raspberrypi_getsrc (char* option)
|
|
|
|
|
{
|
|
|
|
|
chsrc_check_file ("/etc/apt/sources.list.d/raspi.list");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
os_raspberrypi_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
// chsrc_ensure_root(); // HELP: 不确定是否需要
|
2023-09-29 20:51:13 +08:00
|
|
|
|
|
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_raspberrypi);
|
|
|
|
|
|
|
|
|
|
source_info source = os_raspberrypi_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
|
|
|
|
chsrc_backup ("/etc/apt/sources.list.d/raspi.list");
|
|
|
|
|
|
|
|
|
|
char* cmd = xy_strjoin(3, "sed -E -i 's@https?://.*/.*/?@", source.url,
|
|
|
|
|
"@g' /etc/apt/sources.list.d/raspi.list");
|
|
|
|
|
|
|
|
|
|
chsrc_run(cmd);
|
|
|
|
|
chsrc_run("sudo apt update");
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-17 11:33:30 +08:00
|
|
|
|
void
|
|
|
|
|
os_deepin_getsrc(char* option)
|
|
|
|
|
{
|
2023-09-29 20:17:59 +08:00
|
|
|
|
chsrc_check_file (ETC_APT_SOURCELIST);
|
2023-09-17 11:33:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 12:01:43 +08:00
|
|
|
|
/**
|
2023-09-22 13:31:05 +08:00
|
|
|
|
* HELP: 未经测试
|
2023-09-03 12:01:43 +08:00
|
|
|
|
*/
|
2023-09-01 22:23:03 +08:00
|
|
|
|
void
|
2023-09-17 11:33:30 +08:00
|
|
|
|
os_deepin_setsrc (char* option)
|
2023-09-01 22:23:03 +08:00
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-05 20:02:23 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_deepin);
|
2023-09-05 20:02:23 +08:00
|
|
|
|
|
2023-09-17 11:33:30 +08:00
|
|
|
|
source_info source = os_deepin_sources[index];
|
2023-09-05 20:02:23 +08:00
|
|
|
|
chsrc_say_selection(&source);
|
2023-09-01 22:23:03 +08:00
|
|
|
|
|
2023-09-29 20:17:59 +08:00
|
|
|
|
chsrc_backup (ETC_APT_SOURCELIST);
|
2023-09-17 11:33:30 +08:00
|
|
|
|
|
2023-09-26 16:40:12 +08:00
|
|
|
|
char* cmd = xy_strjoin(3,
|
|
|
|
|
"sed -E -i \'s@https?://.*/deepin/?@",
|
|
|
|
|
source.url,
|
|
|
|
|
"@g\' /etc/apt/sources.list");
|
2023-09-26 20:23:43 +08:00
|
|
|
|
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-27 19:54:28 +08:00
|
|
|
|
chsrc_run("sudo apt update");
|
2023-09-05 20:02:23 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-09-03 12:01:43 +08:00
|
|
|
|
}
|
2023-09-17 11:26:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-03 12:01:43 +08:00
|
|
|
|
/**
|
2023-09-17 11:26:31 +08:00
|
|
|
|
* @note fedora 29 及以下版本暂不支持
|
2023-09-03 12:01:43 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_fedora_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-05 20:04:38 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_fedora);
|
2023-09-05 20:04:38 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_fedora_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
2023-09-03 12:01:43 +08:00
|
|
|
|
|
2023-09-17 11:33:30 +08:00
|
|
|
|
xy_warn ("chsrc: fedora 29 及以下版本暂不支持");
|
2023-09-05 16:32:56 +08:00
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
chsrc_backup ("/etc/yum.repos.d/fedora.repo");
|
|
|
|
|
chsrc_backup ("/etc/yum.repos.d/fedora-updates.repo");
|
2023-09-03 12:01:43 +08:00
|
|
|
|
|
|
|
|
|
char* cmd = xy_strjoin(9, "sed -e 's|^metalink=|#metalink=|g' ",
|
|
|
|
|
"-e 's|^#baseurl=http://download.example/pub/fedora/linux/|baseurl=",
|
2023-09-05 20:04:38 +08:00
|
|
|
|
source.url,
|
2023-09-03 12:01:43 +08:00
|
|
|
|
"|g' ",
|
|
|
|
|
"-i.bak ",
|
|
|
|
|
"/etc/yum.repos.d/fedora.repo ",
|
|
|
|
|
"/etc/yum.repos.d/fedora-modular.repo ",
|
|
|
|
|
"/etc/yum.repos.d/fedora-updates.repo ",
|
|
|
|
|
"/etc/yum.repos.d/fedora-updates-modular.repo");
|
2023-09-17 11:33:30 +08:00
|
|
|
|
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-03 12:01:43 +08:00
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
chsrc_info ("替换文件:/etc/yum.repos.d/fedora.repo");
|
|
|
|
|
chsrc_info ("新增文件:/etc/yum.repos.d/fedora-modular.repo");
|
|
|
|
|
chsrc_info ("替换文件:/etc/yum.repos.d/fedora-updates.repo");
|
|
|
|
|
chsrc_info ("新增文件:/etc/yum.repos.d/fedora-updates-modular.repo");
|
2023-09-03 12:01:43 +08:00
|
|
|
|
|
2023-09-27 19:54:28 +08:00
|
|
|
|
chsrc_run ("sudo dnf makecache");
|
2023-09-05 20:04:38 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-09-03 12:01:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-24 20:32:33 +08:00
|
|
|
|
/**
|
|
|
|
|
* HELP: 未经测试
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_opensuse_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root(); // HELP: 不知道是否需要确保root权限
|
2023-09-24 20:32:33 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_opensuse);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_opensuse_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
|
|
|
|
char* source_nselect = "zypper mr -da";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(source_nselect);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
|
|
|
|
|
char* cmd1 = xy_strjoin(3,
|
|
|
|
|
"zypper ar -cfg '",
|
|
|
|
|
source.url,
|
|
|
|
|
"/opensuse/distribution/leap/$releasever/repo/oss/' mirror-oss");
|
|
|
|
|
char* cmd2 = xy_strjoin(3,
|
|
|
|
|
"zypper ar -cfg '",
|
|
|
|
|
source.url,
|
|
|
|
|
"/opensuse/distribution/leap/$releasever/repo/non-oss/' mirror-non-oss");
|
|
|
|
|
char* cmd3 = xy_strjoin(3,
|
|
|
|
|
"zypper ar -cfg '",
|
|
|
|
|
source.url,
|
|
|
|
|
"/opensuse/distribution/leap/$releasever/oss/' mirror-update");
|
|
|
|
|
char* cmd4 = xy_strjoin(3,
|
|
|
|
|
"zypper ar -cfg '",
|
|
|
|
|
source.url,
|
|
|
|
|
"/opensuse/distribution/leap/$releasever/non-oss/' mirror-update-non-oss");
|
|
|
|
|
char* cmd5 = xy_strjoin(3,
|
|
|
|
|
"zypper ar -cfg '",
|
|
|
|
|
source.url,
|
|
|
|
|
"/opensuse/distribution/leap/$releasever/sle/' mirror-sle-update");
|
|
|
|
|
char* cmd6 = xy_strjoin(3,
|
|
|
|
|
"zypper ar -cfg '",
|
|
|
|
|
source.url,
|
|
|
|
|
"/opensuse/distribution/leap/$releasever/backports/' mirror-backports-update");
|
|
|
|
|
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd1);
|
|
|
|
|
chsrc_run(cmd2);
|
|
|
|
|
chsrc_run(cmd3);
|
|
|
|
|
chsrc_run(cmd4);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
|
|
|
|
|
xy_info("chsrc: leap 15.3用户还需 要添加sle和backports源");
|
|
|
|
|
xy_info("chsrc: 另外请确保系统在更新后仅启用了六个软件源,可以使用 zypper lr 检查软件源状态");
|
|
|
|
|
xy_info("chsrc: 并使用 zypper mr -d 禁用多余的软件源");
|
|
|
|
|
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd5);
|
|
|
|
|
chsrc_run(cmd6);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-29 20:15:32 +08:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
os_kali_getsrc (char* option)
|
|
|
|
|
{
|
|
|
|
|
chsrc_check_file (ETC_APT_SOURCELIST);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-05 20:06:04 +08:00
|
|
|
|
/**
|
2023-09-22 13:31:05 +08:00
|
|
|
|
* HELP: 未经测试
|
2023-09-05 20:06:04 +08:00
|
|
|
|
*/
|
2023-09-03 12:01:43 +08:00
|
|
|
|
void
|
|
|
|
|
os_kali_setsrc(char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-05 20:06:04 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_kali);
|
2023-09-05 20:06:04 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_kali_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
2023-09-03 12:01:43 +08:00
|
|
|
|
|
2023-09-29 20:17:59 +08:00
|
|
|
|
chsrc_backup (ETC_APT_SOURCELIST);
|
2023-09-03 12:01:43 +08:00
|
|
|
|
|
2023-09-26 16:40:12 +08:00
|
|
|
|
char* cmd = xy_strjoin(3,
|
|
|
|
|
"sed -E -i \'s@https?://.*/kali/?@",
|
|
|
|
|
source.url,
|
|
|
|
|
"@g\' /etc/apt/sources.list");
|
2023-09-03 12:01:43 +08:00
|
|
|
|
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-27 19:54:28 +08:00
|
|
|
|
chsrc_run("sudo apt update");
|
2023-09-05 20:06:04 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-09-03 12:01:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-17 11:26:31 +08:00
|
|
|
|
|
2023-09-05 20:12:07 +08:00
|
|
|
|
/**
|
2023-09-22 13:31:05 +08:00
|
|
|
|
* HELP: 未经测试
|
2023-09-05 20:12:07 +08:00
|
|
|
|
*/
|
2023-09-03 12:01:43 +08:00
|
|
|
|
void
|
2023-09-06 16:02:26 +08:00
|
|
|
|
os_msys2_setsrc(char* option)
|
2023-09-03 12:01:43 +08:00
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_msys2);
|
2023-09-05 20:11:31 +08:00
|
|
|
|
|
2023-09-06 16:02:26 +08:00
|
|
|
|
source_info source = os_msys2_sources[index];
|
2023-09-05 20:11:31 +08:00
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
chsrc_backup ("/etc/pacman.d/mirrorlist.mingw32");
|
|
|
|
|
chsrc_backup ("/etc/pacman.d/mirrorlist.mingw64");
|
|
|
|
|
chsrc_backup ("/etc/pacman.d/mirrorlist.msys");
|
2023-09-03 12:01:43 +08:00
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
char* prev = xy_strjoin(3, "chsrc: 请针对你的架构下载安装此目录下的文件:",
|
|
|
|
|
source.url,
|
|
|
|
|
"distrib/<架构>/");
|
2023-09-05 16:32:56 +08:00
|
|
|
|
xy_info (prev);
|
2023-09-06 16:06:50 +08:00
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
char* cmd = xy_strjoin(3, "sed -i \"s#https\?://mirror.msys2.org/#",
|
|
|
|
|
source.url,
|
2023-09-05 21:03:58 +08:00
|
|
|
|
"#g\" /etc/pacman.d/mirrorlist* ");
|
2023-09-17 11:26:31 +08:00
|
|
|
|
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-05 20:11:31 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-09-01 22:23:03 +08:00
|
|
|
|
}
|
2023-08-30 20:34:01 +08:00
|
|
|
|
|
2023-09-17 11:26:31 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-05 20:14:58 +08:00
|
|
|
|
/**
|
2023-09-18 21:43:12 +08:00
|
|
|
|
* 参考: https://mirrors.tuna.tsinghua.edu.cn/help/archlinuxcn/
|
2023-09-05 20:14:58 +08:00
|
|
|
|
*/
|
2023-09-05 16:32:56 +08:00
|
|
|
|
void
|
2023-09-05 20:14:58 +08:00
|
|
|
|
os_arch_setsrc(char* option)
|
2023-09-05 16:32:56 +08:00
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-05 20:14:58 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_arch);
|
2023-09-05 20:14:58 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_arch_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
chsrc_backup ("/etc/pacman.d/mirrorlist");
|
2023-09-05 16:32:56 +08:00
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
bool arch_flag = false;
|
2023-09-27 11:35:30 +08:00
|
|
|
|
char* new_file = NULL;
|
2023-09-27 19:31:23 +08:00
|
|
|
|
char* arch = xy_getcmd("arch", 0, NULL);
|
2023-09-26 18:24:18 +08:00
|
|
|
|
|
|
|
|
|
if (strncmp(arch, "x86_64", 6)==0) {
|
2023-09-17 17:31:36 +08:00
|
|
|
|
arch_flag = true;
|
2023-09-26 23:02:12 +08:00
|
|
|
|
new_file = xy_strjoin(3, "Server = ", source.url, "archlinux/$repo/os/$arch");
|
2023-09-17 17:28:28 +08:00
|
|
|
|
}
|
|
|
|
|
else {
|
2023-09-17 17:31:36 +08:00
|
|
|
|
arch_flag = false;
|
2023-09-26 23:02:12 +08:00
|
|
|
|
new_file = xy_strjoin(3, "Server = ", source.url, "archlinuxarm/$repo/os/$arch");
|
2023-09-17 17:28:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 22:14:41 +08:00
|
|
|
|
// TODO: 这里用的是 overwrite 吗?
|
|
|
|
|
chsrc_overwrite_file (new_file, "/etc/pacman.d/mirrorlist");
|
2023-09-17 17:28:28 +08:00
|
|
|
|
|
2023-09-26 22:14:41 +08:00
|
|
|
|
chsrc_info("使用 archlinuxcn");
|
2023-09-17 17:28:28 +08:00
|
|
|
|
|
2023-09-26 22:33:20 +08:00
|
|
|
|
char* towrite = xy_strjoin(3, "[archlinuxcn]\nServer=", source.url, "archlinuxcn/$repo/os/$arch");
|
|
|
|
|
chsrc_append_to_file (towrite, "/etc/pacman.d/mirrorlist");
|
2023-09-05 16:32:56 +08:00
|
|
|
|
|
2023-09-26 22:14:41 +08:00
|
|
|
|
chsrc_run("pacman -Sy archlinux-keyring");
|
2023-09-17 17:31:36 +08:00
|
|
|
|
|
2023-09-27 18:47:49 +08:00
|
|
|
|
if (arch_flag) {
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run("pacman -Syyu");
|
2023-09-18 21:43:12 +08:00
|
|
|
|
} else {
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run("pacman -Syy");
|
2023-09-17 17:31:36 +08:00
|
|
|
|
}
|
2023-09-05 20:14:58 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-09-05 16:32:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-17 11:26:31 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-05 20:19:15 +08:00
|
|
|
|
/**
|
2023-09-22 13:31:05 +08:00
|
|
|
|
* HELP: 未经测试
|
2023-09-05 20:19:15 +08:00
|
|
|
|
*/
|
2023-09-05 16:32:56 +08:00
|
|
|
|
void
|
2023-09-05 20:19:15 +08:00
|
|
|
|
os_gentoo_setsrc(char* option)
|
2023-09-05 16:32:56 +08:00
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-05 20:19:15 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_gentoo);
|
2023-09-05 20:19:15 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_arch_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
chsrc_backup ("/etc/portage/repos.conf/gentoo.conf");
|
2023-09-05 16:32:56 +08:00
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
char* cmd = xy_strjoin(3, "sed -i \"s#rsync://.*/gentoo-portage#rsync://",
|
|
|
|
|
source.url,
|
2023-09-05 21:03:58 +08:00
|
|
|
|
"gentoo-portage#g");
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-05 16:32:56 +08:00
|
|
|
|
|
2023-09-26 22:33:20 +08:00
|
|
|
|
char* towrite = xy_strjoin(3, "GENTOO_MIRRORS=\"https://", source.url, "gentoo\"");
|
2023-09-05 16:32:56 +08:00
|
|
|
|
|
2023-09-26 22:37:59 +08:00
|
|
|
|
chsrc_append_to_file (towrite, "/etc/portage/make.conf");
|
2023-09-05 20:19:15 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
2023-09-05 16:32:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-24 19:17:43 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/rocky/
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_rocky_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-24 19:17:43 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_rocky);
|
2023-09-24 19:17:43 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_rocky_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
|
|
|
|
char* cmd = xy_strjoin(3,
|
|
|
|
|
"sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' "
|
|
|
|
|
"-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=", source.url, "|g' "
|
|
|
|
|
"-i.bak /etc/yum.repos.d/rocky-extras.repo /etc/yum.repos.d/rocky.repo"
|
|
|
|
|
);
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-27 19:54:28 +08:00
|
|
|
|
chsrc_run ("sudo dnf makecache");
|
2023-09-24 19:17:43 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-29 20:15:32 +08:00
|
|
|
|
void
|
|
|
|
|
os_alpine_getsrc (char* option)
|
|
|
|
|
{
|
|
|
|
|
chsrc_check_file ("/etc/apk/repositories");
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-24 20:01:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/alpine/
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_alpine_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
// chsrc_ensure_root(); // HELP: 不确定是否需要root
|
2023-09-24 20:01:46 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_alpine);
|
2023-09-24 20:01:46 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_alpine_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
|
|
|
|
char* cmd = xy_strjoin(3,
|
|
|
|
|
"sed -i 's#https\\?://dl-cdn.alpinelinux.org/alpine#", source.url, "#g' /etc/apk/repositories"
|
|
|
|
|
);
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-24 20:01:46 +08:00
|
|
|
|
|
2023-09-27 19:54:28 +08:00
|
|
|
|
chsrc_run("apk update");
|
2023-09-24 20:01:46 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-24 20:32:33 +08:00
|
|
|
|
void
|
|
|
|
|
os_void_getsrc (char* option)
|
|
|
|
|
{
|
|
|
|
|
char* cmd = "xbps-query -L";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/voidlinux/
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_void_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
// chsrc_ensure_root(); // HELP: 不确定是否需要root
|
2023-09-24 20:32:33 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_void);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_void_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-29 22:15:58 +08:00
|
|
|
|
chsrc_ensure_dir ("/etc/xbps.d");
|
|
|
|
|
char* cmd = "cp /usr/share/xbps.d/*-repository-*.conf /etc/xbps.d/";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
|
|
|
|
|
cmd = xy_strjoin(3,
|
|
|
|
|
"sed -i 's|https://repo-default.voidlinux.org|", source.url, "|g' /etc/xbps.d/*-repository-*.conf"
|
|
|
|
|
);
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
|
|
|
|
|
cmd = xy_strjoin(3,
|
|
|
|
|
"sed -i 's|https://alpha.de.repo.voidlinux.org|", source.url, "|g' /etc/xbps.d/*-repository-*.conf"
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
chsrc_warn("若报错可尝试使用以下命令");
|
2023-09-24 20:32:33 +08:00
|
|
|
|
puts(cmd);
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-29 21:49:11 +08:00
|
|
|
|
/**
|
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/solus/
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_solus_setsrc (char* option)
|
|
|
|
|
{
|
|
|
|
|
chsrc_ensure_root ();
|
|
|
|
|
|
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_solus);
|
|
|
|
|
|
|
|
|
|
source_info source = os_solus_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
|
|
|
|
char* cmd = xy_2strjoin ("sudo eopkg add-repo Solus ", source.url);
|
|
|
|
|
chsrc_run (cmd);
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-06 16:18:21 +08:00
|
|
|
|
/**
|
2023-09-17 13:08:33 +08:00
|
|
|
|
* 似乎会弹出GUI,待确定
|
2023-09-06 16:18:21 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_manjaro_setsrc(char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-17 13:08:33 +08:00
|
|
|
|
char* cmd = "sudo pacman-mirrors -i -c China -m rank";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-06 16:18:21 +08:00
|
|
|
|
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run("sudo pacman -Syy");
|
2023-09-06 16:18:21 +08:00
|
|
|
|
}
|
2023-09-05 20:48:38 +08:00
|
|
|
|
|
2023-09-17 11:26:31 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-29 19:12:57 +08:00
|
|
|
|
void
|
|
|
|
|
os_trisquel_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 20:17:59 +08:00
|
|
|
|
chsrc_check_file (ETC_APT_SOURCELIST);
|
2023-09-29 19:12:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/trisquel/
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_trisquel_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-29 19:12:57 +08:00
|
|
|
|
|
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_trisquel);
|
|
|
|
|
|
|
|
|
|
source_info source = os_trisquel_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-29 20:17:59 +08:00
|
|
|
|
chsrc_backup (ETC_APT_SOURCELIST);
|
2023-09-29 19:12:57 +08:00
|
|
|
|
|
|
|
|
|
char* cmd = xy_strjoin(3, "sed -E -i 's@https?://.*/trisquel/?@", source.url, "@g' /etc/apt/sources.list");
|
|
|
|
|
|
|
|
|
|
puts(cmd);
|
|
|
|
|
chsrc_run("sudo apt update");
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-29 20:01:45 +08:00
|
|
|
|
void
|
|
|
|
|
os_linuxlite_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 20:17:59 +08:00
|
|
|
|
chsrc_check_file (ETC_APT_SOURCELIST);
|
2023-09-29 20:01:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/linuxliteos/
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_linuxlite_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-29 20:01:45 +08:00
|
|
|
|
|
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_linuxlite);
|
|
|
|
|
|
|
|
|
|
source_info source = os_linuxlite_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-29 20:17:59 +08:00
|
|
|
|
chsrc_backup (ETC_APT_SOURCELIST);
|
2023-09-29 20:01:45 +08:00
|
|
|
|
|
|
|
|
|
char* cmd = xy_strjoin(3, "sed -E -i 's@https?://.*/.*/?@", source.url, "@g' /etc/apt/sources.list");
|
|
|
|
|
|
|
|
|
|
chsrc_run("sudo apt update");
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-06 17:08:20 +08:00
|
|
|
|
/**
|
2023-09-22 13:31:05 +08:00
|
|
|
|
* HELP: 未经测试
|
2023-09-06 17:08:20 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_openeuler_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-06 17:08:20 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_openeuler);
|
2023-09-06 17:08:20 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_openeuler_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
chsrc_backup ("/etc/yum.repos.d/openEuler.repo");
|
2023-09-06 17:08:20 +08:00
|
|
|
|
|
2023-09-26 22:33:20 +08:00
|
|
|
|
char* towrite = xy_strjoin(3, "s#http://repo.openeuler.org#", source.url, "#\'< /etc/yum.repos.d/openEuler.repo.bak");;
|
|
|
|
|
chsrc_overwrite_file (towrite, "/etc/yum.repos.d/openEuler.repo");
|
2023-09-06 17:08:20 +08:00
|
|
|
|
|
2023-09-27 19:54:28 +08:00
|
|
|
|
chsrc_run ("sudo dnf makecache");
|
2023-09-06 17:08:20 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-17 11:26:31 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-29 20:15:32 +08:00
|
|
|
|
void
|
|
|
|
|
os_openkylin_getsrc (char* option)
|
|
|
|
|
{
|
|
|
|
|
chsrc_check_file (ETC_APT_SOURCELIST);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-06 17:18:47 +08:00
|
|
|
|
void
|
|
|
|
|
os_openkylin_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-06 17:18:47 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_openkylin);
|
2023-09-06 17:18:47 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_openkylin_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-29 20:17:59 +08:00
|
|
|
|
chsrc_backup (ETC_APT_SOURCELIST);
|
2023-09-06 17:18:47 +08:00
|
|
|
|
|
2023-09-29 20:33:19 +08:00
|
|
|
|
char* cmd = xy_strjoin(3, "sed -E -i 's@https?://.*/openkylin/?@", source.url, "@g'" ETC_APT_SOURCELIST);
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-27 19:54:28 +08:00
|
|
|
|
chsrc_run("sudo apt update");
|
2023-09-06 17:18:47 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-18 21:43:12 +08:00
|
|
|
|
|
2023-09-17 16:56:25 +08:00
|
|
|
|
/**
|
2023-09-27 14:14:19 +08:00
|
|
|
|
* 参考:
|
|
|
|
|
* 1. https://book.bsdcn.org/di-3-zhang-ruan-jian-yuan-ji-bao-guan-li-qi/di-3.2-jie-freebsd-huan-yuan-fang-shi.html
|
|
|
|
|
* 2. https://help.mirrors.cernet.edu.cn/FreeBSD-ports/
|
2023-09-24 21:56:03 +08:00
|
|
|
|
*
|
|
|
|
|
* 据 @ykla,
|
2023-09-29 22:15:58 +08:00
|
|
|
|
* FreeBSD 有五类源:pkg、ports、port、portsnap、update,其中 portsnap 在 FreeBSD 14 已经被移除了
|
2023-09-17 16:56:25 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_freebsd_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 22:15:58 +08:00
|
|
|
|
// chsrc_ensure_root(); // 据 @ykla,FreeBSD不自带 sudo
|
2023-09-17 16:56:25 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_freebsd);
|
2023-09-17 16:56:25 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_freebsd_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-27 14:14:19 +08:00
|
|
|
|
chsrc_info("1. 添加 freebsd-pkg 源 (二进制安装包)");
|
2023-09-29 22:15:58 +08:00
|
|
|
|
chsrc_ensure_dir ("/usr/local/etc/pkg/repos");
|
2023-09-17 16:56:25 +08:00
|
|
|
|
|
2023-09-29 22:15:58 +08:00
|
|
|
|
char* conf = xy_strjoin(3, "/usr/local/etc/pkg/repos/", source.mirror->code, ".conf");
|
2023-09-24 21:56:03 +08:00
|
|
|
|
|
|
|
|
|
char* pkg_content = xy_strjoin(4,
|
2023-09-27 14:14:19 +08:00
|
|
|
|
source.mirror->code, ": { \n"
|
|
|
|
|
" url: \"http://", source.url, "/freebsd-pkg/${ABI}/latest\",\n"
|
|
|
|
|
" mirror_type: \"srv\",\n"
|
|
|
|
|
" signature_type: \"none\",\n"
|
|
|
|
|
" fingerprints: \"/usr/share/keys/pkg\",\n"
|
|
|
|
|
" enabled: yes\n"
|
|
|
|
|
"}\n"
|
|
|
|
|
"FreeBSD: { enabled: no }"
|
|
|
|
|
);
|
2023-09-17 16:56:25 +08:00
|
|
|
|
|
2023-09-29 22:15:58 +08:00
|
|
|
|
chsrc_overwrite_file (pkg_content, conf);
|
|
|
|
|
chsrc_warn (
|
|
|
|
|
xy_strjoin (3, "若要使用季度分支,请在", conf ,"中将latest改为quarterly"));
|
2023-09-18 21:31:48 +08:00
|
|
|
|
|
2023-09-27 14:14:19 +08:00
|
|
|
|
chsrc_warn("若要使用HTTPS源,请先安装securtiy/ca_root_ns,并将'http'改成'https',最后使用'pkg update -f'刷新缓存即可\n");
|
2023-09-29 22:15:58 +08:00
|
|
|
|
puts("");
|
2023-09-17 16:56:25 +08:00
|
|
|
|
|
2023-09-27 14:14:19 +08:00
|
|
|
|
chsrc_info("2. 修改 freebsd-ports 源");
|
|
|
|
|
// @ccmywish: [2023-09-27] 据 @ykla , NJU的freebsd-ports源没有设置 Git,
|
|
|
|
|
// 但是我认为由于使用Git还是要比非Git方便许多,我们尽可能坚持使用Git
|
|
|
|
|
// 而 gitup 又要额外修改它自己的配置,比较麻烦
|
2023-09-24 21:56:03 +08:00
|
|
|
|
bool git_exist = does_the_program_exist (xy_str_to_quietcmd("git version"), "git");
|
|
|
|
|
if (git_exist) {
|
2023-09-27 14:14:19 +08:00
|
|
|
|
if (xy_streql("nju",source.mirror->code)) {
|
|
|
|
|
source = os_freebsd_sources[index-1]; // 使用NJU的前一个源,即USTC源
|
|
|
|
|
}
|
2023-09-24 21:56:03 +08:00
|
|
|
|
char* git_cmd = xy_strjoin(3, "git clone --depth 1 https://", source.url, "/freebsd-ports/ports.git /usr/ports");
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(git_cmd);
|
2023-09-27 14:14:19 +08:00
|
|
|
|
source = os_freebsd_sources[index]; // 恢复至选中的源
|
|
|
|
|
chsrc_warn("下次更新请使用 git -C /usr/ports pull 而非使用 gitup");
|
|
|
|
|
}
|
|
|
|
|
else {
|
2023-09-24 21:56:03 +08:00
|
|
|
|
char* fetch = xy_strjoin(3, "fetch https://", source.url, "/freebsd-ports/ports.tar.gz"); // 70多MB
|
|
|
|
|
char* unzip = "tar -zxvf ports.tar.gz -C /usr/ports";
|
|
|
|
|
char* delete = "rm ports.tar.gz";
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(fetch);
|
|
|
|
|
chsrc_run(unzip);
|
|
|
|
|
chsrc_run(delete);
|
2023-09-27 14:14:19 +08:00
|
|
|
|
chsrc_warn("下次更新请重新下载内容至 /usr/ports");
|
2023-09-24 21:56:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-17 16:56:25 +08:00
|
|
|
|
|
2023-09-27 14:14:19 +08:00
|
|
|
|
chsrc_info("3. 指定 port 源");
|
|
|
|
|
// https://help.mirrors.cernet.edu.cn/FreeBSD-ports/
|
|
|
|
|
chsrc_backup ("/etc/make.conf");
|
|
|
|
|
|
|
|
|
|
char* ports = xy_strjoin(3, "MASTER_SITE_OVERRIDE?=http://", source.url, "/freebsd-ports/distfiles/${DIST_SUBDIR}/");
|
|
|
|
|
chsrc_append_to_file (ports, "/etc/make.conf");
|
2023-09-24 21:56:03 +08:00
|
|
|
|
|
2023-09-17 16:56:25 +08:00
|
|
|
|
|
2023-09-24 21:56:03 +08:00
|
|
|
|
/* 不再换 portsnap */
|
|
|
|
|
/*
|
2023-09-29 22:15:58 +08:00
|
|
|
|
chsrc_backup ("/etc/portsnap.conf");
|
2023-09-17 16:56:25 +08:00
|
|
|
|
|
2023-09-26 22:49:28 +08:00
|
|
|
|
char* portsnap =xy_strjoin(3,"s@(.*)SERVERNAME=[\\.|a-z|A-Z]*@\\1SERVERNAME=", source.url,
|
|
|
|
|
"@g < /etc/portsnap.conf.bak");
|
2023-09-18 21:31:48 +08:00
|
|
|
|
|
2023-09-26 22:49:28 +08:00
|
|
|
|
chsrc_overwrite_file (portsnap, "/etc/portsnap.conf");
|
2023-09-17 16:56:25 +08:00
|
|
|
|
|
2023-09-26 22:49:28 +08:00
|
|
|
|
chsrc_info("portsnap sources changed");
|
|
|
|
|
chsrc_info("获取portsnap更新使用此命令: 'portsnap fetch extract'");
|
2023-09-24 21:56:03 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2023-09-26 22:49:28 +08:00
|
|
|
|
// HELP: 暂时没有源提供
|
2023-09-27 14:14:19 +08:00
|
|
|
|
chsrc_warn ("4. 抱歉,目前境内无 freebsd-update 源,若存在请报告issue,谢谢");
|
2023-09-24 21:56:03 +08:00
|
|
|
|
/*
|
2023-09-26 22:49:28 +08:00
|
|
|
|
chsrc_info("3. 修改 freebsd-update 源");
|
2023-09-17 16:56:25 +08:00
|
|
|
|
|
2023-09-26 22:49:28 +08:00
|
|
|
|
char* update_cp="cp /etc/freebsd-update.conf /etc/freebsd-update.conf.bak";
|
|
|
|
|
chsrc_runcmd(update_cp);
|
2023-09-17 16:56:25 +08:00
|
|
|
|
|
2023-09-26 22:49:28 +08:00
|
|
|
|
char* update =xy_strjoin(3,"s@(.*)SERVERNAME [\\.|a-z|A-Z]*@\\1SERVERNAME ",
|
2023-09-17 16:56:25 +08:00
|
|
|
|
source.url,
|
2023-09-26 22:49:28 +08:00
|
|
|
|
"@g < /etc/freebsd-update.conf.bak");
|
|
|
|
|
|
|
|
|
|
chsrc_overwrite_file (update, "/etc/freebsd-update.conf");
|
|
|
|
|
*/
|
2023-09-17 16:56:25 +08:00
|
|
|
|
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-18 21:43:12 +08:00
|
|
|
|
|
2023-09-24 21:07:39 +08:00
|
|
|
|
void
|
|
|
|
|
os_netbsd_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-26 22:24:48 +08:00
|
|
|
|
chsrc_check_file ("/usr/pkg/etc/pkgin/repositories.conf");
|
2023-09-24 21:07:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 参考:
|
|
|
|
|
* 1. https://mirrors.tuna.tsinghua.edu.cn/help/pkgsrc/
|
|
|
|
|
* 2. https://book.bsdcn.org/di-27-zhang-netbsd/di-27.2-jie-huan-yuan-yu-bao-guan-li-qi.html
|
|
|
|
|
*
|
|
|
|
|
* 根据 @ykla (https://github.com/ykla)
|
|
|
|
|
* NetBSD 默认状态下没有 pkgsrc,用户可能安装了也可能没安装
|
|
|
|
|
*
|
|
|
|
|
* HELP: 未经测试
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_netbsd_setsrc(char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root(); // HELP: 不知道是否需要确保root权限
|
2023-09-24 21:07:39 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_netbsd);
|
2023-09-24 21:07:39 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_netbsd_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
chsrc_backup ("/usr/pkg/etc/pkgin/repositories.conf");
|
2023-09-24 21:07:39 +08:00
|
|
|
|
|
2023-09-27 19:31:23 +08:00
|
|
|
|
char* arch = xy_getcmd("arch", 0, NULL);
|
2023-09-27 11:35:30 +08:00
|
|
|
|
char* vercmd = "cat /etc/os-release | grep \"VERSION=\" | grep -Po \"[8-9].[0-9]+\"";
|
2023-09-27 19:31:23 +08:00
|
|
|
|
char* version = xy_getcmd(vercmd, 0, NULL);
|
2023-09-26 22:14:41 +08:00
|
|
|
|
|
|
|
|
|
char* url = xy_strjoin(5, source.url, arch, "/", version, "/All");
|
|
|
|
|
chsrc_overwrite_file (url, "/usr/pkg/etc/pkgin/repositories.conf");
|
2023-09-24 21:07:39 +08:00
|
|
|
|
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
os_openbsd_getsrc (char* option)
|
|
|
|
|
{
|
2023-09-26 22:24:48 +08:00
|
|
|
|
chsrc_check_file ("/etc/installurl");
|
2023-09-24 21:07:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 参考:
|
|
|
|
|
* 1. https://mirrors.tuna.tsinghua.edu.cn/help/openbsd/
|
|
|
|
|
* 2. https://book.bsdcn.org/di-26-zhang-openbsd/di-26.2-jie-pei-zhi.html
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
os_openbsd_setsrc(char* option)
|
|
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
|
chsrc_ensure_root();
|
2023-09-24 21:07:39 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, os_openbsd);
|
2023-09-24 21:07:39 +08:00
|
|
|
|
|
|
|
|
|
source_info source = os_openbsd_sources[index];
|
|
|
|
|
chsrc_say_selection(&source);
|
|
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
|
chsrc_backup ("/etc/installurl");
|
2023-09-26 22:14:41 +08:00
|
|
|
|
chsrc_overwrite_file (source.url, "/etc/installurl");
|
2023-09-24 21:07:39 +08:00
|
|
|
|
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-10 17:01:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2023-09-22 13:31:05 +08:00
|
|
|
|
wr_tex_check_cmd_ (bool* tlmgr_exist, bool* mpm_exist)
|
2023-09-10 17:01:20 +08:00
|
|
|
|
{
|
|
|
|
|
char* check_cmd = xy_str_to_quietcmd("tlmgr --version");
|
|
|
|
|
*tlmgr_exist = does_the_program_exist (check_cmd, "tlmgr");
|
|
|
|
|
|
|
|
|
|
check_cmd = xy_str_to_quietcmd("mpm --version");
|
|
|
|
|
*mpm_exist = does_the_program_exist (check_cmd, "mpm");
|
|
|
|
|
|
|
|
|
|
if (!*tlmgr_exist && !*mpm_exist) {
|
|
|
|
|
xy_error ("chsrc: 未找到 tlmgr 或 mpm 命令,请检查是否存在(其一)");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
wr_tex_getsrc(char* option)
|
|
|
|
|
{
|
|
|
|
|
bool tlmgr_exist, mpm_exist;
|
2023-09-22 13:31:05 +08:00
|
|
|
|
wr_tex_check_cmd_(&tlmgr_exist, &mpm_exist);
|
2023-09-10 17:01:20 +08:00
|
|
|
|
|
|
|
|
|
if (tlmgr_exist) {
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run("tlmgr option repository");
|
2023-09-10 17:01:20 +08:00
|
|
|
|
}
|
|
|
|
|
if (mpm_exist) {
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run("mpm --get-repository");
|
2023-09-10 17:01:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 参考 https://help.mirrors.cernet.edu.cn/CTAN/
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
wr_tex_setsrc(char* option)
|
|
|
|
|
{
|
|
|
|
|
bool tlmgr_exist, mpm_exist;
|
2023-09-22 13:31:05 +08:00
|
|
|
|
wr_tex_check_cmd_(&tlmgr_exist, &mpm_exist);
|
2023-09-10 17:01:20 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, wr_tex);
|
2023-09-10 17:01:20 +08:00
|
|
|
|
|
|
|
|
|
source_info source = wr_tex_sources[index];
|
|
|
|
|
chsrc_say_selection (&source);
|
|
|
|
|
|
|
|
|
|
char* cmd = NULL;
|
|
|
|
|
|
|
|
|
|
if (tlmgr_exist) {
|
|
|
|
|
cmd = xy_2strjoin("tlmgr option repository ", source.url);
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-10 17:01:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mpm_exist) {
|
|
|
|
|
char* miktex_url = xy_2strjoin(xy_str_delete_suffix(source.url, "texlive/tlnet"), "win32/miktex/tm/packages/");
|
|
|
|
|
cmd = xy_2strjoin("mpm --set-repository=", miktex_url);
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-10 17:01:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-10 17:18:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
wr_emacs_setsrc(char* option)
|
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, wr_emacs);
|
2023-09-10 17:18:05 +08:00
|
|
|
|
|
|
|
|
|
source_info source = wr_emacs_sources[index];
|
|
|
|
|
chsrc_say_selection (&source);
|
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
chsrc_warn("抱歉,Emacs换源涉及Elisp,您可手动查阅并换源:");
|
2023-09-10 17:18:05 +08:00
|
|
|
|
puts(source.url);
|
|
|
|
|
|
|
|
|
|
chsrc_say_thanks (&source);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-10 18:44:34 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-10 21:05:21 +08:00
|
|
|
|
void
|
|
|
|
|
wr_brew_getsrc(char* option)
|
|
|
|
|
{
|
|
|
|
|
char* cmd = "echo HOMEBREW_API_DOMAIN=$HOMEBREW_API_DOMAIN;"
|
|
|
|
|
"echo HOMEBREW_BOTTLE_DOMAIN=$HOMEBREW_BOTTLE_DOMAIN;"
|
|
|
|
|
"echo HOMEBREW_BREW_GIT_REMOTE=$HOMEBREW_BREW_GIT_REMOTE;"
|
|
|
|
|
"echo HOMEBREW_CORE_GIT_REMOTE=$HOMEBREW_CORE_GIT_REMOTE;";
|
|
|
|
|
system(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-17 14:06:21 +08:00
|
|
|
|
/**
|
|
|
|
|
* 参考自: https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
|
|
|
|
|
*
|
|
|
|
|
* 自brew 4.0.0 (2023 年 2 月 16日) 起,
|
|
|
|
|
* HOMEBREW_INSTALL_FROM_API 会成为默认行为,无需设置。大部分用户无需再克隆 homebrew-core 仓库,故无需设置 HOMEBREW_CORE_GIT_REMOTE 环境变量;
|
|
|
|
|
* 但是为了以防万一,我们还是为用户设置该环境变量
|
|
|
|
|
*/
|
2023-09-10 21:05:21 +08:00
|
|
|
|
void
|
|
|
|
|
wr_brew_setsrc(char* option)
|
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, wr_brew);
|
2023-09-10 21:05:21 +08:00
|
|
|
|
|
|
|
|
|
source_info source = wr_brew_sources[index];
|
|
|
|
|
chsrc_say_selection (&source);
|
|
|
|
|
|
2023-09-17 14:06:21 +08:00
|
|
|
|
char* api_domain = xy_strjoin(3, "export HOMEBREW_API_DOMAIN=\"", xy_2strjoin(source.url, "homebrew-bottles/api"), "\"");
|
|
|
|
|
char* bottle_domain = xy_strjoin(3, "export HOMEBREW_BOTTLE_DOMAIN=\"", xy_2strjoin(source.url, "homebrew-bottles"), "\"");
|
|
|
|
|
char* brew_git_remote = xy_strjoin(3, "export HOMEBREW_BREW_GIT_REMOTE=\"", xy_2strjoin(source.url, "git/homebrew/brew.git"), "\"");
|
|
|
|
|
char* core_git_remote = xy_strjoin(3, "export HOMEBREW_CORE_GIT_REMOTE=\"", xy_2strjoin(source.url, "git/homebrew/homebrew-core.git"), "\"");
|
2023-09-10 21:05:21 +08:00
|
|
|
|
|
2023-09-26 22:14:41 +08:00
|
|
|
|
chsrc_append_to_file (api_domain, "~/.bashrc >> ~/.zshrc");
|
|
|
|
|
chsrc_append_to_file (bottle_domain, "~/.bashrc >> ~/.zshrc");
|
|
|
|
|
chsrc_append_to_file (brew_git_remote, "~/.bashrc >> ~/.zshrc");
|
|
|
|
|
chsrc_append_to_file (core_git_remote, "~/.bashrc >> ~/.zshrc");
|
2023-09-10 21:05:21 +08:00
|
|
|
|
|
|
|
|
|
chsrc_say_thanks (&source);
|
2023-09-26 22:14:41 +08:00
|
|
|
|
puts(""); chsrc_warn("请您重启终端使环境变量生效");
|
2023-09-10 21:05:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-17 14:06:21 +08:00
|
|
|
|
|
2023-09-11 11:25:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* 参考: https://mirrors.sjtug.sjtu.edu.cn/docs/guix
|
|
|
|
|
*/
|
2023-09-11 11:06:15 +08:00
|
|
|
|
void
|
2023-09-22 15:36:23 +08:00
|
|
|
|
wr_guix_setsrc (char* option)
|
2023-09-11 11:06:15 +08:00
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, wr_guix);
|
2023-09-11 11:06:15 +08:00
|
|
|
|
|
|
|
|
|
source_info source = wr_guix_sources[index];
|
|
|
|
|
chsrc_say_selection (&source);
|
|
|
|
|
|
|
|
|
|
char* file = xy_strjoin(3, "(list (channel\n"
|
|
|
|
|
" (inherit (car %default-channels))\n"
|
|
|
|
|
" (url \"", source.url, "\")))");
|
|
|
|
|
|
2023-09-22 15:36:23 +08:00
|
|
|
|
xy_warn ("chsrc: 为防止扰乱配置文件,请您手动写入以下内容到 ~/.config/guix/channels.scm 文件中");
|
2023-09-11 11:06:15 +08:00
|
|
|
|
puts(file);
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-29 21:23:58 +08:00
|
|
|
|
|
2023-09-22 15:36:23 +08:00
|
|
|
|
void
|
2023-09-29 21:23:58 +08:00
|
|
|
|
wr_nix_check_cmd ()
|
2023-09-22 15:36:23 +08:00
|
|
|
|
{
|
|
|
|
|
char* check_cmd = xy_str_to_quietcmd("nix-channel --version");
|
|
|
|
|
bool exist = does_the_program_exist (check_cmd, "nix-channel");
|
|
|
|
|
|
|
|
|
|
if (!exist) {
|
2023-09-29 21:23:58 +08:00
|
|
|
|
chsrc_error ("未找到 nix-channel 命令,请检查是否存在");
|
2023-09-22 15:36:23 +08:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-09-26 18:11:38 +08:00
|
|
|
|
* 参考:
|
|
|
|
|
* 1. https://mirrors.bfsu.edu.cn/help/nix-channels/
|
|
|
|
|
* 2. https://gitee.com/RubyMetric/chsrc/issues/I83894
|
2023-09-22 15:36:23 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
wr_nix_setsrc (char* option)
|
|
|
|
|
{
|
2023-09-29 21:23:58 +08:00
|
|
|
|
wr_nix_check_cmd ();
|
2023-09-22 15:36:23 +08:00
|
|
|
|
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, wr_nix);
|
2023-09-22 15:36:23 +08:00
|
|
|
|
|
|
|
|
|
source_info source = wr_nix_sources[index];
|
|
|
|
|
chsrc_say_selection (&source);
|
|
|
|
|
|
|
|
|
|
char* cmd = xy_strjoin(3, "nix-channel --add ", source.url, "nixpkgs-unstable nixpkgs");
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-22 15:36:23 +08:00
|
|
|
|
|
2023-09-26 22:14:41 +08:00
|
|
|
|
char* towrite = xy_strjoin (3, "substituters = ", source.url, "store https://cache.nixos.org/");
|
|
|
|
|
chsrc_append_to_file (towrite , "~/.config/nix/nix.conf");
|
2023-09-26 18:11:38 +08:00
|
|
|
|
|
2023-09-26 22:14:41 +08:00
|
|
|
|
chsrc_run("nix-channel --update");
|
2023-09-22 15:36:23 +08:00
|
|
|
|
|
2023-09-26 22:14:41 +08:00
|
|
|
|
chsrc_info("若您使用的是NixOS,请确认您的系统版本<version>(如22.11),并手动运行:");
|
2023-09-26 18:11:38 +08:00
|
|
|
|
cmd = xy_strjoin(3, "nix-channel --add ", source.url, "nixpkgs-<version> nixpkgs");
|
|
|
|
|
puts(cmd);
|
|
|
|
|
|
|
|
|
|
cmd = xy_strjoin(3, "nix.settings.substituters = [ \"", source.url, "store\" ];");
|
2023-09-26 22:14:41 +08:00
|
|
|
|
chsrc_info("若您使用的是NixOS,请额外添加下述内容至 configuration.nix 中");
|
2023-09-26 18:11:38 +08:00
|
|
|
|
puts(cmd);
|
|
|
|
|
|
2023-09-22 15:36:23 +08:00
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-10 18:44:34 +08:00
|
|
|
|
|
2023-09-11 11:25:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* 参考: https://mirrors.sjtug.sjtu.edu.cn/docs/flathub
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
wr_flathub_setsrc(char* option)
|
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, wr_flathub);
|
2023-09-11 11:25:48 +08:00
|
|
|
|
|
|
|
|
|
source_info source = wr_flathub_sources[index];
|
|
|
|
|
chsrc_say_selection (&source);
|
|
|
|
|
|
|
|
|
|
xy_warn ("chsrc: 若出现问题,可先调用以下命令:");
|
|
|
|
|
char* note = xy_strjoin(3,
|
|
|
|
|
"wget ", source.url, "/flathub.gpg\n"
|
|
|
|
|
"sudo flatpak remote-modify --gpg-import=flathub.gpg flathub"
|
|
|
|
|
);
|
|
|
|
|
puts(note);
|
|
|
|
|
|
|
|
|
|
char* cmd = xy_2strjoin("sudo flatpak remote-modify flathub --url=", source.url);
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run(cmd);
|
2023-09-11 11:25:48 +08:00
|
|
|
|
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-10 22:42:59 +08:00
|
|
|
|
void
|
|
|
|
|
wr_anaconda_setsrc(char* option)
|
|
|
|
|
{
|
2023-09-27 09:40:31 +08:00
|
|
|
|
int index = use_specific_mirror_or_auto_select (option, wr_anaconda);
|
2023-09-10 22:42:59 +08:00
|
|
|
|
|
|
|
|
|
source_info source = wr_anaconda_sources[index];
|
|
|
|
|
chsrc_say_selection (&source);
|
|
|
|
|
|
|
|
|
|
char* main = xy_2strjoin(source.url, "pkgs/main");
|
|
|
|
|
char* r = xy_2strjoin(source.url, "pkgs/r");
|
|
|
|
|
char* msys2 = xy_2strjoin(source.url, "pkgs/msys2");
|
|
|
|
|
char* cloud = xy_2strjoin(source.url, "cloud");
|
|
|
|
|
|
|
|
|
|
char* file = xy_strjoin(22,
|
|
|
|
|
"channels:\n - defaults\n"
|
|
|
|
|
"show_channel_urls: true\ndefault_channels:"
|
|
|
|
|
"\n - ", main,
|
|
|
|
|
"\n - ", r,
|
|
|
|
|
"\n - ", msys2,
|
|
|
|
|
"\ncustom_channels:\n"
|
|
|
|
|
" conda-forge: ", cloud,
|
|
|
|
|
"\n msys2: ", cloud,
|
|
|
|
|
"\n bioconda: ", cloud,
|
|
|
|
|
"\n menpo: ", cloud,
|
|
|
|
|
"\n pytorch: ", cloud,
|
|
|
|
|
"\n pytorch-lts: ", cloud,
|
|
|
|
|
"\n simpleitk: ", cloud,
|
|
|
|
|
"\n deepmodeling: ", cloud);
|
|
|
|
|
|
|
|
|
|
|
2023-09-17 14:19:53 +08:00
|
|
|
|
// TODO: 待确认 windows 上也是这里吗?
|
|
|
|
|
char* config = xy_2strjoin(xy_os_home, "/.condarc");
|
2023-09-10 22:42:59 +08:00
|
|
|
|
|
|
|
|
|
if (xy_on_windows) {
|
|
|
|
|
char* check_cmd = xy_str_to_quietcmd("conda --version");
|
|
|
|
|
bool exist = does_the_program_exist (check_cmd, "conda");
|
|
|
|
|
if (!exist) {
|
|
|
|
|
xy_error ("chsrc: 未找到 conda 命令,请检查是否存在");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2023-09-26 21:41:47 +08:00
|
|
|
|
chsrc_run("conda config --set show_channel_urls yes");
|
2023-09-10 22:42:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-17 14:19:53 +08:00
|
|
|
|
xy_info(xy_strjoin(3, "chsrc: 请向 ", config, " 中手动添加:"));
|
2023-09-10 22:42:59 +08:00
|
|
|
|
puts(file);
|
|
|
|
|
|
|
|
|
|
xy_info("chsrc: 然后运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引");
|
|
|
|
|
chsrc_say_thanks(&source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-02 19:07:30 +08:00
|
|
|
|
/************************************** Begin Target Matrix ****************************************/
|
|
|
|
|
def_target_info(pl_ruby);
|
2023-09-04 09:01:33 +08:00
|
|
|
|
def_target_info(pl_python);
|
2023-09-04 15:24:09 +08:00
|
|
|
|
def_target_info(pl_nodejs);
|
|
|
|
|
def_target_info(pl_perl);
|
2023-09-05 09:28:42 +08:00
|
|
|
|
def_target_info(pl_php);
|
2023-09-27 14:49:00 +08:00
|
|
|
|
def_target_info(pl_lua);
|
2023-09-05 09:28:42 +08:00
|
|
|
|
def_target_info(pl_go);
|
2023-09-05 14:17:31 +08:00
|
|
|
|
def_target_info(pl_rust);
|
2023-09-05 11:09:08 +08:00
|
|
|
|
def_target_info(pl_java);
|
2023-09-10 13:59:53 +08:00
|
|
|
|
def_target_info(pl_dart);
|
2023-09-15 12:30:36 +08:00
|
|
|
|
def_target_info(pl_ocaml);
|
2023-09-05 09:28:42 +08:00
|
|
|
|
def_target_info(pl_r);
|
|
|
|
|
def_target_info(pl_julia);
|
2023-09-02 17:18:44 +08:00
|
|
|
|
|
|
|
|
|
target_info
|
2023-09-10 18:44:34 +08:00
|
|
|
|
pl_clojure_target = {pl_clojure_setsrc, NULL, pl_clojure_sources, pl_clojure_sources_n},
|
2023-09-10 19:35:13 +08:00
|
|
|
|
pl_dotnet_target = {pl_dotnet_setsrc, NULL, pl_dotnet_sources, pl_dotnet_sources_n},
|
|
|
|
|
pl_haskell_target = {pl_haskell_setsrc, NULL, pl_haskell_sources, pl_haskell_sources_n};
|
2023-09-02 17:18:44 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-06 19:05:13 +08:00
|
|
|
|
#define targetinfo(t) (const char*)t
|
|
|
|
|
static const char
|
2023-09-27 15:13:59 +08:00
|
|
|
|
*pl_ruby [] = {"gem", "ruby", "rubygem", "rb", "rubygems",NULL, targetinfo(&pl_ruby_target)},
|
|
|
|
|
*pl_python[] = {"pip", "python", "pypi", "py", NULL, targetinfo(&pl_python_target)},
|
|
|
|
|
*pl_nodejs[] = {"npm", "node", "nodejs", "js", "yarn", NULL, targetinfo(&pl_nodejs_target)},
|
2023-09-02 17:18:44 +08:00
|
|
|
|
*pl_perl [] = {"perl", "cpan", NULL, targetinfo(&pl_perl_target)},
|
2023-09-10 13:59:53 +08:00
|
|
|
|
*pl_php [] = {"php", "composer", NULL, targetinfo(&pl_php_target)},
|
2023-09-27 14:49:00 +08:00
|
|
|
|
*pl_lua [] = {"lua", "luarocks", NULL, targetinfo(&pl_lua_target)},
|
2023-09-02 17:18:44 +08:00
|
|
|
|
*pl_go [] = {"go", "golang", "goproxy", NULL, targetinfo(&pl_go_target)} ,
|
2023-09-10 13:59:53 +08:00
|
|
|
|
*pl_rust [] = {"rust", "cargo", "crate", "crates", NULL, targetinfo(&pl_rust_target)},
|
2023-09-02 17:18:44 +08:00
|
|
|
|
*pl_java [] = {"java", "maven", "gradle", NULL, targetinfo(&pl_java_target)},
|
2023-09-27 15:13:59 +08:00
|
|
|
|
*pl_clojure[] ={"clojure","clojars","cloj", "lein", "leiningen", NULL, targetinfo(&pl_clojure_target)},
|
2023-09-10 21:33:59 +08:00
|
|
|
|
*pl_dart [] = {"dart", "pub", "flutter", NULL, targetinfo(&pl_dart_target)},
|
2023-09-10 13:59:53 +08:00
|
|
|
|
*pl_dotnet[] = {"nuget", "net", ".net", "dotnet", NULL, targetinfo(&pl_dotnet_target)},
|
2023-09-10 19:35:13 +08:00
|
|
|
|
*pl_haskell[] ={"haskell", "cabal", "stack", "hackage", NULL, targetinfo(&pl_haskell_target)},
|
2023-09-15 12:30:36 +08:00
|
|
|
|
*pl_ocaml[] = {"ocaml", "opam", NULL, targetinfo(&pl_ocaml_target)},
|
2023-09-27 15:13:59 +08:00
|
|
|
|
*pl_r [] = {"cran", "r", NULL, targetinfo(&pl_r_target)},
|
2023-09-02 17:18:44 +08:00
|
|
|
|
*pl_julia [] = {"julia", NULL, targetinfo(&pl_julia_target)},
|
2023-08-31 22:57:09 +08:00
|
|
|
|
**pl_packagers[] =
|
|
|
|
|
{
|
2023-09-27 14:49:00 +08:00
|
|
|
|
pl_ruby, pl_python, pl_nodejs, pl_perl, pl_php, pl_lua,
|
2023-09-10 18:44:34 +08:00
|
|
|
|
pl_rust, pl_go, /*pl_dotnet,*/ pl_java, pl_clojure, pl_dart,
|
2023-09-15 12:30:36 +08:00
|
|
|
|
pl_haskell, pl_ocaml,
|
2023-09-02 17:18:44 +08:00
|
|
|
|
pl_r, pl_julia
|
|
|
|
|
};
|
2023-08-30 22:27:08 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-17 11:33:30 +08:00
|
|
|
|
def_target_info(os_ubuntu);
|
2023-09-29 19:49:31 +08:00
|
|
|
|
def_target_info(os_mint);
|
2023-09-17 11:33:30 +08:00
|
|
|
|
def_target_info(os_debian);
|
2023-09-29 20:15:32 +08:00
|
|
|
|
def_target_info(os_kali);
|
|
|
|
|
def_target_info(os_alpine);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
def_target_info(os_void);
|
2023-09-29 19:12:57 +08:00
|
|
|
|
def_target_info(os_trisquel);
|
2023-09-29 20:01:45 +08:00
|
|
|
|
def_target_info(os_linuxlite);
|
2023-09-24 21:07:39 +08:00
|
|
|
|
def_target_info(os_netbsd);
|
|
|
|
|
def_target_info(os_openbsd);
|
2023-09-29 20:15:32 +08:00
|
|
|
|
def_target_info(os_deepin);
|
|
|
|
|
def_target_info(os_openkylin);
|
2023-09-29 20:51:13 +08:00
|
|
|
|
def_target_info(os_raspberrypi);
|
2023-09-24 21:07:39 +08:00
|
|
|
|
|
2023-09-17 11:33:30 +08:00
|
|
|
|
|
2023-09-02 17:18:44 +08:00
|
|
|
|
target_info
|
2023-09-08 22:41:45 +08:00
|
|
|
|
os_fedora_target = {os_fedora_setsrc, NULL, os_fedora_sources, os_fedora_sources_n},
|
2023-09-18 21:31:48 +08:00
|
|
|
|
os_opensuse_target = {os_opensuse_setsrc, NULL, os_opensuse_sources, os_opensuse_sources_n},
|
|
|
|
|
os_msys2_target = {os_msys2_setsrc, NULL, os_msys2_sources, os_msys2_sources_n},
|
2023-09-08 22:41:45 +08:00
|
|
|
|
os_arch_target = {os_arch_setsrc, NULL, os_arch_sources, os_arch_sources_n},
|
2023-09-06 17:08:20 +08:00
|
|
|
|
os_manjaro_target = {os_manjaro_setsrc, NULL, NULL, 0},
|
2023-09-08 22:41:45 +08:00
|
|
|
|
os_gentoo_target = {os_gentoo_setsrc, NULL, os_gentoo_sources, os_gentoo_sources_n},
|
2023-09-24 19:17:43 +08:00
|
|
|
|
os_rocky_target = {os_rocky_setsrc, NULL, os_rocky_sources, os_rocky_sources_n},
|
2023-09-29 21:49:11 +08:00
|
|
|
|
os_solus_target = {os_solus_setsrc, NULL, os_solus_sources, os_solus_sources_n},
|
2023-09-18 21:31:48 +08:00
|
|
|
|
os_freebsd_target = {os_freebsd_setsrc, NULL, os_freebsd_sources, os_freebsd_sources_n},
|
2023-09-29 20:33:19 +08:00
|
|
|
|
os_openeuler_target = {os_openeuler_setsrc, NULL, os_openeuler_sources, os_openeuler_sources_n};
|
2023-09-08 22:41:45 +08:00
|
|
|
|
|
2023-09-06 19:05:13 +08:00
|
|
|
|
static const char
|
2023-09-18 21:31:48 +08:00
|
|
|
|
*os_ubuntu [] = {"ubuntu", NULL, targetinfo(&os_ubuntu_target)},
|
2023-09-29 19:49:31 +08:00
|
|
|
|
*os_mint [] = {"mint", NULL, targetinfo(&os_mint_target)},
|
2023-09-18 21:31:48 +08:00
|
|
|
|
*os_debian [] = {"debian", "deb", NULL, targetinfo(&os_debian_target)},
|
|
|
|
|
*os_fedora [] = {"fedora", NULL, targetinfo(&os_fedora_target)},
|
2023-09-27 15:13:59 +08:00
|
|
|
|
*os_opensuse [] = {"suse", "opensuse", NULL, targetinfo(&os_opensuse_target)},
|
2023-09-18 21:31:48 +08:00
|
|
|
|
*os_kali [] = {"kali", NULL, targetinfo(&os_kali_target)},
|
|
|
|
|
*os_msys2 [] = {"msys2", "msys", NULL, targetinfo(&os_msys2_target)},
|
|
|
|
|
*os_arch [] = {"arch", NULL, targetinfo(&os_arch_target)},
|
|
|
|
|
*os_manjaro [] = {"manjaro", NULL, targetinfo(&os_manjaro_target)},
|
|
|
|
|
*os_gentoo [] = {"gentoo", NULL, targetinfo(&os_gentoo_target)},
|
2023-09-24 19:17:43 +08:00
|
|
|
|
*os_rocky [] = {"rocky", "rockylinux", NULL, targetinfo(&os_rocky_target)},
|
2023-09-24 20:01:46 +08:00
|
|
|
|
*os_alpine [] = {"alpine", NULL, targetinfo(&os_alpine_target)},
|
2023-09-24 20:32:33 +08:00
|
|
|
|
*os_void [] = {"void", "voidlinux", NULL, targetinfo(&os_void_target)},
|
2023-09-29 21:49:11 +08:00
|
|
|
|
*os_solus [] = {"solus", NULL, targetinfo(&os_solus_target)},
|
2023-09-29 19:12:57 +08:00
|
|
|
|
*os_trisquel [] = {"trisquel", NULL, targetinfo(&os_trisquel_target)},
|
2023-09-29 20:01:45 +08:00
|
|
|
|
*os_linuxlite [] = {"lite", "linuxlite", NULL, targetinfo(&os_linuxlite_target)},
|
2023-09-29 20:51:13 +08:00
|
|
|
|
*os_raspberrypi [] = {"raspi", "raspberrypi",NULL, targetinfo(&os_raspberrypi_target)},
|
2023-09-18 21:31:48 +08:00
|
|
|
|
*os_freebsd [] = {"freebsd", NULL, targetinfo(&os_freebsd_target)},
|
|
|
|
|
*os_netbsd [] = {"netbsd", NULL, targetinfo(&os_netbsd_target)},
|
|
|
|
|
*os_openbsd [] = {"openbsd", NULL, targetinfo(&os_openbsd_target)},
|
|
|
|
|
*os_deepin [] = {"deepin", NULL, targetinfo(&os_deepin_target)},
|
2023-09-27 15:15:40 +08:00
|
|
|
|
*os_openeuler [] = {"euler", "openeuler", NULL, targetinfo(&os_openeuler_target)},
|
|
|
|
|
*os_openkylin [] = {"kylin", "openkylin", NULL, targetinfo(&os_openkylin_target)},
|
2023-08-31 22:57:09 +08:00
|
|
|
|
**os_systems[] =
|
|
|
|
|
{
|
2023-09-29 19:49:31 +08:00
|
|
|
|
os_ubuntu, os_mint, os_debian, os_fedora, os_opensuse, os_kali,
|
2023-09-08 22:41:45 +08:00
|
|
|
|
os_arch, os_manjaro, os_gentoo,
|
2023-09-24 19:17:43 +08:00
|
|
|
|
os_rocky,
|
2023-09-29 21:49:11 +08:00
|
|
|
|
os_alpine, os_void, os_solus,
|
2023-09-29 20:51:13 +08:00
|
|
|
|
os_trisquel, os_linuxlite, os_raspberrypi,
|
2023-09-29 20:56:06 +08:00
|
|
|
|
os_freebsd, os_netbsd, os_openbsd,
|
2023-09-08 22:41:45 +08:00
|
|
|
|
os_msys2,
|
2023-09-29 20:56:06 +08:00
|
|
|
|
os_deepin, os_openeuler, os_openkylin,
|
2023-09-02 17:18:44 +08:00
|
|
|
|
};
|
2023-08-31 16:38:58 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-10 21:05:21 +08:00
|
|
|
|
def_target_info(wr_brew);
|
2023-09-11 11:06:15 +08:00
|
|
|
|
def_target_info(wr_tex);
|
2023-09-10 17:01:20 +08:00
|
|
|
|
|
2023-09-02 17:18:44 +08:00
|
|
|
|
target_info
|
2023-09-11 11:25:48 +08:00
|
|
|
|
wr_flathub_target = {wr_flathub_setsrc, NULL, wr_flathub_sources, wr_flathub_sources_n},
|
2023-09-22 15:36:23 +08:00
|
|
|
|
wr_nix_target = {wr_nix_setsrc, NULL, wr_nix_sources, wr_nix_sources_n},
|
2023-09-11 11:25:48 +08:00
|
|
|
|
wr_guix_target = {wr_guix_setsrc, NULL, wr_guix_sources, wr_guix_sources_n},
|
|
|
|
|
wr_emacs_target = {wr_emacs_setsrc, NULL, wr_emacs_sources, wr_emacs_sources_n},
|
|
|
|
|
wr_anaconda_target = {wr_anaconda_setsrc, NULL, wr_anaconda_sources, wr_anaconda_sources_n};
|
2023-09-02 17:18:44 +08:00
|
|
|
|
|
2023-09-06 19:05:13 +08:00
|
|
|
|
static const char
|
2023-09-11 11:25:48 +08:00
|
|
|
|
*wr_brew [] = {"brew", "homebrew", NULL, targetinfo(&wr_brew_target)},
|
|
|
|
|
*wr_flathub [] = {"flathub", NULL, targetinfo(&wr_flathub_target)},
|
2023-09-22 15:36:23 +08:00
|
|
|
|
*wr_nix [] = {"nix", NULL, targetinfo(&wr_nix_target)},
|
2023-09-11 11:25:48 +08:00
|
|
|
|
*wr_guix [] = {"guix", NULL, targetinfo(&wr_guix_target)},
|
2023-09-10 17:18:05 +08:00
|
|
|
|
*wr_emacs [] = {"emacs", "elpa", NULL, targetinfo(&wr_emacs_target)},
|
2023-09-10 17:01:20 +08:00
|
|
|
|
*wr_tex [] = {"latex", "ctan", "tex", "texlive", "miktex", "tlmgr", "mpm", NULL, targetinfo(&wr_tex_target)},
|
2023-09-11 11:25:48 +08:00
|
|
|
|
*wr_anaconda[] = {"conda", "anaconda", NULL, targetinfo(&wr_anaconda_target)},
|
2023-08-31 22:57:09 +08:00
|
|
|
|
**wr_softwares[] =
|
|
|
|
|
{
|
2023-09-22 15:36:23 +08:00
|
|
|
|
wr_brew, wr_flathub, wr_nix, wr_guix, wr_emacs, wr_tex, wr_anaconda
|
2023-08-31 22:57:09 +08:00
|
|
|
|
};
|
2023-09-02 17:18:44 +08:00
|
|
|
|
#undef targetinfo
|
2023-09-02 19:07:30 +08:00
|
|
|
|
/************************************** End Target Matrix ****************************************/
|
2023-08-30 22:27:08 +08:00
|
|
|
|
|
|
|
|
|
|
2023-09-06 19:05:13 +08:00
|
|
|
|
static const char*
|
2023-08-28 22:21:33 +08:00
|
|
|
|
usage[] = {
|
2023-09-05 15:46:31 +08:00
|
|
|
|
"维护: https://gitee.com/RubyMetric/chsrc\n",
|
2023-08-30 11:33:23 +08:00
|
|
|
|
|
2023-09-05 15:46:31 +08:00
|
|
|
|
"使用: chsrc <command> [target] [mirror]",
|
2023-09-03 20:49:55 +08:00
|
|
|
|
"help 打印此帮助,或 h, -h, --help",
|
2023-09-17 13:33:41 +08:00
|
|
|
|
"list (或 ls, 或 l) 列出可用镜像源,和可换源软件",
|
|
|
|
|
"list mirror/target 列出可用镜像源,或可换源软件",
|
|
|
|
|
"list os/lang/ware 列出可换源的操作系统/编程语言/软件",
|
2023-09-03 20:49:55 +08:00
|
|
|
|
"list <target> 查看该软件可以使用哪些源",
|
|
|
|
|
"cesu <target> 对该软件所有源测速",
|
|
|
|
|
"get <target> 查看当前软件的源使用情况",
|
|
|
|
|
"set <target> 换源,自动测速后挑选最快源",
|
2023-09-05 13:06:04 +08:00
|
|
|
|
"set <target> def(ault) 换源,默认使用维护团队测速第一的源",
|
2023-09-03 20:49:55 +08:00
|
|
|
|
"set <target> <mirror> 换源,指定使用某镜像站\n"
|
2023-08-28 22:21:33 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2023-08-28 22:43:37 +08:00
|
|
|
|
void
|
2023-08-29 15:54:21 +08:00
|
|
|
|
call_cmd (void* cmdptr, const char* arg)
|
2023-08-28 22:43:37 +08:00
|
|
|
|
{
|
2023-08-29 15:54:21 +08:00
|
|
|
|
void (*cmd_func)(const char*) = cmdptr;
|
2023-08-28 23:10:09 +08:00
|
|
|
|
if (NULL==arg) {
|
2023-08-30 11:33:23 +08:00
|
|
|
|
xy_info("chsrc: 将使用默认镜像");
|
2023-08-28 23:10:09 +08:00
|
|
|
|
}
|
2023-08-28 22:43:37 +08:00
|
|
|
|
cmd_func(arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-08-31 21:40:32 +08:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
print_available_mirrors ()
|
|
|
|
|
{
|
2023-09-02 20:02:59 +08:00
|
|
|
|
xy_info ("chsrc: 支持以下镜像站,荣耀均归属于这些站点,以及它们的开发/维护者们");
|
2023-09-05 15:53:06 +08:00
|
|
|
|
xy_warn ("chsrc: 下方 code 列,可用于指定使用某镜像站,请使用 chsrc set <target> <code>");
|
2023-09-03 16:42:17 +08:00
|
|
|
|
printf ("%-14s%-30s%-41s ", "code", "服务商缩写", "服务商URL"); puts("服务商名称");
|
|
|
|
|
puts ("-------------------------------------------------------------------------------------------------");
|
2023-08-31 21:48:05 +08:00
|
|
|
|
for (int i=0; i<xy_arylen(available_mirrors); i++)
|
2023-08-31 21:40:32 +08:00
|
|
|
|
{
|
|
|
|
|
mirror_info* mir = available_mirrors[i];
|
2023-09-03 16:42:17 +08:00
|
|
|
|
printf ("%-14s%-18s%-41s ", mir->code, mir->abbr, mir->site); puts(mir->name);
|
2023-08-31 21:40:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2023-09-06 19:05:13 +08:00
|
|
|
|
print_supported_targets_ (const char*** array, size_t size)
|
2023-08-31 21:40:32 +08:00
|
|
|
|
{
|
|
|
|
|
for (int i=0; i<size; i++)
|
|
|
|
|
{
|
2023-09-06 19:05:13 +08:00
|
|
|
|
const char** target = array[i];
|
2023-08-31 21:40:32 +08:00
|
|
|
|
const char* alias = target[0];
|
|
|
|
|
for (int k=1; alias!=NULL; k++)
|
|
|
|
|
{
|
|
|
|
|
printf ("%s\t", alias);
|
|
|
|
|
alias = target[k];
|
|
|
|
|
}
|
|
|
|
|
puts("");
|
|
|
|
|
}
|
|
|
|
|
puts("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
print_supported_targets ()
|
|
|
|
|
{
|
|
|
|
|
xy_info ("chsrc: 支持对以下目标换源 (同一行表示这几个命令兼容)");
|
|
|
|
|
xy_warn ("编程语言开发");
|
2023-08-31 21:48:05 +08:00
|
|
|
|
print_supported_targets_ (pl_packagers, xy_arylen(pl_packagers));
|
2023-08-31 21:40:32 +08:00
|
|
|
|
xy_warn ("操作系统");
|
2023-08-31 21:48:05 +08:00
|
|
|
|
print_supported_targets_ (os_systems, xy_arylen(os_systems));
|
2023-08-31 21:40:32 +08:00
|
|
|
|
xy_warn ("软件");
|
2023-08-31 21:48:05 +08:00
|
|
|
|
print_supported_targets_ (wr_softwares, xy_arylen(wr_softwares));
|
2023-08-31 21:40:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-17 13:28:50 +08:00
|
|
|
|
void
|
|
|
|
|
print_supported_pl ()
|
|
|
|
|
{
|
|
|
|
|
xy_info ("chsrc: 支持对以下编程语言生态换源 (同一行表示这几个命令兼容)");
|
|
|
|
|
print_supported_targets_ (pl_packagers, xy_arylen(pl_packagers));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
print_supported_os ()
|
|
|
|
|
{
|
|
|
|
|
xy_info ("chsrc: 支持对以下操作系统换源 (同一行表示这几个命令兼容)");
|
|
|
|
|
print_supported_targets_ (os_systems, xy_arylen(os_systems));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
print_supported_wr ()
|
|
|
|
|
{
|
|
|
|
|
xy_info ("chsrc: 支持对以下软件换源 (同一行表示这几个命令兼容)");
|
|
|
|
|
print_supported_targets_ (wr_softwares, xy_arylen(wr_softwares));
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 21:40:32 +08:00
|
|
|
|
|
2023-08-31 22:57:09 +08:00
|
|
|
|
|
2023-09-02 16:49:55 +08:00
|
|
|
|
/**
|
|
|
|
|
* 用于 chsrc list <target>
|
|
|
|
|
*/
|
|
|
|
|
void
|
2023-09-09 16:56:03 +08:00
|
|
|
|
print_supported_sources_for_target (source_info sources[], size_t size)
|
2023-09-02 16:49:55 +08:00
|
|
|
|
{
|
2023-09-09 16:56:03 +08:00
|
|
|
|
for (int i=0;i<size;i++)
|
2023-09-02 16:49:55 +08:00
|
|
|
|
{
|
|
|
|
|
source_info src = sources[i];
|
|
|
|
|
const mirror_info* mir = src.mirror;
|
2023-09-03 16:42:17 +08:00
|
|
|
|
printf ("%-14s%-18s%-50s ",mir->code, mir->abbr, src.url);
|
2023-09-02 16:49:55 +08:00
|
|
|
|
puts(mir->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-06 17:06:09 +08:00
|
|
|
|
void
|
2023-08-29 15:54:21 +08:00
|
|
|
|
print_help ()
|
2023-08-28 22:21:33 +08:00
|
|
|
|
{
|
2023-09-05 21:02:59 +08:00
|
|
|
|
puts(xy_strjoin(3, "chsrc: Change Source (GPLv3) ",
|
|
|
|
|
xy_str_to_magenta(Chsrc_Version), " by RubyMetric\n"));
|
2023-08-31 21:48:05 +08:00
|
|
|
|
for (int i=0; i<xy_arylen(usage); i++) {
|
2023-08-31 19:51:19 +08:00
|
|
|
|
puts (usage[i]);
|
2023-08-28 22:21:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-01 17:17:45 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 遍历我们内置的targets列表,查询用户输入`input`是否与我们支持的某个target匹配
|
|
|
|
|
*
|
2023-09-02 19:38:32 +08:00
|
|
|
|
* @param[out] target_info 如果匹配到,则返回内置targets列表中最后的target_info信息
|
2023-09-01 17:17:45 +08:00
|
|
|
|
*
|
|
|
|
|
* @return 匹配到则返回true,未匹配到则返回false
|
|
|
|
|
*/
|
|
|
|
|
bool
|
2023-09-06 19:05:13 +08:00
|
|
|
|
iterate_targets_(const char*** array, size_t size, const char* input, const char*** target_info)
|
2023-09-01 17:17:45 +08:00
|
|
|
|
{
|
|
|
|
|
int matched = 0;
|
|
|
|
|
|
2023-09-06 19:05:13 +08:00
|
|
|
|
const char** target = NULL;
|
2023-09-01 17:17:45 +08:00
|
|
|
|
int k = 0;
|
|
|
|
|
const char* alias = NULL;
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<size; i++) {
|
|
|
|
|
target = array[i];
|
|
|
|
|
alias = target[k];
|
|
|
|
|
while (NULL!=alias) {
|
|
|
|
|
if (xy_streql(input, alias)) {
|
|
|
|
|
matched = 1; break;
|
|
|
|
|
}
|
|
|
|
|
k++;
|
|
|
|
|
alias = target[k];
|
|
|
|
|
}
|
|
|
|
|
if (!matched) k = 0;
|
|
|
|
|
if (matched) break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 18:47:49 +08:00
|
|
|
|
if (!matched) {
|
2023-09-02 19:38:32 +08:00
|
|
|
|
*target_info = NULL;
|
2023-09-01 17:17:45 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
k++;
|
|
|
|
|
alias = target[k];
|
|
|
|
|
} while (NULL!=alias);
|
2023-09-02 19:38:32 +08:00
|
|
|
|
*target_info = target + k + 1;
|
2023-09-01 17:17:45 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-02 19:38:32 +08:00
|
|
|
|
#define iterate_targets(ary, input, target) iterate_targets_(ary, xy_arylen(ary), input, target)
|
2023-09-01 17:17:45 +08:00
|
|
|
|
|
2023-09-02 20:02:59 +08:00
|
|
|
|
#define Target_Set_Source 1
|
|
|
|
|
#define Target_Get_Source 2
|
|
|
|
|
#define Target_Cesu_Source 3
|
|
|
|
|
#define Target_List_Source 4
|
2023-09-01 17:17:45 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 寻找target,并根据`code`执行相应的操作
|
|
|
|
|
*
|
2023-09-05 14:17:31 +08:00
|
|
|
|
* @param input 用户输入的目标
|
|
|
|
|
* @param code 对target要执行的操作
|
|
|
|
|
* @param option 额外的指示,可为NULL
|
2023-09-01 17:17:45 +08:00
|
|
|
|
*
|
|
|
|
|
* @return 找到目标返回true,未找到返回false
|
|
|
|
|
*/
|
|
|
|
|
bool
|
2023-09-03 17:57:45 +08:00
|
|
|
|
get_target (const char* input, int code, char* option)
|
2023-09-01 17:17:45 +08:00
|
|
|
|
{
|
2023-09-06 19:05:13 +08:00
|
|
|
|
const char** target_tmp = NULL;
|
2023-09-01 17:17:45 +08:00
|
|
|
|
|
2023-09-02 19:38:32 +08:00
|
|
|
|
bool matched = iterate_targets(pl_packagers, input, &target_tmp);
|
|
|
|
|
if (!matched) matched = iterate_targets(os_systems, input, &target_tmp);
|
|
|
|
|
if (!matched) matched = iterate_targets(wr_softwares, input, &target_tmp);
|
2023-09-01 17:17:45 +08:00
|
|
|
|
|
|
|
|
|
if (!matched) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-02 19:38:32 +08:00
|
|
|
|
target_info* target = (target_info*) *target_tmp;
|
|
|
|
|
|
2023-09-04 09:01:33 +08:00
|
|
|
|
if (Target_Set_Source==code)
|
|
|
|
|
{
|
2023-09-03 17:57:45 +08:00
|
|
|
|
if (target->setfn) target->setfn(option);
|
2023-09-05 15:53:06 +08:00
|
|
|
|
else xy_error (xy_strjoin(3, "chsrc: 暂未对 ", input, " 实现set功能,欢迎贡献"));
|
2023-09-01 17:17:45 +08:00
|
|
|
|
}
|
2023-09-04 09:01:33 +08:00
|
|
|
|
else if (Target_Get_Source==code)
|
|
|
|
|
{
|
2023-09-02 20:02:59 +08:00
|
|
|
|
if (target->getfn) target->getfn("");
|
2023-09-05 15:53:06 +08:00
|
|
|
|
else xy_error (xy_strjoin(3, "chsrc: 暂未对 ", input, " 实现get功能,欢迎贡献"));
|
2023-09-01 17:17:45 +08:00
|
|
|
|
}
|
2023-09-04 09:01:33 +08:00
|
|
|
|
else if (Target_List_Source==code)
|
|
|
|
|
{
|
2023-09-05 15:53:06 +08:00
|
|
|
|
xy_info (xy_strjoin(3,"chsrc: 对 ", input ," 支持以下镜像站,荣耀均归属于这些站点,以及它们的开发/维护者们"));
|
|
|
|
|
xy_warn (xy_strjoin(3, "chsrc: 下方 code 列,可用于指定使用某源,请使用 chsrc set ", input, " <code>"));
|
2023-09-03 16:42:17 +08:00
|
|
|
|
printf ("%-14s%-35s%-45s ", "code", "服务商缩写", "服务源URL"); puts("服务商名称");
|
|
|
|
|
puts ("--------------------------------------------------------------------------------------------------------");
|
2023-09-09 16:56:03 +08:00
|
|
|
|
print_supported_sources_for_target (target->sources, target->sources_n);
|
2023-09-01 17:17:45 +08:00
|
|
|
|
}
|
2023-09-04 09:01:33 +08:00
|
|
|
|
else if (Target_Cesu_Source==code)
|
|
|
|
|
{
|
|
|
|
|
char* check_cmd = xy_str_to_quietcmd("curl --version");
|
|
|
|
|
bool exist_b = does_the_program_exist (check_cmd, "curl");
|
2023-09-04 19:19:30 +08:00
|
|
|
|
if (!exist_b) {
|
|
|
|
|
xy_error ("chsrc: 没有curl命令,无法测速");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2023-09-27 09:40:31 +08:00
|
|
|
|
auto_select_ (target->sources, target->sources_n, input-3);
|
2023-09-04 09:01:33 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
2023-09-02 20:02:59 +08:00
|
|
|
|
}
|
2023-09-01 17:17:45 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-08-28 22:21:33 +08:00
|
|
|
|
int
|
2023-08-29 15:54:21 +08:00
|
|
|
|
main (int argc, char const *argv[])
|
2023-08-28 22:21:33 +08:00
|
|
|
|
{
|
2023-08-31 19:51:19 +08:00
|
|
|
|
xy_useutf8(); argc -= 1;
|
2023-08-29 21:58:51 +08:00
|
|
|
|
|
2023-08-31 19:51:19 +08:00
|
|
|
|
if (argc==0) {
|
2023-08-28 22:21:33 +08:00
|
|
|
|
print_help(); return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 20:24:06 +08:00
|
|
|
|
const char* command = argv[1];
|
|
|
|
|
|
2023-09-01 17:17:45 +08:00
|
|
|
|
bool matched = false;
|
|
|
|
|
|
2023-08-31 20:24:06 +08:00
|
|
|
|
/* chsrc help */
|
2023-09-01 17:21:42 +08:00
|
|
|
|
if (xy_streql(command, "h") ||
|
|
|
|
|
xy_streql(command, "-h") ||
|
2023-08-31 20:24:06 +08:00
|
|
|
|
xy_streql(command, "help") ||
|
|
|
|
|
xy_streql(command, "--help"))
|
|
|
|
|
{
|
|
|
|
|
print_help();
|
|
|
|
|
return 0;
|
2023-08-28 23:10:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 20:24:06 +08:00
|
|
|
|
/* chsrc list */
|
2023-09-01 17:38:59 +08:00
|
|
|
|
else if (xy_streql(command, "list") ||
|
|
|
|
|
xy_streql(command, "l") ||
|
|
|
|
|
xy_streql(command, "ls"))
|
2023-08-31 20:24:06 +08:00
|
|
|
|
{
|
|
|
|
|
if (argc < 2) {
|
2023-08-31 21:40:32 +08:00
|
|
|
|
print_available_mirrors();
|
|
|
|
|
puts("");
|
|
|
|
|
print_supported_targets();
|
2023-08-31 20:24:06 +08:00
|
|
|
|
} else {
|
2023-09-01 17:38:59 +08:00
|
|
|
|
|
|
|
|
|
if (xy_streql(argv[2],"mirrors")) {
|
|
|
|
|
print_available_mirrors(); return 0;
|
|
|
|
|
}
|
|
|
|
|
if (xy_streql(argv[2],"mirror")) {
|
|
|
|
|
print_available_mirrors(); return 0;
|
|
|
|
|
}
|
|
|
|
|
if (xy_streql(argv[2],"targets")) {
|
|
|
|
|
print_supported_targets(); return 0;
|
|
|
|
|
}
|
|
|
|
|
if (xy_streql(argv[2],"target")) {
|
|
|
|
|
print_supported_targets(); return 0;
|
|
|
|
|
}
|
2023-09-17 13:28:50 +08:00
|
|
|
|
if (xy_streql(argv[2],"os")) {
|
|
|
|
|
print_supported_os(); return 0;
|
|
|
|
|
}
|
|
|
|
|
if (xy_streql(argv[2],"lang")) {
|
|
|
|
|
print_supported_pl(); return 0;
|
|
|
|
|
}
|
|
|
|
|
if (xy_streql(argv[2],"pl")) {
|
|
|
|
|
print_supported_pl(); return 0;
|
|
|
|
|
}
|
|
|
|
|
if (xy_streql(argv[2],"language")) {
|
|
|
|
|
print_supported_pl(); return 0;
|
|
|
|
|
}
|
|
|
|
|
if (xy_streql(argv[2],"software")) {
|
|
|
|
|
print_supported_wr(); return 0;
|
|
|
|
|
}
|
|
|
|
|
if (xy_streql(argv[2],"ware")) {
|
|
|
|
|
print_supported_wr(); return 0;
|
|
|
|
|
}
|
2023-09-03 17:57:45 +08:00
|
|
|
|
matched = get_target(argv[2], Target_List_Source, NULL);
|
2023-09-01 17:17:45 +08:00
|
|
|
|
if (!matched) goto not_matched;
|
2023-08-31 20:24:06 +08:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* chsrc cesu */
|
2023-09-01 17:38:59 +08:00
|
|
|
|
else if (xy_streql(command, "cesu") ||
|
|
|
|
|
xy_streql(command, "ce") ||
|
|
|
|
|
xy_streql(command, "c"))
|
2023-08-31 20:24:06 +08:00
|
|
|
|
{
|
|
|
|
|
if (argc < 2) {
|
2023-09-01 17:38:59 +08:00
|
|
|
|
xy_error ("chsrc: 请您提供想要测速源的软件名; 使用 chsrc list targets 查看所有支持的软件");
|
2023-08-31 20:24:06 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2023-09-03 17:57:45 +08:00
|
|
|
|
matched = get_target(argv[2], Target_Cesu_Source, NULL);
|
2023-09-02 20:02:59 +08:00
|
|
|
|
if (!matched) goto not_matched;
|
2023-08-31 20:24:06 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* chsrc get */
|
2023-09-01 17:38:59 +08:00
|
|
|
|
else if (xy_streql(command, "get") ||
|
|
|
|
|
xy_streql(command, "g"))
|
2023-08-31 20:24:06 +08:00
|
|
|
|
{
|
|
|
|
|
if (argc < 2) {
|
2023-09-01 17:38:59 +08:00
|
|
|
|
xy_error ("chsrc: 请您提供想要查看源的软件名; 使用 chsrc list targets 查看所有支持的软件");
|
2023-08-31 20:24:06 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2023-09-03 17:57:45 +08:00
|
|
|
|
matched = get_target(argv[2], Target_Get_Source, NULL);
|
2023-09-01 17:17:45 +08:00
|
|
|
|
if (!matched) goto not_matched;
|
2023-08-31 20:24:06 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* chsrc set */
|
2023-09-01 17:38:59 +08:00
|
|
|
|
else if (xy_streql(command, "set") ||
|
|
|
|
|
xy_streql(command, "s"))
|
2023-08-31 20:24:06 +08:00
|
|
|
|
{
|
|
|
|
|
if (argc < 2) {
|
2023-09-01 17:38:59 +08:00
|
|
|
|
xy_error ("chsrc: 请您提供想要设置源的软件名; 使用 chsrc list targets 查看所有支持的软件");
|
2023-08-31 20:24:06 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2023-09-03 17:57:45 +08:00
|
|
|
|
|
|
|
|
|
char* option = NULL;
|
|
|
|
|
if (argc >= 3) {
|
|
|
|
|
option = (char*) argv[3]; // 暂时我们只接受最多三个参数
|
|
|
|
|
}
|
|
|
|
|
matched = get_target(argv[2], Target_Set_Source, option);
|
2023-09-01 17:17:45 +08:00
|
|
|
|
if (!matched) goto not_matched;
|
2023-08-31 20:24:06 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 不支持的命令 */
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
xy_error ("chsrc: 不支持的命令,请使用 chsrc help 查看使用方式");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-01 17:17:45 +08:00
|
|
|
|
not_matched:
|
2023-08-29 23:07:48 +08:00
|
|
|
|
if (!matched) {
|
2023-09-01 17:38:59 +08:00
|
|
|
|
xy_info("chsrc: 暂不支持的换源目标,请使用 chsrc list targets 查看可换源软件");
|
2023-09-01 17:17:45 +08:00
|
|
|
|
return 1;
|
2023-08-29 23:07:48 +08:00
|
|
|
|
}
|
2023-08-28 22:21:33 +08:00
|
|
|
|
}
|