RubyMetric / chsrc

chsrc 全平台通用换源工具与框架. Change Source for every software on every platform from the command line.
https://gitee.com/RubyMetric/chsrc
GNU General Public License v3.0
1.52k stars 64 forks source link

MAC换源brew异常 #44

Closed Viknopx closed 1 month ago

Viknopx commented 1 month ago

怀疑是cp命令的兼容性问题,系统版本为:

版本:14.2.1 芯片:Apple M1

以下是完整日志:

➜ ~ chsrc set brew
[chsrc 检查] √ 命令 curl 存在 测速 https://mirrors.tuna.tsinghua.edu.cn/ ... 908.72 KByte/s 测速 https://mirrors.bfsu.edu.cn/ ... 924.65 KByte/s 测速 https://mirrors.zju.edu.cn/ ... 682.54 KByte/s 测速 https://mirrors.sustech.edu.cn/ ... 889.40 KByte/s 最快镜像站: 北京外国语大学开源软件镜像站 选中镜像站: BFSU (bfsu)

[chsrc 运行] cp ~/.zshrc ~/.zshrc.bak --backup='t' cp: --backup=t is not a directory [chsrc 运行] 命令执行失败,返回码 256 chsrc: 关键错误,强制结束

ccmywish commented 1 month ago

@Viknopx

已修复cp的问题,可重新使用README中的下载链接试用。

另外,homebrew 换源上次有人反馈有问题,但是后续简单修正了之后,对方没再接着测试。借此机会,请帮忙验证下homebrew的换源是否正确,谢谢!

Viknopx commented 1 month ago

感谢回复,但还是有问题:

会强制检测环境,报错

[chsrc 运行] cp -f ~/.zshrc ~/.zshrc.bak
[chsrc 提示] 备份文件名为 ~/.zshrc.bak
[chsrc 运行] cp -f ~/.bashrc ~/.bashrc.bak
cp: /Users/xxxx/.bashrc: No such file or directory
[chsrc 运行] 命令执行失败,返回码 256
chsrc: 关键错误,强制结束

手动touch该文件之后继续报错:


[chsrc 运行] cp -f ~/.zshrc ~/.zshrc.bak
[chsrc 提示] 备份文件名为 ~/.zshrc.bak
[chsrc 运行] cp -f ~/.bashrc ~/.bashrc.bak
[chsrc 提示] 备份文件名为 ~/.bashrc.bak
[chsrc 运行] mkdir -p ~/.bashrc >> ~ 1>/dev/null 2>&1 
sh: /Users/xxxx: Is a directory
[chsrc 运行] 命令执行失败,返回码 256
chsrc: 关键错误,强制结束
ccmywish commented 1 month ago

@Viknopx

已修复,这次我在自己机器上试了一下,应该没问题了。麻烦你再测试一下。

Viknopx commented 1 month ago

感谢回复,以上问题均已解决,可以正常换源。

有两个小问题

1.每次执行都会去写一遍配置文件,导致无效数据过多:


# Generated by chsrc v0.1.7.rc5-2024/07/09
export HOMEBREW_API_DOMAIN="https://mirrors.sustech.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.sustech.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.sustech.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.sustech.edu.cn/git/homebrew/homebrew-core.git"

# Generated by chsrc v0.1.7.rc5-2024/07/09
export HOMEBREW_API_DOMAIN="https://mirrors.sustech.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.sustech.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.sustech.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.sustech.edu.cn/git/homebrew/homebrew-core.git"

# Generated by chsrc v0.1.7.rc5-2024/07/09
export HOMEBREW_API_DOMAIN="https://mirrors.sustech.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.sustech.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.sustech.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.sustech.edu.cn/git/homebrew/homebrew-core.git"
➜  ~ 

2.执行完需要手动重启终端或者手动source,请问不自动source是有什么兼容性考量吗?

ccmywish commented 1 month ago
  1. 是的,这个目前就是直接往~/.zshrc里写。目前没有考虑去删除。所以用户如果需要重新换Homebrew的源,可能需要手动删除。

  2. 不能自动source是因为,我们是用C语言写的,不是用shell写的,无法自动source

Viknopx commented 1 month ago

明白,感谢支持和回复。