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.32k stars 54 forks source link

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

Closed jesongit closed 2 weeks ago

jesongit commented 1 month ago

使用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
--------------------------------
换源完成,感谢镜像提供方: 北京外国语大学开源软件镜像站
ccmywish commented 1 month ago

@jesongit 感谢反馈,这个也是之前我们预料到的问题,我们还没有对 docker 做过任何适配

  1. Docker 镜像中一般都没有 sudo,但是目前我们很多外部程序运行时都加了 sudo
  2. 你所反映的这个问题:不存在 /etc/apt/sources.list,还是第一次见,我将考虑如何处理

我们将尽可能在下一次release v0.1.6 中解决该问题

ccmywish commented 4 weeks ago

sudo 的问题已调整。

但没有sources.list是一个非常糟糕的情况,我不想在代码里塞一整个文件内容(如果加了这个,那就还有其他镜像也可能需要加进来)。所以暂时可能解决不了这个问题。

jesongit commented 3 weeks ago

是否可以考虑在仓库加上对应系统的默认sources.list, 如果文件不存在,用curl之类的下载仓库文件中默认文件放在那即可,这样不影响后续替换内容的功能

ccmywish commented 3 weeks ago

@jesongit

已添加支持。在Ubuntu上已经测试过没有问题,Debian 还没有实际测试过。请下载使用最新版,如若测试无问题,请关闭此issue,谢谢

jesongit commented 3 weeks ago

问题场景测试没问题,感谢

jesongit commented 3 weeks ago

另外我测试的是 debian12,格式和之前有些不同,发现写入的默认源应该是有错的 正确的设置应该是下面这样,后缀和12之前系统有些不同,没pr过不太会,麻烦改下

deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main non-free-firmware contrib
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
ccmywish commented 3 weeks ago

@jesongit

感谢指出,已修复。可以重新测试一下 🤝