fixup some bug in China mirror

This commit is contained in:
Tlntin
2023-04-29 12:06:37 +08:00
parent d86a35c25b
commit f090d6f0a5
9 changed files with 2354 additions and 2336 deletions

22
bin/helpers/rust.ts vendored
View File

@@ -1,21 +1,23 @@
import { IS_WIN } from '@/utils/platform.js';
import ora from 'ora';
import shelljs from 'shelljs';
import logger from '@/options/logger.js';
import { shellExec } from '../utils/shell.js';
import {isChinaDomain} from '@/utils/ip_addr.js'
const is_china = isChinaDomain("sh.rustup.rs");
let RustInstallScriptFocMac = "";
if (is_china) {
RustInstallScriptFocMac =
'export RUSTUP_DIST_SERVER="https://rsproxy.cn" && export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup" && curl --proto "=https" --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh';
} else {
RustInstallScriptFocMac =
"curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y";
}
const RustInstallScriptForWin = 'winget install --id Rustlang.Rustup';
export async function installRust() {
const is_china = await isChinaDomain("sh.rustup.rs");
let RustInstallScriptFocMac = "";
if (is_china) {
logger.info("it's in China, use rust cn mirror to install rust");
RustInstallScriptFocMac =
'export RUSTUP_DIST_SERVER="https://rsproxy.cn" && export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup" && curl --proto "=https" --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh';
} else {
RustInstallScriptFocMac =
"curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y";
}
const RustInstallScriptForWin = 'winget install --id Rustlang.Rustup';
const spinner = ora('Downloading Rust').start();
try {
await shellExec(IS_WIN ? RustInstallScriptForWin : RustInstallScriptFocMac);