mirror of
https://github.com/codex-storage/cli.git
synced 2025-02-28 16:40:43 +00:00
refactor installationHandlers.js to simplify installation command execution and remove redundant code
This commit is contained in:
parent
5ed9af4420
commit
0484003a45
@ -123,7 +123,7 @@ async function performInstall(config) {
|
|||||||
|
|
||||||
await runCommand('curl -LO --ssl-no-revoke https://get.codex.storage/install.cmd');
|
await runCommand('curl -LO --ssl-no-revoke https://get.codex.storage/install.cmd');
|
||||||
await runCommand(`set "INSTALL_DIR=${installPath}" && "${process.cwd()}\\install.cmd"`);
|
await runCommand(`set "INSTALL_DIR=${installPath}" && "${process.cwd()}\\install.cmd"`);
|
||||||
|
|
||||||
await saveCodexExePath(config, path.join(installPath, "codex.exe"));
|
await saveCodexExePath(config, path.join(installPath, "codex.exe"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -150,24 +150,10 @@ async function performInstall(config) {
|
|||||||
|
|
||||||
const downloadCommand = 'curl -# --connect-timeout 10 --max-time 60 -L https://get.codex.storage/install.sh -o install.sh && chmod +x install.sh';
|
const downloadCommand = 'curl -# --connect-timeout 10 --max-time 60 -L https://get.codex.storage/install.sh -o install.sh && chmod +x install.sh';
|
||||||
await runCommand(downloadCommand);
|
await runCommand(downloadCommand);
|
||||||
|
|
||||||
if (platform === 'darwin') {
|
|
||||||
const timeoutCommand = `perl -e '
|
|
||||||
eval {
|
|
||||||
local $SIG{ALRM} = sub { die "timeout\\n" };
|
|
||||||
alarm(120);
|
|
||||||
system("INSTALL_DIR=\\"${installPath}\\" bash install.sh");
|
|
||||||
alarm(0);
|
|
||||||
};
|
|
||||||
die if $@;
|
|
||||||
'`;
|
|
||||||
await runCommand(timeoutCommand);
|
|
||||||
} else {
|
|
||||||
await runCommand(`INSTALL_DIR="${installPath}" timeout 120 bash install.sh`);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
await runCommand(`INSTALL_DIR="${installPath}" timeout 120 bash install.sh`);
|
||||||
await saveCodexExePath(config, path.join(installPath, "codex"));
|
await saveCodexExePath(config, path.join(installPath, "codex"));
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.message.includes('ECONNREFUSED') || error.message.includes('ETIMEDOUT')) {
|
if (error.message.includes('ECONNREFUSED') || error.message.includes('ETIMEDOUT')) {
|
||||||
throw new Error('Installation failed. Please check your internet connection and try again.');
|
throw new Error('Installation failed. Please check your internet connection and try again.');
|
||||||
@ -182,7 +168,7 @@ async function performInstall(config) {
|
|||||||
await runCommand('rm -f install.sh').catch(() => {});
|
await runCommand('rm -f install.sh').catch(() => {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const version = await getCodexVersion(config);
|
const version = await getCodexVersion(config);
|
||||||
console.log(chalk.green(version));
|
console.log(chalk.green(version));
|
||||||
@ -200,7 +186,7 @@ async function performInstall(config) {
|
|||||||
console.log(showInfoMessage(
|
console.log(showInfoMessage(
|
||||||
"Please review the configuration before starting Codex."
|
"Please review the configuration before starting Codex."
|
||||||
));
|
));
|
||||||
|
|
||||||
spinner.success();
|
spinner.success();
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -11,4 +11,4 @@ export async function runCommand(command) {
|
|||||||
console.error('Error:', error.message);
|
console.error('Error:', error.message);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user