mirror of
https://gitee.com/ineo6/homebrew-install.git
synced 2025-04-06 03:58:05 +08:00
feat: 添加镜像助手
This commit is contained in:
parent
3c1e7fd60d
commit
156fea7b4b
15
.dumi/theme/builtins/SourceGenerate.less
Normal file
15
.dumi/theme/builtins/SourceGenerate.less
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
@import (reference) '../style/variables.less';
|
||||||
|
|
||||||
|
.@{prefix}-source-generate {
|
||||||
|
text-align: center;
|
||||||
|
margin: 16px 0;
|
||||||
|
|
||||||
|
&-tool {
|
||||||
|
display: flex;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
|
||||||
|
&-query {
|
||||||
|
margin-right: 6px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
203
.dumi/theme/builtins/SourceGenerate.tsx
Normal file
203
.dumi/theme/builtins/SourceGenerate.tsx
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { Select, Tooltip } from 'antd';
|
||||||
|
import { QuestionCircleOutlined } from '@ant-design/icons';
|
||||||
|
// @ts-ignore
|
||||||
|
import SourceCode from 'dumi-theme-default/src/builtins/SourceCode';
|
||||||
|
|
||||||
|
import './SourceGenerate.less';
|
||||||
|
import { Mirror, mirrorData, Platform } from '../constants';
|
||||||
|
|
||||||
|
const Option = Select.Option;
|
||||||
|
|
||||||
|
const mirrorConfig = [
|
||||||
|
{
|
||||||
|
key: Mirror.USTC,
|
||||||
|
value: '中科大',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: Mirror.Tsinghua,
|
||||||
|
value: '清华',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: Mirror.BFSU,
|
||||||
|
value: '北京外国语',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: Mirror.Tencent,
|
||||||
|
value: '腾讯',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const platformList = [
|
||||||
|
{
|
||||||
|
key: Platform.MacOS,
|
||||||
|
value: 'macOS',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: Platform.Windows,
|
||||||
|
value: 'Windows',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: Platform.Linux,
|
||||||
|
value: 'Linux',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const SourceGenerate = ({ first }) => {
|
||||||
|
const [mirror, setMirror] = useState<Mirror>(Mirror.USTC);
|
||||||
|
const [platform, setPlatform] = useState<Platform>(Platform.MacOS);
|
||||||
|
const [terminalType, setTerminalType] = useState<string>('zsh');
|
||||||
|
|
||||||
|
function generateMirror() {
|
||||||
|
const matchMirror = mirrorData[`${mirror}Mirror`] || {};
|
||||||
|
|
||||||
|
const shellArray = ['# 脚本'];
|
||||||
|
|
||||||
|
shellArray.push(
|
||||||
|
`git -C "$(brew --repo)" remote set-url origin ${matchMirror.brew}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (platform === Platform.Linux && matchMirror.linuxCore) {
|
||||||
|
shellArray.push(
|
||||||
|
`git -C "$(brew --repo homebrew/core)" remote set-url origin ${matchMirror.linuxCore}`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
shellArray.push(
|
||||||
|
`git -C "$(brew --repo homebrew/core)" remote set-url origin ${matchMirror.core}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
shellArray.push(
|
||||||
|
`git -C "$(brew --repo homebrew/cask)" remote set-url origin ${matchMirror.cask}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateFirstMirrorSet() {
|
||||||
|
const matchMirror = mirrorData[`${mirror}Mirror`] || {};
|
||||||
|
|
||||||
|
const shellArray = ['# 1.执行安装脚本'];
|
||||||
|
|
||||||
|
shellArray.push(`export HOMEBREW_BREW_GIT_REMOTE="${matchMirror.brew}"`);
|
||||||
|
|
||||||
|
if (platform === Platform.Linux && matchMirror.linuxCore) {
|
||||||
|
shellArray.push(
|
||||||
|
`export HOMEBREW_CORE_GIT_REMOTE="${matchMirror.linuxCore}"`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
shellArray.push(`export HOMEBREW_CORE_GIT_REMOTE="${matchMirror.core}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
shellArray.push(
|
||||||
|
'/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');
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="__dumi-default-source-generate">
|
||||||
|
<div className="__dumi-default-source-generate-tool">
|
||||||
|
<div className="__dumi-default-source-generate-tool-query">
|
||||||
|
<label>镜像:</label>
|
||||||
|
<Select
|
||||||
|
size="small"
|
||||||
|
value={mirror}
|
||||||
|
onChange={value => setMirror(value as Mirror)}
|
||||||
|
style={{ width: '120px' }}
|
||||||
|
>
|
||||||
|
{mirrorConfig.map(config => (
|
||||||
|
<Option value={config.key} key={config.key}>
|
||||||
|
{config.value}
|
||||||
|
</Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="__dumi-default-source-generate-tool-query">
|
||||||
|
<label>平台:</label>
|
||||||
|
<Select
|
||||||
|
size="small"
|
||||||
|
value={platform}
|
||||||
|
onChange={value => setPlatform((1 * (value as any)) as Platform)}
|
||||||
|
style={{ width: '120px' }}
|
||||||
|
>
|
||||||
|
{platformList.map(config => (
|
||||||
|
<Option value={config.key} key={config.key}>
|
||||||
|
{config.value}
|
||||||
|
</Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="__dumi-default-source-generate-tool-query">
|
||||||
|
<label>终端类型:</label>
|
||||||
|
<Select
|
||||||
|
size="small"
|
||||||
|
value={terminalType}
|
||||||
|
onChange={value => setTerminalType(value)}
|
||||||
|
style={{ width: '120px' }}
|
||||||
|
>
|
||||||
|
<Option value="zsh">zsh</Option>
|
||||||
|
<Option value="bash">bash</Option>
|
||||||
|
</Select>
|
||||||
|
<Tooltip
|
||||||
|
overlayStyle={{ width: '360px', maxWidth: '360px' }}
|
||||||
|
title={
|
||||||
|
<div>
|
||||||
|
<p>macOS Catalina(10.15.x)以及更高版本默认是zsh</p>
|
||||||
|
<p>
|
||||||
|
执行命令echo $SHELL
|
||||||
|
<br />
|
||||||
|
显示/bin/bash则是bash,显示/bin/zsh则是zsh
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<QuestionCircleOutlined style={{ marginLeft: '8px' }} />
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<SourceCode
|
||||||
|
code={first ? generateFirstMirrorSet() : generateMirror()}
|
||||||
|
lang="bash"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SourceGenerate;
|
56
.dumi/theme/constants/index.ts
Normal file
56
.dumi/theme/constants/index.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
export const tencentMirror = {
|
||||||
|
brew: 'https://mirrors.cloud.tencent.com/homebrew/brew.git',
|
||||||
|
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',
|
||||||
|
linuxBottles: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const tsinghuaMirror = {
|
||||||
|
brew: 'https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git',
|
||||||
|
core: 'https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git',
|
||||||
|
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',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ustcMirror = {
|
||||||
|
brew: 'https://mirrors.ustc.edu.cn/brew.git',
|
||||||
|
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',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const bfsuMirror = {
|
||||||
|
brew: 'https://mirrors.bfsu.edu.cn/git/homebrew/brew.git',
|
||||||
|
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',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const mirrorData: { [key: string]: any } = {
|
||||||
|
bfsuMirror,
|
||||||
|
ustcMirror,
|
||||||
|
tencentMirror,
|
||||||
|
tsinghuaMirror,
|
||||||
|
};
|
||||||
|
|
||||||
|
export enum Mirror {
|
||||||
|
BFSU = 'bfsu',
|
||||||
|
Tsinghua = 'tsinghua',
|
||||||
|
Tencent = 'tencent',
|
||||||
|
USTC = 'ustc',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum Platform {
|
||||||
|
MacOS,
|
||||||
|
Linux,
|
||||||
|
Windows,
|
||||||
|
}
|
16
.umirc.ts
16
.umirc.ts
@ -49,7 +49,11 @@ export default defineConfig({
|
|||||||
children: ['/guide/index', '/guide/how-it-works', '/guide/start'],
|
children: ['/guide/index', '/guide/how-it-works', '/guide/start'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'M1芯片 ',
|
title: '工 具',
|
||||||
|
children: ['/guide/change-source'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'M1芯片',
|
||||||
path: '/guide/m1/',
|
path: '/guide/m1/',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -58,6 +62,16 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
extraBabelPlugins: [
|
||||||
|
[
|
||||||
|
'import',
|
||||||
|
{
|
||||||
|
libraryName: 'antd',
|
||||||
|
libraryDirectory: 'es',
|
||||||
|
style: 'css',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
analytics: {
|
analytics: {
|
||||||
ga: 'UA-39288503-8',
|
ga: 'UA-39288503-8',
|
||||||
baidu: 'be934bce3f81621badc0bb5b581ab622',
|
baidu: 'be934bce3f81621badc0bb5b581ab622',
|
||||||
|
13
docs/guide/change-source.md
Normal file
13
docs/guide/change-source.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# 镜像助手
|
||||||
|
|
||||||
|
## 如果你是初次安装,并且需要换其他源
|
||||||
|
|
||||||
|
脚本默认内置中科大镜像,如果需要换源,请使用小助手获取安装脚本:
|
||||||
|
|
||||||
|
<SourceGenerate first="true"></SourceGenerate>
|
||||||
|
|
||||||
|
## 如果你已经安装过,需要换源
|
||||||
|
|
||||||
|
选择"镜像"、"平台"、"终端类型"后,会自动生成对应的设置镜像脚本。
|
||||||
|
|
||||||
|
<SourceGenerate></SourceGenerate>
|
@ -12,6 +12,8 @@ order: 3
|
|||||||
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
|
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> 默认使用中科大源,如果需要换源参考 [换源](/guide/change-source/)。
|
||||||
|
|
||||||
如果命令执行中卡在下面信息:
|
如果命令执行中卡在下面信息:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
@ -47,6 +49,8 @@ brew update
|
|||||||
|
|
||||||
<h2 id='part3'>设置镜像</h2>
|
<h2 id='part3'>设置镜像</h2>
|
||||||
|
|
||||||
|
> 更新:强烈建议使用[镜像助手](/guide/change-source/),你可以自助获取镜像脚本,目前支持中科大、清华、腾讯、北京外国语镜像源。
|
||||||
|
|
||||||
### 中科大源
|
### 中科大源
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
@ -98,16 +102,6 @@ source ~/.bash_profile
|
|||||||
|
|
||||||
> 注意:上述区别仅仅是`.zprofile`和`.bash_profile`不同,上下文如有再次提及编辑`.zprofile`,均按此方法判断具体操作的文件。
|
> 注意:上述区别仅仅是`.zprofile`和`.bash_profile`不同,上下文如有再次提及编辑`.zprofile`,均按此方法判断具体操作的文件。
|
||||||
|
|
||||||
如果想使用清华源:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
把
|
|
||||||
https://mirrors.ustc.edu.cn/homebrew-bottles
|
|
||||||
|
|
||||||
替换为
|
|
||||||
https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
|
|
||||||
```
|
|
||||||
|
|
||||||
至此,安装和设置操作都完成了。
|
至此,安装和设置操作都完成了。
|
||||||
|
|
||||||
### 恢复默认源
|
### 恢复默认源
|
||||||
|
@ -5,7 +5,7 @@ hero:
|
|||||||
image: /images/homebrew-256x256.png
|
image: /images/homebrew-256x256.png
|
||||||
actions:
|
actions:
|
||||||
- text: 快速开始
|
- text: 快速开始
|
||||||
link: /guide/
|
link: /guide/start/
|
||||||
footer: Open-source MIT Licensed | Copyright © 2021<br />Powered by [Neo](https://github.com/ineo6)
|
footer: Open-source MIT Licensed | Copyright © 2021<br />Powered by [Neo](https://github.com/ineo6)
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -17,7 +17,8 @@ footer: Open-source MIT Licensed | Copyright © 2021<br />Powered by [Neo](https
|
|||||||
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
|
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
|
||||||
```
|
```
|
||||||
|
|
||||||
<Center>将以上命令粘贴至终端。</Center>
|
<Center>将以上命令粘贴至终端。脚本内置<a target="_blank" href="http://mirrors.ustc.edu.cn/help/brew.git.html">中科大镜像</a>,所以能让Homebrew安装速度飞快。</Center>
|
||||||
<Center>脚本内置<a target="_blank" href="http://mirrors.ustc.edu.cn/help/brew.git.html">中科大镜像</a>,所以让Homebrew安装速度飞快。</Center>
|
|
||||||
|
|
||||||
<Center>如果对安装有疑问,请通过 <a href="/guide/start/">快速开始</a> 安装。</Center>
|
<Center>如果想使用其他源安装,或者已安装但是想换源,请使用<a href="/guide/change-source/">镜像助手</a>获取脚本。</Center>
|
||||||
|
|
||||||
|
<Center>更详细的安装说明,请点击 <a href="/guide/start/">快速开始</a> 开始安装。</Center>
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/ineo6/homebrew-install#readme",
|
"homepage": "https://github.com/ineo6/homebrew-install#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel-plugin-import": "^1.13.3",
|
||||||
"chalk": "^4.1.0",
|
"chalk": "^4.1.0",
|
||||||
"download-git-repo": "^3.0.2",
|
"download-git-repo": "^3.0.2",
|
||||||
"dumi": "^1.0.12",
|
"dumi": "^1.0.12",
|
||||||
@ -42,5 +43,9 @@
|
|||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
"sitemap": "^6.3.5",
|
"sitemap": "^6.3.5",
|
||||||
"yorkie": "^2.0.0"
|
"yorkie": "^2.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@ant-design/icons": "^4.5.0",
|
||||||
|
"antd": "^4.13.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user