UNPKG

@porosys/pss

Version:

Porosys Server Setup (pss): General-purpose server setup and automation tool (including Netdata management)

58 lines (57 loc) 2.1 kB
import { execa } from 'execa'; import chalk from 'chalk'; import { input } from '@inquirer/prompts'; const disableMongoRepo = async () => { console.log(chalk.yellow('⚠️ Disabling MongoDB repository to bypass 403 error')); try { await execa('sudo', [ 'sed', '-i', 's/^deb.*mongodb.org.*focal/#deb/', '/etc/apt/sources.list.d/mongodb-org-5.0.list', ]); console.log(chalk.green('✅ MongoDB repository temporarily disabled')); } catch (err) { console.error(chalk.red('❌ Failed to disable MongoDB repository:'), err); throw err; } }; const enableMongoRepo = async () => { console.log(chalk.yellow('⚠️ Re-enabling MongoDB repository after update')); try { await execa('sudo', [ 'sed', '-i', 's/^#deb.*mongodb.org.*focal/deb/', '/etc/apt/sources.list.d/mongodb-org-5.0.list', ]); console.log(chalk.green('✅ MongoDB repository re-enabled')); } catch (err) { console.error(chalk.red('❌ Failed to re-enable MongoDB repository:'), err); } }; export const installBinary = async (binary, packageName) => { const pkg = packageName || binary; console.log(`📦 Installing ${pkg}...`); try { const shouldInstallInput = await input({ message: `⚠️ ${binary} is not installed. Would you like to install it now? (Y/n): `, }); const shouldInstall = /^y(es)?$/i.test(shouldInstallInput.trim()); if (!shouldInstall) { console.log(`❌ ${binary} is required. Setup cancelled by user.`); process.exit(1); } await disableMongoRepo(); await execa('sudo', ['apt', 'update'], { stdio: 'inherit' }); await execa('sudo', ['apt', 'install', '-y', pkg], { stdio: 'inherit' }); await enableMongoRepo(); console.log(`✅ ${pkg} installed successfully.`); } catch (err) { console.error(`❌ Failed to install ${pkg}:`, err); process.exit(1); } };