2023-09-09 16:49:06 +08:00
|
|
|
/** ------------------------------------------------------------
|
2024-06-11 20:18:02 +08:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2024-07-31 12:38:52 +08:00
|
|
|
* Copyright © 2023-2024 Aoran Zeng, Heng Guo
|
2024-06-11 20:18:02 +08:00
|
|
|
* -------------------------------------------------------------
|
2024-08-15 20:51:36 +08:00
|
|
|
* Project Authors : Aoran Zeng <ccmywish@qq.com>
|
|
|
|
* | Heng Guo <2085471348@qq.com>
|
|
|
|
* Contributors : Aaron Ruan <aaron212cn@outlook.com>
|
|
|
|
* | Rui Chen <rui@chenrui.dev>
|
|
|
|
* | Shengwei Chen <414685209@qq.com>
|
|
|
|
* | BlockLune <blocklune@gmail.com>
|
|
|
|
* |
|
|
|
|
* Created On : <2023-08-28>
|
|
|
|
* Last Modified : <2024-08-15>
|
2023-09-09 16:49:06 +08:00
|
|
|
*
|
2024-06-11 20:18:02 +08:00
|
|
|
* chsrc: Change Source —— 全平台通用命令行换源工具
|
2023-09-09 16:49:06 +08:00
|
|
|
* ------------------------------------------------------------*/
|
2023-08-29 15:54:21 +08:00
|
|
|
|
2024-08-09 03:30:30 +08:00
|
|
|
#define Chsrc_Version "v0.1.7.2.dev1-2024/08/09"
|
2024-07-24 18:42:08 +08:00
|
|
|
#define Chsrc_Maintain_URL "https://github.com/RubyMetric/chsrc"
|
|
|
|
#define Chsrc_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc"
|
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
|
|
|
|
2024-08-09 02:16:09 +08:00
|
|
|
#include "recipe/lang/ruby.c"
|
2024-08-08 19:08:47 +08:00
|
|
|
#include "recipe/lang/python.c"
|
2024-08-09 02:33:10 +08:00
|
|
|
#include "recipe/lang/nodejs.c"
|
2024-08-09 02:52:42 +08:00
|
|
|
#include "recipe/lang/perl.c"
|
2024-08-09 02:55:15 +08:00
|
|
|
#include "recipe/lang/php.c"
|
2024-08-09 02:20:15 +08:00
|
|
|
#include "recipe/lang/lua.c"
|
2024-08-09 02:27:53 +08:00
|
|
|
#include "recipe/lang/go.c"
|
2024-08-09 02:58:24 +08:00
|
|
|
#include "recipe/lang/java.c"
|
2024-08-09 03:04:04 +08:00
|
|
|
#include "recipe/lang/rust.c"
|
2023-08-31 15:54:47 +08:00
|
|
|
|
|
|
|
|
2023-09-03 20:49:55 +08:00
|
|
|
void
|
2024-06-14 00:17:21 +08:00
|
|
|
pl_dotnet_getsrc (char *option)
|
2023-09-03 20:49:55 +08:00
|
|
|
{
|
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
|
2024-06-14 00:17:21 +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-04 20:27:37 +08:00
|
|
|
|
2023-09-10 18:44:34 +08:00
|
|
|
void
|
2024-04-18 23:16:50 +08:00
|
|
|
pl_clojure_setsrc (char *option)
|
2023-09-10 18:44:34 +08:00
|
|
|
{
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (pl_clojure);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-10 18:44:34 +08:00
|
|
|
|
2024-08-08 17:34:41 +08:00
|
|
|
chsrc_note2 ("抱歉,Clojure换源较复杂,您可手动查阅并换源:");
|
2024-04-18 23:16:50 +08:00
|
|
|
puts (source.url);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeManual);
|
2023-09-10 18:44:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-08-15 21:22:46 +08:00
|
|
|
#include "recipe/lang/dart.c"
|
2024-08-15 21:19:31 +08:00
|
|
|
#include "recipe/lang/haskell.c"
|
2024-08-15 21:00:08 +08:00
|
|
|
#include "recipe/lang/ocaml.c"
|
2024-08-15 21:04:49 +08:00
|
|
|
#include "recipe/lang/r.c"
|
2024-08-15 21:14:10 +08:00
|
|
|
#include "recipe/lang/julia.c"
|
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"
|
2024-06-11 17:36:16 +08:00
|
|
|
#define ETC_OSRELEASE "/etc/os-release"
|
|
|
|
|
2024-06-11 21:02:24 +08:00
|
|
|
#define Debian_debian 1
|
|
|
|
#define Debian_deriv_ubuntu 2
|
2024-06-11 17:36:16 +08:00
|
|
|
|
|
|
|
/**
|
2024-06-11 21:02:24 +08:00
|
|
|
* 当不存在该文件时,我们只能拼凑一个假的出来,但该函数目前只适用于 Ubuntu 和 Debian
|
2024-06-11 17:36:16 +08:00
|
|
|
* 因为其它的 Debian 变体可能不使用 ETC_APT_SOURCELIST,也可能并不适用 `VERSION_CODENAME`
|
2024-06-11 21:02:24 +08:00
|
|
|
*
|
|
|
|
* @return 文件是否存在
|
2024-06-11 17:36:16 +08:00
|
|
|
*/
|
2024-06-11 21:02:24 +08:00
|
|
|
bool
|
|
|
|
ensure_apt_sourcelist (int debian_type)
|
2024-06-11 17:36:16 +08:00
|
|
|
{
|
2024-06-14 15:15:59 +08:00
|
|
|
bool exist = chsrc_check_file (ETC_APT_SOURCELIST);
|
2024-06-11 17:36:16 +08:00
|
|
|
|
|
|
|
if (exist)
|
|
|
|
{
|
2024-06-11 21:02:24 +08:00
|
|
|
return true;
|
2024-06-11 17:36:16 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("将生成新的源配置文件");
|
2024-06-11 17:36:16 +08:00
|
|
|
}
|
|
|
|
|
2024-06-11 21:38:58 +08:00
|
|
|
// 反向引用需要escape一下
|
|
|
|
char *codename = xy_run ("sed -nr 's/VERSION_CODENAME=(.*)/\\1/p' " ETC_OSRELEASE, 0, NULL);
|
2024-06-11 17:49:35 +08:00
|
|
|
codename = xy_str_delete_suffix (codename, "\n");
|
2024-06-11 17:36:16 +08:00
|
|
|
|
2024-06-14 14:34:02 +08:00
|
|
|
char *version_id = xy_run ("sed -nr 's/VERSION_ID=(.*)/\\1/p' " ETC_OSRELEASE, 0, NULL);
|
|
|
|
version_id = xy_str_delete_suffix (codename, "\n");
|
|
|
|
double version = atof (version_id);
|
|
|
|
|
2024-06-11 21:02:24 +08:00
|
|
|
char *makeup = NULL;
|
|
|
|
|
|
|
|
if (debian_type == Debian_deriv_ubuntu)
|
|
|
|
{
|
2024-06-11 21:14:44 +08:00
|
|
|
makeup = xy_strjoin (9,
|
2024-06-21 02:08:14 +08:00
|
|
|
"# Generated by chsrc " Chsrc_Version "\n\n"
|
2024-06-11 21:14:44 +08:00
|
|
|
"deb " Chsrc_Maintain_URL "/ubuntu ", codename, " main restricted universe multiverse\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/ubuntu ", codename, "-updates main restricted universe multiverse\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/ubuntu ", codename, "-backports main restricted universe multiverse\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/ubuntu ", codename, "-security main restricted universe multiverse\n");
|
2024-06-11 21:02:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-06-14 14:34:02 +08:00
|
|
|
if (version >= 12)
|
|
|
|
{
|
|
|
|
// https://wiki.debian.org/SourcesList
|
|
|
|
// https://mirrors.tuna.tsinghua.edu.cn/help/debian/
|
|
|
|
// 从 Debian 12 开始,开始有一项 non-free-firmware
|
|
|
|
makeup = xy_strjoin (9,
|
2024-06-21 02:08:14 +08:00
|
|
|
"# Generated by chsrc " Chsrc_Version "\n\n"
|
2024-06-14 14:34:02 +08:00
|
|
|
"deb " Chsrc_Maintain_URL "/debian ", codename, " main contrib non-free non-free-firmware\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/debian ", codename, "-updates main contrib non-free non-free-firmware\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/debian ", codename, "-backports main contrib non-free non-free-firmware\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/debian-security ", codename, "-security main contrib non-free non-free-firmware\n");
|
|
|
|
// 上述 debian-security 这种写法是和 Debian 10不同的,所以我们只能支持 Debian 11+
|
|
|
|
}
|
|
|
|
else if (version >= 11)
|
|
|
|
{
|
|
|
|
makeup = xy_strjoin (9,
|
2024-06-11 21:14:44 +08:00
|
|
|
"# Generated by chsrc " Chsrc_Version "(" Chsrc_Maintain_URL ")\n\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/debian ", codename, " main contrib non-free\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/debian ", codename, "-updates main contrib non-free\n"
|
2024-06-14 14:34:02 +08:00
|
|
|
"deb " Chsrc_Maintain_URL "/debian ", codename, "-backports main contrib non-free\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/debian-security ", codename, "-security main contrib non-free\n");
|
|
|
|
}
|
|
|
|
else if (version >= 10)
|
|
|
|
{
|
|
|
|
makeup = xy_strjoin (9,
|
|
|
|
"# Generated by chsrc " Chsrc_Version "(" Chsrc_Maintain_URL ")\n\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/debian ", codename, " main contrib non-free\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/debian ", codename, "-updates main contrib non-free\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/debian ", codename, "-backports main contrib non-free\n"
|
|
|
|
"deb " Chsrc_Maintain_URL "/debian-security ", codename, "/updates main contrib non-free\n");
|
|
|
|
// 上述 debian-security 这种写法是和 Debian 11 不同的
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
chsrc_error ("您的Debian版本过低(<10),暂不支持换源");
|
2024-06-14 15:01:52 +08:00
|
|
|
exit (Exit_Unsupported);
|
2024-06-14 14:34:02 +08:00
|
|
|
}
|
2024-06-11 21:02:24 +08:00
|
|
|
}
|
2024-06-11 17:36:16 +08:00
|
|
|
|
|
|
|
FILE *f = fopen (ETC_APT_SOURCELIST, "w");
|
2024-06-11 21:02:24 +08:00
|
|
|
fwrite (makeup, strlen (makeup), 1, f);
|
2024-06-11 17:36:16 +08:00
|
|
|
fclose (f);
|
2024-06-11 21:02:24 +08:00
|
|
|
return false;
|
2024-06-11 17:36:16 +08:00
|
|
|
}
|
|
|
|
|
2023-09-29 20:15:32 +08:00
|
|
|
|
|
|
|
|
2024-06-12 23:58:57 +08:00
|
|
|
/**
|
2024-06-14 14:34:02 +08:00
|
|
|
* @note 从 Debian 12 开始,Debain 的软件源配置文件变更为 DEB822 格式,
|
|
|
|
* 路径为: /etc/apt/sources.list.d/debian.sources"
|
|
|
|
*
|
|
|
|
* @note 从 Ubuntu 24.04 开始,Ubuntu 的软件源配置文件变更为 DEB822 格式,
|
2024-06-12 23:58:57 +08:00
|
|
|
* 路径为: /etc/apt/sources.list.d/ubuntu.sources
|
|
|
|
*/
|
2024-06-14 14:34:02 +08:00
|
|
|
#define ETC_APT_DEB822_Debian_Sources "/etc/apt/sources.list.d/debian.sources"
|
|
|
|
#define ETC_APT_DEB822_Ubuntu_Sources "/etc/apt/sources.list.d/ubuntu.sources"
|
2024-06-12 23:58:57 +08:00
|
|
|
|
2023-09-17 11:33:30 +08:00
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_ubuntu_getsrc (char *option)
|
2023-09-17 11:33:30 +08:00
|
|
|
{
|
2024-06-14 15:15:59 +08:00
|
|
|
if (chsrc_check_file (ETC_APT_DEB822_Ubuntu_Sources))
|
2024-06-12 23:58:57 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file (ETC_APT_DEB822_Ubuntu_Sources);
|
2024-06-12 23:58:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-14 15:15:59 +08:00
|
|
|
if (chsrc_check_file (ETC_APT_SOURCELIST))
|
2024-06-13 00:39:31 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file (ETC_APT_SOURCELIST);
|
2024-06-13 00:39:31 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_error2 ("缺少源配置文件!但仍可直接通过 chsrc set ubuntu 来添加使用新的源");
|
2024-06-13 00:39:31 +08:00
|
|
|
return;
|
2023-09-17 11:33:30 +08:00
|
|
|
}
|
|
|
|
|
2024-06-12 23:58:57 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 此函数基本和 os_ubuntu_setsrc() 一致
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
os_ubuntu_setsrc_for_deb822 (char *option)
|
|
|
|
{
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_ubuntu);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2024-06-12 23:58:57 +08:00
|
|
|
|
2024-06-14 14:34:02 +08:00
|
|
|
chsrc_backup (ETC_APT_DEB822_Ubuntu_Sources);
|
2024-06-12 23:58:57 +08:00
|
|
|
|
2024-06-21 10:55:43 +08:00
|
|
|
char *arch = chsrc_get_cpuarch ();
|
2024-06-12 23:58:57 +08:00
|
|
|
char *cmd = NULL;
|
|
|
|
if (strncmp (arch, "x86_64", 6)==0)
|
|
|
|
{
|
2024-06-14 14:34:02 +08:00
|
|
|
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " ETC_APT_DEB822_Ubuntu_Sources);
|
2024-06-12 23:58:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-06-14 14:34:02 +08:00
|
|
|
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " ETC_APT_DEB822_Ubuntu_Sources);
|
2024-06-12 23:58:57 +08:00
|
|
|
}
|
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-12 23:58:57 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
|
|
|
}
|
|
|
|
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
os_ubuntu_setsrc (char *option)
|
2023-08-30 14:24:26 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-22 13:07:49 +08:00
|
|
|
|
2024-06-14 15:15:59 +08:00
|
|
|
if (chsrc_check_file (ETC_APT_DEB822_Ubuntu_Sources))
|
2024-06-12 23:58:57 +08:00
|
|
|
{
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("将基于新格式换源");
|
2024-06-12 23:58:57 +08:00
|
|
|
os_ubuntu_setsrc_for_deb822 (option);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-11 21:02:24 +08:00
|
|
|
bool sourcelist_exist = ensure_apt_sourcelist (Debian_deriv_ubuntu);
|
2024-06-11 17:36:16 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_ubuntu);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-08-30 20:05:03 +08:00
|
|
|
|
2024-06-11 21:02:24 +08:00
|
|
|
// 不存在的时候,用的是我们生成的无效文件,不要备份
|
|
|
|
if (sourcelist_exist)
|
|
|
|
{
|
|
|
|
chsrc_backup (ETC_APT_SOURCELIST);
|
|
|
|
}
|
2023-08-30 14:24:26 +08:00
|
|
|
|
2024-06-21 10:55:43 +08:00
|
|
|
char *arch = chsrc_get_cpuarch ();
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = NULL;
|
2024-06-21 10:55:43 +08:00
|
|
|
if (0==strncmp (arch, "x86_64", 6))
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-06-11 21:02:24 +08:00
|
|
|
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu/?@", source.url, "@g\' " ETC_APT_SOURCELIST);
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-06-11 21:02:24 +08:00
|
|
|
cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/ubuntu-ports/?@", source.url, "-ports@g\' " ETC_APT_SOURCELIST);
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2023-09-05 18:58:08 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
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
|
2024-06-12 23:58:57 +08:00
|
|
|
os_mint_getsrc (char *option)
|
2023-09-29 19:49:31 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file ("/etc/apt/sources.list.d/official-package-repositories.list");
|
2023-09-29 19:49:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/linuxmint/
|
|
|
|
*/
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_mint_setsrc (char *option)
|
2023-09-29 19:49:31 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-29 19:49:31 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_mint);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-29 19:49:31 +08:00
|
|
|
|
|
|
|
chsrc_backup ("/etc/apt/sources.list.d/official-package-repositories.list");
|
|
|
|
|
2024-04-25 16:33:17 +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");
|
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
2024-08-08 17:34:41 +08:00
|
|
|
chsrc_warn2 ("完成后请不要再使用 mintsources(自带的图形化软件源设置工具)进行任何操作,因为在操作后,无论是否有按“确定”,mintsources 均会覆写我们刚才换源的内容");
|
2023-09-29 19:49:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-17 11:33:30 +08:00
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_debian_getsrc (char *option)
|
2023-09-17 11:33:30 +08:00
|
|
|
{
|
2024-06-14 15:15:59 +08:00
|
|
|
if (chsrc_check_file (ETC_APT_DEB822_Debian_Sources))
|
2024-06-14 14:34:02 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file (ETC_APT_DEB822_Debian_Sources);
|
2024-06-14 14:34:02 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-14 15:15:59 +08:00
|
|
|
if (chsrc_check_file (ETC_APT_SOURCELIST))
|
2024-06-14 14:34:02 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file (ETC_APT_SOURCELIST);
|
2024-06-14 14:34:02 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_error2 ("缺少源配置文件!但仍可直接通过 chsrc set debian 来添加使用新的源");
|
2024-06-14 14:34:02 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
os_debian_setsrc_for_deb822 (char *option)
|
|
|
|
{
|
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_debian);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2024-06-14 14:34:02 +08:00
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并需要您运行:");
|
2024-06-14 14:34:02 +08:00
|
|
|
puts ("apt install apt-transport-https ca-certificates");
|
|
|
|
|
|
|
|
chsrc_backup (ETC_APT_DEB822_Debian_Sources);
|
|
|
|
|
2024-07-08 18:29:35 +08:00
|
|
|
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/debian/?@", source.url, "@g' " ETC_APT_DEB822_Debian_Sources);
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2024-06-14 14:34:02 +08:00
|
|
|
|
|
|
|
// debian-security 源和其他源不一样
|
2024-07-08 18:29:35 +08:00
|
|
|
cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/debian-security/?@", source.url, "-security@g' " ETC_APT_DEB822_Debian_Sources);
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2024-06-14 14:34:02 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-14 14:34:02 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
2023-09-17 11:33:30 +08:00
|
|
|
}
|
|
|
|
|
2024-06-14 14:34:02 +08:00
|
|
|
|
2023-09-06 16:39:29 +08:00
|
|
|
/**
|
2024-06-14 14:34:02 +08:00
|
|
|
* Debian 10 Buster 以上版本默认支持 HTTPS 源。如果遇到无法拉取 HTTPS 源的情况,请先使用 HTTP 源并安装
|
2024-06-08 06:11:49 +08:00
|
|
|
* apt install apt-transport-https ca-certificates
|
2023-09-06 16:39:29 +08:00
|
|
|
*/
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_debian_setsrc (char *option)
|
2023-09-06 16:39:29 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-06 16:39:29 +08:00
|
|
|
|
2024-06-14 15:15:59 +08:00
|
|
|
if (chsrc_check_file (ETC_APT_DEB822_Debian_Sources))
|
2024-06-14 14:34:02 +08:00
|
|
|
{
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("将基于新格式换源");
|
2024-06-14 14:34:02 +08:00
|
|
|
os_debian_setsrc_for_deb822 (option);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-11 21:02:24 +08:00
|
|
|
// Docker环境下,Debian镜像可能不存在该文件
|
|
|
|
bool sourcelist_exist = ensure_apt_sourcelist (Debian_debian);
|
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_debian);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-06 16:39:29 +08:00
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并需要您运行:");
|
2024-06-08 06:11:49 +08:00
|
|
|
puts ("apt install apt-transport-https ca-certificates");
|
2023-09-17 11:33:30 +08:00
|
|
|
|
2024-06-11 21:02:24 +08:00
|
|
|
// 不存在的时候,用的是我们生成的无效文件,不要备份
|
|
|
|
if (sourcelist_exist)
|
|
|
|
{
|
|
|
|
chsrc_backup (ETC_APT_SOURCELIST);
|
|
|
|
}
|
2023-09-06 16:39:29 +08:00
|
|
|
|
2024-06-11 21:02:24 +08:00
|
|
|
char *cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/debian/?@", source.url, "@g\' " ETC_APT_SOURCELIST);
|
2023-09-17 11:33:30 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
2023-09-06 16:39:29 +08:00
|
|
|
}
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
os_raspberrypi_getsrc (char *option)
|
2023-09-29 20:51:13 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file ("/etc/apt/sources.list.d/raspi.list");
|
2023-09-29 20:51:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_raspberrypi_setsrc (char *option)
|
2023-09-29 20:51:13 +08:00
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
// chsrc_ensure_root(); // HELP: 不确定是否需要
|
2023-09-29 20:51:13 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_raspberrypi);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-29 20:51:13 +08:00
|
|
|
|
|
|
|
chsrc_backup ("/etc/apt/sources.list.d/raspi.list");
|
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/.*/?@", source.url,
|
2023-09-29 20:51:13 +08:00
|
|
|
"@g' /etc/apt/sources.list.d/raspi.list");
|
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-29 20:51:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-21 01:34:35 +08:00
|
|
|
#define OS_Armbian_SOURCELIST "/etc/apt/sources.list.d/armbian.list"
|
2024-06-21 01:24:46 +08:00
|
|
|
void
|
|
|
|
os_armbian_getsrc (char *option)
|
|
|
|
{
|
2024-06-21 01:34:35 +08:00
|
|
|
if (chsrc_check_file (OS_Armbian_SOURCELIST))
|
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file (OS_Armbian_SOURCELIST);
|
2024-06-21 01:34:35 +08:00
|
|
|
return;
|
|
|
|
}
|
2024-06-21 01:24:46 +08:00
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_error2 ("缺少源配置文件!路径:" OS_Armbian_SOURCELIST);
|
2024-06-21 01:24:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 参考: https://mirrors.tuna.tsinghua.edu.cn/help/armbian
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
os_armbian_setsrc (char *option)
|
|
|
|
{
|
|
|
|
chsrc_ensure_root ();
|
|
|
|
|
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_armbian);
|
|
|
|
chsrc_confirm_source (&source);
|
|
|
|
|
2024-06-21 01:34:35 +08:00
|
|
|
chsrc_backup (OS_Armbian_SOURCELIST);
|
2024-06-21 01:24:46 +08:00
|
|
|
|
|
|
|
char *cmd = xy_strjoin (3, "sed -E -i 's@https?[^ ]*armbian/?[^ ]*@", source.url,
|
2024-06-21 01:34:35 +08:00
|
|
|
"@g' " OS_Armbian_SOURCELIST);
|
2024-06-21 01:24:46 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-21 01:24:46 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
|
|
|
}
|
2024-06-21 01:34:35 +08:00
|
|
|
#undef OS_Armbian_SOURCELIST
|
2024-06-21 01:24:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-17 11:33:30 +08:00
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_deepin_getsrc(char *option)
|
2023-09-17 11:33:30 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_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
|
2024-04-25 16:33:17 +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
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_deepin);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&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
|
|
|
|
2024-06-14 00:17:21 +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
|
|
|
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
os_fedora_setsrc (char *option)
|
2023-09-03 12:01:43 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-05 20:04:38 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_fedora);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-03 12:01:43 +08:00
|
|
|
|
2024-08-08 17:34:41 +08:00
|
|
|
chsrc_note2 ("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
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char* cmd = xy_strjoin (9, "sed -e 's|^metalink=|#metalink=|g' ",
|
2023-09-03 12:01:43 +08:00
|
|
|
"-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
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2023-09-03 12:01:43 +08:00
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_log2 ("已替换文件 /etc/yum.repos.d/fedora.repo");
|
|
|
|
chsrc_log2 ("已新增文件 /etc/yum.repos.d/fedora-modular.repo");
|
|
|
|
chsrc_log2 ("已替换文件 /etc/yum.repos.d/fedora-updates.repo");
|
|
|
|
chsrc_log2 ("已新增文件 /etc/yum.repos.d/fedora-updates-modular.repo");
|
2023-09-03 12:01:43 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run ("dnf makecache", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
2023-09-03 12:01:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-24 20:32:33 +08:00
|
|
|
/**
|
|
|
|
* HELP: 未经测试
|
|
|
|
*/
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_opensuse_setsrc (char *option)
|
2023-09-24 20:32:33 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root (); // HELP: 不知道是否需要确保root权限
|
2023-09-24 20:32:33 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_opensuse);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *source_nselect = "zypper mr -da";
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (source_nselect, RunOpt_Default);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd1 = xy_strjoin (3,
|
2023-09-24 20:32:33 +08:00
|
|
|
"zypper ar -cfg '",
|
|
|
|
source.url,
|
|
|
|
"/opensuse/distribution/leap/$releasever/repo/oss/' mirror-oss");
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd2 = xy_strjoin (3,
|
2023-09-24 20:32:33 +08:00
|
|
|
"zypper ar -cfg '",
|
|
|
|
source.url,
|
|
|
|
"/opensuse/distribution/leap/$releasever/repo/non-oss/' mirror-non-oss");
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd3 = xy_strjoin (3,
|
2023-09-24 20:32:33 +08:00
|
|
|
"zypper ar -cfg '",
|
|
|
|
source.url,
|
|
|
|
"/opensuse/distribution/leap/$releasever/oss/' mirror-update");
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd4 = xy_strjoin (3,
|
2023-09-24 20:32:33 +08:00
|
|
|
"zypper ar -cfg '",
|
|
|
|
source.url,
|
|
|
|
"/opensuse/distribution/leap/$releasever/non-oss/' mirror-update-non-oss");
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd5 = xy_strjoin (3,
|
2023-09-24 20:32:33 +08:00
|
|
|
"zypper ar -cfg '",
|
|
|
|
source.url,
|
|
|
|
"/opensuse/distribution/leap/$releasever/sle/' mirror-sle-update");
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd6 = xy_strjoin (3,
|
2023-09-24 20:32:33 +08:00
|
|
|
"zypper ar -cfg '",
|
|
|
|
source.url,
|
|
|
|
"/opensuse/distribution/leap/$releasever/backports/' mirror-backports-update");
|
|
|
|
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd1, RunOpt_Default);
|
|
|
|
chsrc_run (cmd2, RunOpt_Default);
|
|
|
|
chsrc_run (cmd3, RunOpt_Default);
|
|
|
|
chsrc_run (cmd4, RunOpt_Default);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("leap 15.3用户还需要添加sle和backports源");
|
|
|
|
chsrc_note2 ("另外请确保系统在更新后仅启用了六个软件源,可以使用 zypper lr 检查软件源状态");
|
|
|
|
chsrc_note2 ("并使用 zypper mr -d 禁用多余的软件源");
|
2023-09-24 20:32:33 +08:00
|
|
|
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd5, RunOpt_Default);
|
|
|
|
chsrc_run (cmd6, RunOpt_Default);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-24 20:32:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-29 20:15:32 +08:00
|
|
|
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_kali_getsrc (char *option)
|
2023-09-29 20:15:32 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file (ETC_APT_SOURCELIST);
|
2023-09-29 20:15:32 +08:00
|
|
|
}
|
|
|
|
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
os_kali_setsrc (char *option)
|
2023-09-03 12:01:43 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-05 20:06:04 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_kali);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&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
|
|
|
|
2024-06-14 00:17:21 +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
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-14 00:17:21 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
os_msys2_setsrc (char *option)
|
2023-09-03 12:01:43 +08:00
|
|
|
{
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_msys2);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-05 20:11:31 +08:00
|
|
|
|
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
|
|
|
|
2024-06-08 08:35:07 +08:00
|
|
|
char *prev = xy_strjoin (3, "请针对你的架构下载安装此目录下的文件:",
|
2023-09-26 23:02:12 +08:00
|
|
|
source.url,
|
|
|
|
"distrib/<架构>/");
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 (prev);
|
2023-09-06 16:06:50 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = xy_strjoin (3, "sed -i \"s#https\?://mirror.msys2.org/#",
|
2024-06-08 12:38:41 +08:00
|
|
|
source.url,
|
|
|
|
"#g\" /etc/pacman.d/mirrorlist* ");
|
2023-09-17 11:26:31 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-01 22:23:03 +08:00
|
|
|
}
|
2023-08-30 20:34:01 +08:00
|
|
|
|
2023-09-17 11:26:31 +08:00
|
|
|
|
|
|
|
|
2024-07-03 14:04:21 +08:00
|
|
|
#define OS_Pacman_MirrorList "/etc/pacman.d/mirrorlist"
|
|
|
|
void
|
|
|
|
os_arch_getsrc (char *option)
|
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file (OS_Pacman_MirrorList);
|
2024-07-03 14:04:21 +08:00
|
|
|
}
|
|
|
|
|
2023-09-05 20:14:58 +08:00
|
|
|
/**
|
2024-07-03 12:38:49 +08:00
|
|
|
* 参考:
|
|
|
|
* 1. https://mirrors.tuna.tsinghua.edu.cn/help/archlinux/
|
|
|
|
* 2. https://mirrors.tuna.tsinghua.edu.cn/help/archlinuxarm/
|
2023-09-05 20:14:58 +08:00
|
|
|
*/
|
2023-09-05 16:32:56 +08:00
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_arch_setsrc (char *option)
|
2023-09-05 16:32:56 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-05 20:14:58 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_arch);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-05 20:14:58 +08:00
|
|
|
|
2024-07-03 12:38:49 +08:00
|
|
|
chsrc_backup (OS_Pacman_MirrorList);
|
2023-09-05 16:32:56 +08:00
|
|
|
|
2024-07-03 14:04:21 +08:00
|
|
|
bool is_x86 = false;
|
|
|
|
char *to_write = NULL;
|
2024-06-21 10:55:43 +08:00
|
|
|
char *arch = chsrc_get_cpuarch ();
|
2023-09-26 18:24:18 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
if (strncmp(arch, "x86_64", 6)==0)
|
|
|
|
{
|
2024-07-03 14:04:21 +08:00
|
|
|
is_x86 = true;
|
|
|
|
to_write = xy_strjoin (3, "Server = ", source.url, "/$repo/os/$arch");
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-07-03 14:04:21 +08:00
|
|
|
is_x86 = false;
|
|
|
|
to_write = xy_strjoin (3, "Server = ", source.url, "arm/$arch/$repo");
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2023-09-17 17:28:28 +08:00
|
|
|
|
2024-07-03 14:04:21 +08:00
|
|
|
// 越前面的优先级越高
|
|
|
|
chsrc_prepend_to_file (to_write, OS_Pacman_MirrorList);
|
2023-09-17 17:31:36 +08:00
|
|
|
|
2024-07-03 14:04:21 +08:00
|
|
|
if (is_x86)
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run ("pacman -Syyu", RunOpt_No_Last_New_Line);
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run ("pacman -Syy", RunOpt_No_Last_New_Line);
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-05 16:32:56 +08:00
|
|
|
}
|
|
|
|
|
2023-09-17 11:26:31 +08:00
|
|
|
|
2024-07-03 12:38:49 +08:00
|
|
|
void
|
|
|
|
os_archlinuxcn_getsrc (char *option)
|
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file (OS_Pacman_MirrorList);
|
2024-07-03 12:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 参考 https://mirrors.tuna.tsinghua.edu.cn/help/archlinuxcn/
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
os_archlinuxcn_setsrc (char *option)
|
|
|
|
{
|
|
|
|
chsrc_ensure_root ();
|
|
|
|
|
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_archlinuxcn);
|
|
|
|
chsrc_confirm_source (&source);
|
|
|
|
|
|
|
|
chsrc_backup (OS_Pacman_MirrorList);
|
|
|
|
|
|
|
|
bool arch_flag = false;
|
|
|
|
char *arch = chsrc_get_cpuarch ();
|
|
|
|
|
|
|
|
char *towrite = xy_strjoin (3, "[archlinuxcn]\nServer = ", source.url, "$arch");
|
2024-07-03 14:04:21 +08:00
|
|
|
// 越前面的优先级越高
|
|
|
|
chsrc_prepend_to_file (towrite, OS_Pacman_MirrorList);
|
2024-07-03 12:38:49 +08:00
|
|
|
|
2024-07-29 21:43:53 +08:00
|
|
|
chsrc_run ("pacman-key --lsign-key \"farseerfc@archlinux.org\"", RunOpt_Dont_Abort_On_Failure);
|
2024-07-03 14:04:21 +08:00
|
|
|
chsrc_run ("pacman -Sy archlinuxcn-keyring", RunOpt_Default);
|
2024-07-03 12:38:49 +08:00
|
|
|
|
|
|
|
chsrc_run ("pacman -Syy", RunOpt_No_Last_New_Line);
|
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
|
|
|
}
|
|
|
|
#undef OS_Pacman_MirrorList
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
os_gentoo_setsrc (char *option)
|
2023-09-05 16:32:56 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-05 20:19:15 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_gentoo);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-05 20:19:15 +08:00
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
chsrc_backup ("/etc/portage/repos.conf/gentoo.conf");
|
2023-09-05 16:32:56 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = xy_strjoin (3, "sed -i \"s#rsync://.*/gentoo-portage#rsync://",
|
2023-09-26 23:02:12 +08:00
|
|
|
source.url,
|
2023-09-05 21:03:58 +08:00
|
|
|
"gentoo-portage#g");
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2023-09-05 16:32:56 +08:00
|
|
|
|
2024-04-25 16:33:17 +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");
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-05 16:32:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-24 19:17:43 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/rocky/
|
|
|
|
*/
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_rocky_setsrc (char *option)
|
2023-09-24 19:17:43 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-24 19:17:43 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_rocky);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-24 19:17:43 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = xy_strjoin (3,
|
2024-06-08 06:11:49 +08:00
|
|
|
"sed -e 's|^mirrorlist=|#mirrorlist=|g' "
|
2023-09-24 19:17:43 +08:00
|
|
|
"-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"
|
|
|
|
);
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
|
|
|
chsrc_run ("dnf makecache", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-24 19:17:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-12 21:47:29 +08:00
|
|
|
/**
|
|
|
|
* 参考: https://developer.aliyun.com/mirror/almalinux
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
os_alma_setsrc (char *option)
|
|
|
|
{
|
|
|
|
chsrc_ensure_root ();
|
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_alma);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2024-06-12 21:47:29 +08:00
|
|
|
|
|
|
|
char *cmd = xy_strjoin (3,
|
|
|
|
"sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#\\s*baseurl=https://repo.almalinux.org/almalinux|baseurl=", source.url, "|g' -i.bak /etc/yum.repos.d/almalinux*.repo");
|
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
|
|
|
chsrc_run ("dnf makecache", RunOpt_No_Last_New_Line);
|
2024-08-08 17:17:11 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
2024-06-12 21:47:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-24 19:17:43 +08:00
|
|
|
|
2023-09-29 20:15:32 +08:00
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_alpine_getsrc (char *option)
|
2023-09-29 20:15:32 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file ("/etc/apk/repositories");
|
2023-09-29 20:15:32 +08:00
|
|
|
}
|
|
|
|
|
2023-09-24 20:01:46 +08:00
|
|
|
/**
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/alpine/
|
|
|
|
*/
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_alpine_setsrc (char *option)
|
2023-09-24 20:01:46 +08:00
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
// chsrc_ensure_root(); // HELP: 不确定是否需要root
|
2023-09-24 20:01:46 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_alpine);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-24 20:01:46 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char* cmd = xy_strjoin (3,
|
2023-09-24 20:01:46 +08:00
|
|
|
"sed -i 's#https\\?://dl-cdn.alpinelinux.org/alpine#", source.url, "#g' /etc/apk/repositories"
|
|
|
|
);
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2023-09-24 20:01:46 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run ("apk update", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-24 20:01:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-24 20:32:33 +08:00
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_void_getsrc (char *option)
|
2023-09-24 20:32:33 +08:00
|
|
|
{
|
|
|
|
char* cmd = "xbps-query -L";
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd, RunOpt_No_Last_New_Line);
|
2023-09-24 20:32:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/voidlinux/
|
|
|
|
*/
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_void_setsrc (char *option)
|
2023-09-24 20:32:33 +08:00
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
// chsrc_ensure_root(); // HELP: 不确定是否需要root
|
2023-09-24 20:32:33 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_void);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
2023-09-29 22:15:58 +08:00
|
|
|
chsrc_ensure_dir ("/etc/xbps.d");
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = "cp /usr/share/xbps.d/*-repository-*.conf /etc/xbps.d/";
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
cmd = xy_strjoin (3,
|
2023-09-24 20:32:33 +08:00
|
|
|
"sed -i 's|https://repo-default.voidlinux.org|", source.url, "|g' /etc/xbps.d/*-repository-*.conf"
|
|
|
|
);
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2023-09-24 20:32:33 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
cmd = xy_strjoin (3,
|
2023-09-24 20:32:33 +08:00
|
|
|
"sed -i 's|https://alpha.de.repo.voidlinux.org|", source.url, "|g' /etc/xbps.d/*-repository-*.conf"
|
|
|
|
);
|
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("若报错可尝试使用以下命令:");
|
2024-04-25 16:33:17 +08:00
|
|
|
puts (cmd);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-24 20:32:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-29 21:49:11 +08:00
|
|
|
/**
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/solus/
|
|
|
|
*/
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_solus_setsrc (char *option)
|
2023-09-29 21:49:11 +08:00
|
|
|
{
|
|
|
|
chsrc_ensure_root ();
|
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_solus);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-29 21:49:11 +08:00
|
|
|
|
2024-06-08 06:11:49 +08:00
|
|
|
char *cmd = xy_2strjoin ("eopkg add-repo Solus ", source.url);
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
2023-09-29 21:49:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
os_manjaro_setsrc (char *option)
|
2023-09-06 16:18:21 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2024-06-08 06:11:49 +08:00
|
|
|
char *cmd = "pacman-mirrors -i -c China -m rank";
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2023-09-06 16:18:21 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run ("pacman -Syy", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (NULL, ChsrcTypeAuto);
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
os_trisquel_getsrc (char *option)
|
2023-09-29 19:12:57 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file (ETC_APT_SOURCELIST);
|
2023-09-29 19:12:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/trisquel/
|
|
|
|
*/
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_trisquel_setsrc (char *option)
|
2023-09-29 19:12:57 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-29 19:12:57 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_trisquel);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-29 19:12:57 +08:00
|
|
|
|
2023-09-29 20:17:59 +08:00
|
|
|
chsrc_backup (ETC_APT_SOURCELIST);
|
2023-09-29 19:12:57 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/trisquel/?@", source.url, "@g' /etc/apt/sources.list");
|
2023-09-29 19:12:57 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-29 19:12:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-29 20:01:45 +08:00
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_linuxlite_getsrc (char *option)
|
2023-09-29 20:01:45 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file (ETC_APT_SOURCELIST);
|
2023-09-29 20:01:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 参考: https://help.mirrors.cernet.edu.cn/linuxliteos/
|
|
|
|
*/
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_linuxlite_setsrc (char *option)
|
2023-09-29 20:01:45 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-29 20:01:45 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_linuxlite);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-29 20:01:45 +08:00
|
|
|
|
2023-09-29 20:17:59 +08:00
|
|
|
chsrc_backup (ETC_APT_SOURCELIST);
|
2023-09-29 20:01:45 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/.*/?@", source.url, "@g' /etc/apt/sources.list");
|
2023-09-29 20:01:45 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
2023-09-29 20:01:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-08 18:30:28 +08:00
|
|
|
#include "./recipe/os/openwrt.c"
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
os_openeuler_setsrc (char *option)
|
2023-09-06 17:08:20 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-06 17:08:20 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_openeuler);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-06 17:08:20 +08:00
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
chsrc_backup ("/etc/yum.repos.d/openEuler.repo");
|
2023-09-06 17:08:20 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *towrite = xy_strjoin (3, "s#http://repo.openeuler.org#",
|
|
|
|
source.url,
|
|
|
|
"#\'< /etc/yum.repos.d/openEuler.repo.bak");
|
|
|
|
|
2023-09-26 22:33:20 +08:00
|
|
|
chsrc_overwrite_file (towrite, "/etc/yum.repos.d/openEuler.repo");
|
2023-09-06 17:08:20 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run ("dnf makecache", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
2023-09-06 17:08:20 +08:00
|
|
|
}
|
|
|
|
|
2023-09-17 11:26:31 +08:00
|
|
|
|
2024-06-12 23:18:19 +08:00
|
|
|
/**
|
|
|
|
* 参考: https://mirrors.hust.edu.cn/docs/anolis
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
os_anolis_setsrc (char *option)
|
|
|
|
{
|
|
|
|
chsrc_ensure_root ();
|
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_anolis);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2024-06-12 23:18:19 +08:00
|
|
|
|
|
|
|
char *cmd = xy_strjoin (3, "sed -i.bak -E 's|https?://(mirrors\\.openanolis\\.cn/anolis)|", source.url, "|g' /etc/yum.repos.d/*.repo");
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2024-06-12 23:18:19 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run ("dnf makecache", RunOpt_Default);
|
|
|
|
chsrc_run ("dnf update", RunOpt_No_Last_New_Line);
|
2024-06-12 23:18:19 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
|
|
|
}
|
|
|
|
|
2023-09-17 11:26:31 +08:00
|
|
|
|
2023-09-29 20:15:32 +08:00
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_openkylin_getsrc (char *option)
|
2023-09-29 20:15:32 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_file (ETC_APT_SOURCELIST);
|
2023-09-29 20:15:32 +08:00
|
|
|
}
|
|
|
|
|
2023-09-06 17:18:47 +08:00
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_openkylin_setsrc (char *option)
|
2023-09-06 17:18:47 +08:00
|
|
|
{
|
2023-09-29 21:28:02 +08:00
|
|
|
chsrc_ensure_root();
|
2023-09-06 17:18:47 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_openkylin);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-06 17:18:47 +08:00
|
|
|
|
2023-09-29 20:17:59 +08:00
|
|
|
chsrc_backup (ETC_APT_SOURCELIST);
|
2023-09-06 17:18:47 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/openkylin/?@", source.url, "@g'" ETC_APT_SOURCELIST);
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-06 17:18:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
os_freebsd_setsrc (char *option)
|
2023-09-17 16:56:25 +08:00
|
|
|
{
|
2024-06-08 06:11:49 +08:00
|
|
|
// 据 @ykla,FreeBSD不自带sudo,但是我们依然要保证是root权限
|
2024-06-14 01:02:23 +08:00
|
|
|
chsrc_ensure_root ();
|
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
|
|
|
|
2023-10-05 09:28:34 +08:00
|
|
|
SourceInfo source = os_freebsd_sources[index];
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-17 16:56:25 +08:00
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_log2 ("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
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *conf = xy_strjoin (3, "/usr/local/etc/pkg/repos/", source.mirror->code, ".conf");
|
2023-09-24 21:56:03 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *pkg_content = xy_strjoin (4,
|
2023-09-27 14:14:19 +08:00
|
|
|
source.mirror->code, ": { \n"
|
2023-10-05 17:22:54 +08:00
|
|
|
" url: \"http://", source.url, "/freebsd-pkg/${ABI}/latest\",\n"
|
|
|
|
"}\n"
|
|
|
|
"FreeBSD: { enabled: no }"
|
2023-09-27 14:14:19 +08:00
|
|
|
);
|
2023-09-17 16:56:25 +08:00
|
|
|
|
2023-09-29 22:15:58 +08:00
|
|
|
chsrc_overwrite_file (pkg_content, conf);
|
2024-08-08 17:34:41 +08:00
|
|
|
chsrc_note2 (
|
2023-09-29 22:15:58 +08:00
|
|
|
xy_strjoin (3, "若要使用季度分支,请在", conf ,"中将latest改为quarterly"));
|
2023-09-18 21:31:48 +08:00
|
|
|
|
2024-08-08 17:34:41 +08:00
|
|
|
chsrc_note2 ("若要使用HTTPS源,请先安装securtiy/ca_root_ns,并将'http'改成'https',最后使用'pkg update -f'刷新缓存即可\n");
|
2024-04-25 16:33:17 +08:00
|
|
|
puts ("");
|
2023-09-17 16:56:25 +08:00
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_log2 ("2. 修改 freebsd-ports 源");
|
2023-09-27 14:14:19 +08:00
|
|
|
// @ccmywish: [2023-09-27] 据 @ykla , NJU的freebsd-ports源没有设置 Git,
|
|
|
|
// 但是我认为由于使用Git还是要比非Git方便许多,我们尽可能坚持使用Git
|
|
|
|
// 而 gitup 又要额外修改它自己的配置,比较麻烦
|
2024-04-25 16:33:17 +08:00
|
|
|
bool git_exist = query_program_exist (xy_str_to_quietcmd ("git version"), "git");
|
|
|
|
if (git_exist)
|
|
|
|
{
|
|
|
|
if (xy_streql("nju",source.mirror->code))
|
|
|
|
{
|
|
|
|
source = os_freebsd_sources[index-1]; // 使用NJU的前一个源,即USTC源
|
|
|
|
}
|
|
|
|
char *git_cmd = xy_strjoin (3, "git clone --depth 1 https://", source.url, "/freebsd-ports/ports.git /usr/ports");
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (git_cmd, RunOpt_Default);
|
2024-04-25 16:33:17 +08:00
|
|
|
source = os_freebsd_sources[index]; // 恢复至选中的源
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("下次更新请使用 git -C /usr/ports pull 而非使用 gitup");
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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";
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (fetch, RunOpt_Default);
|
|
|
|
chsrc_run (unzip, RunOpt_Default);
|
|
|
|
chsrc_run (delete, RunOpt_Default);
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_log2 ("下次更新请重新下载内容至 /usr/ports");
|
2023-09-27 14:14:19 +08:00
|
|
|
}
|
2023-09-24 21:56:03 +08:00
|
|
|
|
2023-09-17 16:56:25 +08:00
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_log2 ("3. 指定 port 源");
|
2023-09-27 14:14:19 +08:00
|
|
|
// https://help.mirrors.cernet.edu.cn/FreeBSD-ports/
|
|
|
|
chsrc_backup ("/etc/make.conf");
|
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *ports = xy_strjoin (3, "MASTER_SITE_OVERRIDE?=http://", source.url, "/freebsd-ports/distfiles/${DIST_SUBDIR}/");
|
2023-09-27 14:14:19 +08:00
|
|
|
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
|
|
|
|
2024-06-08 15:13:37 +08:00
|
|
|
char *portsnap =xy_strjoin(3,"s@(.*)SERVERNAME=[\\.|a-z|A-Z]*@\\1SERVERNAME=", source.url,
|
2023-09-26 22:49:28 +08:00
|
|
|
"@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
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_log2 ("portsnap sources changed");
|
|
|
|
chsrc_log2 ("获取portsnap更新使用此命令: 'portsnap fetch extract'");
|
2023-09-24 21:56:03 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-09-26 22:49:28 +08:00
|
|
|
// HELP: 暂时没有源提供
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("4. 抱歉,目前境内无 freebsd-update 源,若存在请报告issue,谢谢");
|
2023-09-24 21:56:03 +08:00
|
|
|
/*
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_log2 ("3. 修改 freebsd-update 源");
|
2023-09-17 16:56:25 +08:00
|
|
|
|
2024-06-08 15:13:37 +08:00
|
|
|
char *update_cp = "cp /etc/freebsd-update.conf /etc/freebsd-update.conf.bak";
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (update_cp, RunOpt_Default);
|
2023-09-17 16:56:25 +08:00
|
|
|
|
2024-06-08 15:13:37 +08:00
|
|
|
char *update =xy_strjoin (3,"s@(.*)SERVERNAME [\\.|a-z|A-Z]*@\\1SERVERNAME ",
|
|
|
|
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
|
|
|
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeSemiAuto);
|
2023-09-17 16:56:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-18 21:43:12 +08:00
|
|
|
|
2023-09-24 21:07:39 +08:00
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_netbsd_getsrc (char *option)
|
2023-09-24 21:07:39 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_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
|
2024-04-25 16:33:17 +08:00
|
|
|
os_netbsd_setsrc (char *option)
|
2023-09-24 21:07:39 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root (); // HELP: 不知道是否需要确保root权限
|
2023-09-24 21:07:39 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_netbsd);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-24 21:07:39 +08:00
|
|
|
|
2023-09-26 23:02:12 +08:00
|
|
|
chsrc_backup ("/usr/pkg/etc/pkgin/repositories.conf");
|
2023-09-24 21:07:39 +08:00
|
|
|
|
2024-06-21 10:55:43 +08:00
|
|
|
char *arch = chsrc_get_cpuarch ();
|
2024-04-25 16:33:17 +08:00
|
|
|
char *vercmd = "cat /etc/os-release | grep \"VERSION=\" | grep -Po \"[8-9].[0-9]+\"";
|
2024-06-11 17:05:15 +08:00
|
|
|
char *version = xy_run (vercmd, 0, NULL);
|
2023-09-26 22:14:41 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *url = xy_strjoin (5, source.url, arch, "/", version, "/All");
|
2023-09-26 22:14:41 +08:00
|
|
|
chsrc_overwrite_file (url, "/usr/pkg/etc/pkgin/repositories.conf");
|
2023-09-24 21:07:39 +08:00
|
|
|
|
2024-06-21 10:55:43 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-24 21:07:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_openbsd_getsrc (char *option)
|
2023-09-24 21:07:39 +08:00
|
|
|
{
|
2024-07-09 13:04:37 +08:00
|
|
|
chsrc_view_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
|
2024-04-25 16:33:17 +08:00
|
|
|
os_openbsd_setsrc (char *option)
|
2023-09-24 21:07:39 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-24 21:07:39 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_openbsd);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-24 21:07:39 +08:00
|
|
|
|
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
|
|
|
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-24 21:07:39 +08:00
|
|
|
}
|
|
|
|
|
2023-09-30 11:38:47 +08:00
|
|
|
/**
|
|
|
|
* 参考:
|
|
|
|
* https://mirrors.tuna.tsinghua.edu.cn/help/ros/
|
|
|
|
*/
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
os_ros_setsrc (char *option)
|
2023-09-30 11:38:47 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
chsrc_ensure_root ();
|
2023-09-30 11:38:47 +08:00
|
|
|
|
2024-06-14 00:17:21 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (os_ros);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-30 11:38:47 +08:00
|
|
|
|
|
|
|
chsrc_backup ("/etc/apt/sources.list.d/ros-latest.list");
|
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = NULL;
|
2023-09-30 11:38:47 +08:00
|
|
|
cmd = xy_strjoin(3, "sed -E -i \'s@https?://.*/ros/ubuntu/?@", source.url, "@/ros/ubuntug\' /etc/apt/sources.list");
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run(cmd, RunOpt_Default);
|
2023-09-30 11:38:47 +08:00
|
|
|
|
2024-06-08 06:11:49 +08:00
|
|
|
cmd = "apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654";
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2023-09-30 11:38:47 +08:00
|
|
|
|
2024-06-24 21:38:16 +08:00
|
|
|
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-30 11:38:47 +08:00
|
|
|
}
|
|
|
|
|
2023-09-24 21:07:39 +08:00
|
|
|
|
|
|
|
|
2023-09-10 17:01:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
wr_tex_check_cmd (bool *tlmgr_exist, bool *mpm_exist)
|
2023-09-10 17:01:20 +08:00
|
|
|
{
|
2024-06-14 01:02:23 +08:00
|
|
|
*tlmgr_exist = chsrc_check_program ("tlmgr");
|
|
|
|
*mpm_exist = chsrc_check_program ("mpm");
|
2023-09-10 17:01:20 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
if (!*tlmgr_exist && !*mpm_exist)
|
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_error ("未找到 tlmgr 或 mpm 命令,请检查是否存在(其一)");
|
2024-04-25 16:33:17 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2023-09-10 17:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2024-06-07 21:17:29 +08:00
|
|
|
wr_tex_getsrc (char *option)
|
2023-09-10 17:01:20 +08:00
|
|
|
{
|
|
|
|
bool tlmgr_exist, mpm_exist;
|
2023-10-05 17:14:04 +08:00
|
|
|
wr_tex_check_cmd (&tlmgr_exist, &mpm_exist);
|
2023-09-10 17:01:20 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
if (tlmgr_exist)
|
|
|
|
{
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run("tlmgr option repository", RunOpt_Default);
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
|
|
|
if (mpm_exist)
|
|
|
|
{
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run("mpm --get-repository", RunOpt_Default);
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2023-09-10 17:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 参考 https://help.mirrors.cernet.edu.cn/CTAN/
|
|
|
|
*/
|
|
|
|
void
|
2024-06-07 21:17:29 +08:00
|
|
|
wr_tex_setsrc (char *option)
|
2023-09-10 17:01:20 +08:00
|
|
|
{
|
|
|
|
bool tlmgr_exist, mpm_exist;
|
2023-10-05 17:14:04 +08:00
|
|
|
wr_tex_check_cmd (&tlmgr_exist, &mpm_exist);
|
2023-09-10 17:01:20 +08:00
|
|
|
|
2024-06-14 00:22:39 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (wr_tex);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-10 17:01:20 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = NULL;
|
2023-09-10 17:01:20 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
if (tlmgr_exist)
|
|
|
|
{
|
|
|
|
cmd = xy_2strjoin ("tlmgr option repository ", source.url);
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2023-09-10 17:01:20 +08:00
|
|
|
|
2024-04-25 16:33:17 +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);
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2023-09-10 17:01:20 +08:00
|
|
|
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeUntested);
|
2023-09-10 17:01:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-08-09 02:46:25 +08:00
|
|
|
#include "recipe/ware/emacs.c"
|
2023-09-10 18:44:34 +08:00
|
|
|
|
2024-06-08 10:15:23 +08:00
|
|
|
|
2024-06-07 21:17:29 +08:00
|
|
|
void
|
|
|
|
wr_winget_getsrc (char *option)
|
|
|
|
{
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run ("winget source list", RunOpt_Default);
|
2024-06-07 21:17:29 +08:00
|
|
|
}
|
|
|
|
|
2024-06-07 22:28:06 +08:00
|
|
|
/* 参考:https://mirrors.ustc.edu.cn/help/winget-source.html */
|
2024-06-07 21:17:29 +08:00
|
|
|
void
|
|
|
|
wr_winget_setsrc (char *option)
|
|
|
|
{
|
2024-06-14 00:22:39 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (wr_winget);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2024-06-07 21:17:29 +08:00
|
|
|
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run ("winget source remove winget", RunOpt_Default);
|
|
|
|
chsrc_run (xy_2strjoin ("winget source add winget ", source.url), RunOpt_Default);
|
2024-06-07 21:17:29 +08:00
|
|
|
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
2024-06-07 21:17:29 +08:00
|
|
|
}
|
|
|
|
|
2024-06-07 22:30:35 +08:00
|
|
|
void
|
|
|
|
wr_winget_resetsrc (char *option)
|
|
|
|
{
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run ("winget source reset winget", RunOpt_Default);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (NULL, ChsrcTypeAuto);
|
2024-06-07 22:30:35 +08:00
|
|
|
}
|
|
|
|
|
2023-09-10 18:44:34 +08:00
|
|
|
|
2024-06-08 10:15:23 +08:00
|
|
|
|
2023-09-10 21:05:21 +08:00
|
|
|
void
|
2024-06-07 21:17:29 +08:00
|
|
|
wr_brew_getsrc (char *option)
|
2023-09-10 21:05:21 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = "echo HOMEBREW_API_DOMAIN=$HOMEBREW_API_DOMAIN;"
|
2023-09-10 21:05:21 +08:00
|
|
|
"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;";
|
2024-04-25 16:33:17 +08:00
|
|
|
system (cmd);
|
2023-09-10 21:05:21 +08:00
|
|
|
}
|
|
|
|
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
wr_brew_setsrc (char *option)
|
2023-09-10 21:05:21 +08:00
|
|
|
{
|
2024-06-14 00:22:39 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (wr_brew);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-10 21:05:21 +08:00
|
|
|
|
2024-07-09 15:04:03 +08:00
|
|
|
char *splitter = "\n\n# Generated by chsrc " Chsrc_Version;
|
2024-06-21 02:08:14 +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"), "\"");
|
2024-04-25 16:33:17 +08:00
|
|
|
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
|
|
|
|
2024-07-09 13:17:57 +08:00
|
|
|
char *zshrc = "~/.zshrc";
|
|
|
|
chsrc_backup (zshrc);
|
|
|
|
chsrc_append_to_file (splitter, zshrc);
|
|
|
|
chsrc_append_to_file (api_domain, zshrc);
|
|
|
|
chsrc_append_to_file (bottle_domain, zshrc);
|
|
|
|
chsrc_append_to_file (brew_git_remote, zshrc);
|
|
|
|
chsrc_append_to_file (core_git_remote, zshrc);
|
|
|
|
|
|
|
|
char *bashrc = "~/.bashrc";
|
|
|
|
if (xy_file_exist (bashrc))
|
|
|
|
{
|
|
|
|
chsrc_backup ("~/.bashrc");
|
|
|
|
chsrc_append_to_file (splitter, bashrc);
|
|
|
|
chsrc_append_to_file (api_domain, bashrc);
|
|
|
|
chsrc_append_to_file (bottle_domain, bashrc);
|
|
|
|
chsrc_append_to_file (brew_git_remote, bashrc);
|
|
|
|
chsrc_append_to_file (core_git_remote, bashrc);
|
|
|
|
}
|
2023-09-10 21:05:21 +08:00
|
|
|
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("请您重启终端使Homebrew环境变量生效");
|
2024-06-08 10:15:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 参考:https://mirrors.tuna.tsinghua.edu.cn/help/CocoaPods/
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wr_cocoapods_setsrc (char *option)
|
|
|
|
{
|
2024-06-14 00:22:39 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (wr_cocoapods);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2024-06-08 10:15:23 +08:00
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("请手动执行以下命令:");
|
2024-06-08 10:15:23 +08:00
|
|
|
|
|
|
|
say ("cd ~/.cocoapods/repos");
|
|
|
|
say ("pod repo remove master");
|
|
|
|
char *git_cmd = xy_strjoin (3, "git clone ", source.url, " master");
|
|
|
|
say (git_cmd);
|
|
|
|
say ("");
|
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("最后进入项目工程目录,在Podfile中第一行加入:");
|
2024-06-08 10:15:23 +08:00
|
|
|
char *source_str = xy_strjoin (3, "source '", source.url, "'");
|
|
|
|
say (source_str);
|
|
|
|
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeManual);
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
wr_guix_setsrc (char *option)
|
2023-09-11 11:06:15 +08:00
|
|
|
{
|
2024-06-14 00:22:39 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (wr_guix);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-11 11:06:15 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *file = xy_strjoin (3, "(list (channel\n"
|
|
|
|
" (inherit (car %default-channels))\n"
|
|
|
|
" (url \"", source.url, "\")))");
|
2023-09-11 11:06:15 +08:00
|
|
|
|
2024-08-08 17:34:41 +08:00
|
|
|
chsrc_note2 ("为防止扰乱配置文件,请您手动写入以下内容到 ~/.config/guix/channels.scm 文件中");
|
2024-04-25 16:33:17 +08:00
|
|
|
puts (file);
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeManual);
|
2023-09-11 11:06:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2024-06-14 01:02:23 +08:00
|
|
|
chsrc_ensure_program ("nix-channel");
|
2023-09-22 15:36:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
wr_nix_setsrc (char *option)
|
2023-09-22 15:36:23 +08:00
|
|
|
{
|
2023-09-29 21:23:58 +08:00
|
|
|
wr_nix_check_cmd ();
|
2023-09-22 15:36:23 +08:00
|
|
|
|
2024-06-14 00:22:39 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (wr_nix);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-22 15:36:23 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *cmd = xy_strjoin (3, "nix-channel --add ", source.url, "nixpkgs-unstable nixpkgs");
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2023-09-22 15:36:23 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *towrite = xy_strjoin (3, "substituters = ", source.url, "store https://cache.nixos.org/");
|
2023-09-26 22:14:41 +08:00
|
|
|
chsrc_append_to_file (towrite , "~/.config/nix/nix.conf");
|
2023-09-26 18:11:38 +08:00
|
|
|
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run ("nix-channel --update", RunOpt_Default);
|
2023-09-22 15:36:23 +08:00
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("若您使用的是NixOS,请确认您的系统版本<version>(如22.11),并手动运行:");
|
2024-04-25 16:33:17 +08:00
|
|
|
cmd = xy_strjoin (3, "nix-channel --add ", source.url, "nixpkgs-<version> nixpkgs");
|
|
|
|
puts (cmd);
|
2023-09-26 18:11:38 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
cmd = xy_strjoin (3, "nix.settings.substituters = [ \"", source.url, "store\" ];");
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("若您使用的是NixOS,请额外添加下述内容至 configuration.nix 中");
|
2024-04-25 16:33:17 +08:00
|
|
|
puts (cmd);
|
2023-09-26 18:11:38 +08:00
|
|
|
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeSemiAuto);
|
2023-09-22 15:36:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-08-09 02:03:35 +08:00
|
|
|
#include "recipe/ware/docker.c"
|
2024-06-08 14:20:15 +08:00
|
|
|
|
|
|
|
|
2023-09-11 11:25:48 +08:00
|
|
|
/**
|
|
|
|
* 参考: https://mirrors.sjtug.sjtu.edu.cn/docs/flathub
|
|
|
|
*/
|
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
wr_flathub_setsrc (char *option)
|
2023-09-11 11:25:48 +08:00
|
|
|
{
|
2024-06-14 00:22:39 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (wr_flathub);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-11 11:25:48 +08:00
|
|
|
|
2024-08-08 17:34:41 +08:00
|
|
|
chsrc_note2 ("若出现问题,可先调用以下命令:");
|
2024-04-25 16:33:17 +08:00
|
|
|
char *note = xy_strjoin (3,
|
2023-09-11 11:25:48 +08:00
|
|
|
"wget ", source.url, "/flathub.gpg\n"
|
2024-06-08 06:11:49 +08:00
|
|
|
"flatpak remote-modify --gpg-import=flathub.gpg flathub"
|
2023-09-11 11:25:48 +08:00
|
|
|
);
|
2024-04-25 16:33:17 +08:00
|
|
|
puts (note);
|
2023-09-11 11:25:48 +08:00
|
|
|
|
2024-06-08 06:11:49 +08:00
|
|
|
char *cmd = xy_2strjoin ("flatpak remote-modify flathub --url=", source.url);
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run (cmd, RunOpt_Default);
|
2023-09-11 11:25:48 +08:00
|
|
|
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeAuto);
|
2023-09-11 11:25:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-10 22:42:59 +08:00
|
|
|
void
|
2024-04-25 16:33:17 +08:00
|
|
|
wr_anaconda_setsrc (char *option)
|
2023-09-10 22:42:59 +08:00
|
|
|
{
|
2024-06-14 00:22:39 +08:00
|
|
|
SourceInfo source;
|
|
|
|
chsrc_yield_source (wr_anaconda);
|
2024-06-14 15:07:04 +08:00
|
|
|
chsrc_confirm_source (&source);
|
2023-09-10 22:42:59 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
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");
|
2023-09-10 22:42:59 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
char *file = xy_strjoin (22,
|
2023-09-10 22:42:59 +08:00
|
|
|
"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 上也是这里吗?
|
2024-04-25 16:33:17 +08:00
|
|
|
char *config = xy_2strjoin (xy_os_home, "/.condarc");
|
2023-09-10 22:42:59 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
if (xy_on_windows)
|
|
|
|
{
|
2024-06-14 01:02:23 +08:00
|
|
|
bool exist = chsrc_check_program ("conda");
|
2024-04-25 16:33:17 +08:00
|
|
|
if (!exist)
|
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_error ("未找到 conda 命令,请检查是否存在");
|
2024-06-14 15:01:52 +08:00
|
|
|
exit (Exit_UserCause);
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2024-06-14 15:51:54 +08:00
|
|
|
chsrc_run ("conda config --set show_channel_urls yes", RunOpt_Default);
|
2023-09-10 22:42:59 +08:00
|
|
|
}
|
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 (xy_strjoin (3, "请向 ", config, " 中手动添加:"));
|
2024-04-25 16:33:17 +08:00
|
|
|
puts (file);
|
2023-09-10 22:42:59 +08:00
|
|
|
|
2024-08-08 15:52:13 +08:00
|
|
|
chsrc_note2 ("然后运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引");
|
2024-06-08 12:38:41 +08:00
|
|
|
chsrc_say_lastly (&source, ChsrcTypeSemiAuto);
|
2023-09-10 22:42:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-08-15 20:51:36 +08:00
|
|
|
#include "recipe/catalog.c"
|
2023-08-30 22:27:08 +08:00
|
|
|
|
|
|
|
|
2024-06-07 21:17:29 +08:00
|
|
|
static const char *
|
2024-06-08 13:26:52 +08:00
|
|
|
Chsrc_Usage[] = {
|
2024-07-24 18:42:08 +08:00
|
|
|
"维护: " Chsrc_Maintain_URL "\n",
|
2023-08-30 11:33:23 +08:00
|
|
|
|
2024-06-05 13:51:24 +08:00
|
|
|
"使用: chsrc <command> [options] [target] [mirror]",
|
2023-09-03 20:49:55 +08:00
|
|
|
"help 打印此帮助,或 h, -h, --help",
|
2024-06-08 13:26:52 +08:00
|
|
|
"issue 查看相关issue",
|
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> 换源,自动测速后挑选最快源",
|
2024-06-05 13:38:04 +08:00
|
|
|
"set <target> first 换源,使用维护团队测速第一的源",
|
2024-06-05 15:07:13 +08:00
|
|
|
"set <target> <mirror> 换源,指定使用某镜像站 (通过list命令查看)",
|
2024-06-14 17:00:38 +08:00
|
|
|
"set <target> https://abc 换源,用户自定义源URL",
|
2024-06-05 16:13:46 +08:00
|
|
|
"reset <target> 重置,使用上游默认使用的源\n",
|
2024-06-05 13:51:24 +08:00
|
|
|
|
|
|
|
"选项:",
|
2024-08-09 01:46:58 +08:00
|
|
|
"-dry Dry Run,模拟换源过程,命令仅打印并不运行",
|
2024-06-05 13:51:24 +08:00
|
|
|
"-ipv6 使用IPv6测速",
|
2024-06-11 22:21:18 +08:00
|
|
|
"-local 仅对某项目而非全局换源 (通过issue命令查看支持情况)"
|
2023-08-28 22:21:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-08-31 21:40:32 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
print_available_mirrors ()
|
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_info ("支持以下镜像站");
|
2024-07-24 18:54:20 +08:00
|
|
|
chsrc_info ("下方 code 列,可用于指定使用某镜像站,请使用 chsrc set <target> <code>\n");
|
|
|
|
printf ("%-14s%-30s%-41s ", "code", "服务商简写", "服务商URL"); puts ("服务商名称");
|
2023-09-03 16:42:17 +08:00
|
|
|
puts ("-------------------------------------------------------------------------------------------------");
|
2024-07-24 18:54:20 +08:00
|
|
|
for (int i = 0; i < xy_arylen (available_mirrors); i++)
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-06-05 14:42:31 +08:00
|
|
|
MirrorSite* mir = available_mirrors[i];
|
2024-07-24 18:54:20 +08:00
|
|
|
printf ("%-14s%-18s%-41s ", mir->code, mir->abbr, mir->site); puts (mir->name);
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2023-08-31 21:40:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2024-06-07 21:17:29 +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++)
|
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
const char **target = array[i];
|
|
|
|
const char *alias = target[0];
|
|
|
|
for (int k=1; alias!=NULL; k++)
|
|
|
|
{
|
|
|
|
printf ("%s\t", alias);
|
|
|
|
alias = target[k];
|
|
|
|
}
|
|
|
|
puts ("");
|
2023-08-31 21:40:32 +08:00
|
|
|
}
|
2024-04-25 16:33:17 +08:00
|
|
|
puts ("");
|
2023-08-31 21:40:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_supported_targets ()
|
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_info ("支持对以下目标换源 (同一行表示这几个命令兼容)"); puts("");
|
2024-06-08 15:13:37 +08:00
|
|
|
puts (xy_str_to_blue ("编程语言开发"));
|
2024-06-05 12:50:43 +08:00
|
|
|
puts ("-------------------------");
|
2023-08-31 21:48:05 +08:00
|
|
|
print_supported_targets_ (pl_packagers, xy_arylen(pl_packagers));
|
2024-06-08 15:13:37 +08:00
|
|
|
puts (xy_str_to_blue ("操作系统"));
|
2024-06-05 12:50:43 +08:00
|
|
|
puts ("-------------------------");
|
2023-08-31 21:48:05 +08:00
|
|
|
print_supported_targets_ (os_systems, xy_arylen(os_systems));
|
2024-06-08 15:13:37 +08:00
|
|
|
puts (xy_str_to_blue ("软件"));
|
2024-06-05 12:50:43 +08:00
|
|
|
puts ("-------------------------");
|
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 ()
|
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_info ("支持对以下编程语言生态换源 (同一行表示这几个命令兼容)");
|
2023-09-17 13:28:50 +08:00
|
|
|
print_supported_targets_ (pl_packagers, xy_arylen(pl_packagers));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_supported_os ()
|
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_info ("支持对以下操作系统换源 (同一行表示这几个命令兼容)");
|
2023-09-17 13:28:50 +08:00
|
|
|
print_supported_targets_ (os_systems, xy_arylen(os_systems));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_supported_wr ()
|
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_info ("支持对以下软件换源 (同一行表示这几个命令兼容)");
|
2023-09-17 13:28:50 +08:00
|
|
|
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-10-05 09:28:34 +08:00
|
|
|
print_supported_sources_for_target (SourceInfo 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++)
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
|
|
|
SourceInfo src = sources[i];
|
2024-06-05 14:42:31 +08:00
|
|
|
const MirrorSite *mir = src.mirror;
|
2024-07-24 18:54:20 +08:00
|
|
|
if (NULL == src.url)
|
|
|
|
{
|
|
|
|
src.url = "Please help to add the upstream url!";
|
|
|
|
}
|
2024-04-25 16:33:17 +08:00
|
|
|
printf ("%-14s%-18s%-50s ", mir->code, mir->abbr, src.url);
|
|
|
|
puts (mir->name);
|
|
|
|
}
|
2023-09-02 16:49:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-06 17:06:09 +08:00
|
|
|
void
|
2024-06-05 09:24:39 +08:00
|
|
|
cli_print_version ()
|
2023-08-28 22:21:33 +08:00
|
|
|
{
|
2024-07-09 14:38:52 +08:00
|
|
|
puts (xy_strjoin (3, "chsrc: Change Source (GPL-3.0) ",
|
2024-06-07 20:24:00 +08:00
|
|
|
xy_str_to_magenta (Chsrc_Version), " by RubyMetric"));
|
2024-06-05 09:24:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
cli_print_help ()
|
|
|
|
{
|
2024-07-24 18:42:08 +08:00
|
|
|
puts ("");
|
|
|
|
for (int i=0; i<xy_arylen (Chsrc_Usage); i++)
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-06-08 13:26:52 +08:00
|
|
|
puts (Chsrc_Usage[i]);
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2023-08-28 22:21:33 +08:00
|
|
|
}
|
|
|
|
|
2024-06-08 13:14:14 +08:00
|
|
|
void
|
|
|
|
cli_print_issues ()
|
|
|
|
{
|
|
|
|
puts (
|
|
|
|
"chsrc issues: Gitee和GitHub两边同时接受issue\n\n"
|
|
|
|
"- https://gitee.com/RubyMetric/chsrc/issues\n"
|
|
|
|
"- https://github.com/RubyMetric/chsrc/issues\n\n"
|
|
|
|
|
|
|
|
"目前支持reset命令的源: https://gitee.com/RubyMetric/chsrc/issues/I9V6EV\n"
|
|
|
|
"目前支持-local选项的源: https://gitee.com/RubyMetric/chsrc/issues/I9V5I0\n"
|
|
|
|
"已收录的镜像站: https://gitee.com/RubyMetric/chsrc/wikis\n"
|
|
|
|
);
|
2024-06-08 13:26:52 +08:00
|
|
|
|
2024-06-14 01:02:23 +08:00
|
|
|
if (chsrc_check_program ("gh"))
|
2024-06-08 13:26:52 +08:00
|
|
|
{
|
2024-06-14 01:02:23 +08:00
|
|
|
char *cmd = xy_str_to_quietcmd ("gh browse --repo RubyMetric/chsrc");
|
|
|
|
system (cmd);
|
2024-06-08 13:26:52 +08:00
|
|
|
}
|
2024-06-08 13:14:14 +08:00
|
|
|
}
|
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
|
2024-04-25 16:33:17 +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;
|
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
const char **target = NULL;
|
2023-09-01 17:17:45 +08:00
|
|
|
int k = 0;
|
2024-04-25 16:33:17 +08:00
|
|
|
const char *alias = NULL;
|
2023-09-01 17:17:45 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
for (int i=0; i<size; i++)
|
|
|
|
{
|
|
|
|
target = array[i];
|
2023-09-01 17:17:45 +08:00
|
|
|
alias = target[k];
|
2024-04-25 16:33:17 +08:00
|
|
|
while (NULL!=alias)
|
|
|
|
{
|
|
|
|
if (xy_streql(input, alias))
|
|
|
|
{
|
|
|
|
matched = 1; break;
|
|
|
|
}
|
|
|
|
k++;
|
|
|
|
alias = target[k];
|
|
|
|
}
|
|
|
|
if (!matched) k = 0;
|
|
|
|
if (matched) break;
|
2023-09-01 17:17:45 +08:00
|
|
|
}
|
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
if (!matched)
|
|
|
|
{
|
|
|
|
*target_info = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
2023-09-01 17:17:45 +08:00
|
|
|
|
|
|
|
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-10-04 18:48:35 +08:00
|
|
|
typedef enum {
|
2024-06-07 22:28:06 +08:00
|
|
|
TargetOp_Get_Source = 1,
|
|
|
|
TargetOp_Set_Source,
|
|
|
|
TargetOp_Reset_Source,
|
2024-06-05 12:50:43 +08:00
|
|
|
TargetOp_Cesu_Source,
|
|
|
|
TargetOp_List_Source
|
2023-10-04 18:48:35 +08:00
|
|
|
} TargetOp;
|
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
|
2024-04-25 16:33:17 +08:00
|
|
|
get_target (const char *input, TargetOp code, char *option)
|
2023-09-01 17:17:45 +08:00
|
|
|
{
|
2024-04-25 16:33:17 +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;
|
|
|
|
}
|
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
TargetInfo *target = (TargetInfo*) *target_tmp;
|
2023-09-02 19:38:32 +08:00
|
|
|
|
2024-06-05 12:50:43 +08:00
|
|
|
if (TargetOp_Set_Source==code)
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
|
|
|
if (target->setfn) target->setfn(option);
|
2024-06-08 13:26:52 +08:00
|
|
|
else chsrc_error (xy_strjoin (3, "暂未对 ", input, " 实现set功能,邀您帮助: chsrc issue"));
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2024-06-07 22:28:06 +08:00
|
|
|
else if (TargetOp_Reset_Source==code)
|
|
|
|
{
|
2024-06-07 23:56:42 +08:00
|
|
|
if (target->resetfn) target->resetfn(option);
|
2024-06-08 13:26:52 +08:00
|
|
|
else chsrc_error (xy_strjoin (3, "暂未对 ", input, " 实现reset功能,邀您帮助: chsrc issue"));
|
2024-06-07 22:28:06 +08:00
|
|
|
// puts ("将重置并恢复上游默认使用的源");
|
|
|
|
}
|
2024-06-05 12:50:43 +08:00
|
|
|
else if (TargetOp_Get_Source==code)
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
|
|
|
if (target->getfn) target->getfn("");
|
2024-06-08 13:26:52 +08:00
|
|
|
else chsrc_error (xy_strjoin (3, "暂未对 ", input, " 实现get功能,邀您帮助: chsrc issue"));
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2024-06-05 12:50:43 +08:00
|
|
|
else if (TargetOp_List_Source==code)
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-07-31 12:38:52 +08:00
|
|
|
chsrc_info (xy_strjoin (3, "对 ", input, " 支持以下镜像站"));
|
2024-07-24 18:54:20 +08:00
|
|
|
chsrc_info (xy_strjoin (3, "下方 code 列,可用于指定使用某源,请使用 chsrc set ", input, " <code>\n"));
|
|
|
|
printf ("%-14s%-35s%-45s ", "code", "服务商简写", "服务源URL"); puts ("服务商名称");
|
2024-04-25 16:33:17 +08:00
|
|
|
puts ("--------------------------------------------------------------------------------------------------------");
|
|
|
|
print_supported_sources_for_target (target->sources, target->sources_n);
|
|
|
|
}
|
2024-06-05 12:50:43 +08:00
|
|
|
else if (TargetOp_Cesu_Source==code)
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
|
|
|
auto_select_ (target->sources, target->sources_n, input-3);
|
|
|
|
return true;
|
2023-09-04 19:19:30 +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
|
|
|
{
|
2024-04-25 16:33:17 +08:00
|
|
|
xy_useutf8 (); argc -= 1;
|
2023-08-29 21:58:51 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
if (argc==0)
|
|
|
|
{
|
2024-06-07 20:24:00 +08:00
|
|
|
cli_print_version ();
|
|
|
|
cli_print_help ();
|
|
|
|
return 0;
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2023-08-28 22:21:33 +08:00
|
|
|
|
2024-04-25 16:33:17 +08:00
|
|
|
const char *command = argv[1];
|
2023-08-31 20:24:06 +08:00
|
|
|
|
2024-06-05 09:18:48 +08:00
|
|
|
// chsrc set target mirror
|
|
|
|
// 1 2 3
|
|
|
|
int cli_arg_Target_pos = 2;
|
|
|
|
int cli_arg_Mirror_pos = cli_arg_Target_pos + 1;
|
|
|
|
const char *target = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
// chsrc set -ipv6 target mirror
|
|
|
|
// 1 2 3 4
|
|
|
|
// argc = 4
|
|
|
|
for (int i=2; i<=argc ;i++)
|
|
|
|
{
|
|
|
|
if (xy_str_start_with (argv[i], "-"))
|
|
|
|
{
|
|
|
|
if (xy_streql (argv[i], "-ipv6"))
|
|
|
|
{
|
2024-08-09 01:49:14 +08:00
|
|
|
CliOpt_IPv6 = true;
|
2024-06-05 09:18:48 +08:00
|
|
|
}
|
|
|
|
else if (xy_streql (argv[i], "-local"))
|
|
|
|
{
|
2024-08-09 01:49:14 +08:00
|
|
|
CliOpt_Locally = true;
|
2024-06-05 09:18:48 +08:00
|
|
|
}
|
|
|
|
else if (xy_streql (argv[i], "-en") || xy_streql (argv[i], "-english"))
|
|
|
|
{
|
2024-08-09 01:49:14 +08:00
|
|
|
CliOpt_InEnglish = true;
|
2024-06-05 09:18:48 +08:00
|
|
|
}
|
2024-08-09 01:46:58 +08:00
|
|
|
else if (xy_streql (argv[i], "-dry"))
|
|
|
|
{
|
|
|
|
CliOpt_DryRun = true;
|
|
|
|
chsrc_log (to_boldyellow ("**开启Dry Run模式,模拟换源过程(跳过测速),命令仅打印并不运行**\n"));
|
|
|
|
}
|
2024-06-05 09:18:48 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
chsrc_error (xy_2strjoin ("未识别的命令行选项 ", argv[i])); return 1;
|
|
|
|
}
|
|
|
|
cli_arg_Target_pos++;
|
|
|
|
cli_arg_Mirror_pos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-01 17:17:45 +08:00
|
|
|
bool matched = false;
|
|
|
|
|
2023-08-31 20:24:06 +08:00
|
|
|
/* chsrc help */
|
2024-04-25 16:33:17 +08:00
|
|
|
if (xy_streql (command, "h") ||
|
|
|
|
xy_streql (command, "-h") ||
|
|
|
|
xy_streql (command, "help") ||
|
|
|
|
xy_streql (command, "--help"))
|
|
|
|
{
|
2024-06-05 09:24:39 +08:00
|
|
|
cli_print_version ();
|
2024-06-05 09:18:48 +08:00
|
|
|
cli_print_help ();
|
2024-04-25 16:33:17 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2023-08-28 23:10:09 +08:00
|
|
|
|
2024-06-05 09:24:39 +08:00
|
|
|
/* chsrc -v */
|
|
|
|
else if (xy_streql (command, "-v") ||
|
|
|
|
xy_streql (command, "-version") ||
|
|
|
|
xy_streql (command, "--version")||
|
|
|
|
xy_streql (command, "ver") ||
|
|
|
|
xy_streql (command, "version"))
|
|
|
|
{
|
|
|
|
cli_print_version ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-08-31 20:24:06 +08:00
|
|
|
/* chsrc list */
|
2024-04-25 16:33:17 +08:00
|
|
|
else if (xy_streql (command, "list") ||
|
|
|
|
xy_streql (command, "l") ||
|
|
|
|
xy_streql (command, "ls"))
|
|
|
|
{
|
2024-06-05 09:18:48 +08:00
|
|
|
if (argc < cli_arg_Target_pos)
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
|
|
|
print_available_mirrors ();
|
|
|
|
puts ("");
|
|
|
|
print_supported_targets ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-06-05 09:18:48 +08:00
|
|
|
target = argv[cli_arg_Target_pos];
|
2024-07-31 12:38:52 +08:00
|
|
|
if (xy_streql (target, "mirrors") || xy_streql (target, "mirror"))
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-07-31 12:38:52 +08:00
|
|
|
print_available_mirrors (); return 0;
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2024-07-31 12:38:52 +08:00
|
|
|
else if (xy_streql (target, "targets") || xy_streql (target, "target"))
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-07-31 12:38:52 +08:00
|
|
|
print_supported_targets (); return 0;
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2024-07-31 12:38:52 +08:00
|
|
|
else if (xy_streql (target, "os"))
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-07-31 12:38:52 +08:00
|
|
|
print_supported_os (); return 0;
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
2024-07-31 12:38:52 +08:00
|
|
|
else if (xy_streql (target, "lang") || xy_streql (target, "pl") || xy_streql (target, "language"))
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
|
|
|
print_supported_pl(); return 0;
|
|
|
|
}
|
2024-07-31 12:38:52 +08:00
|
|
|
else if (xy_streql (target, "ware") || xy_streql (target, "software"))
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-07-31 12:38:52 +08:00
|
|
|
print_supported_wr (); return 0;
|
2024-04-25 16:33:17 +08:00
|
|
|
}
|
|
|
|
|
2024-07-31 12:38:52 +08:00
|
|
|
matched = get_target (target, TargetOp_List_Source, NULL);
|
2024-04-25 16:33:17 +08:00
|
|
|
if (!matched) goto not_matched;
|
|
|
|
}
|
|
|
|
return 0;
|
2023-08-31 20:24:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* chsrc cesu */
|
2024-04-25 16:33:17 +08:00
|
|
|
else if (xy_streql (command, "cesu") ||
|
|
|
|
xy_streql (command, "ce") ||
|
|
|
|
xy_streql (command, "c"))
|
|
|
|
{
|
2024-06-05 09:18:48 +08:00
|
|
|
if (argc < cli_arg_Target_pos)
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_error ("请您提供想要测速源的软件名; 使用 chsrc list targets 查看所有支持的软件");
|
2024-04-25 16:33:17 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2024-06-05 09:18:48 +08:00
|
|
|
target = argv[cli_arg_Target_pos];
|
2024-06-05 12:50:43 +08:00
|
|
|
matched = get_target (target, TargetOp_Cesu_Source, NULL);
|
2024-04-25 16:33:17 +08:00
|
|
|
if (!matched) goto not_matched;
|
|
|
|
return 0;
|
2023-08-31 20:24:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* chsrc get */
|
2024-04-25 16:33:17 +08:00
|
|
|
else if (xy_streql (command, "get") ||
|
|
|
|
xy_streql (command, "g"))
|
|
|
|
{
|
2024-06-05 09:18:48 +08:00
|
|
|
if (argc < cli_arg_Target_pos)
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_error ("请您提供想要查看源的软件名; 使用 chsrc list targets 查看所有支持的软件");
|
2024-04-25 16:33:17 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2024-06-05 09:18:48 +08:00
|
|
|
target = argv[cli_arg_Target_pos];
|
2024-06-05 12:50:43 +08:00
|
|
|
matched = get_target (target, TargetOp_Get_Source, NULL);
|
2024-04-25 16:33:17 +08:00
|
|
|
if (!matched) goto not_matched;
|
|
|
|
return 0;
|
2023-08-31 20:24:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* chsrc set */
|
2024-04-25 16:33:17 +08:00
|
|
|
else if (xy_streql (command, "set") ||
|
|
|
|
xy_streql (command, "s"))
|
|
|
|
{
|
2024-06-05 09:18:48 +08:00
|
|
|
if (argc < cli_arg_Target_pos)
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_error ("请您提供想要设置源的软件名; 使用 chsrc list targets 查看所有支持的软件");
|
2024-04-25 16:33:17 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2023-09-03 17:57:45 +08:00
|
|
|
|
2024-06-05 09:18:48 +08:00
|
|
|
target = argv[cli_arg_Target_pos];
|
2024-06-13 23:27:59 +08:00
|
|
|
char *mirrorCode_or_url = NULL;
|
2024-07-31 12:38:52 +08:00
|
|
|
if (argc >= cli_arg_Mirror_pos)
|
|
|
|
{
|
|
|
|
mirrorCode_or_url = xy_strdup (argv[cli_arg_Mirror_pos]);
|
|
|
|
}
|
2024-06-05 12:50:43 +08:00
|
|
|
|
2024-06-13 23:27:59 +08:00
|
|
|
matched = get_target (target, TargetOp_Set_Source, mirrorCode_or_url);
|
2024-04-25 16:33:17 +08:00
|
|
|
if (!matched) goto not_matched;
|
|
|
|
return 0;
|
2023-09-03 17:57:45 +08:00
|
|
|
}
|
2023-08-31 20:24:06 +08:00
|
|
|
|
2024-06-05 15:07:13 +08:00
|
|
|
/* chsrc reset */
|
|
|
|
else if (xy_streql (command, "reset") ||
|
|
|
|
xy_streql (command, "rest") ||
|
|
|
|
xy_streql (command, "r"))
|
|
|
|
{
|
|
|
|
if (argc < cli_arg_Target_pos)
|
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_error ("请您提供想要重置源的软件名; 使用 chsrc list targets 查看所有支持的软件");
|
2024-06-05 15:07:13 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
target = argv[cli_arg_Target_pos];
|
2024-06-07 22:28:06 +08:00
|
|
|
matched = get_target (target, TargetOp_Reset_Source, NULL);
|
2024-06-05 15:07:13 +08:00
|
|
|
if (!matched) goto not_matched;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-06-08 13:14:14 +08:00
|
|
|
/* chsrc issue */
|
|
|
|
else if (xy_streql (command, "issue") ||
|
|
|
|
xy_streql (command, "issues") ||
|
|
|
|
xy_streql (command, "isue") ||
|
|
|
|
xy_streql (command, "i"))
|
|
|
|
{
|
|
|
|
cli_print_issues ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-08-31 20:24:06 +08:00
|
|
|
/* 不支持的命令 */
|
|
|
|
else
|
2024-04-25 16:33:17 +08:00
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_error (xy_strjoin (3, "不支持的命令 ", command, ". 请使用 chsrc help 查看使用方式"));
|
2024-04-25 16:33:17 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2023-08-31 20:24:06 +08:00
|
|
|
|
2023-09-01 17:17:45 +08:00
|
|
|
not_matched:
|
2024-04-25 16:33:17 +08:00
|
|
|
if (!matched)
|
|
|
|
{
|
2024-06-08 08:35:07 +08:00
|
|
|
chsrc_error ("暂不支持的换源目标,请使用 chsrc list targets 查看可换源软件");
|
2024-04-25 16:33:17 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2023-08-28 22:21:33 +08:00
|
|
|
}
|