UNPKG

@porosys/pss

Version:

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

136 lines (113 loc) • 3.53 kB
import { input, password, confirm } from '@inquirer/prompts'; import { execa } from 'execa'; import chalk from 'chalk'; import { loadConfig, saveConfig } from '../../config/config.helper'; import { setupApacheAuth } from './setup-apache-auth.helper'; import { createHealthAlarmNotifyConf } from './create-health-alarm-notify-conf.helper'; import { updateEmailConfig } from './update-email-config.helper'; import { netdataInstallDependencies } from './netdata-install.constant'; import { installBinary } from '../../../utils/install-binary.util'; export const netdataInstallCommand = async () => { console.log(chalk.green.bold('\nšŸ›  Netdata Installer\n')); const existingConfig = await loadConfig(); const port = await input({ message: 'What port should Netdata listen on?', default: existingConfig?.port || '19999', }); const serverName = await input({ message: 'What is your server domain? (used as ServerName)', default: 'platform.poroshatfilter.com', }); const username = await input({ message: 'Choose a username:', default: 'netdataadmin', }); const userPassword = await password({ message: 'Choose a password:', mask: '*', }); const emailSender = await input({ message: 'Enter the EMAIL_SENDER address:', }); const defaultRecipient = await input({ message: 'Enter the DEFAULT_RECIPIENT_EMAIL address:', }); const proceed = await confirm({ message: 'Proceed with installation?', default: true, }); const answers = { port, serverName, username, password: userPassword, proceed, }; if (!answers.proceed) { console.log(chalk.yellow('\n🚫 Installation aborted by user.')); process.exit(0); } const config = { port: answers.port, allowFirewall: true, disableCloud: true, disableAutoUpdate: false, forceStatic: true, }; console.log(chalk.gray(`\nSelected config:`)); console.log(config); const flags = [ '--stable-channel', '--non-interactive', config.disableAutoUpdate && '--no-updates', config.disableCloud && '--disable-telemetry', config.forceStatic && '--static-only', ].filter(Boolean) as string[]; console.log(chalk.blue(`\nšŸ“„ Downloading Netdata installer...`)); try { await execa( 'wget', [ '-O', '/tmp/netdata-kickstart.sh', 'https://get.netdata.cloud/kickstart.sh', ], { stdio: 'inherit', }, ); console.log(chalk.blue(`\nšŸš€ Running Netdata installer...`)); await execa('bash', ['/tmp/netdata-kickstart.sh', ...flags], { stdio: 'inherit', }); console.log(chalk.green('\nāœ… Netdata installation complete.')); } catch (err) { console.error(chalk.red('\nāŒ Installation failed:'), err); process.exit(1); } const healthAlarmNotifyConfPath = await createHealthAlarmNotifyConf(); // install dependencies for (const dep of netdataInstallDependencies) { await installBinary(dep.binary, dep.packageName); } await updateEmailConfig( healthAlarmNotifyConfPath, emailSender, defaultRecipient, ); await saveConfig({ port: config.port, restartPolicy: existingConfig?.restartPolicy || 'ask', }); await setupApacheAuth({ port: config.port, serverName: answers.serverName, username: answers.username, password: answers.password, }); console.log( chalk.green.bold( `\nšŸŽ‰ Installation finished. Access Netdata at http://${answers.serverName}/\n`, ), ); };