// Functions related to OS and installing software import { execSync } from 'child_process' // Detects the operating system we are running on export function detectOS() { let distro try { execSync('[ -f "/etc/debian_version" ]') distro = 'debian' console.log(`${greenChalk('Debian')}, Ubuntu, or Raspbian OS detected.`) } catch(err) {} try { execSync('[ -f "/etc/arch-release" ]') distro = 'arch' console.log(`${greenChalk('Arch or Manjaro-based')} OS detected.`) } catch(err) {} try { execSync('[ -f "/etc/fedora-release" ]') distro = 'fedora' console.log(`${greenChalk('Fedora')} OS detected.`) } catch(err) {} try { execSync('[ $(uname | grep -c "Darwin") -eq 1 ]') distro = 'mac' console.log(`${greenChalk('MacOS')} detected.`) } catch(err) {} if(!distro) { console.log("Your OS was not recognized, sorry.") process.exit(1) } return distro } // Runs the correct command to update all your software for any recognized OS export function updateSoftware() { distro = detectOS() if(!distro) { console.log("Your OS was not recognized, so nothing was updated, sorry.") return false } console.log('Updating your software from repositories...') console.log(`(You may need to input your ${chalk.blue.bold("'sudo' password")} here)`) switch(distro) { case 'debian': execSync('sudo apt update && sudo apt autoremove && sudo apt upgrade') break case 'arch': execSync('sudo pacman -Syu --noconfirm') break case 'fedora': execSync('sudo dnf update && sudo dnf upgrade') break case 'mac': execSync('install && sudo brew update') break } return true } // Installs core dependencies required by Alchemy and the AO export function installRequired() { distro = detectOS() if(!distro) { console.log("Your OS was not recognized, so nothing was installed, sorry.") return false } console.log('Installing Alchemy and AO installation process core dependencies (fast if already installed)...') console.log(`(You may need to input your ${chalk.blue.bold("'sudo' password")} here)`) // Install OS-specific requirements switch(distro) { case 'debian': execSync('sudo apt install build-essential') // Some of these might not be required execSync('source ~/Alchemy/ingredients/lead && install_if_needed sqlite3 zlib1g-dev libtool-bin autoconf autoconf-archive automake autotools-dev libgmp-dev libsqlite3-dev python python3 python3-mako libsodium-dev build-essential pkg-config libev-dev libcurl4-gnutls-dev libssl-dev fakeroot devscripts') break case 'arch': try { execSync('[[ ! $(pacman -Qg base-devel) ]]') execSync('sudo pacman -S base-devel --noconfirm') } catch(err) {} execSync('source ~/Alchemy/ingredients/lead && install_if_needed python gmp sqlite3 autoconf-archive pkgconf libev python-mako python-pip net-tools zlib libsodium gettext nginx') break case 'fedora': execSync('source ~/Alchemy/ingredients/lead && install_if_needed sqlite3 autoconf autoconf-archive automake python python3 python3-mako pkg-config fakeroot devscripts') break } // Install on every OS execSync('source ~/Alchemy/ingredients/lead && install_if_needed git wget make') try { execSync('[ -z $NVM_DIR ]') execSync('source ingredients/iron && install_nvm') console.log(`Installed nvm.`) } catch(err) {} return true } // Sets node to the current version used by the AO export function setNodeVersion() { execSync('source ingredients/iron && set_node_to v16.13.0') }