chsrc/src/chsrc.c

1199 lines
32 KiB
C
Raw Normal View History

/** ------------------------------------------------------------
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>
2024-08-16 01:17:38 +08:00
* Last Modified : <2024-08-16>
*
2024-06-11 20:18:02 +08:00
* chsrc: Change Source
* ------------------------------------------------------------*/
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"
#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"
void
pl_dotnet_getsrc (char *option)
{
2023-09-26 21:09:16 +08:00
chsrc_error ("暂时无法查看NuGet源,若有需求,请您提交issue");
}
/**
* NuGet
*/
void
pl_dotnet_setsrc (char *option)
{
2023-09-26 21:09:16 +08:00
chsrc_error ("暂时无法为NuGet换源,若有需求,请您提交issue");
}
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
{
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);
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
2024-08-16 02:00:27 +08:00
#include "recipe/os/apt-family/common.h"
#include "recipe/os/apt-family/debian.c"
#include "recipe/os/apt-family/ubuntu.c"
2024-08-16 02:15:36 +08:00
#include "recipe/os/apt-family/linuxmint.c"
2024-08-16 02:00:27 +08:00
#include "recipe/os/apt-family/trisquel.c"
2024-08-16 02:07:38 +08:00
#include "recipe/os/apt-family/armbian.c"
2024-08-16 02:25:45 +08:00
#include "recipe/os/apt-family/raspberrypi.c"
2024-08-16 02:40:09 +08:00
#include "recipe/os/apt-family/ros.c"
void
2024-04-25 16:33:17 +08:00
os_deepin_getsrc(char *option)
{
2024-08-16 02:00:27 +08:00
chsrc_view_file (OS_Apt_SourceList);
}
/**
2023-09-22 13:31:05 +08:00
* HELP:
*/
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
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
2024-08-16 02:00:27 +08:00
chsrc_backup (OS_Apt_SourceList);
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);
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
/**
* @note fedora 29
*/
void
2024-04-25 16:33:17 +08:00
os_fedora_setsrc (char *option)
{
2024-04-25 16:33:17 +08:00
chsrc_ensure_root ();
2023-09-05 20:04:38 +08:00
SourceInfo source;
chsrc_yield_source (os_fedora);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
2024-08-08 17:34:41 +08:00
chsrc_note2 ("Fedora 29 及以下版本暂不支持");
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");
2024-04-25 16:33:17 +08:00
char* cmd = xy_strjoin (9, "sed -e 's|^metalink=|#metalink=|g' ",
"-e 's|^#baseurl=http://download.example/pub/fedora/linux/|baseurl=",
2023-09-05 20:04:38 +08:00
source.url,
"|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");
2024-06-24 21:38:16 +08:00
chsrc_run (cmd, RunOpt_Default);
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");
2024-06-24 21:38:16 +08:00
chsrc_run ("dnf makecache", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeAuto);
}
2024-08-16 01:17:38 +08:00
#include "recipe/os/opensuse.c"
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-08-16 02:00:27 +08:00
chsrc_view_file (OS_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
*/
void
2024-04-25 16:33:17 +08:00
os_kali_setsrc (char *option)
{
2024-04-25 16:33:17 +08:00
chsrc_ensure_root ();
2023-09-05 20:06:04 +08:00
SourceInfo source;
chsrc_yield_source (os_kali);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
2024-08-16 02:00:27 +08:00
chsrc_backup (OS_Apt_SourceList);
char *cmd = xy_strjoin (3, "sed -E -i \'s@https?://.*/kali/?@",
source.url,
"@g\' /etc/apt/sources.list");
2024-06-24 21:38:16 +08:00
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
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
*/
void
2024-04-25 16:33:17 +08:00
os_msys2_setsrc (char *option)
{
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");
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/#",
source.url,
"#g\" /etc/pacman.d/mirrorlist* ");
2024-06-24 21:38:16 +08:00
chsrc_run (cmd, RunOpt_Default);
chsrc_say_lastly (&source, ChsrcTypeUntested);
2023-09-01 22:23:03 +08:00
}
2023-08-30 20:34:01 +08:00
2024-08-16 01:08:51 +08:00
#include "recipe/os/arch.c"
2024-08-16 01:04:07 +08:00
#include "recipe/os/gentoo.c"
/**
* : https://help.mirrors.cernet.edu.cn/rocky/
*/
void
2024-04-25 16:33:17 +08:00
os_rocky_setsrc (char *option)
{
2024-04-25 16:33:17 +08:00
chsrc_ensure_root ();
SourceInfo source;
chsrc_yield_source (os_rocky);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
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' "
"-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);
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
/**
* : https://developer.aliyun.com/mirror/almalinux
*/
void
os_alma_setsrc (char *option)
{
chsrc_ensure_root ();
SourceInfo source;
chsrc_yield_source (os_alma);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
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-08-16 00:51:46 +08:00
#include "recipe/os/alpine.c"
2024-08-16 00:54:09 +08:00
#include "recipe/os/void.c"
2024-08-16 00:56:39 +08:00
#include "recipe/os/solus.c"
/**
* GUI
*/
void
2024-04-25 16:33:17 +08:00
os_manjaro_setsrc (char *option)
{
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);
2024-06-24 21:38:16 +08:00
chsrc_run ("pacman -Syy", RunOpt_No_Last_New_Line);
chsrc_say_lastly (NULL, ChsrcTypeAuto);
}
2023-09-05 20:48:38 +08:00
void
2024-04-25 16:33:17 +08:00
os_linuxlite_getsrc (char *option)
{
2024-08-16 02:00:27 +08:00
chsrc_view_file (OS_Apt_SourceList);
}
/**
* : https://help.mirrors.cernet.edu.cn/linuxliteos/
*/
void
2024-04-25 16:33:17 +08:00
os_linuxlite_setsrc (char *option)
{
2024-04-25 16:33:17 +08:00
chsrc_ensure_root ();
SourceInfo source;
chsrc_yield_source (os_linuxlite);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
2024-08-16 02:00:27 +08:00
chsrc_backup (OS_Apt_SourceList);
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");
2024-06-24 21:38:16 +08:00
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeAuto);
}
2024-08-16 02:40:09 +08:00
#include "recipe/os/openwrt.c"
2024-08-08 18:30:28 +08:00
/**
2023-09-22 13:31:05 +08:00
* HELP:
*/
void
2024-04-25 16:33:17 +08:00
os_openeuler_setsrc (char *option)
{
2024-04-25 16:33:17 +08:00
chsrc_ensure_root ();
SourceInfo source;
chsrc_yield_source (os_openeuler);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
2023-09-26 23:02:12 +08:00
chsrc_backup ("/etc/yum.repos.d/openEuler.repo");
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");
2024-06-24 21:38:16 +08:00
chsrc_run ("dnf makecache", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeAuto);
}
2024-06-12 23:18:19 +08:00
/**
* : https://mirrors.hust.edu.cn/docs/anolis
*/
void
os_anolis_setsrc (char *option)
{
chsrc_ensure_root ();
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-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-08-16 02:00:27 +08:00
chsrc_view_file (OS_Apt_SourceList);
2023-09-29 20:15:32 +08:00
}
void
2024-04-25 16:33:17 +08:00
os_openkylin_setsrc (char *option)
{
2023-09-29 21:28:02 +08:00
chsrc_ensure_root();
SourceInfo source;
chsrc_yield_source (os_openkylin);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
2024-08-16 02:00:27 +08:00
chsrc_backup (OS_Apt_SourceList);
2024-08-16 02:00:27 +08:00
char *cmd = xy_strjoin (3, "sed -E -i 's@https?://.*/openkylin/?@", source.url, "@g'" OS_Apt_SourceList);
2024-06-24 21:38:16 +08:00
chsrc_run (cmd, RunOpt_Default);
chsrc_run ("apt update", RunOpt_No_Last_New_Line);
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
2024-08-16 01:26:33 +08:00
#include "recipe/os/freebsd.c"
2024-08-16 01:23:29 +08:00
#include "recipe/os/netbsd.c"
2024-08-16 01:21:05 +08:00
#include "recipe/os/openbsd.c"
2023-09-24 21:07:39 +08:00
void
2024-04-25 16:33:17 +08:00
wr_tex_check_cmd (bool *tlmgr_exist, bool *mpm_exist)
{
2024-06-14 01:02:23 +08:00
*tlmgr_exist = chsrc_check_program ("tlmgr");
*mpm_exist = chsrc_check_program ("mpm");
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);
}
}
void
2024-06-07 21:17:29 +08:00
wr_tex_getsrc (char *option)
{
bool tlmgr_exist, mpm_exist;
2023-10-05 17:14:04 +08:00
wr_tex_check_cmd (&tlmgr_exist, &mpm_exist);
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
}
}
/**
* https://help.mirrors.cernet.edu.cn/CTAN/
*/
void
2024-06-07 21:17:29 +08:00
wr_tex_setsrc (char *option)
{
bool tlmgr_exist, mpm_exist;
2023-10-05 17:14:04 +08:00
wr_tex_check_cmd (&tlmgr_exist, &mpm_exist);
SourceInfo source;
chsrc_yield_source (wr_tex);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
2024-04-25 16:33:17 +08:00
char *cmd = NULL;
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
}
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
}
chsrc_say_lastly (&source, ChsrcTypeUntested);
}
2024-08-09 02:46:25 +08:00
#include "recipe/ware/emacs.c"
2023-09-10 18:44:34 +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
}
/* 参考:https://mirrors.ustc.edu.cn/help/winget-source.html */
2024-06-07 21:17:29 +08:00
void
wr_winget_setsrc (char *option)
{
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
chsrc_say_lastly (&source, ChsrcTypeAuto);
2024-06-07 21:17:29 +08:00
}
void
wr_winget_resetsrc (char *option)
{
2024-06-14 15:51:54 +08:00
chsrc_run ("winget source reset winget", RunOpt_Default);
chsrc_say_lastly (NULL, ChsrcTypeAuto);
}
2023-09-10 18:44:34 +08:00
void
2024-06-07 21:17:29 +08:00
wr_brew_getsrc (char *option)
{
2024-04-25 16:33:17 +08:00
char *cmd = "echo HOMEBREW_API_DOMAIN=$HOMEBREW_API_DOMAIN;"
"echo HOMEBREW_BOTTLE_DOMAIN=$HOMEBREW_BOTTLE_DOMAIN;"
"echo HOMEBREW_BREW_GIT_REMOTE=$HOMEBREW_BREW_GIT_REMOTE;"
"echo HOMEBREW_CORE_GIT_REMOTE=$HOMEBREW_CORE_GIT_REMOTE;";
2024-04-25 16:33:17 +08:00
system (cmd);
}
2023-09-17 14:06:21 +08:00
/**
* : https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
*
* brew 4.0.0 (2023 2 16)
* HOMEBREW_INSTALL_FROM_API homebrew-core HOMEBREW_CORE_GIT_REMOTE
*
*/
void
2024-04-25 16:33:17 +08:00
wr_brew_setsrc (char *option)
{
SourceInfo source;
chsrc_yield_source (wr_brew);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
char *splitter = "\n\n# Generated by chsrc " Chsrc_Version;
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"), "\"");
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);
}
chsrc_say_lastly (&source, ChsrcTypeAuto);
2024-08-08 15:52:13 +08:00
chsrc_note2 ("请您重启终端使Homebrew环境变量生效");
}
/**
* https://mirrors.tuna.tsinghua.edu.cn/help/CocoaPods/
*/
void
wr_cocoapods_setsrc (char *option)
{
SourceInfo source;
chsrc_yield_source (wr_cocoapods);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
2024-08-08 15:52:13 +08:00
chsrc_note2 ("请手动执行以下命令:");
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中第一行加入:");
char *source_str = xy_strjoin (3, "source '", source.url, "'");
say (source_str);
chsrc_say_lastly (&source, ChsrcTypeManual);
}
2023-09-17 14:06:21 +08:00
/**
* : https://mirrors.sjtug.sjtu.edu.cn/docs/guix
*/
void
2024-04-25 16:33:17 +08:00
wr_guix_setsrc (char *option)
{
SourceInfo source;
chsrc_yield_source (wr_guix);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
2024-04-25 16:33:17 +08:00
char *file = xy_strjoin (3, "(list (channel\n"
" (inherit (car %default-channels))\n"
" (url \"", source.url, "\")))");
2024-08-08 17:34:41 +08:00
chsrc_note2 ("为防止扰乱配置文件,请您手动写入以下内容到 ~/.config/guix/channels.scm 文件中");
2024-04-25 16:33:17 +08:00
puts (file);
chsrc_say_lastly (&source, ChsrcTypeManual);
}
2023-09-29 21:23:58 +08:00
void
2023-09-29 21:23:58 +08:00
wr_nix_check_cmd ()
{
2024-06-14 01:02:23 +08:00
chsrc_ensure_program ("nix-channel");
}
/**
* :
* 1. https://mirrors.bfsu.edu.cn/help/nix-channels/
* 2. https://gitee.com/RubyMetric/chsrc/issues/I83894
*/
void
2024-04-25 16:33:17 +08:00
wr_nix_setsrc (char *option)
{
2023-09-29 21:23:58 +08:00
wr_nix_check_cmd ();
SourceInfo source;
chsrc_yield_source (wr_nix);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
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);
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");
2024-06-14 15:51:54 +08:00
chsrc_run ("nix-channel --update", RunOpt_Default);
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);
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);
chsrc_say_lastly (&source, ChsrcTypeSemiAuto);
}
2024-08-09 02:03:35 +08:00
#include "recipe/ware/docker.c"
/**
* : https://mirrors.sjtug.sjtu.edu.cn/docs/flathub
*/
void
2024-04-25 16:33:17 +08:00
wr_flathub_setsrc (char *option)
{
SourceInfo source;
chsrc_yield_source (wr_flathub);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
2024-08-08 17:34:41 +08:00
chsrc_note2 ("若出现问题,可先调用以下命令:");
2024-04-25 16:33:17 +08:00
char *note = xy_strjoin (3,
"wget ", source.url, "/flathub.gpg\n"
2024-06-08 06:11:49 +08:00
"flatpak remote-modify --gpg-import=flathub.gpg flathub"
);
2024-04-25 16:33:17 +08:00
puts (note);
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);
chsrc_say_lastly (&source, ChsrcTypeAuto);
}
void
2024-04-25 16:33:17 +08:00
wr_anaconda_setsrc (char *option)
{
SourceInfo source;
chsrc_yield_source (wr_anaconda);
2024-06-14 15:07:04 +08:00
chsrc_confirm_source (&source);
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");
2024-04-25 16:33:17 +08:00
char *file = xy_strjoin (22,
"channels:\n - defaults\n"
"show_channel_urls: true\ndefault_channels:"
"\n - ", main,
"\n - ", r,
"\n - ", msys2,
"\ncustom_channels:\n"
" conda-forge: ", cloud,
"\n msys2: ", cloud,
"\n bioconda: ", cloud,
"\n menpo: ", cloud,
"\n pytorch: ", cloud,
"\n pytorch-lts: ", cloud,
"\n simpleitk: ", cloud,
"\n deepmodeling: ", cloud);
2023-09-17 14:19:53 +08:00
// TODO: 待确认 windows 上也是这里吗?
2024-04-25 16:33:17 +08:00
char *config = xy_2strjoin (xy_os_home, "/.condarc");
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);
}
2024-08-08 15:52:13 +08:00
chsrc_note2 (xy_strjoin (3, "请向 ", config, " 中手动添加:"));
2024-04-25 16:33:17 +08:00
puts (file);
2024-08-08 15:52:13 +08:00
chsrc_note2 ("然后运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引");
chsrc_say_lastly (&source, ChsrcTypeSemiAuto);
}
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]",
"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 列出可换源的操作系统/编程语言/软件",
"list <target> 查看该软件可以使用哪些源",
"cesu <target> 对该软件所有源测速",
"get <target> 查看当前软件的源使用情况",
"set <target> 换源,自动测速后挑选最快源",
"set <target> first 换源,使用维护团队测速第一的源",
"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");
2024-08-15 23:04:56 +08:00
printf (" %-13s%-35s%-38s", "code", "镜像站简写", "镜像站URL"); puts ("镜像站名称");
puts ("------- ----------- ------------------------------------- ---------------------");
// 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("");
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));
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));
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
}
void
print_supported_pl ()
{
2024-06-08 08:35:07 +08:00
chsrc_info ("支持对以下编程语言生态换源 (同一行表示这几个命令兼容)");
print_supported_targets_ (pl_packagers, xy_arylen(pl_packagers));
}
void
print_supported_os ()
{
2024-06-08 08:35:07 +08:00
chsrc_info ("支持对以下操作系统换源 (同一行表示这几个命令兼容)");
print_supported_targets_ (os_systems, xy_arylen(os_systems));
}
void
print_supported_wr ()
{
2024-06-08 08:35:07 +08:00
chsrc_info ("支持对以下软件换源 (同一行表示这几个命令兼容)");
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 truefalse
*/
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 {
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 truefalse
*/
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
}
else if (TargetOp_Reset_Source==code)
{
if (target->resetfn) target->resetfn(option);
2024-06-08 13:26:52 +08:00
else chsrc_error (xy_strjoin (3, "暂未对 ", input, " 实现reset功能,邀您帮助: chsrc issue"));
// 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"));
2024-08-15 23:04:56 +08:00
printf (" %-14s%-35s%-43s ", "code", "镜像站简写", "换源URL"); puts ("镜像站名称");
puts ("--------- -------------- ----------------------------------------------- ---------------------");
2024-04-25 16:33:17 +08:00
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];
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;
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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];
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
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
}
/* 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 查看所有支持的软件");
return 1;
}
target = argv[cli_arg_Target_pos];
matched = get_target (target, TargetOp_Reset_Source, NULL);
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;
}
/* 不支持的命令 */
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-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
}