MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / main

Function main

install/install.ts:707–759  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

705];
706
707async function main() {
708 try {
709 if (process.env.REGION) {
710 if (process.env.REGION !== 'CN') CN = false;
711 } else {
712 console.log('Getting IP info to find best mirror:');
713 const res = await fetch('https://ipinfo.io', { headers: { accept: 'application/json' } }).then((r) => r.json());
714 delete res.readme;
715 console.log(res);
716 if (res.country !== 'CN') CN = false;
717 }
718 } catch (e) {
719 console.error(e);
720 console.log('Cannot find the best mirror. Fallback to default.');
721 }
722 const steps = Steps();
723 for (let i = 0; i < steps.length; i++) {
724 const step = steps[i];
725 if (!step.silent) log.info(step.init);
726 if (!(step.skip?.())) {
727 for (let op of step.operations) {
728 if (!(op instanceof Array)) op = [op, {}] as any;
729 if (op[0].toString().startsWith('nix-env')) op[1].retry = true;
730 if (typeof op[0] === 'string') {
731 retry = 0;
732 let res = exec(op[0], { stdio: 'inherit' });
733 while (res.code && op[1].ignore !== true) {
734 if (op[1].retry && retry < 30) {
735 log.warn('Retry in 3 secs... (%s)', op[0]);
736
737 await sleep(3000);
738 res = exec(op[0], { stdio: 'inherit' });
739 retry++;
740 } else log.fatal('Error when running %s', op[0]);
741 }
742 } else {
743 retry = 0;
744 let res = await op[0](op[1]);
745 while (res === 'retry') {
746 if (retry < 30) {
747 log.warn('Retry in 3 secs...');
748
749 await sleep(3000);
750
751 res = await op[0](op[1]);
752 retry++;
753 } else log.fatal('Error installing');
754 }
755 }
756 }
757 } else if (!step.silent) log.info('info.skip');
758 }
759}
760main().catch(log.fatal);
761global.main = main;

Callers 1

install.tsFile · 0.85

Calls 8

StepsFunction · 0.85
logMethod · 0.80
thenMethod · 0.80
execFunction · 0.70
sleepFunction · 0.70
errorMethod · 0.45
infoMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected