diff --git a/deno.json b/deno.json index 7b5e73e..8569ebb 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@serve.zone/nupst", - "version": "4.0.6", + "version": "4.0.7", "exports": "./mod.ts", "tasks": { "dev": "deno run --allow-all mod.ts", diff --git a/ts/cli/service-handler.ts b/ts/cli/service-handler.ts index 46ba92b..9422d0c 100644 --- a/ts/cli/service-handler.ts +++ b/ts/cli/service-handler.ts @@ -129,81 +129,32 @@ export class ServiceHandler { try { // Check if running as root this.checkRootAccess( - 'This command must be run as root to update NUPST and refresh the systemd service.', + 'This command must be run as root to update NUPST.', ); - const boxWidth = 45; - logger.logBoxTitle('NUPST Update Process', boxWidth); - logger.logBoxLine('Updating NUPST from repository...'); - - // Determine the installation directory (assuming it's either /opt/nupst or the current directory) - const { existsSync } = await import('fs'); - let installDir = '/opt/nupst'; - - if (!existsSync(installDir)) { - // If not installed in /opt/nupst, use the current directory - const { dirname } = await import('path'); - installDir = dirname(dirname(process.argv[1])); // Go up two levels from the executable - logger.logBoxLine(`Using local installation directory: ${installDir}`); - } + console.log(''); + logger.info('Updating NUPST to latest version...'); + console.log(''); try { - // 1. Update the repository - logger.logBoxLine('Pulling latest changes from git repository...'); - execSync(`cd ${installDir} && git fetch origin && git reset --hard origin/main`, { - stdio: 'pipe', + // Download and run the install script + // This handles everything: download binary, stop service, replace, restart + const installUrl = 'https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh'; + + logger.dim('Downloading install script...'); + execSync(`curl -sSL ${installUrl} | bash`, { + stdio: 'inherit', // Show install script output to user }); - // 2. Run the install.sh script - logger.logBoxLine('Running install.sh to update NUPST...'); - execSync(`cd ${installDir} && bash ./install.sh`, { stdio: 'pipe' }); - - // 3. Run the setup.sh script with force flag to update Node.js and dependencies - logger.logBoxLine('Running setup.sh to update Node.js and dependencies...'); - execSync(`cd ${installDir} && bash ./setup.sh --force`, { stdio: 'pipe' }); - - // 4. Refresh the systemd service - logger.logBoxLine('Refreshing systemd service...'); - - // First check if service exists - let serviceExists = false; - try { - const output = execSync('systemctl list-unit-files | grep nupst.service').toString(); - serviceExists = output.includes('nupst.service'); - } catch (error) { - // If grep fails (service not found), serviceExists remains false - serviceExists = false; - } - - if (serviceExists) { - // Stop the service if it's running - const isRunning = - execSync('systemctl is-active nupst.service || true').toString().trim() === 'active'; - if (isRunning) { - logger.logBoxLine('Stopping nupst service...'); - execSync('systemctl stop nupst.service'); - } - - // Reinstall the service - logger.logBoxLine('Reinstalling systemd service...'); - await this.nupst.getSystemd().install(); - - // Restart the service if it was running - if (isRunning) { - logger.logBoxLine('Restarting nupst service...'); - execSync('systemctl start nupst.service'); - } - } else { - logger.logBoxLine('Systemd service not installed, skipping service refresh.'); - logger.logBoxLine('Run "nupst enable" to install the service.'); - } - - logger.logBoxLine('Update completed successfully!'); - logger.logBoxEnd(); + console.log(''); + logger.success('Update completed successfully!'); + logger.dim('Run "nupst service status" to verify the update.'); + console.log(''); } catch (error) { - logger.logBoxLine('Error during update process:'); - logger.logBoxLine(`${error instanceof Error ? error.message : String(error)}`); - logger.logBoxEnd(); + console.log(''); + logger.error('Update failed'); + logger.dim(`${error instanceof Error ? error.message : String(error)}`); + console.log(''); process.exit(1); } } catch (error) {