Add the automatic replacement of domestic source function of pake-cli

This commit is contained in:
Tlntin
2023-04-08 12:21:18 +08:00
parent 994b1d4157
commit 79488e445f
6 changed files with 117 additions and 8 deletions

14
bin/helpers/rust.ts vendored
View File

@@ -2,9 +2,17 @@ import { IS_WIN } from '@/utils/platform.js';
import ora from 'ora';
import shelljs from 'shelljs';
import { shellExec } from '../utils/shell.js';
import {isChinaDomain} from '@/utils/ip_addr.js'
const RustInstallScriptFocMac =
"curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y";
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() {
@@ -21,5 +29,5 @@ export async function installRust() {
}
export function checkRustInstalled() {
return shelljs.exec('rustc --version', { silent: true }).code === 0;
return shelljs.exec('source "$HOME/.cargo/env" && rustc --version', { silent: true }).code === 0;
}