From 0dba3904cf1f38e83a5f5e03a1a1fd23de06638a Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Mon, 14 Jul 2025 17:06:10 +0800 Subject: [PATCH] Rewrite old source list for `Ubuntu` and `Debian` --- src/recipe/os/APT/common.h | 53 +++++++++----------------- src/recipe/os/APT/rawstr4c.h | 16 ++++++++ src/recipe/os/APT/rawstr4c.md | 70 +++++++++++++++++++++++++++++++++++ tool/rawstr4c/README.md | 4 +- 4 files changed, 106 insertions(+), 37 deletions(-) create mode 100644 src/recipe/os/APT/rawstr4c.h create mode 100644 src/recipe/os/APT/rawstr4c.md diff --git a/src/recipe/os/APT/common.h b/src/recipe/os/APT/common.h index a3f560f..1fc51de 100644 --- a/src/recipe/os/APT/common.h +++ b/src/recipe/os/APT/common.h @@ -5,10 +5,12 @@ * Contributors : happy game * | * Created On : <2024-06-14> - * Major Revision : 2 - * Last Modified : <2025-03-25> + * Major Revision : 3 + * Last Modified : <2025-07-14> * ------------------------------------------------------------*/ +#include "rawstr4c.h" + #define OS_Apt_SourceList "/etc/apt/sources.list" #define OS_Apt_SourceList_D "/etc/apt/sources.list.d/" @@ -63,7 +65,7 @@ ensure_debian_or_ubuntu_old_sourcelist (int debian_type) else { char *msg = ENGLISH ? "Will generate a new source list file" - : "将生成新的源配置文件"; + : "将生成新的源配置文件"; chsrc_note2 (msg); } @@ -78,53 +80,34 @@ ensure_debian_or_ubuntu_old_sourcelist (int debian_type) if (debian_type == OS_Is_Ubuntu) { - makeup = xy_strjoin (9, - "# Generated by chsrc " Chsrc_Version "\n\n" - "deb " Chsrc_Maintain_URL "/ubuntu ", codename, " main restricted universe multiverse\n" - "deb " Chsrc_Maintain_URL "/ubuntu ", codename, "-updates main restricted universe multiverse\n" - "deb " Chsrc_Maintain_URL "/ubuntu ", codename, "-backports main restricted universe multiverse\n" - "deb " Chsrc_Maintain_URL "/ubuntu ", codename, "-security main restricted universe multiverse\n"); + makeup = xy_str_gsub (RAWSTR_os_apt_based_ubuntu_old_source_list, "@v@", Chsrc_Version); + makeup = xy_str_gsub (makeup, "@1@", Chsrc_Maintain_URL); + makeup = xy_str_gsub (makeup, "@2@", codename); } else { if (version >= 12) /* bookworm */ { - /** - * https://wiki.debian.org/SourcesList - * https://mirrors.tuna.tsinghua.edu.cn/help/debian/ - * 从 Debian 12 开始,开始有一项 non-free-firmware - */ - makeup = xy_strjoin (9, - "# Generated by chsrc " Chsrc_Version "\n\n" - "deb " Chsrc_Maintain_URL "/debian ", codename, " main contrib non-free non-free-firmware\n" - "deb " Chsrc_Maintain_URL "/debian ", codename, "-updates main contrib non-free non-free-firmware\n" - "deb " Chsrc_Maintain_URL "/debian ", codename, "-backports main contrib non-free non-free-firmware\n" - "deb " Chsrc_Maintain_URL "/debian-security ", codename, "-security main contrib non-free non-free-firmware\n"); - /* 上述 debian-security 这种写法是和 Debian 10不同的,所以我们只能支持 Debian 11+ */ + makeup = xy_str_gsub (RAWSTR_os_apt_based_debian_12_source_list, "@v@", Chsrc_Version); + makeup = xy_str_gsub (makeup, "@1@", Chsrc_Maintain_URL); + makeup = xy_str_gsub (makeup, "@2@", codename); } else if (version >= 11) /* bullseye */ { - makeup = xy_strjoin (9, - "# Generated by chsrc " Chsrc_Version "(" Chsrc_Maintain_URL ")\n\n" - "deb " Chsrc_Maintain_URL "/debian ", codename, " main contrib non-free\n" - "deb " Chsrc_Maintain_URL "/debian ", codename, "-updates main contrib non-free\n" - "deb " Chsrc_Maintain_URL "/debian ", codename, "-backports main contrib non-free\n" - "deb " Chsrc_Maintain_URL "/debian-security ", codename, "-security main contrib non-free\n"); + makeup = xy_str_gsub (RAWSTR_os_apt_based_debian_11_source_list, "@v@", Chsrc_Version); + makeup = xy_str_gsub (makeup, "@1@", Chsrc_Maintain_URL); + makeup = xy_str_gsub (makeup, "@2@", codename); } else if (version >= 10) /* buster */ { - makeup = xy_strjoin (9, - "# Generated by chsrc " Chsrc_Version "(" Chsrc_Maintain_URL ")\n\n" - "deb " Chsrc_Maintain_URL "/debian ", codename, " main contrib non-free\n" - "deb " Chsrc_Maintain_URL "/debian ", codename, "-updates main contrib non-free\n" - "deb " Chsrc_Maintain_URL "/debian ", codename, "-backports main contrib non-free\n" - "deb " Chsrc_Maintain_URL "/debian-security ", codename, "/updates main contrib non-free\n"); - /* 上述 debian-security 这种写法是和 Debian 11 不同的 */ + makeup = xy_str_gsub (RAWSTR_os_apt_based_debian_10_source_list, "@v@", Chsrc_Version); + makeup = xy_str_gsub (makeup, "@1@", Chsrc_Maintain_URL); + makeup = xy_str_gsub (makeup, "@2@", codename); } else { char *msg = ENGLISH ? "Your Debian version is too low (<10) for chsrc to support" - : "你的 Debian 版本过低 (<10),暂不支持换源"; + : "你的 Debian 版本过低 (<10),暂不支持换源"; chsrc_error (msg); exit (Exit_Unsupported); } diff --git a/src/recipe/os/APT/rawstr4c.h b/src/recipe/os/APT/rawstr4c.h new file mode 100644 index 0000000..30fb6a6 --- /dev/null +++ b/src/recipe/os/APT/rawstr4c.h @@ -0,0 +1,16 @@ +#pragma once + +/** + * Generated by rawstr4c v0.1.0.1-2025/07/14 + * + * Date: 2025-07-14T17:01:22.816708+08:00 + */ + +char RAWSTR_os_apt_based_ubuntu_old_source_list[] = "\x23\x20\x47\x65\x6e\x65\x72\x61\x74\x65\x64\x20\x62\x79\x20\x63\x68\x73\x72\x63\x20\x40\x76\x40\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x75\x62\x75\x6e\x74\x75\x20\x40\x32\x40\x20\x6d\x61\x69\x6e\x20\x72\x65\x73\x74\x72\x69\x63\x74\x65\x64\x20\x75\x6e\x69\x76\x65\x72\x73\x65\x20\x6d\x75\x6c\x74\x69\x76\x65\x72\x73\x65\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x75\x62\x75\x6e\x74\x75\x20\x40\x32\x40\x2d\x75\x70\x64\x61\x74\x65\x73\x20\x6d\x61\x69\x6e\x20\x72\x65\x73\x74\x72\x69\x63\x74\x65\x64\x20\x75\x6e\x69\x76\x65\x72\x73\x65\x20\x6d\x75\x6c\x74\x69\x76\x65\x72\x73\x65\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x75\x62\x75\x6e\x74\x75\x20\x40\x32\x40\x2d\x62\x61\x63\x6b\x70\x6f\x72\x74\x73\x20\x6d\x61\x69\x6e\x20\x72\x65\x73\x74\x72\x69\x63\x74\x65\x64\x20\x75\x6e\x69\x76\x65\x72\x73\x65\x20\x6d\x75\x6c\x74\x69\x76\x65\x72\x73\x65\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x75\x62\x75\x6e\x74\x75\x20\x40\x32\x40\x2d\x73\x65\x63\x75\x72\x69\x74\x79\x20\x6d\x61\x69\x6e\x20\x72\x65\x73\x74\x72\x69\x63\x74\x65\x64\x20\x75\x6e\x69\x76\x65\x72\x73\x65\x20\x6d\x75\x6c\x74\x69\x76\x65\x72\x73\x65\x0a"; + +char RAWSTR_os_apt_based_debian_12_source_list[] = "\x23\x20\x47\x65\x6e\x65\x72\x61\x74\x65\x64\x20\x62\x79\x20\x63\x68\x73\x72\x63\x20\x40\x76\x40\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x64\x65\x62\x69\x61\x6e\x20\x40\x32\x40\x20\x6d\x61\x69\x6e\x20\x63\x6f\x6e\x74\x72\x69\x62\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x2d\x66\x69\x72\x6d\x77\x61\x72\x65\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x64\x65\x62\x69\x61\x6e\x20\x40\x32\x40\x2d\x75\x70\x64\x61\x74\x65\x73\x20\x6d\x61\x69\x6e\x20\x63\x6f\x6e\x74\x72\x69\x62\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x2d\x66\x69\x72\x6d\x77\x61\x72\x65\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x64\x65\x62\x69\x61\x6e\x20\x40\x32\x40\x2d\x62\x61\x63\x6b\x70\x6f\x72\x74\x73\x20\x6d\x61\x69\x6e\x20\x63\x6f\x6e\x74\x72\x69\x62\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x2d\x66\x69\x72\x6d\x77\x61\x72\x65\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x64\x65\x62\x69\x61\x6e\x2d\x73\x65\x63\x75\x72\x69\x74\x79\x20\x40\x32\x40\x2d\x73\x65\x63\x75\x72\x69\x74\x79\x20\x6d\x61\x69\x6e\x20\x63\x6f\x6e\x74\x72\x69\x62\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x2d\x66\x69\x72\x6d\x77\x61\x72\x65\x0a"; + +char RAWSTR_os_apt_based_debian_11_source_list[] = "\x23\x20\x47\x65\x6e\x65\x72\x61\x74\x65\x64\x20\x62\x79\x20\x63\x68\x73\x72\x63\x20\x40\x76\x40\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x64\x65\x62\x69\x61\x6e\x20\x40\x32\x40\x20\x6d\x61\x69\x6e\x20\x63\x6f\x6e\x74\x72\x69\x62\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x64\x65\x62\x69\x61\x6e\x20\x40\x32\x40\x2d\x75\x70\x64\x61\x74\x65\x73\x20\x6d\x61\x69\x6e\x20\x63\x6f\x6e\x74\x72\x69\x62\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x64\x65\x62\x69\x61\x6e\x20\x40\x32\x40\x2d\x62\x61\x63\x6b\x70\x6f\x72\x74\x73\x20\x6d\x61\x69\x6e\x20\x63\x6f\x6e\x74\x72\x69\x62\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x64\x65\x62\x69\x61\x6e\x2d\x73\x65\x63\x75\x72\x69\x74\x79\x20\x40\x32\x40\x2d\x73\x65\x63\x75\x72\x69\x74\x79\x20\x6d\x61\x69\x6e\x20\x63\x6f\x6e\x74\x72\x69\x62\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x0a"; + +char RAWSTR_os_apt_based_debian_10_source_list[] = "\x23\x20\x47\x65\x6e\x65\x72\x61\x74\x65\x64\x20\x62\x79\x20\x63\x68\x73\x72\x63\x20\x40\x76\x40\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x64\x65\x62\x69\x61\x6e\x20\x40\x32\x40\x20\x6d\x61\x69\x6e\x20\x63\x6f\x6e\x74\x72\x69\x62\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x64\x65\x62\x69\x61\x6e\x20\x40\x32\x40\x2d\x75\x70\x64\x61\x74\x65\x73\x20\x6d\x61\x69\x6e\x20\x63\x6f\x6e\x74\x72\x69\x62\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x64\x65\x62\x69\x61\x6e\x20\x40\x32\x40\x2d\x62\x61\x63\x6b\x70\x6f\x72\x74\x73\x20\x6d\x61\x69\x6e\x20\x63\x6f\x6e\x74\x72\x69\x62\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x0a\x64\x65\x62\x20\x40\x31\x40\x2f\x64\x65\x62\x69\x61\x6e\x2d\x73\x65\x63\x75\x72\x69\x74\x79\x20\x40\x32\x40\x2f\x75\x70\x64\x61\x74\x65\x73\x20\x6d\x61\x69\x6e\x20\x63\x6f\x6e\x74\x72\x69\x62\x20\x6e\x6f\x6e\x2d\x66\x72\x65\x65\x0a"; + diff --git a/src/recipe/os/APT/rawstr4c.md b/src/recipe/os/APT/rawstr4c.md new file mode 100644 index 0000000..645fa03 --- /dev/null +++ b/src/recipe/os/APT/rawstr4c.md @@ -0,0 +1,70 @@ + + +# rawstr4c input + +- prefix = `RAWSTR_os_apt_based` +- output = `:global-variable-only-header` +- translate = `:hex` +- keep-postfix = `false` + + + +## Ubuntu old source list + +```sh +# Generated by chsrc @v@ +deb @1@/ubuntu @2@ main restricted universe multiverse +deb @1@/ubuntu @2@-updates main restricted universe multiverse +deb @1@/ubuntu @2@-backports main restricted universe multiverse +deb @1@/ubuntu @2@-security main restricted universe multiverse +``` + + + +## Debian 12 source list + +```sh +# Generated by chsrc @v@ +deb @1@/debian @2@ main contrib non-free non-free-firmware +deb @1@/debian @2@-updates main contrib non-free non-free-firmware +deb @1@/debian @2@-backports main contrib non-free non-free-firmware +deb @1@/debian-security @2@-security main contrib non-free non-free-firmware +``` + +从 Debian 12 开始,开始有一项 `non-free-firmware` + +- https://wiki.debian.org/SourcesList +- https://mirrors.tuna.tsinghua.edu.cn/help/debian/ + + + +## Debian 11 source list + +```sh +# Generated by chsrc @v@ +deb @1@/debian @2@ main contrib non-free +deb @1@/debian @2@-updates main contrib non-free +deb @1@/debian @2@-backports main contrib non-free +deb @1@/debian-security @2@-security main contrib non-free +``` + + +## Debian 10 source list + +```sh +# Generated by chsrc @v@ +deb @1@/debian @2@ main contrib non-free +deb @1@/debian @2@-updates main contrib non-free +deb @1@/debian @2@-backports main contrib non-free +deb @1@/debian-security @2@/updates main contrib non-free +``` + +上述 debian-security 这种写法是和 Debian 11 不同的,我们只支持到这里 diff --git a/tool/rawstr4c/README.md b/tool/rawstr4c/README.md index 81c6e88..1a723d2 100644 --- a/tool/rawstr4c/README.md +++ b/tool/rawstr4c/README.md @@ -7,7 +7,7 @@ ! Contributors : Nul None ! | ! Created On : <2025-07-12> - ! Last Modified : <2025-07-13> + ! Last Modified : <2025-07-14> ! ---------------------------------------------------------- --> # rawstr4c @@ -73,7 +73,7 @@ just rawstr4c ./src/recipe/ware - name = - 生成的变量名,默认将会包含前缀和后缀 + 生成的变量名,默认将会包含前缀和后缀。如果没有给该配置项,将会使用该节标题 - name-literally = `false` | `true`