Skip to content

Commit

Permalink
Implement reset for Fedora
Browse files Browse the repository at this point in the history
[GitHub #117 #111]
  • Loading branch information
ccmywish committed Nov 4, 2024
1 parent 5a225c4 commit 0373e81
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
12 changes: 8 additions & 4 deletions include/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Contributors : Shengwei Chen <[email protected]>
* |
* Created On : <2023-08-29>
* Last Modified : <2024-10-09>
* Last Modified : <2024-11-04>
*
* 通用镜像站与换源信息
* ------------------------------------------------------------*/
Expand Down Expand Up @@ -192,8 +192,10 @@ typedef struct TargetInfo_t {


#define def_target_inner_s(t) NULL, t##_setsrc, NULL, NULL
#define def_target_inner_gs(t) t##_getsrc, t##_setsrc, NULL, NULL
#define def_target_inner_sr(t) NULL, t##_setsrc, t##_resetsrc, NULL
#define def_target_inner_sf(t) NULL, t##_setsrc, NULL, t##_feat
#define def_target_inner_srf(t) NULL, t##_setsrc, t##_resetsrc, t##_feat
#define def_target_inner_gs(t) t##_getsrc, t##_setsrc, NULL, NULL
#define def_target_inner_gsr(t) t##_getsrc, t##_setsrc, t##_resetsrc, NULL
#define def_target_inner_gsf(t) t##_getsrc, t##_setsrc, NULL, t##_feat
#define def_target_inner_gsrf(t) t##_getsrc, t##_setsrc, t##_resetsrc, t##_feat
Expand All @@ -202,9 +204,11 @@ typedef struct TargetInfo_t {

// 大部分target还不支持reset,所以暂时先默认设置为NULL来过渡
#define def_target(t) TargetInfo t##_target = {def_target_inner_gs(t),def_target_sourcesn(t)}
#define def_target_gs(t) TargetInfo t##_target = {def_target_inner_gs(t),def_target_sourcesn(t)}
#define def_target_s(t) TargetInfo t##_target = {def_target_inner_s(t),def_target_sourcesn(t)}
#define def_target_sr(t) TargetInfo t##_target = {def_target_inner_sr(t),def_target_sourcesn(t)}
#define def_target_sf(t) TargetInfo t##_target = {def_target_inner_sf(t),def_target_sourcesn(t)}
#define def_target_srf(t) TargetInfo t##_target = {def_target_inner_srf(t),def_target_sourcesn(t)}
#define def_target_gs(t) TargetInfo t##_target = {def_target_inner_gs(t),def_target_sourcesn(t)}
#define def_target_gsr(t) TargetInfo t##_target = {def_target_inner_gsr(t),def_target_sourcesn(t)}
#define def_target_gsf(t) TargetInfo t##_target = {def_target_inner_gsf(t),def_target_sourcesn(t)}
#define def_target_gsrf(t) TargetInfo t##_target = {def_target_inner_gsrf(t),def_target_sourcesn(t)}
#define def_target_s(t) TargetInfo t##_target = {def_target_inner_s(t),def_target_sourcesn(t)}
28 changes: 19 additions & 9 deletions src/recipe/os/YUM/Fedora-Linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Heng Guo <[email protected]>
* Contributors : Aoran Zeng <[email protected]>
* | happy game <[email protected]>
* Contributors : Aoran Zeng <[email protected]>
* |
* Created On : <2023-09-26>
* Last Modified : <2024-11-04>
*
Expand All @@ -15,7 +16,7 @@
*/
static SourceInfo
os_fedora_sources[] = {
{&Upstream, "http://download.example/pub/fedora/linux"},
{&Upstream, "http://download.example/pub/fedora/linux"},
{&Ali, "https://mirrors.aliyun.com/fedora"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/fedora"},
{&Ustc, "https://mirrors.ustc.edu.cn/fedora"},
Expand All @@ -36,6 +37,8 @@ def_sources_n(os_fedora);
void
os_fedora_setsrc (char *option)
{
char *setsrc_type = xy_streql (option, SetsrcType_Reset) ? SetsrcType_Reset : SetsrcType_Auto;

chsrc_ensure_root ();

chsrc_yield_source_and_confirm (os_fedora);
Expand All @@ -45,16 +48,17 @@ os_fedora_setsrc (char *option)
chsrc_backup ("/etc/yum.repos.d/fedora.repo");
chsrc_backup ("/etc/yum.repos.d/fedora-updates.repo");

// 取消注释 baseurl
// 取消对 baseurl 的注释
char* cmd = xy_strjoin (5, "sed ",
"-i 's|^#baseurl=|baseurl=",
"|g' ",
"/etc/yum.repos.d/fedora.repo ",
"/etc/yum.repos.d/fedora-updates.repo");
chsrc_run (cmd, RunOpt_Default);

// fedora的换源涉及 /etc/yum.repos.d/fedora.repo和 /etc/yum.repos.d/fedora-updates.repo
// 需要替换 baseurl=source.url/releases/... 和 baseurl=source.url/releases/...
// 替换
// (1) baseurl=<<URL>>/releases/...
// (2) baseurl=<<URL>>/updates/...
cmd = xy_strjoin (7, "sed ",
"-i -E 's!^baseurl=.*?/(releases|updates)/!baseurl=",
source.url,
Expand All @@ -69,25 +73,31 @@ os_fedora_setsrc (char *option)
chsrc_log2 ("(2) /etc/yum.repos.d/fedora-updates.repo");

chsrc_run ("dnf makecache", RunOpt_No_Last_New_Line);
chsrc_conclude (&source, SetsrcType_Auto);

chsrc_conclude (&source, setsrc_type);
}


void
os_fedora_resetsrc (char *option)
{
os_fedora_setsrc (SetsrcType_Reset);
}


FeatInfo
os_fedora_feat (char *option)
{
FeatInfo f = {0};

f.can_get = false;
f.can_reset = false;
f.can_reset = true;

f.cap_locally = CanNot;
f.can_english = true;
f.can_english = false;
f.can_user_define = true;

return f;
}

def_target_sf(os_fedora);

0 comments on commit 0373e81

Please sign in to comment.