uninstalling node option

This commit is contained in:
Kumaraguru 2024-10-31 15:27:33 +00:00
parent 18ab25869c
commit 5f5a5e1b76
No known key found for this signature in database
GPG Key ID: 4E4555A84ECD28F7
2 changed files with 37 additions and 13 deletions

View File

@ -9,6 +9,7 @@ import chalk from 'chalk';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import { dirname } from 'path'; import { dirname } from 'path';
import axios from 'axios'; import axios from 'axios';
import * as fs from 'fs/promises';
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename); const __dirname = dirname(__filename);
@ -93,16 +94,16 @@ async function installCodex() { // TODO : TEST INSTALLATION TO SEE IF BACKGROUND
const downloadCommand = 'curl -# -L https://get.codex.storage/install.sh | bash'; const downloadCommand = 'curl -# -L https://get.codex.storage/install.sh | bash';
await runCommand(downloadCommand); await runCommand(downloadCommand);
console.log(chalk.green('Codex binaries downloaded')); console.log(chalk.green('Codex binaries downloaded'));
console.log(chalk.cyanBright('\nInstalling dependencies...'));
console.log(chalk.cyanBright('Installing dependencies...'));
await runCommand('sudo apt update && sudo apt install libgomp1'); await runCommand('sudo apt update && sudo apt install libgomp1');
console.log(chalk.green('Dependencies installed')); console.log(chalk.green('Dependencies installed successfully!'));
const version = await runCommand('\ncodex --version');
const version = await runCommand('codex --version'); console.log(chalk.green('Codex is successfully installed!'));
console.log(chalk.green('Codex is successfully installed. Version:')); console.log(chalk.cyanBright(version));
console.log(chalk.cyanBright(version)); await showNavigationMenu();
} catch (error) { } catch (error) {
console.error(chalk.red('Failed to install Codex:', error.message)); console.error(chalk.red('Failed to install Codex:', error.message));
await showNavigationMenu();
} }
} }
@ -124,6 +125,7 @@ async function runCodex() {
await showNavigationMenu(); await showNavigationMenu();
} }
else { else {
const { discPort, listenPort } = await inquirer.prompt([ const { discPort, listenPort } = await inquirer.prompt([
{ {
type: 'number', type: 'number',
@ -165,7 +167,6 @@ async function runCodex() {
} }
async function checkNodeStatus() { async function checkNodeStatus() {
if (platform === 'win32') { if (platform === 'win32') {
console.log(chalk.yellow('Coming soon for Windows!')); console.log(chalk.yellow('Coming soon for Windows!'));
@ -372,6 +373,26 @@ else{
} }
async function uninstallCodex() {
const binaryPath = '/usr/local/bin/codex';
try {
console.log(`Attempting to remove Codex binary from ${binaryPath} using sudo...`);
// Use sudo rm to delete the Codex binary
await runCommand(`sudo rm ${binaryPath}`);
console.log(`Codex binary removed from ${binaryPath}.`);
await showNavigationMenu();
} catch (error) {
if (error.code === 'ENOENT') {
console.log('Codex binary not found, nothing to uninstall.');
} else {
console.error(chalk.red(`Looks like Codex is not installed yet. Please install before trying to remove the Codex binaries.`));
}
await showNavigationMenu();
}
}
async function main() { async function main() {
while (true) { while (true) {
@ -383,18 +404,18 @@ async function main() {
name: 'choice', name: 'choice',
message: 'Select an option:', message: 'Select an option:',
choices: [ choices: [
'1. Download Codex node', '1. Download and install Codex',
'2. Run Codex node', '2. Run Codex node',
'3. Check node status', '3. Check node status',
'4. Upload a file', '4. Upload a file',
'5. Download a file', '5. Download a file',
'6. Show local data', '6. Show local data',
'7. Exit' '7. Uninstall Codex node',
] ]
} }
]); ]);
if (choice.startsWith('7.')) { if (choice.startsWith('8')) {
console.log(chalk.cyanBright('\nGoodbye! 👋\n')); console.log(chalk.cyanBright('\nGoodbye! 👋\n'));
break; break;
} }
@ -406,7 +427,7 @@ async function main() {
case '2': case '2':
await runCodex(); await runCodex();
return; return;
case '3': case '3':
await checkNodeStatus(); await checkNodeStatus();
break; break;
case '4': case '4':
@ -418,6 +439,9 @@ async function main() {
case '6': case '6':
await showLocalFiles(); await showLocalFiles();
break; break;
case '7':
await uninstallCodex();
break;
} }
console.log('\n'); // Add some spacing between operations console.log('\n'); // Add some spacing between operations

View File

@ -1,6 +1,6 @@
{ {
"name": "codexstorage", "name": "codexstorage",
"version": "1.0.2", "version": "1.0.4",
"description": "", "description": "",
"type": "module", "type": "module",
"main": "index.js", "main": "index.js",