11/** ------------------------------------------------------------
22 * SPDX-License-Identifier: GPL-3.0-or-later
33 * -------------------------------------------------------------
4- * File Authors : Aoran Zeng <[email protected] > 5- 6- * Contributors : Yangmoooo <[email protected] > 7- * |
8- * Created On : <2023-09-02>
9- * Last Modified : <2024-12-18>
4+ * File Authors : Aoran Zeng <[email protected] > 5+ 6+ * Contributors : Yangmoooo <[email protected] > 7+ * | GitHub Copilot <https://github.com/copilot>
8+ * |
9+ * Created On : <2023-09-02>
10+ * Major Revision : 3
11+ * Last Modified : <2025-03-25>
1012 * ------------------------------------------------------------*/
1113
1214static SourceProvider_t os_debian_upstream =
@@ -55,20 +57,30 @@ os_debian_getsrc (char *option)
5557 return ;
5658}
5759
60+
61+ static bool
62+ os_debian_does_old_sourcelist_use_cdrom (void )
63+ {
64+ /* 我们只检查旧版sourcelist,因为 common.h 中的填充只支持旧版 */
65+ char * cmd = xy_2strjoin ("grep -q '^deb cdrom:' " , OS_Apt_SourceList );
66+ int ret = system (cmd );
67+ bool use_cdrom = ret == 0 ;
68+
69+ return use_cdrom ;
70+ }
71+
72+
5873void
5974os_debian_setsrc_for_deb822 (char * option )
6075{
6176 chsrc_yield_source_and_confirm (os_debian );
6277
63- chsrc_note2 ("如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并需要您运行:" );
64- puts ("apt install apt-transport-https ca-certificates" );
65-
6678 chsrc_backup (OS_Debian_SourceList_DEB822 );
6779
6880 char * cmd = xy_strjoin (3 , "sed -E -i 's@https?://.*/debian/?@" , source .url , "@g' " OS_Debian_SourceList_DEB822 );
6981 chsrc_run (cmd , RunOpt_Default );
7082
71- // debian-security 源和其他源不一样
83+ /* debian-security 源和其他源不一样 */
7284 cmd = xy_strjoin (3 , "sed -E -i 's@https?://.*/debian-security/?@" , source .url , "-security@g' " OS_Debian_SourceList_DEB822 );
7385 chsrc_run (cmd , RunOpt_Default );
7486
@@ -80,6 +92,8 @@ os_debian_setsrc_for_deb822 (char *option)
8092
8193
8294/**
95+ * 处理旧版(非DEB822) sourcelist 的换源
96+ *
8397 * Debian 10 Buster 以上版本默认支持 HTTPS 源。如果遇到无法拉取 HTTPS 源的情况,请先使用 HTTP 源并安装
8498 * apt install apt-transport-https ca-certificates
8599 */
@@ -90,27 +104,46 @@ os_debian_setsrc (char *option)
90104
91105 if (chsrc_check_file (OS_Debian_SourceList_DEB822 ))
92106 {
93- chsrc_note2 ("将基于新格式换源 " );
107+ chsrc_note2 ("将基于新格式(DEB822)换源 " );
94108 os_debian_setsrc_for_deb822 (option );
95109 return ;
96110 }
97111
112+ chsrc_note2 ("将基于旧格式(非DEB822)换源" );
98113
99- // Docker环境下,Debian镜像可能不存在该文件
114+ /* Docker环境下,Debian镜像可能不存在该文件 */
100115 bool sourcelist_exist = ensure_apt_sourcelist (OS_Is_Debian_Literally );
101116
117+ /**
118+ * 处理带有CDROM源的sourcelist
119+ *
120+ * https://github.com/RubyMetric/chsrc/issues/185#issuecomment-2746072917
121+ */
122+ if (sourcelist_exist )
123+ {
124+ bool use_cdrom = os_debian_does_old_sourcelist_use_cdrom ();
125+ if (use_cdrom )
126+ {
127+ chsrc_backup (OS_Debian_old_SourceList );
128+ system ("rm " OS_Debian_old_SourceList );
129+ chsrc_warn2 ("旧版源配置文件中使用了 CDROM 源,已删除(但备份)该配置文件,重新配置" );
130+ /* 现在的情况是:系统中已经没有配置文件了 */
131+ sourcelist_exist = ensure_apt_sourcelist (OS_Is_Debian_Literally );
132+ }
133+ }
134+
102135 chsrc_yield_source_and_confirm (os_debian );
103136
104137 chsrc_note2 ("如果遇到无法拉取 HTTPS 源的情况,我们会使用 HTTP 源并需要您运行:" );
105- puts ("apt install apt-transport-https ca-certificates" );
138+ say ("apt install apt-transport-https ca-certificates" );
106139
107- // 不存在的时候,用的是我们生成的无效文件 ,不要备份
140+ /* 不存在的时候,用的是我们生成的用来填充占位的无效文件 ,不要备份 */
108141 if (sourcelist_exist )
109142 {
110- chsrc_backup (OS_Apt_SourceList );
143+ chsrc_backup (OS_Debian_old_SourceList );
111144 }
112145
113- char * cmd = xy_strjoin (3 , "sed -E -i \'s@https?://.*/debian/?@" , source .url , "@g\' " OS_Apt_SourceList );
146+ char * cmd = xy_strjoin (3 , "sed -E -i \'s@https?://.*/debian/?@" , source .url , "@g\' " OS_Debian_old_SourceList );
114147
115148 chsrc_run (cmd , RunOpt_Default );
116149 chsrc_run ("apt update" , RunOpt_No_Last_New_Line );
@@ -145,4 +178,3 @@ os_debian_feat (char *option)
145178}
146179
147180def_target_gsrf (os_debian );
148-
0 commit comments