mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
install: try alternative mirror
This commit is contained in:
1 parent
9dc6818fd7
commit
3f14d7a63e
1 file changed
+35
-6
+35
-6
@@ -95,8 +95,8 @@ function randomstring(digit = 32, dict = defaultDict) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
let password = randomstring(32);
|
let password = randomstring(32);
|
||||||
// TODO read from args
|
// eslint-disable-next-line
|
||||||
const CN = true;
|
let CN = true;
|
||||||
|
|
||||||
const nixBin = `${process.env.HOME}/.nix-profile/bin`;
|
const nixBin = `${process.env.HOME}/.nix-profile/bin`;
|
||||||
const entry = (source: string, target = source, ro = true) => `\
|
const entry = (source: string, target = source, ro = true) => `\
|
||||||
@@ -179,7 +179,7 @@ function rollbackResolveField() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const steps = [
|
const Steps = () => [
|
||||||
{
|
{
|
||||||
init: 'install.preparing',
|
init: 'install.preparing',
|
||||||
operations: [
|
operations: [
|
||||||
@@ -231,8 +231,25 @@ const steps = [
|
|||||||
init: 'install.hydro',
|
init: 'install.hydro',
|
||||||
operations: [
|
operations: [
|
||||||
() => removeOptionalEsbuildDeps(),
|
() => removeOptionalEsbuildDeps(),
|
||||||
|
() => {
|
||||||
|
if (!CN) return;
|
||||||
|
try {
|
||||||
|
exec('yarn config set registry https://registry.npmmirror.com/');
|
||||||
|
exec('yarn global add hydrooj @hydrooj/ui-default @hydrooj/hydrojudge');
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Failed to install from npmmirror, fallback to yarnpkg');
|
||||||
|
} finally {
|
||||||
|
exec('yarn config set registry https://registry.yarnpkg.com');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
exec('yarn global add hydrooj @hydrooj/ui-default @hydrooj/hydrojudge');
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Failed to check update from yarnpkg');
|
||||||
|
}
|
||||||
|
},
|
||||||
['yarn global add hydrooj @hydrooj/ui-default @hydrooj/hydrojudge', { retry: true }],
|
['yarn global add hydrooj @hydrooj/ui-default @hydrooj/hydrojudge', { retry: true }],
|
||||||
() => writeFileSync(`${process.env.HOME}/.hydro/addon.json`, '["@hydrooj/ui-default","@hydrooj/hydrojudge"]'),
|
() => writeFileSync(`${process.env.HOME}/.hydro/addon.json`, '["@hydrooj/ui-default","@hydrooj/hydrojudge"]'),
|
||||||
|
() => rollbackResolveField(),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -308,7 +325,6 @@ const steps = [
|
|||||||
},
|
},
|
||||||
() => log.info('extra.dbUser'),
|
() => log.info('extra.dbUser'),
|
||||||
() => log.info('extra.dbPassword', password),
|
() => log.info('extra.dbPassword', password),
|
||||||
() => rollbackResolveField(),
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -327,10 +343,22 @@ const steps = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
try {
|
||||||
|
console.log('Getting IP info to find best mirror:');
|
||||||
|
const res = await fetch('https://ipinfo.io', { headers: { accept: 'application/json' } }).then((r) => r.json());
|
||||||
|
delete res.readme;
|
||||||
|
console.log(res);
|
||||||
|
if (res.country !== 'CN') CN = false;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
console.log('Cannot find the best mirror. Fallback to default.');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
const steps = Steps();
|
||||||
for (let i = 0; i < steps.length; i++) {
|
for (let i = 0; i < steps.length; i++) {
|
||||||
const step = steps[i];
|
const step = steps[i];
|
||||||
if (!step.silent) log.info(step.init);
|
if (!step.silent) log.info(step.init);
|
||||||
if (!(step.skip && step.skip())) {
|
if (!(step.skip?.())) {
|
||||||
for (let op of step.operations) {
|
for (let op of step.operations) {
|
||||||
if (!(op instanceof Array)) op = [op, {}] as any;
|
if (!(op instanceof Array)) op = [op, {}] as any;
|
||||||
if (op[0].toString().startsWith('nix-env')) op[1].retry = true;
|
if (op[0].toString().startsWith('nix-env')) op[1].retry = true;
|
||||||
@@ -346,7 +374,7 @@ async function main() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
retry = 0;
|
retry = 0;
|
||||||
let res = op[0](op[1]);
|
let res = await op[0](op[1]);
|
||||||
while (res === 'retry') {
|
while (res === 'retry') {
|
||||||
if (retry < 30) {
|
if (retry < 30) {
|
||||||
log.warn('Retry...');
|
log.warn('Retry...');
|
||||||
@@ -361,3 +389,4 @@ async function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
main().catch(log.fatal);
|
main().catch(log.fatal);
|
||||||
|
global.main = main;
|
||||||
Reference in new issue
Block a user