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>
|
2024-08-16 01:17:38 +08:00
|
|
|
* Last Modified : <2024-08-16>
|
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
|
|
|
|
2024-08-16 03:54:12 +08:00
|
|
|
#include "recipe/lang/dart.c"
|
|
|
|
#include "recipe/lang/haskell.c"
|
|
|
|
#include "recipe/lang/ocaml.c"
|
|
|
|
#include "recipe/lang/r.c"
|
|
|
|
#include "recipe/lang/julia.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-16 02:48:26 +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:48:26 +08:00
|
|
|
// Debian-based
|
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 03:23:21 +08:00
|
|
|
#include "recipe/os/apt-family/Kali-Linux.c"
|
2024-08-16 02:48:26 +08:00
|
|
|
// Ubuntu-based
|
2024-08-16 03:21:51 +08:00
|
|
|
#include "recipe/os/apt-family/Linux-Mint.c"
|
2024-08-16 02:48:26 +08:00
|
|
|
#include "recipe/os/apt-family/trisquel.c"
|
2024-08-16 03:19:31 +08:00
|
|
|
#include "recipe/os/apt-family/Linux-Lite.c"
|
2024-08-16 02:48:26 +08:00
|
|
|
// Independent
|
|
|
|
#include "recipe/os/apt-family/ros.c"
|
2024-08-16 03:39:18 +08:00
|
|
|
#include "recipe/os/apt-family/openKylin.c"
|
2024-08-16 02:48:26 +08:00
|
|
|
#include "recipe/os/apt-family/deepin.c"
|
2023-09-17 11:26:31 +08:00
|
|
|
|
|
|
|
|
2024-08-16 03:34:27 +08:00
|
|
|
#include "recipe/os/yum-family/common.h"
|
2024-08-16 03:07:51 +08:00
|
|
|
#include "recipe/os/yum-family/Fedora-Linux.c"
|
2024-08-16 03:02:58 +08:00
|
|
|
#include "recipe/os/yum-family/AlmaLinux.c"
|
2024-08-16 03:13:56 +08:00
|
|
|
#include "recipe/os/yum-family/Rocky-Linux.c"
|
2024-08-16 03:34:27 +08:00
|
|
|
#include "recipe/os/yum-family/openEuler.c"
|
2024-08-16 03:50:03 +08:00
|
|
|
#include "recipe/os/yum-family/Anolis-OS.c"
|
2023-09-17 11:26:31 +08:00
|
|
|
|
2024-08-16 03:54:12 +08:00
|
|
|
#include "recipe/os/opensuse.c"
|
2023-09-17 11:26:31 +08:00
|
|
|
|
2024-08-16 04:00:36 +08:00
|
|
|
|
|
|
|
#include "recipe/os/pacman-family/Arch-Linux.c"
|
|
|
|
#include "recipe/os/pacman-family/Manjaro-Linux.c"
|
|
|
|
#include "recipe/os/pacman-family/MSYS2.c"
|
2024-06-12 21:47:29 +08:00
|
|
|
|
2024-08-16 03:54:12 +08:00
|
|
|
#include "recipe/os/gentoo.c"
|
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"
|
2024-08-16 02:40:09 +08:00
|
|
|
#include "recipe/os/openwrt.c"
|
2024-08-08 18:30:28 +08:00
|
|
|
|
|
|
|
|
2024-08-16 04:02:25 +08:00
|
|
|
#include "recipe/os/BSD/FreeBSD.c"
|
|
|
|
#include "recipe/os/BSD/NetBSD.c"
|
|
|
|
#include "recipe/os/BSD/OpenBSD.c"
|
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-08-16 04:07:54 +08:00
|
|
|
#include "recipe/ware/Homebrew.c"
|
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");
|
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("");
|
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"));
|
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];
|
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
|
|
|
}
|