From 66b2d36c39b300efdf7e12774e91b1622aec8692 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Fri, 16 Aug 2024 04:07:54 +0800 Subject: [PATCH] Split homebrew out --- include/source.h | 17 +------- src/chsrc.c | 56 +------------------------- src/recipe/catalog.c | 5 +-- src/recipe/ware/Homebrew.c | 81 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 74 deletions(-) create mode 100644 src/recipe/ware/Homebrew.c diff --git a/include/source.h b/include/source.h index 1cea65c..381912a 100644 --- a/include/source.h +++ b/include/source.h @@ -164,21 +164,6 @@ wr_winget_sources[] = { }, -/** - * @time 2023-09-10 更新 - * @note { - * 1. 这些链接将会在setsrc函数中补充完整 - * 2. 不确定 Sustech 能否工作 - * } - */ -wr_brew_sources[] = { - {&Upstream, NULL}, - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/"}, - {&Bfsu, "https://mirrors.bfsu.edu.cn/"}, - {&Zju, "https://mirrors.zju.edu.cn/"}, - {&Sustech, "https://mirrors.sustech.edu.cn/"} -}, - /** * @time 2024-06-08 更新 @@ -265,7 +250,7 @@ def_sources_n(pl_dotnet); def_sources_n(wr_winget); -def_sources_n(wr_brew); def_sources_n(wr_cocoapods); +def_sources_n(wr_cocoapods); def_sources_n(wr_flathub); def_sources_n(wr_nix); def_sources_n(wr_guix); diff --git a/src/chsrc.c b/src/chsrc.c index 875b321..c84097a 100644 --- a/src/chsrc.c +++ b/src/chsrc.c @@ -207,61 +207,7 @@ wr_winget_resetsrc (char *option) } - -void -wr_brew_getsrc (char *option) -{ - char *cmd = "echo HOMEBREW_API_DOMAIN=$HOMEBREW_API_DOMAIN;" - "echo HOMEBREW_BOTTLE_DOMAIN=$HOMEBREW_BOTTLE_DOMAIN;" - "echo HOMEBREW_BREW_GIT_REMOTE=$HOMEBREW_BREW_GIT_REMOTE;" - "echo HOMEBREW_CORE_GIT_REMOTE=$HOMEBREW_CORE_GIT_REMOTE;"; - system (cmd); -} - -/** - * 参考自: https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/ - * - * 自brew 4.0.0 (2023 年 2 月 16日) 起, - * HOMEBREW_INSTALL_FROM_API 会成为默认行为,无需设置。大部分用户无需再克隆 homebrew-core 仓库,故无需设置 HOMEBREW_CORE_GIT_REMOTE 环境变量; - * 但是为了以防万一,我们还是为用户设置该环境变量 - */ -void -wr_brew_setsrc (char *option) -{ - SourceInfo source; - chsrc_yield_source (wr_brew); - chsrc_confirm_source (&source); - - char *splitter = "\n\n# Generated by chsrc " Chsrc_Version; - char *api_domain = xy_strjoin (3, "export HOMEBREW_API_DOMAIN=\"", xy_2strjoin (source.url, "homebrew-bottles/api"), "\""); - char *bottle_domain = xy_strjoin (3, "export HOMEBREW_BOTTLE_DOMAIN=\"", xy_2strjoin (source.url, "homebrew-bottles"), "\""); - char *brew_git_remote = xy_strjoin (3, "export HOMEBREW_BREW_GIT_REMOTE=\"", xy_2strjoin (source.url, "git/homebrew/brew.git"), "\""); - char *core_git_remote = xy_strjoin (3, "export HOMEBREW_CORE_GIT_REMOTE=\"", xy_2strjoin (source.url, "git/homebrew/homebrew-core.git"), "\""); - - char *zshrc = "~/.zshrc"; - chsrc_backup (zshrc); - chsrc_append_to_file (splitter, zshrc); - chsrc_append_to_file (api_domain, zshrc); - chsrc_append_to_file (bottle_domain, zshrc); - chsrc_append_to_file (brew_git_remote, zshrc); - chsrc_append_to_file (core_git_remote, zshrc); - - char *bashrc = "~/.bashrc"; - if (xy_file_exist (bashrc)) - { - chsrc_backup ("~/.bashrc"); - chsrc_append_to_file (splitter, bashrc); - chsrc_append_to_file (api_domain, bashrc); - chsrc_append_to_file (bottle_domain, bashrc); - chsrc_append_to_file (brew_git_remote, bashrc); - chsrc_append_to_file (core_git_remote, bashrc); - } - - chsrc_say_lastly (&source, ChsrcTypeAuto); - chsrc_note2 ("请您重启终端使Homebrew环境变量生效"); -} - - +#include "recipe/ware/Homebrew.c" /** * 参考:https://mirrors.tuna.tsinghua.edu.cn/help/CocoaPods/ diff --git a/src/recipe/catalog.c b/src/recipe/catalog.c index e943fd2..3ee769e 100644 --- a/src/recipe/catalog.c +++ b/src/recipe/catalog.c @@ -93,7 +93,6 @@ static const char def_target_full(wr_winget); -def_target(wr_brew); def_target_noget (wr_cocoapods); def_target_noget (wr_flathub); def_target_noget (wr_nix); @@ -103,7 +102,7 @@ def_target(wr_tex); static const char *wr_winget [] = {"winget", NULL, t(&wr_winget_target)}, -*wr_brew [] = {"brew", "homebrew", NULL, t(&wr_brew_target)}, +*wr_homebrew[] = {"brew", "homebrew", NULL, t(&wr_homebrew_target)}, *wr_cocoapods[] = {"cocoa", "cocoapods","pod", "cocoapod", NULL, t(&wr_cocoapods_target)}, *wr_dockerhub [] ={"dockerhub", "docker", NULL, t(&wr_dockerhub_target)}, *wr_flathub [] = {"flathub", NULL, t(&wr_flathub_target)}, @@ -114,7 +113,7 @@ static const char *wr_anaconda[] = {"conda", "anaconda", NULL, t(&wr_anaconda_target)}, **wr_softwares[] = { - wr_winget, wr_brew, wr_cocoapods, wr_dockerhub, wr_flathub, wr_nix, wr_guix, wr_emacs, wr_tex, wr_anaconda + wr_winget, wr_homebrew, wr_cocoapods, wr_dockerhub, wr_flathub, wr_nix, wr_guix, wr_emacs, wr_tex, wr_anaconda }; #undef t diff --git a/src/recipe/ware/Homebrew.c b/src/recipe/ware/Homebrew.c new file mode 100644 index 0000000..bae0886 --- /dev/null +++ b/src/recipe/ware/Homebrew.c @@ -0,0 +1,81 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * File Authors : Aoran Zeng + * Contributors : Nil Null + * Created On : <2023-09-10> + * Last Modified : <2024-08-15> + * ------------------------------------------------------------*/ + +/** + * @time 2023-09-10 更新 + * @note { + * 1. 这些链接将会在setsrc函数中补充完整 + * 2. 不确定 Sustech 能否工作 + * } + */ +static SourceInfo +wr_homebrew_sources[] = { + {&Upstream, NULL}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/"}, + {&Bfsu, "https://mirrors.bfsu.edu.cn/"}, + {&Zju, "https://mirrors.zju.edu.cn/"}, + {&Sustech, "https://mirrors.sustech.edu.cn/"} +}; +def_sources_n(wr_homebrew); + + +void +wr_homebrew_getsrc (char *option) +{ + char *cmd = "echo HOMEBREW_API_DOMAIN=$HOMEBREW_API_DOMAIN;" + "echo HOMEBREW_BOTTLE_DOMAIN=$HOMEBREW_BOTTLE_DOMAIN;" + "echo HOMEBREW_BREW_GIT_REMOTE=$HOMEBREW_BREW_GIT_REMOTE;" + "echo HOMEBREW_CORE_GIT_REMOTE=$HOMEBREW_CORE_GIT_REMOTE;"; + system (cmd); +} + +/** + * 参考自: https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/ + * + * 自brew 4.0.0 (2023 年 2 月 16日) 起, + * HOMEBREW_INSTALL_FROM_API 会成为默认行为,无需设置。大部分用户无需再克隆 homebrew-core 仓库,故无需设置 HOMEBREW_CORE_GIT_REMOTE 环境变量; + * 但是为了以防万一,我们还是为用户设置该环境变量 + */ +void +wr_homebrew_setsrc (char *option) +{ + SourceInfo source; + chsrc_yield_source (wr_homebrew); + chsrc_confirm_source (&source); + + char *splitter = "\n\n# Generated by chsrc " Chsrc_Version; + char *api_domain = xy_strjoin (3, "export HOMEBREW_API_DOMAIN=\"", xy_2strjoin (source.url, "homebrew-bottles/api"), "\""); + char *bottle_domain = xy_strjoin (3, "export HOMEBREW_BOTTLE_DOMAIN=\"", xy_2strjoin (source.url, "homebrew-bottles"), "\""); + char *brew_git_remote = xy_strjoin (3, "export HOMEBREW_BREW_GIT_REMOTE=\"", xy_2strjoin (source.url, "git/homebrew/brew.git"), "\""); + char *core_git_remote = xy_strjoin (3, "export HOMEBREW_CORE_GIT_REMOTE=\"", xy_2strjoin (source.url, "git/homebrew/homebrew-core.git"), "\""); + + char *zshrc = "~/.zshrc"; + chsrc_backup (zshrc); + chsrc_append_to_file (splitter, zshrc); + chsrc_append_to_file (api_domain, zshrc); + chsrc_append_to_file (bottle_domain, zshrc); + chsrc_append_to_file (brew_git_remote, zshrc); + chsrc_append_to_file (core_git_remote, zshrc); + + char *bashrc = "~/.bashrc"; + if (xy_file_exist (bashrc)) + { + chsrc_backup ("~/.bashrc"); + chsrc_append_to_file (splitter, bashrc); + chsrc_append_to_file (api_domain, bashrc); + chsrc_append_to_file (bottle_domain, bashrc); + chsrc_append_to_file (brew_git_remote, bashrc); + chsrc_append_to_file (core_git_remote, bashrc); + } + + chsrc_say_lastly (&source, ChsrcTypeAuto); + chsrc_note2 ("请您重启终端使Homebrew环境变量生效"); +} + +def_target(wr_homebrew);