Split homebrew out

This commit is contained in:
Aoran Zeng
2024-08-16 04:07:54 +08:00
parent cb2fc02ad7
commit 66b2d36c39
4 changed files with 85 additions and 74 deletions

View File

@@ -0,0 +1,81 @@
/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org>
* 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);