Skip to content

Commit 89ff5b2

Browse files
committed
feat(recipe): 支持 omarchy 换源
- omarchy dish: 更换 pacman.conf 的 [omarchy] 段 (OPR) 源,仅提供官方上游 stable 源 - 提供 chsrc reset omarchy 恢复官方 OPR 源 - edge 通道用户换源前警告将切换到 stable - 用 source_is_userdefine() 判断用户自定义源 - setsrc 末尾用 chsrc_note2() 提示可另换 Arch 主源 - Omarchy 官方仅发布 x86_64,其他架构报错退出 - Arch 主仓库源与 arch 完全一致,提示用户额外使用 chsrc set arch
1 parent 3e281d4 commit 89ff5b2

3 files changed

Lines changed: 115 additions & 0 deletions

File tree

‎src/chsrc-main.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ chsrc_register_chefs_and_sauciers ()
9191
chef_register_contributor ("@NewbieXvwu", "Mingzhe Jiang", "newbiexvwu@gmail.com", NULL);
9292
chef_register_contributor ("@daocoder", "daocoder", "daocoder@foxmail.com", NULL);
9393
chef_register_contributor ("@JIAFALSEDREAM", "假发", "jiafa@hello-happy.world", NULL);
94+
chef_register_contributor ("@yayoinoyume", "YAYOI27", "yayoi27@yayoi.uk", NULL);
9495

9596
/**
9697
* AI贡献者:

‎src/recipe/menu.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* File Authors : @ccmywish
55
* Contributors : @Mikachu2333
66
* | @BingChunMoLi
7+
* | @yayoinoyume
78
* |
89
* Created On : <2023-09-01>
910
* Major Revision : 6
@@ -86,6 +87,7 @@
8687
#include "os/YUM/Anolis-OS.c"
8788

8889
#include "os/pacman/Arch-Linux.c"
90+
#include "os/pacman/Omarchy.c"
8991
#include "os/pacman/Manjaro-Linux.c"
9092
#include "os/pacman/MSYS2.c"
9193

@@ -209,6 +211,7 @@ chsrc_init_menu ()
209211
add (arch);
210212
add (archlinuxcn);
211213
add (manjaro);
214+
add (omarchy);
212215
add (gentoo);
213216
add (rockylinux);
214217
add (almalinux);

‎src/recipe/os/pacman/Omarchy.c‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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

Comments
 (0)