|
| 1 | +/** ------------------------------------------------------------ |
| 2 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | + * ------------------------------------------------------------*/ |
| 4 | + |
| 5 | +#define OS_Pacman_Omarchy_Conf "/etc/pacman.conf" |
| 6 | + |
| 7 | + |
| 8 | +/** ------------------------------------------------------------ |
| 9 | + * omarchy dish (换 OPR 专属仓库) |
| 10 | + * |
| 11 | + * Omarchy 的 Arch Linux 主仓库源与 arch 完全一致,请额外使用 |
| 12 | + * `chsrc set arch` 来更换;本 dish 只负责 [omarchy] 段 (OPR)。 |
| 13 | + * ------------------------------------------------------------*/ |
| 14 | + |
| 15 | +def_dish(os_omarchy, "omarchy"); |
| 16 | + |
| 17 | +void |
| 18 | +os_omarchy_prepare () |
| 19 | +{ |
| 20 | + chef_prep_this_dish (os_omarchy, gsr); |
| 21 | + |
| 22 | + chef_set_recipe_created_on (this, "2026-09-04"); |
| 23 | + chef_set_recipe_last_updated (this, "2026-09-06"); |
| 24 | + |
| 25 | + chef_set_chefs (this, 1, "@yayoinoyume"); |
| 26 | + chef_set_sauciers (this, 0); |
| 27 | + |
| 28 | + chef_set_os_scope (this); |
| 29 | + chef_deny_english(this); |
| 30 | + chef_allow_user_define(this); |
| 31 | + |
| 32 | + chef_set_note (this, |
| 33 | + "Omarchy 是基于 Arch Linux 开发的发行版,除官方专属软件包仓库 (OPR) 外,其余换源与 Arch 保持一致。" |
| 34 | + "本菜品仅更换 OPR 源;Arch Linux 主仓库请另行 chsrc set arch,恢复官方 OPR 源请 chsrc reset omarchy。" |
| 35 | + "注意: omarchy-refresh-pacman 更新脚本会覆盖此配置,换源后若被还原,请重新执行", |
| 36 | + "Omarchy is an Arch Linux-based distro; apart from its official package repository (OPR), source switching is the same as Arch. " |
| 37 | + "This dish only switches the OPR source; use chsrc set arch for the Arch Linux main source, and chsrc reset omarchy to restore the official OPR source. " |
| 38 | + "Note: omarchy-refresh-pacman may overwrite this configuration; rerun if it reverts"); |
| 39 | + |
| 40 | + def_sources_begin() |
| 41 | + {&UpstreamProvider, "https://pkgs.omarchy.org/stable/$arch", DelegateToUpstream} |
| 42 | + def_sources_end() |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +void |
| 47 | +os_omarchy_getsrc (char *option) |
| 48 | +{ |
| 49 | + chsrc_view_file (OS_Pacman_Omarchy_Conf); |
| 50 | +} |
| 51 | + |
| 52 | + |
| 53 | +/** |
| 54 | + * @consult |
| 55 | + * 1. https://github.com/basecamp/omarchy 官方 pacman.conf 模板 (仅 x86_64) |
| 56 | + */ |
| 57 | +void |
| 58 | +os_omarchy_setsrc (char *option) |
| 59 | +{ |
| 60 | + /* Omarchy 官方仅发布 x86_64 仓库,非 x86_64 无 OPR */ |
| 61 | + char *arch = chsrc_get_cpuarch (); |
| 62 | + if (strncmp (arch, "x86_64", 6) != 0) |
| 63 | + { |
| 64 | + chsrc_error ("Omarchy 目前仅支持 x86_64 架构"); |
| 65 | + exit (Exit_Unsupported); |
| 66 | + } |
| 67 | + |
| 68 | + chsrc_ensure_root (); |
| 69 | + |
| 70 | + chsrc_use_this_source (os_omarchy); |
| 71 | + |
| 72 | + chsrc_backup (OS_Pacman_Omarchy_Conf); |
| 73 | + |
| 74 | + /* 上游默认源基于 stable 通道,edge 通道用户换源后将切换到 stable */ |
| 75 | + bool is_edge = xy_run_get_status ("grep -q '^Server = https://pkgs.omarchy.org/edge/' " OS_Pacman_Omarchy_Conf) == 0; |
| 76 | + if (is_edge && !source_is_userdefine (&source)) |
| 77 | + chsrc_warn2 ("检测到当前使用 edge 通道,上游默认源基于 stable 通道,继续执行将切换到 stable"); |
| 78 | + |
| 79 | + /* 幂等: 替换 [omarchy] 段的 Server 行为所选源;已是所选源则跳过 */ |
| 80 | + char *exists_cmd = xy_strcat (3, "grep -qxF 'Server = ", source.url, "' " OS_Pacman_Omarchy_Conf); |
| 81 | + if (xy_run_get_status (exists_cmd) == 0) |
| 82 | + { |
| 83 | + chsrc_debug ("recipe", "所选 Server 行已存在,跳过 pacman.conf 修改"); |
| 84 | + } |
| 85 | + else |
| 86 | + { |
| 87 | + char *sed_cmd = xy_strcat (4, "sed -i 's|^Server = https://pkgs.omarchy.org/.*|Server = ", |
| 88 | + source.url, "|' ", OS_Pacman_Omarchy_Conf); |
| 89 | + chsrc_run (sed_cmd, RunOpt_Default); |
| 90 | + } |
| 91 | + |
| 92 | + /* 清理本地陈旧 omarchy.db 缓存: 残留旧 sig 会导致 -Syy 验签失败 */ |
| 93 | + chsrc_run ("rm -f /var/lib/pacman/sync/omarchy.db /var/lib/pacman/sync/omarchy.db.sig", RunOpt_Default); |
| 94 | + |
| 95 | + chsrc_run ("pacman -Syy", RunOpt_No_Last_New_Line); |
| 96 | + |
| 97 | + chsrc_determine_chgtype (ChgType_Auto); |
| 98 | + chsrc_conclude (&source); |
| 99 | + |
| 100 | + chsrc_note2 (ENGLISH |
| 101 | + ? "This dish only switches the OPR source; use chsrc set arch for the Arch Linux main source." |
| 102 | + : "本菜品仅更换 OPR 源;Arch Linux 主仓库请另行 chsrc set arch。"); |
| 103 | +} |
| 104 | + |
| 105 | + |
| 106 | +void |
| 107 | +os_omarchy_resetsrc (char *option) |
| 108 | +{ |
| 109 | + /* reset 模式下 chsrc_use_this_source 返回官方源,即恢复官方 stable 通道 */ |
| 110 | + os_omarchy_setsrc (option); |
| 111 | +} |
0 commit comments