Git Product home page Git Product logo

chsrc's Introduction

chsrc logo

全平台命令行换源工具,目标支持 Linux (包括麒麟、openEuler、deepin 等), Windows, macOS, BSD 等尽可能多的操作系统,龙芯、飞腾、RISC-V 等尽可能多的 CPU

我们使用 C99 来完成上述目标。我们并不使用 Python 或 JS 等解释语言,因为一个简单的换源工具,不应该强行塞给用户一个庞大的解释器和数十、数百 MB 其他文件。

本软件为自由软件,SDPX 软件许可证为 GPL-3.0-or-later and MIT


示例

chsrc logo

需要你的帮助

如果你想要通过 scoopbrewyay 等系统包管理工具来安装和更新chsrc,请帮助我们达到下面的要求。

  • 缺乏 AUR 维护者
  • homebrew 维护者
  • 缺乏 scoop 维护者
  • scoop 要求英文输出

若您可提供维护,请访问 issue#16 on GitHub


安装

Packaging status

以下方式均下载到当前目录,可直接通过 ./chsrc 运行。

Windows

# x64
curl -L https://gitee.com/RubyMetric/chsrc/releases/download/pre/chsrc-x64-windows.exe -o chsrc.exe

# x86
curl -L https://gitee.com/RubyMetric/chsrc/releases/download/pre/chsrc-x86-windows.exe -o chsrc.exe

Linux

# x64
curl -L https://gitee.com/RubyMetric/chsrc/releases/download/pre/chsrc-x64-linux -o chsrc; chmod +x ./chsrc

# aarch64
curl -L https://gitee.com/RubyMetric/chsrc/releases/download/pre/chsrc-aarch64-linux -o chsrc; chmod +x ./chsrc

# riscv64
curl -L https://gitee.com/RubyMetric/chsrc/releases/download/pre/chsrc-riscv64-linux -o chsrc; chmod +x ./chsrc

# armv7
curl -L https://gitee.com/RubyMetric/chsrc/releases/download/pre/chsrc-armv7-linux -o chsrc; chmod +x ./chsrc

macOS

可以通过 homebrew 安装,感谢 @Aaron-212@chenrui333

brew install chsrc

或手动下载二进制文件 (最新版,有时比 homebrew 提供的更新)

# M1/aarch64
curl -L https://gitee.com/RubyMetric/chsrc/releases/download/pre/chsrc-aarch64-macos -o chsrc; chmod +x ./chsrc

# x64
curl -L https://gitee.com/RubyMetric/chsrc/releases/download/pre/chsrc-x64-macos -o chsrc; chmod +x ./chsrc

BSD

git clone https://gitee.com/RubyMetric/chsrc.git; cd chsrc
clang -Iinclude src/chsrc.c -o chsrc

其他平台

git clone https://gitee.com/RubyMetric/chsrc.git; cd chsrc; make

使用

使用: chsrc <command> [options] [target] [mirror]

help                      # 打印此帮助,或 h, -h, --help
issue                     # 查看相关issue
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命令查看)
set  <target> https://abc # 换源,用户自定义源URL
reset <target>            # 重置,使用上游默认使用的源

选项:
-ipv6                     # 使用IPv6测速
-local                    # 仅对某项目而非全局换源 (仅部分软件如bundler,pdm支持)

当你不想自动测速的时候,你可以直接指定某镜像站,源URL,以及指定维护团队已测试的最快镜像站。

chsrc set ruby           # 测速,寻找最快者,换源
#
chsrc ls  ruby           # 列出可用的镜像站
chsrc set ruby rubychina # 使用 RubyChina 作为镜像站
# 或您有自己的镜像地址
chsrc set ruby https://gems.ruby-china.com/ # 使用自定义URL
#
chsrc set ruby first     # 使用维护团队测试的最快镜像站

对部分支持局部换源的,可以避免全局换源。

chsrc set -local bundler
chsrc set -local pdm

编程语言开发

chsrc set ruby    或 set gem
chsrc set python  或 set pip / pdm # 同时换pip和pdm
chsrc set node    或 set npm / nodejs / yarn / pnpm # 同时换3个
chsrc set perl    或 set cpan
chsrc set php     或 set composer
chsrc set lua     或 set luarocks

chsrc set go
chsrc set rust    或 set cargo / crate
chsrc set java    或 set maven / mvn / gradle
chsrc set clojure 或 set clojars
chsrc set dart    或 set pub / flutter # 同时会为flutter换源
chsrc set haskell 或 set hackage/cabal/stack
chsrc set ocaml   或 set opam

# 同时会为 bioconductor 换源
chsrc set r       或 set cran
chsrc set julia

操作系统

sudo chsrc set ubuntu
sudo chsrc set mint  或 linuxmint
sudo chsrc set debian
sudo chsrc set fedora
sudo chsrc set suse  或 set opensuse
sudo chsrc set kali
sudo chsrc set arch
sudo chsrc set archlinuxcn
sudo chsrc set manjaro
sudo chsrc set gentoo
sudo chsrc set rocky 或 set rockylinux
sudo chsrc set alma  或 set almalinux
sudo chsrc set alpine
sudo chsrc set void  或 set voidlinux
sudo chsrc set solus
sudo chsrc set ros   或 set ros2
sudo chsrc set trisquel
sudo chsrc set lite  或 set linuxlite
sudo chsrc set raspi 或 set raspberrypi
sudo chsrc set armbian

sudo chsrc set euler  或 set openeuler
sudo chsrc set anolis 或 set openanolis
sudo chsrc set kylin  或 set openkylin
sudo chsrc set deepin

chsrc set msys2 或 set msys

# BSD
sudo chsrc set freebsd
sudo chsrc set openbsd
sudo chsrc set netbsd

软件

chsrc set winget
chsrc set brew      或 set homebrew
chsrc set cocoapods 或 set cocoa / pod
chsrc set dockerhub 或 set docker
chsrc set flathub
chsrc set nix
chsrc set guix
chsrc set emacs  或 set elpa
chsrc set tex    或 set ctan / latex / texlive / miktex
chsrc set conda  或 set anaconda

开发

请安装好 gccclangmake 以及 curl

# 使用 dev 分支开发
git clone https://gitee.com/RubyMetric/chsrc.git -b dev

make          # 默认使用 cc 编译
make CC=clang # 使用 clang 编译
make CC=gcc   # 使用 gcc   编译

make test    # 测试命令
make test-xy # 测试 xy.h
make clean

许可证

  • chsrc 主程序采用 GPL-3.0-or-later 许可证,保证该软件的永久自由
  • xy.h 使用 MIT 许可证,保证该库可以在尽可能多的情况下复用

致谢

感谢各个镜像站提供的优质免费镜像服务,使用的镜像站见 source.h.

另外感谢以下项目:

  1. MirrorZ 教育网镜像站
  2. 清华大学 Tuna
  3. Thanks Mirror 项目 by @eryajf

chsrc's People

Contributors

ccmywish avatar chenrui333 avatar gchuchu avatar livelycode36 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chsrc's Issues

ubuntu换源sed命令无效

source里面本来的语句:

deb http://cn.archive.ubuntu.com/ubuntu jammy-updates main restricted

替换正则:

sed -E 's@(^[^#]* .*)http[:|\.|\/|a-z|A-Z]*\/ubuntu\/@\1https://mirrors.bfsu.edu.cn/ubuntu/@'< /etc/apt/sources.list.bak | cat > /etc/apt/sources.list

不知道你们这个正则为啥这么复杂。我是手动跑下面的语句修改的:

sed -i 's/https?:\/\/.*\/ubuntu/https:\/\/mirrors.bfsu.edu.cn\/ubuntu/g' /etc/apt/sources.list

Add os armbian

没撸过C,根据commit记录改的,不知道是否标准

环境

功能

  • 增加了对armbian的支持

测试
在机器上,编译测试通过
image

如果换源方法有问题,或者还未支持该软件换源,我该如何贡献?

多提 issue

每个组织、个人的技术栈都很不同,所以chsrc很难涵盖所有能换源的东西。

但是尽可能换所有源,这是chsrc想要达到的目标,所以如果有任何换源需求,请你大胆提出。

  1. issues on Gitee
  2. issues on GitHub

多测试,多反馈

基于上述目标,我们的开发环境很难完全测试。所以当你发现有问题的时候,请直接提issue,并附上输出信息。


不需要C语言也可贡献

chsrc为了达到全平台的支持,使用了C语言。这一点提高了贡献者的门槛。但是这并非说你无法贡献。如果发现chsrc现有实现的换源方法有问题,或还未实现该换源:

  1. 而你非常清楚该如何换源时(甚至你已经自己编写、或找到其他人写的换源脚本):

    你可以直接告知我们具体的命令,或用shell脚本的方式告诉我们如何换源,我们将转换为等效的C语言进入程序。可以使用 sed, awk 等外部命令,但是请确保平台上一定存在。

  2. 当你自己也不清楚该如何换源时:

    请尽量寻找好他人撰写的换源的细致教程,当我们实现后,请第一时间测试并反馈。

EndeavourOS 换源缺少 `arch` 命令

$ sudo ./chsrc set arch
测速 https://developer.aliyun.com/mirror/ ... 926.60 KByte/s
测速 https://mirrors.bfsu.edu.cn/ ... 23.13 MByte/s
测速 https://mirrors.ustc.edu.cn/ ... 27.13 MByte/s
测速 https://mirrors.tuna.tsinghua.edu.cn/ ... 10.91 MByte/s
测速 https://mirrors.tencent.com/ ... 14.32 MByte/s
测速 https://mirrors.huaweicloud.com/ ... 10.45 MByte/s
测速 https://mirrors.163.com/ ... 6.00 MByte/s
测速 https://mirrors.sohu.com/ ... 6.36 KByte/s
最快镜像站: **科学技术大学开源镜像站
选中镜像站: USTC (ustc)

运行 cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak --backup='t'
chsrc: 备份文件名 /etc/pacman.d/mirrorlist.bak
sh: line 1: arch: command not found
[1]    6801 segmentation fault  sudo ./chsrc set arch

添加 set `all [optional]<os|lang|ware>` 命令

这条命令能够极大的方便大量环境的初始化配置,而不用一个一个打

使用场景:

  • pacstrap 一整个环境后运行
  • 非持久化临时移动开发环境快速配置
  • etc...

fork数不足

只有两个原因

  1. 用c写的,多数人不玩c。
  2. 作者自己写的太完善了,啥都包括了,谁蛋疼的去fork。
  3. lol。这不是issue。

功能需求: 从配置文件中读取源信息而不是写死到.h文件里

写在代码里的源要想更新只能从头更新二进制程序, 如果源已经更新而程序用了旧的, 可能会让用户非常困惑.

配置文件可以放到 github 或者 gitee 的 release 里, 没有什么代价. 也最好支持在命令行指定源配置文件, 这样有一些自定义源需求也可以不需要改代码来实现.

谢谢这个仓库

连续两次更换 ubuntu 的源会导致添加出错

假设原来的源是
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
要添加的源是 https://mirrors.internal.local/nexus/repository/ubuntu22.04
执行的命令是
chsrc set ubuntu https://mirrors.internal.local/nexus/repository/ubuntu22.04
首次执行后,可以成功使用
但是假设我记错了发行版,现在需要进行修复,执行的命令如下
chsrc set ubuntu https://mirrors.internal.local/nexus/repository/ubuntu24.04
之后 apt update 就会出错了
查看 sourcelist.list,发现源变成了了下面这样
https://mirrors.internal.local/nexus/repository/ubuntu22.04/24.04
如果多次执行,这行就会一直变长

在Windows上使用Microsoft Store安装的Python换源会遇到权限问题

完整运行日志如下

PS C:\Users\用户名> sudo  ./chsrc set pip
[chsrc 检查] √ 命令 python3 存在
[chsrc 检查] x 命令 pdm 不存在
[chsrc 检查] √ 命令 curl 存在
测速 https://mirrors.bfsu.edu.cn/ ... 1.01 MByte/s
测速 https://mirror.lzu.edu.cn/ ... 24.91 MByte/s
测速 https://mirrors.jlu.edu.cn/ ... 7.86 MByte/s
测速 https://mirrors.sjtug.sjtu.edu.cn/ ... 12.78 MByte/s
测速 https://mirrors.tuna.tsinghua.edu.cn/ ... 2.04 MByte/s
测速 https://developer.aliyun.com/mirror/ ... 294.12 KByte/s
测速 https://mirrors.tencent.com/ ... 1.25 MByte/s
测速 https://mirrors.huaweicloud.com/ ... 7.35 MByte/s
测速 https://mirrors.hust.edu.cn/ ... 3.84 MByte/s
最快镜像站: 兰州大学开源社区镜像站
选中镜像站: LZUOSS (lzu)
--------------------------------
[chsrc 运行] python3 -m pip config set global.index-url https://mirror.lzu.edu.cn/pypi/web/simple
Writing to C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\pip.ini
ERROR: Unable to save configuration. Please report this as a bug.
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\site-packages\pip\_internal\configuration.py", line 215, in save
    with open(fname, "w") as f:
         ^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\\pip.ini'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\site-packages\pip\_internal\commands\configuration.py", line 265, in _save_configuration
    self.configuration.save()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\site-packages\pip\_internal\configuration.py", line 218, in save
    raise ConfigurationError(
pip._internal.exceptions.ConfigurationError: An error occurred while writing to the configuration file C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\pip.ini: [Errno 13] Permission denied: 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\\pip.ini'
ERROR: Internal Error.
[chsrc 运行] 命令执行失败,返回码 1
chsrc: 关键错误,强制结束

可能的解决方案:
https://devv.ai/search?threadId=dpqkqovuws1s

dockerhub 可用源

xxx@xxx:~$ sudo ./chsrc set docker
chsrc: 当前 dockerhub 无任何可用源,请联系维护者

Arch 换源导致 404

以华为源为例,换源后mirrorlists文件会设置以下内容

Server = https://mirrors.huaweicloud.com/archlinux/archlinuxarm/$repo/os/$arch
[archlinuxcn]
Server=https://mirrors.huaweicloud.com/archlinux/archlinuxcn/$repo/os/$arch

同时控制台报错:

[chsrc 运行] pacman -Sy archlinux-keyring
error: could not register 'archlinuxcn' database (database already registered)
error: could not register 'archlinuxcn' database (database already registered)

有效设置路径应该为:Server = https://mirrors.huaweicloud.com/archlinux/$repo/os/$arch
且huawei源貌似不提供archlinuxcn。

`conda` 换源过程中提示信息有些含糊不清

如下方日志,有点不太能理解,是需要用户手动操作吗?

测速 https://mirrors.tuna.tsinghua.edu.cn/ ... 10.51 MByte/s
测速 https://mirrors.bfsu.edu.cn/ ... 10.54 MByte/s
测速 https://mirrors.zju.edu.cn/ ... 3.28 MByte/s
测速 https://mirrors.sjtug.sjtu.edu.cn/ ... 10.30 MByte/s
最快镜像站: 北京外国语大学开源软件镜像站
选中镜像站: BFSU (bfsu)
√ 命令 conda 存在
~~~~~~~~~~~
运行 conda config --set show_channel_urls yes
chsrc: 请向 C:\Users\1900/.condarc 中手动添加:
channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/main
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/r
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.bfsu.edu.cn/anaconda/cloud
  msys2: https://mirrors.bfsu.edu.cn/anaconda/cloud
  bioconda: https://mirrors.bfsu.edu.cn/anaconda/cloud
  menpo: https://mirrors.bfsu.edu.cn/anaconda/cloud
  pytorch: https://mirrors.bfsu.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.bfsu.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.bfsu.edu.cn/anaconda/cloud
  deepmodeling: https://mirrors.bfsu.edu.cn/anaconda/cloud
chsrc: 然后运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引
--------------------------------
换源完成,感谢镜像提供方: 北京外国语大学开源软件镜像站

改成这种形式的提示会不会好点

测速 https://mirrors.tuna.tsinghua.edu.cn/ ... 10.51 MByte/s
测速 https://mirrors.bfsu.edu.cn/ ... 10.54 MByte/s
测速 https://mirrors.zju.edu.cn/ ... 3.28 MByte/s
测速 https://mirrors.sjtug.sjtu.edu.cn/ ... 10.30 MByte/s
最快镜像站: 北京外国语大学开源软件镜像站
选中镜像站: BFSU (bfsu)
√ 命令 conda 存在
!conda无法自动更新配置文件,请根据下方提示手动操作
~~~~~~~~~~~
1. 运行 conda config --set show_channel_urls yes
2. 请用编辑器打开 C:\Users\1900/.condarc 手动添加以下内容:
channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/main
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/r
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.bfsu.edu.cn/anaconda/cloud
  msys2: https://mirrors.bfsu.edu.cn/anaconda/cloud
  bioconda: https://mirrors.bfsu.edu.cn/anaconda/cloud
  menpo: https://mirrors.bfsu.edu.cn/anaconda/cloud
  pytorch: https://mirrors.bfsu.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.bfsu.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.bfsu.edu.cn/anaconda/cloud
  deepmodeling: https://mirrors.bfsu.edu.cn/anaconda/cloud
3. chsrc: 然后运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引
--------------------------------
换源完成,感谢镜像提供方: 北京外国语大学开源软件镜像站

`docker`镜像中`sudo`不存在 + 配置文件可能不存在

使用docker构建镜像时,debian 镜像中,默认没有 sources.list 文件,会导致换源失败,打印如下

./chsrc set debian first
使用维护团队测速第一的源
选中镜像站: BFSU (bfsu)
chsrc: 如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并需要您运行:
sudo apt install apt-transport-https ca-certificates
~~~~~~~~~~~
运行 cp /etc/apt/sources.list /etc/apt/sources.list.bak --backup='t'
cp: cannot stat '/etc/apt/sources.list': No such file or directory
chsrc: 备份文件名 /etc/apt/sources.list.bak
~~~~~~~~~~~
运行 sed -E -i 's@https?://.*/debian/?@https://mirrors.bfsu.edu.cn/debian@g' /etc/apt/sources.list
sed: can't read /etc/apt/sources.list: No such file or directory
~~~~~~~~~~~
运行 sudo apt update
sh: 1: sudo: not found
--------------------------------
换源完成,感谢镜像提供方: 北京外国语大学开源软件镜像站

请同时查看Gitee上的issue是否存在

双边 issue

因为这个软件本身就是为了换源,服务国内网络,所以我们也主要在Gitee上协作开发,防止最坏的情况发生。

大多数issue都已经在Gitee上存放着了,可先检索 https://gitee.com/RubyMetric/chsrc/issues

但若你没有Gitee账号,或因别的原因,想要在GitHub上发issue,我们也完全接受 😉

双边 PR

2024-06-21:可以从GitHub和Gitee任何一边发起PR,请在 dev 分支上开发。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.