From a0362348b096cc4fbfb64c6d4d8515f07bd751c6 Mon Sep 17 00:00:00 2001 From: neo Date: Thu, 15 Apr 2021 11:11:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=81=A2=E5=A4=8Dbottles=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dumi/theme/builtins/SourceGenerate.tsx | 33 +++++++++++++++++++++++++ .dumi/theme/constants/index.ts | 15 +++++------ docs/guide/m1.md | 10 +++++++- docs/guide/start.md | 29 ++++++++++++++++++++++ 4 files changed, 79 insertions(+), 8 deletions(-) diff --git a/.dumi/theme/builtins/SourceGenerate.tsx b/.dumi/theme/builtins/SourceGenerate.tsx index 2fbea5c..8e6719a 100644 --- a/.dumi/theme/builtins/SourceGenerate.tsx +++ b/.dumi/theme/builtins/SourceGenerate.tsx @@ -73,6 +73,22 @@ const SourceGenerate = ({ first }) => { shellArray.push('brew update'); + shellArray.push(''); + + const file = terminalType === 'zsh' ? '.zprofile' : '.bash_profile'; + + if (platform === Platform.Linux && matchMirror.linuxBottles) { + shellArray.push( + `echo 'export HOMEBREW_BOTTLE_DOMAIN=${matchMirror.linuxBottles}' >> ~/${file}`, + ); + } else { + shellArray.push( + `echo 'export HOMEBREW_BOTTLE_DOMAIN=${matchMirror.bottles}' >> ~/${file}`, + ); + } + + shellArray.push(`source ~/${file}`); + return shellArray.join('\n'); } @@ -95,6 +111,23 @@ const SourceGenerate = ({ first }) => { '/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"', ); + shellArray.push(''); + shellArray.push('# 2.安装完成后设置'); + + const file = terminalType === 'zsh' ? '.zprofile' : '.bash_profile'; + + if (platform === Platform.Linux && matchMirror.linuxBottles) { + shellArray.push( + `echo 'export HOMEBREW_BOTTLE_DOMAIN=${matchMirror.linuxBottles}' >> ~/${file}`, + ); + } else { + shellArray.push( + `echo 'export HOMEBREW_BOTTLE_DOMAIN=${matchMirror.bottles}' >> ~/${file}`, + ); + } + + shellArray.push(`source ~/${file}`); + return shellArray.join('\n'); } diff --git a/.dumi/theme/constants/index.ts b/.dumi/theme/constants/index.ts index 7e91204..f06ab79 100644 --- a/.dumi/theme/constants/index.ts +++ b/.dumi/theme/constants/index.ts @@ -3,7 +3,7 @@ export const tencentMirror = { core: 'https://mirrors.cloud.tencent.com/homebrew/homebrew-core.git', linuxCore: 'https://mirrors.cloud.tencent.com/homebrew/linuxbrew-core.git', cask: 'https://mirrors.cloud.tencent.com/homebrew/homebrew-cask.git', - bottles: 'https://mirrors.cloud.tencent.com/homebrew-bottles/bottles', + bottles: 'https://mirrors.cloud.tencent.com/homebrew-bottles/bottles/', linuxBottles: '', }; @@ -13,8 +13,9 @@ export const tsinghuaMirror = { linuxCore: 'https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/linuxbrew-core.git', cask: 'https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git', - bottles: 'https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles', - linuxBottles: 'https://mirrors.tuna.tsinghua.edu.cn/linuxbrew-bottles', + bottles: 'https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles/', + linuxBottles: + 'https://mirrors.tuna.tsinghua.edu.cn/linuxbrew-bottles/bottles/', }; export const ustcMirror = { @@ -22,8 +23,8 @@ export const ustcMirror = { core: 'https://mirrors.ustc.edu.cn/homebrew-core.git', linuxCore: 'https://mirrors.ustc.edu.cn/linuxbrew-core.git', cask: 'https://mirrors.ustc.edu.cn/homebrew-cask.git', - bottles: 'https://mirrors.ustc.edu.cn/homebrew-bottles', - linuxBottles: 'https://mirrors.ustc.edu.cn/linuxbrew-bottles', + bottles: 'https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/', + linuxBottles: 'https://mirrors.ustc.edu.cn/linuxbrew-bottles/bottles/', }; export const bfsuMirror = { @@ -31,8 +32,8 @@ export const bfsuMirror = { core: 'https://mirrors.bfsu.edu.cn/git/homebrew/homebrew-core.git', linuxCore: 'https://mirrors.bfsu.edu.cn/git/homebrew/linuxbrew-core.git', cask: 'https://mirrors.bfsu.edu.cn/git/homebrew/homebrew-cask.git', - bottles: 'https://mirrors.bfsu.edu.cn/homebrew-bottles', - linuxBottles: 'https://mirrors.bfsu.edu.cn/linuxbrew-bottles', + bottles: 'https://mirrors.bfsu.edu.cn/homebrew-bottles/bottles/', + linuxBottles: 'https://mirrors.bfsu.edu.cn/linuxbrew-bottles/bottles/', }; export const mirrorData: { [key: string]: any } = { diff --git a/docs/guide/m1.md b/docs/guide/m1.md index db38faf..a38d302 100644 --- a/docs/guide/m1.md +++ b/docs/guide/m1.md @@ -68,7 +68,7 @@ alias ibrew='arch -x86_64 /usr/local/bin/brew' ## 设置镜像 -**注意:本文中的安装脚本会设置中科大源镜像,如果你也想设置`cask`的镜像,请按下面注释部分选择执行代码。** +**注意:本文中的安装脚本会设置中科大源镜像,如果你也想设置`cask`和`bottles`的镜像,请按下面注释部分选择执行代码。** 更详细的教程可以参考前面的文章:[设置镜像](/guide/start/#part3) 。 @@ -85,6 +85,14 @@ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc # cask git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git + +# bottles for zsh 和下面2选1 +echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zprofile +source ~/.zprofile + +# bottles for bash 和上面2选1 +echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile +source ~/.bash_profile ``` **如果觉得教程有用,欢迎多多分享宣传~** diff --git a/docs/guide/start.md b/docs/guide/start.md index ba82059..ee15c63 100644 --- a/docs/guide/start.md +++ b/docs/guide/start.md @@ -77,6 +77,33 @@ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna brew update ``` +### 设置 bottles 镜像 + +设置环境变量需要注意终端的类型,可以先通过以下方式获取: + +执行命令`echo $SHELL`,根据结果判断: + +- `/bin/zsh` => `zsh` => `.zprofile` +- `/bin/bash` => `bash` => `.bash_profile` + +然后继续正式操作,以**中科大源**为例: + +从`macOS Catalina`(10.15.x) 版开始,`Mac`使用`zsh`作为默认`Shell`,对应文件是`.zprofile`,所以命令为: + +```shell +echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.zprofile +source ~/.zprofile +``` + +如果是`macOS Mojave` 及更低版本,并且没有自己配置过`zsh`,对应文件则是`.bash_profile`: + +```shell +echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/bottles' >> ~/.bash_profile +source ~/.bash_profile +``` + +> 注意:上述区别仅仅是`.zprofile`和`.bash_profile`不同,上下文如有再次提及编辑`.zprofile`,均按此方法判断具体操作的文件。 + 至此,安装和设置操作都完成了。 ### 恢复默认源 @@ -91,6 +118,8 @@ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/H brew update ``` +`homebrew-bottles`配置只能手动删除,将 `~/.zprofile` 文件中的 `HOMEBREW_BOTTLE_DOMAIN=https://mirrors.xxx.com`内容删除,并执行 `source ~/.zprofile`。 + ## 如何卸载 Homebrew 使用官方脚本同样会遇到`uninstall`地址无法访问问题,可以使用下面脚本: