2022-11-29 22:26:34 -08:00
|
|
|
|
#!/usr/bin/env zx
|
|
|
|
|
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const execSync = require('child_process').execSync
|
2022-11-29 22:26:34 -08:00
|
|
|
|
|
2022-12-02 15:07:52 -08:00
|
|
|
|
// Log symbols
|
|
|
|
|
const figuresDefault = {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
bullet: '●',
|
|
|
|
|
circle: '◯',
|
|
|
|
|
cross: '✖',
|
|
|
|
|
lozenge: '◆',
|
|
|
|
|
play: '▶',
|
|
|
|
|
pointer: '❯',
|
|
|
|
|
square: '◼',
|
|
|
|
|
star: '★',
|
|
|
|
|
tick: '✔'
|
|
|
|
|
}
|
2022-12-02 15:07:52 -08:00
|
|
|
|
|
|
|
|
|
const figuresFallback = {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
bullet: '■',
|
|
|
|
|
circle: '□',
|
|
|
|
|
cross: '×',
|
|
|
|
|
lozenge: '♦',
|
|
|
|
|
play: '►',
|
|
|
|
|
pointer: '>',
|
|
|
|
|
square: '■',
|
|
|
|
|
star: '✶',
|
|
|
|
|
tick: '√'
|
|
|
|
|
}
|
2022-12-02 15:07:52 -08:00
|
|
|
|
|
|
|
|
|
function isUnicodeSupported() {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
if (process.platform !== 'win32') {
|
2022-12-02 15:07:52 -08:00
|
|
|
|
// Linux console (kernel)
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return process.env.TERM !== 'linux'
|
2022-12-02 15:07:52 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
Boolean(process.env.CI) ||
|
|
|
|
|
// Windows Terminal
|
|
|
|
|
Boolean(process.env.WT_SESSION) ||
|
|
|
|
|
// ConEmu and cmder
|
2022-12-24 20:48:43 -08:00
|
|
|
|
process.env.ConEmuTask === '{cmd::Cmder}' ||
|
|
|
|
|
process.env.TERM_PROGRAM === 'vscode' ||
|
|
|
|
|
process.env.TERM === 'xterm-256color' ||
|
|
|
|
|
process.env.TERM === 'alacritty'
|
|
|
|
|
)
|
2022-12-02 15:07:52 -08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const figures = isUnicodeSupported() ? figuresDefault : figuresFallback
|
2022-12-02 15:07:52 -08:00
|
|
|
|
|
|
|
|
|
function log(type, label, msg) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
let icon, message
|
|
|
|
|
if (type === 'info') {
|
|
|
|
|
icon = chalk.cyanBright(figures.pointer)
|
|
|
|
|
message = chalk.gray.bold(msg)
|
|
|
|
|
} else if (type === 'star') {
|
|
|
|
|
icon = chalk.yellowBright(figures.star)
|
|
|
|
|
message = chalk.bold(msg)
|
|
|
|
|
} else if (type === 'success') {
|
|
|
|
|
icon = chalk.greenBright(figures.play)
|
|
|
|
|
message = chalk.bold(msg)
|
|
|
|
|
} else if (type === 'warn') {
|
|
|
|
|
icon = `${chalk.yellowBright(figures.lozenge)} ${chalk.bold.black.bgYellowBright(' WARNING ')}`
|
|
|
|
|
message = chalk.yellowBright(msg)
|
|
|
|
|
} else if (type === 'error') {
|
|
|
|
|
icon = `${chalk.redBright(figures.cross)} ${chalk.black.bold.bgRedBright(' ERROR ')}`
|
|
|
|
|
message = chalk.redBright(msg)
|
2022-12-02 15:07:52 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const outputMessage = `${icon} ${chalk.bold(label)} ${message}`
|
|
|
|
|
console.log(outputMessage)
|
2022-12-02 15:07:52 -08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-24 20:48:43 -08:00
|
|
|
|
let installData
|
2023-01-03 20:39:23 -08:00
|
|
|
|
let installOrders = {}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const installOrdersPre = []
|
|
|
|
|
const installOrdersPost = []
|
|
|
|
|
const installOrdersSystemd = []
|
|
|
|
|
let brewUpdated, osType, osID, snapRefreshed
|
2022-11-29 22:26:34 -08:00
|
|
|
|
|
|
|
|
|
// Download the installation map
|
|
|
|
|
async function downloadInstallData() {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const response = await fetch('https://gitlab.com/megabyte-labs/hiawatha-dotfiles/-/raw/master/software.yml')
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (response.ok) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const text = await response.text()
|
|
|
|
|
return YAML.parse(text)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Catalog Download', `Failed to download the installation map`)
|
|
|
|
|
log('info', 'Catalog Download', `Falling back to local version of software.yml`)
|
|
|
|
|
const text = fs.readFileSync(process.env.HOME + '/.local/share/chezmoi/software.yml').toString()
|
|
|
|
|
return YAML.parse(text)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Creates the installOrders object which maps package managers to arrays of packages to install
|
2022-12-25 06:00:18 -08:00
|
|
|
|
let generateInstallOrderCount = 0
|
2022-12-08 23:57:44 -08:00
|
|
|
|
async function generateInstallOrders(pkgsToInstall) {
|
2022-12-25 10:55:58 -08:00
|
|
|
|
const installerPreference = await OSTypeInstallerKey()
|
|
|
|
|
const preferenceOrder = installData.installerPreference[installerPreference]
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const logStage = 'Install Orders'
|
|
|
|
|
const packagesToInstall = pkgsToInstall
|
|
|
|
|
const softwarePackages = installData.softwarePackages
|
2022-12-25 06:00:18 -08:00
|
|
|
|
if (generateInstallOrderCount === 0) {
|
|
|
|
|
log('info', logStage, `Installer preference category detected as ${installerPreference}`)
|
|
|
|
|
log('info', logStage, `Preference order acquired:`)
|
|
|
|
|
console.log(preferenceOrder)
|
|
|
|
|
}
|
|
|
|
|
generateInstallOrderCount++
|
|
|
|
|
log('info', logStage, `New packages discovered for processing: ${pkgsToInstall} (${pkgsToInstall.length} items)`)
|
2022-12-04 21:46:23 -08:00
|
|
|
|
pkgFor: for (let pkg of packagesToInstall) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
let packageKey
|
|
|
|
|
if (softwarePackages[pkg + ':' + osID]) {
|
|
|
|
|
packageKey = pkg + ':' + osID
|
|
|
|
|
} else if (softwarePackages[pkg + ':' + osType]) {
|
|
|
|
|
packageKey = pkg + ':' + osType
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else if (softwarePackages[pkg]) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
packageKey = pkg
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('warn', logStage, `The package \`${pkg}\` was not found in the installation map`)
|
|
|
|
|
continue
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
for (let preference of preferenceOrder) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
let currentSelector, doubleScoped, scopedPkgManager, scopedSystem, normalCheck
|
2022-12-04 21:46:23 -08:00
|
|
|
|
if (
|
2022-12-24 20:48:43 -08:00
|
|
|
|
softwarePackages[packageKey][preference + ':' + osID] ||
|
|
|
|
|
softwarePackages[packageKey][preference + ':' + osType] ||
|
2022-12-04 21:46:23 -08:00
|
|
|
|
softwarePackages[packageKey][preference]
|
|
|
|
|
) {
|
|
|
|
|
// Handle the _when attribute
|
2022-12-24 20:48:43 -08:00
|
|
|
|
currentSelector = 'when'
|
2022-12-04 21:46:23 -08:00
|
|
|
|
doubleScoped =
|
2022-12-24 20:48:43 -08:00
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + preference + ':' + osID] ||
|
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + osID + ':' + preference] ||
|
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + preference + ':' + osType] ||
|
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + osType + ':' + preference]
|
|
|
|
|
scopedPkgManager = softwarePackages[packageKey]['_' + currentSelector + ':' + preference]
|
2022-12-04 21:46:23 -08:00
|
|
|
|
scopedSystem =
|
2022-12-24 20:48:43 -08:00
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + osID] ||
|
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + osType]
|
|
|
|
|
normalCheck = softwarePackages[packageKey]['_' + currentSelector]
|
2022-12-04 21:46:23 -08:00
|
|
|
|
if (doubleScoped) {
|
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $doubleScoped
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
let pref
|
|
|
|
|
if (softwarePackages[packageKey]['_' + currentSelector + ':' + preference + ':' + osID]) {
|
|
|
|
|
pref = preference + ':' + osID
|
|
|
|
|
} else if (softwarePackages[packageKey]['_' + currentSelector + ':' + preference + ':' + osType]) {
|
|
|
|
|
pref = preference + ':' + osType
|
|
|
|
|
} else if (softwarePackages[packageKey]['_' + currentSelector + ':' + osID + ':' + preference]) {
|
|
|
|
|
pref = osID + ':' + preference
|
|
|
|
|
} else if (softwarePackages[packageKey]['_' + currentSelector + ':' + osType + ':' + preference]) {
|
|
|
|
|
pref = osType + ':' + preference
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Skipping Package', `${pkg} is being skipped because of the _when:${pref} condition`)
|
|
|
|
|
continue pkgFor
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
|
|
|
|
} else if (scopedPkgManager) {
|
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $scopedPkgManager
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const pref = preference
|
|
|
|
|
log('info', 'Skipping Package', `${pkg} is being skipped because of the _when:${pref} condition`)
|
|
|
|
|
continue pkgFor
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
|
|
|
|
} else if (scopedSystem) {
|
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $scopedSystem
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
let pref
|
|
|
|
|
if (softwarePackages[packageKey]['_' + currentSelector + ':' + osID]) {
|
|
|
|
|
pref = osID
|
|
|
|
|
} else if (softwarePackages[packageKey]['_' + currentSelector + ':' + osType]) {
|
|
|
|
|
pref = osType
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Skipping Package', `${pkg} is being skipped because of the _when:${pref} condition`)
|
|
|
|
|
continue pkgFor
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
|
|
|
|
} else if (normalCheck) {
|
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $(normalCheck)
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Skipping Package', `${pkg} is being skipped because of the _when condition`)
|
|
|
|
|
continue pkgFor
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle the _bin attribute
|
2022-12-24 20:48:43 -08:00
|
|
|
|
currentSelector = 'bin'
|
2022-12-04 21:46:23 -08:00
|
|
|
|
doubleScoped =
|
2022-12-24 20:48:43 -08:00
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + preference + ':' + osID] ||
|
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + osID + ':' + preference] ||
|
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + preference + ':' + osType] ||
|
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + osType + ':' + preference]
|
|
|
|
|
scopedPkgManager = softwarePackages[packageKey]['_' + currentSelector + ':' + preference]
|
2022-12-04 21:46:23 -08:00
|
|
|
|
scopedSystem =
|
2022-12-24 20:48:43 -08:00
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + osID] ||
|
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + osType]
|
|
|
|
|
normalCheck = softwarePackages[packageKey]['_' + currentSelector]
|
2022-12-04 21:46:23 -08:00
|
|
|
|
if (doubleScoped) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const bin =
|
|
|
|
|
typeof doubleScoped === 'string'
|
|
|
|
|
? which.sync(doubleScoped, { nothrow: true })
|
|
|
|
|
: doubleScoped.map((x) => which.sync(x, { nothrow: true })).every((y) => !!y)
|
2022-12-04 22:26:27 -08:00
|
|
|
|
if (bin) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
let pref
|
|
|
|
|
if (softwarePackages[packageKey]['_' + currentSelector + ':' + preference + ':' + osID]) {
|
|
|
|
|
pref = preference + ':' + osID
|
|
|
|
|
} else if (softwarePackages[packageKey]['_' + currentSelector + ':' + preference + ':' + osType]) {
|
|
|
|
|
pref = preference + ':' + osType
|
|
|
|
|
} else if (softwarePackages[packageKey]['_' + currentSelector + ':' + osID + ':' + preference]) {
|
|
|
|
|
pref = osID + ':' + preference
|
|
|
|
|
} else if (softwarePackages[packageKey]['_' + currentSelector + ':' + osType + ':' + preference]) {
|
|
|
|
|
pref = osType + ':' + preference
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Skipping Package', `${pkg} is being skipped because of the _bin:${pref} condition`)
|
|
|
|
|
log('info', 'Skipping Package', `${bin} is already in the PATH`)
|
|
|
|
|
continue pkgFor
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
|
|
|
|
} else if (scopedPkgManager) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const bin =
|
|
|
|
|
typeof scopedPkgManager === 'string'
|
|
|
|
|
? which.sync(scopedPkgManager, { nothrow: true })
|
|
|
|
|
: scopedPkgManager.map((x) => which.sync(x, { nothrow: true })).every((y) => !!y)
|
2022-12-04 22:26:27 -08:00
|
|
|
|
if (bin) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const pref = preference
|
|
|
|
|
log('info', 'Skipping Package', `${pkg} is being skipped because of the _bin:${pref} condition`)
|
|
|
|
|
log('info', 'Skipping Package', `${bin} is already in the PATH`)
|
|
|
|
|
continue pkgFor
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
|
|
|
|
} else if (scopedSystem) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const bin =
|
|
|
|
|
typeof scopedSystem === 'string'
|
|
|
|
|
? which.sync(scopedSystem, { nothrow: true })
|
|
|
|
|
: scopedSystem.map((x) => which.sync(x, { nothrow: true })).every((y) => !!y)
|
2022-12-04 22:26:27 -08:00
|
|
|
|
if (bin) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
let pref
|
|
|
|
|
if (softwarePackages[packageKey]['_' + currentSelector + ':' + osID]) {
|
|
|
|
|
pref = osID
|
|
|
|
|
} else if (softwarePackages[packageKey]['_' + currentSelector + ':' + osType]) {
|
|
|
|
|
pref = osType
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Skipping Package', `${pkg} is being skipped because of the _bin:${pref} condition`)
|
|
|
|
|
log('info', 'Skipping Package', `${bin} is already in the PATH`)
|
|
|
|
|
continue pkgFor
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
|
|
|
|
} else if (normalCheck) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const bin =
|
|
|
|
|
typeof normalCheck === 'string'
|
|
|
|
|
? which.sync(normalCheck, { nothrow: true })
|
|
|
|
|
: normalCheck.map((x) => which.sync(x, { nothrow: true })).every((y) => !!y)
|
2022-12-04 22:26:27 -08:00
|
|
|
|
if (bin) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Skipping Package', `${pkg} is being skipped because of the _bin condition`)
|
|
|
|
|
log('info', 'Skipping Package', `${bin} is already in the PATH`)
|
|
|
|
|
continue pkgFor
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-08 23:57:44 -08:00
|
|
|
|
|
|
|
|
|
// Handle the _deps attribute
|
2022-12-24 20:48:43 -08:00
|
|
|
|
currentSelector = 'deps'
|
2022-12-08 23:57:44 -08:00
|
|
|
|
doubleScoped =
|
2022-12-24 20:48:43 -08:00
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + preference + ':' + osID] ||
|
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + osID + ':' + preference] ||
|
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + preference + ':' + osType] ||
|
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + osType + ':' + preference]
|
|
|
|
|
scopedPkgManager = softwarePackages[packageKey]['_' + currentSelector + ':' + preference]
|
2022-12-08 23:57:44 -08:00
|
|
|
|
scopedSystem =
|
2022-12-24 20:48:43 -08:00
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + osID] ||
|
|
|
|
|
softwarePackages[packageKey]['_' + currentSelector + ':' + osType]
|
|
|
|
|
normalCheck = softwarePackages[packageKey]['_' + currentSelector]
|
2022-12-08 23:57:44 -08:00
|
|
|
|
if (doubleScoped) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
let pref
|
|
|
|
|
if (softwarePackages[packageKey]['_' + currentSelector + ':' + preference + ':' + osID]) {
|
|
|
|
|
pref = preference + ':' + osID
|
|
|
|
|
log('info', 'Installing Dependencies', `Installing dependencies for ${packageKey}.${pref}`)
|
2022-12-25 06:00:18 -08:00
|
|
|
|
await generateInstallOrders(softwarePackages[packageKey][pref])
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (softwarePackages[packageKey]['_' + currentSelector + ':' + preference + ':' + osType]) {
|
|
|
|
|
pref = preference + ':' + osType
|
|
|
|
|
log('info', 'Installing Dependencies', `Installing dependencies for ${packageKey}.${pref}`)
|
2022-12-25 06:00:18 -08:00
|
|
|
|
await generateInstallOrders(softwarePackages[packageKey][pref])
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (softwarePackages[packageKey]['_' + currentSelector + ':' + osID + ':' + preference]) {
|
|
|
|
|
pref = osID + ':' + preference
|
|
|
|
|
log('info', 'Installing Dependencies', `Installing dependencies for ${packageKey}.${pref}`)
|
2022-12-25 06:00:18 -08:00
|
|
|
|
await generateInstallOrders(softwarePackages[packageKey][pref])
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (softwarePackages[packageKey]['_' + currentSelector + ':' + osType + ':' + preference]) {
|
|
|
|
|
pref = osType + ':' + preference
|
|
|
|
|
log('info', 'Installing Dependencies', `Installing dependencies for ${packageKey}.${pref}`)
|
2022-12-25 06:00:18 -08:00
|
|
|
|
await generateInstallOrders(softwarePackages[packageKey][pref])
|
2022-12-08 23:57:44 -08:00
|
|
|
|
}
|
|
|
|
|
} else if (scopedPkgManager) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const pref = preference
|
|
|
|
|
log('info', 'Installing Dependencies', `Installing dependencies for ${packageKey}.${pref}`)
|
2022-12-25 06:00:18 -08:00
|
|
|
|
await generateInstallOrders(softwarePackages[packageKey][pref])
|
2022-12-08 23:57:44 -08:00
|
|
|
|
} else if (scopedSystem) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
let pref
|
|
|
|
|
if (softwarePackages[packageKey]['_' + currentSelector + ':' + osID]) {
|
|
|
|
|
pref = osID
|
|
|
|
|
log('info', 'Installing Dependencies', `Installing dependencies for ${packageKey}.${pref}`)
|
2022-12-25 06:00:18 -08:00
|
|
|
|
await generateInstallOrders(softwarePackages[packageKey][pref])
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (softwarePackages[packageKey]['_' + currentSelector + ':' + osType]) {
|
|
|
|
|
pref = osType
|
|
|
|
|
log('info', 'Installing Dependencies', `Installing dependencies for ${packageKey}.${pref}`)
|
2022-12-25 06:00:18 -08:00
|
|
|
|
await generateInstallOrders(softwarePackages[packageKey][pref])
|
2022-12-08 23:57:44 -08:00
|
|
|
|
}
|
|
|
|
|
} else if (normalCheck) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Installing Dependencies', `Installing dependencies for ${packageKey}.deps`)
|
2022-12-25 06:00:18 -08:00
|
|
|
|
await generateInstallOrders(softwarePackages[packageKey]['_deps'])
|
2022-12-08 23:57:44 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
if (softwarePackages[packageKey][preference + ':' + osID]) {
|
2022-12-04 21:46:23 -08:00
|
|
|
|
await updateInstallMaps(
|
|
|
|
|
preference,
|
|
|
|
|
softwarePackages[packageKey],
|
2022-12-24 20:48:43 -08:00
|
|
|
|
preference + ':' + osID,
|
2022-12-04 21:46:23 -08:00
|
|
|
|
pkg,
|
2022-12-08 21:19:29 -08:00
|
|
|
|
packageKey,
|
|
|
|
|
softwarePackages
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
|
|
|
|
break
|
|
|
|
|
} else if (softwarePackages[packageKey][preference + ':' + osType]) {
|
2022-12-04 21:46:23 -08:00
|
|
|
|
await updateInstallMaps(
|
|
|
|
|
preference,
|
|
|
|
|
softwarePackages[packageKey],
|
2022-12-24 20:48:43 -08:00
|
|
|
|
preference + ':' + osType,
|
2022-12-04 21:46:23 -08:00
|
|
|
|
pkg,
|
2022-12-08 21:19:29 -08:00
|
|
|
|
packageKey,
|
|
|
|
|
softwarePackages
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
|
|
|
|
break
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} else if (softwarePackages[packageKey][preference]) {
|
|
|
|
|
await updateInstallMaps(
|
|
|
|
|
preference,
|
|
|
|
|
softwarePackages[packageKey],
|
|
|
|
|
preference,
|
|
|
|
|
pkg,
|
2022-12-08 21:19:29 -08:00
|
|
|
|
packageKey,
|
|
|
|
|
softwarePackages
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
|
|
|
|
break
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-25 06:00:18 -08:00
|
|
|
|
if (generateInstallOrderCount === 1) {
|
|
|
|
|
return installOrders
|
|
|
|
|
} else {
|
|
|
|
|
generateInstallOrderCount--
|
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update install, pre-hook, and post-hook objects
|
2022-12-24 20:48:43 -08:00
|
|
|
|
async function updateInstallMaps(preference, packages, scopedPreference, pkg, packageKey, softwarePackages) {
|
|
|
|
|
const preHook = getHook(packages, 'pre', scopedPreference, preference)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (preHook) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
installOrdersPre.concat(typeof preHook === 'string' ? [preHook] : preHook)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const postHook = getHook(packages, 'post', scopedPreference, preference)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (postHook) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
installOrdersPost.concat(typeof postHook === 'string' ? [postHook] : postHook)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const systemdHook = getHook(packages, 'systemd', scopedPreference, preference)
|
2022-12-08 21:19:29 -08:00
|
|
|
|
if (systemdHook) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
installOrdersSystemd.concat(typeof systemdHook === 'string' ? [systemdHook] : systemdHook)
|
2022-12-08 21:19:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (!installOrders[preference]) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
installOrders[preference] = []
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Install Orders', `Found a match for the package \`${pkg}\` (${packageKey} via ${scopedPreference})`)
|
|
|
|
|
const newPackages = packages[scopedPreference]
|
|
|
|
|
const newPkgs = typeof newPackages === 'string' ? [newPackages] : newPackages
|
2022-12-25 03:28:08 -08:00
|
|
|
|
if (preference === 'snap' && softwarePackages[pkg]['_snapClassic'] === true) {
|
2022-12-08 21:19:29 -08:00
|
|
|
|
if (!installOrders[preference + '-classic']) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
installOrders[preference + '-classic'] = []
|
2022-12-08 21:19:29 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
installOrders[preference + '-classic'] = installOrders[preference].concat(newPkgs)
|
2022-12-08 21:19:29 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
installOrders[preference] = installOrders[preference].concat(newPkgs)
|
2022-12-08 21:19:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get pre / post install hooks
|
|
|
|
|
function getHook(packages, hook, scopedPreference, preference) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const hookLabel = '_' + hook + ':'
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (packages[hookLabel + scopedPreference]) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return packages[hookLabel + scopedPreference]
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else if (packages[hookLabel + preference]) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return packages[hookLabel + preference]
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else if (packages[hookLabel + osID]) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return packages
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else if (packages[hookLabel + osType]) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return packages[hookLabel + osType]
|
|
|
|
|
} else if (packages['_' + hook]) {
|
|
|
|
|
return packages['_' + hook]
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Acquire OS type installer key (for the installerPreference data key)
|
|
|
|
|
async function OSTypeInstallerKey() {
|
2022-12-24 08:57:06 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const apt = which.sync('apt-get', { nothrow: true })
|
|
|
|
|
const dnf = which.sync('dnf', { nothrow: true })
|
|
|
|
|
const freebsdPkg = which.sync('pkg', { nothrow: true })
|
|
|
|
|
const freebsdVersion = which.sync('freebsd-version', { nothrow: true })
|
|
|
|
|
const pacman = which.sync('pacman', { nothrow: true })
|
|
|
|
|
const yum = which.sync('yum', { nothrow: true })
|
|
|
|
|
const zypper = which.sync('zypper', { nothrow: true })
|
2022-12-24 08:57:06 -08:00
|
|
|
|
if (apt) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return 'apt'
|
2022-12-24 08:57:06 -08:00
|
|
|
|
} else if (dnf || yum) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return 'dnf'
|
2022-12-24 08:57:06 -08:00
|
|
|
|
} else if (pacman) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return 'pacman'
|
2022-12-24 08:57:06 -08:00
|
|
|
|
} else if (zypper) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return 'zypper'
|
2022-12-24 08:57:06 -08:00
|
|
|
|
} else if (freebsdPkg && freebsdVersion) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return 'freebsd'
|
2022-12-24 08:57:06 -08:00
|
|
|
|
} else {
|
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`test -d /Applications && test -d /Library`
|
|
|
|
|
return 'darwin'
|
2022-12-24 08:57:06 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return 'windows'
|
2022-12-24 08:57:06 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 08:57:06 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'OS Detection', 'There was an error determining the type of operating system')
|
2022-12-24 08:57:06 -08:00
|
|
|
|
console.error(e)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Acquire OS type
|
|
|
|
|
async function OSType() {
|
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`test -d /Applications && test -d /Library`
|
|
|
|
|
return 'darwin'
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-11-29 22:26:34 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`test -f /etc/os-release`
|
|
|
|
|
return 'linux'
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return 'windows'
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Acquire release ID (for Linux)
|
|
|
|
|
async function releaseID() {
|
|
|
|
|
const ID = await $`
|
|
|
|
|
if [ -f /etc/os-release ]; then
|
|
|
|
|
. /etc/os-release
|
|
|
|
|
echo -n $ID
|
|
|
|
|
fi
|
2022-12-24 20:48:43 -08:00
|
|
|
|
`
|
|
|
|
|
return ID.stdout
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Post-install hook
|
|
|
|
|
async function afterInstall(packageManager) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const logStage = 'Post-Install Package Manager'
|
|
|
|
|
if (packageManager === 'appimage') {
|
|
|
|
|
} else if (packageManager === 'ansible') {
|
|
|
|
|
log('info', logStage, `Ensuring temporary passwordless sudo privileges used by Ansible are removed`)
|
|
|
|
|
const gsed = which.sync('gsed', { nothrow: true })
|
2022-12-02 15:28:30 -08:00
|
|
|
|
if (gsed) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`sudo gsed -i '/# TEMPORARY FOR ANSIBLE INSTALL/d' /etc/sudoers`
|
2022-12-02 15:28:30 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`sudo sed -i '/# TEMPORARY FOR ANSIBLE INSTALL/d' /etc/sudoers`
|
2022-12-02 15:28:30 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'apk') {
|
|
|
|
|
} else if (packageManager === 'apt') {
|
2022-12-06 04:53:19 -08:00
|
|
|
|
try {
|
2022-12-25 03:05:03 -08:00
|
|
|
|
await $`sudo apt-get autoclean`
|
2023-01-03 18:01:42 -08:00
|
|
|
|
await $`sudo apt-get -y autoremove`
|
2022-12-06 04:53:19 -08:00
|
|
|
|
} catch (e) {
|
2022-12-25 03:05:03 -08:00
|
|
|
|
log('error', logStage, 'Error cleaning up apt-get')
|
2022-12-06 04:53:19 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'basher') {
|
|
|
|
|
} else if (packageManager === 'binary') {
|
|
|
|
|
} else if (packageManager === 'brew' || packageManager === 'cask') {
|
|
|
|
|
} else if (packageManager === 'cargo') {
|
|
|
|
|
} else if (packageManager === 'choco') {
|
|
|
|
|
} else if (packageManager === 'crew') {
|
|
|
|
|
} else if (packageManager === 'dnf') {
|
|
|
|
|
} else if (packageManager === 'flatpak') {
|
|
|
|
|
} else if (packageManager === 'gem') {
|
|
|
|
|
} else if (packageManager === 'go') {
|
|
|
|
|
} else if (packageManager === 'nix') {
|
|
|
|
|
} else if (packageManager === 'npm') {
|
|
|
|
|
} else if (packageManager === 'pacman') {
|
|
|
|
|
} else if (packageManager === 'pipx') {
|
|
|
|
|
} else if (packageManager === 'pkg') {
|
|
|
|
|
} else if (packageManager === 'port') {
|
|
|
|
|
} else if (packageManager === 'scoop') {
|
|
|
|
|
} else if (packageManager === 'script') {
|
|
|
|
|
} else if (packageManager === 'snap') {
|
|
|
|
|
} else if (packageManager === 'whalebrew') {
|
|
|
|
|
} else if (packageManager === 'winget') {
|
|
|
|
|
} else if (packageManager === 'yay') {
|
|
|
|
|
} else if (packageManager === 'zypper') {
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-08 23:57:44 -08:00
|
|
|
|
async function ensurePackage(dep) {
|
|
|
|
|
const target = which.sync(dep, { nothrow: true })
|
|
|
|
|
if (!target) {
|
2022-12-08 22:37:26 -08:00
|
|
|
|
if (osType === 'linux') {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const apk = which.sync('apk', { nothrow: true })
|
2022-12-25 03:05:03 -08:00
|
|
|
|
const apt = which.sync('apt-get', { nothrow: true })
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const dnf = which.sync('dnf', { nothrow: true })
|
2023-01-03 19:52:32 -08:00
|
|
|
|
const pkg = which.sync('pkg', { nothrow: true })
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const yum = which.sync('yum', { nothrow: true })
|
|
|
|
|
const pacman = which.sync('pacman', { nothrow: true })
|
|
|
|
|
const zypper = which.sync('zypper', { nothrow: true })
|
2022-12-08 22:37:26 -08:00
|
|
|
|
if (apk) {
|
2022-12-25 02:03:54 -08:00
|
|
|
|
await $`sudo apk add ${dep}`
|
2022-12-08 22:37:26 -08:00
|
|
|
|
} else if (apt) {
|
2022-12-25 11:07:19 -08:00
|
|
|
|
if (updateDone['apt-get'] !== true) {
|
2022-12-08 22:37:26 -08:00
|
|
|
|
await beforeInstall('apt-get')
|
|
|
|
|
}
|
2023-01-03 19:52:32 -08:00
|
|
|
|
try {
|
|
|
|
|
log('info', 'apt-get Installation', `Checking if ${dep} is already installed`)
|
|
|
|
|
await $`dpkg -l ${dep} | grep -E '^ii' > /dev/null`
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log('info', 'apt-get Installation', `Installing ${dep} since it is not already present on the system`)
|
|
|
|
|
await $`sudo apt-get install -y ${dep}`
|
|
|
|
|
}
|
2022-12-08 22:37:26 -08:00
|
|
|
|
} else if (dnf) {
|
2022-12-25 11:07:19 -08:00
|
|
|
|
if (updateDone['dnf'] !== true) {
|
2022-12-08 22:37:26 -08:00
|
|
|
|
await beforeInstall('dnf')
|
|
|
|
|
}
|
2023-01-03 19:52:32 -08:00
|
|
|
|
try {
|
|
|
|
|
log('info', 'dnf Installation', `Checking if ${dep} is already installed`)
|
|
|
|
|
await $`rpm -qa | grep ${dep} > /dev/null`
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log('info', 'dnf Installation', `Installing ${dep} since it is not already present on the system`)
|
|
|
|
|
await $`sudo dnf install -y ${dep}`
|
|
|
|
|
}
|
2022-12-08 22:37:26 -08:00
|
|
|
|
} else if (yum) {
|
2022-12-25 11:07:19 -08:00
|
|
|
|
if (updateDone['yum'] !== true) {
|
|
|
|
|
await beforeInstall('yum')
|
2022-12-08 22:37:26 -08:00
|
|
|
|
}
|
2023-01-03 19:52:32 -08:00
|
|
|
|
try {
|
|
|
|
|
log('info', 'YUM Installation', `Checking if ${dep} is already installed`)
|
|
|
|
|
await $`rpm -qa | grep ${dep} > /dev/null`
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log('info', 'YUM Installation', `Installing ${dep} since it is not already present on the system`)
|
|
|
|
|
await $`sudo yum install -y ${dep}`
|
|
|
|
|
}
|
2022-12-08 22:37:26 -08:00
|
|
|
|
} else if (pacman) {
|
2022-12-25 11:07:19 -08:00
|
|
|
|
if (updateDone['pacman'] !== true) {
|
2022-12-08 22:37:26 -08:00
|
|
|
|
await beforeInstall('pacman')
|
|
|
|
|
}
|
2023-01-03 19:52:32 -08:00
|
|
|
|
try {
|
|
|
|
|
log('info', 'Pacman Installation', `Checking if ${dep} is already installed`)
|
|
|
|
|
await $`pacman -Qs ${dep}`
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log('info', 'Pacman Installation', `Installing ${dep} since it is not already present on the system`)
|
|
|
|
|
await $`sudo pacman -Sy ${dep}`
|
|
|
|
|
}
|
2022-12-08 22:37:26 -08:00
|
|
|
|
} else if (zypper) {
|
2022-12-25 11:07:19 -08:00
|
|
|
|
if (updateDone['zypper'] !== true) {
|
2022-12-08 22:37:26 -08:00
|
|
|
|
await beforeInstall('zypper')
|
|
|
|
|
}
|
2023-01-03 19:52:32 -08:00
|
|
|
|
try {
|
|
|
|
|
log('info', 'Zypper Installation', `Checking if ${dep} is already installed`)
|
|
|
|
|
await $`rpm -qa | grep ${dep} > /dev/null`
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log('info', 'Zypper Installation', `Installing ${dep} since it is not already present on the system`)
|
|
|
|
|
await $`sudo zypper install -y ${dep}`
|
|
|
|
|
}
|
|
|
|
|
} else if (pkg) {
|
|
|
|
|
if (updateDone['pkg'] !== true) {
|
|
|
|
|
await beforeInstall('pkg')
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
log('info', 'pkg Installation', `Checking if ${dep} is already installed`)
|
|
|
|
|
await $`pkg info -Ix ${dep} > /dev/null`
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log('info', 'pkg Installation', `Installing ${dep} since it is not already present on the system`)
|
|
|
|
|
await $`sudo pkg install -y ${dep}`
|
|
|
|
|
}
|
2022-12-08 22:37:26 -08:00
|
|
|
|
}
|
|
|
|
|
} else if (osType === 'darwin') {
|
|
|
|
|
if (updateDone['brew'] !== true) {
|
|
|
|
|
await beforeInstall('brew')
|
|
|
|
|
}
|
2022-12-08 23:57:44 -08:00
|
|
|
|
await $`brew install ${dep}`
|
2022-12-08 22:37:26 -08:00
|
|
|
|
} else if (osType === 'windows') {
|
|
|
|
|
if (updateDone['choco'] !== true) {
|
|
|
|
|
await beforeInstall('choco')
|
|
|
|
|
}
|
2022-12-08 23:57:44 -08:00
|
|
|
|
await `choco install -y ${dep}`
|
2022-12-08 22:37:26 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 22:26:34 -08:00
|
|
|
|
// Pre-install hook
|
2022-12-08 22:37:26 -08:00
|
|
|
|
const updateDone = {}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
async function beforeInstall(packageManager) {
|
2022-12-08 22:37:26 -08:00
|
|
|
|
updateDone[packageManager] = true
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const logStage = 'Pre-Install Package Manager'
|
|
|
|
|
if (packageManager === 'appimage') {
|
|
|
|
|
} else if (packageManager === 'ansible') {
|
|
|
|
|
log('info', logStage, `Temporarily enabling passwordless sudo for Ansible role installations`)
|
|
|
|
|
await $`echo "$(whoami) ALL=(ALL:ALL) NOPASSWD: ALL # TEMPORARY FOR ANSIBLE INSTALL" | sudo tee -a /etc/sudoers`
|
2022-12-05 12:15:57 -08:00
|
|
|
|
log('info', logStage, 'Running Ansible setup task so facts are cached')
|
2022-12-06 13:04:49 -08:00
|
|
|
|
const unbuffer = which.sync('unbuffer', { nothrow: true })
|
|
|
|
|
let unbufferPrefix = ''
|
|
|
|
|
if (unbuffer) {
|
2022-12-06 14:24:46 -08:00
|
|
|
|
unbufferPrefix = 'unbuffer'
|
2022-12-06 13:04:49 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`${unbufferPrefix} ansible 127.0.0.1 -vv -e '{ ansible_connection: "local", ansible_user: "${process.env.USER}", install_homebrew: False }' -m setup`
|
|
|
|
|
} else if (packageManager === 'apk') {
|
|
|
|
|
await $`sudo apk update`
|
|
|
|
|
} else if (packageManager === 'apt') {
|
2022-12-25 03:05:03 -08:00
|
|
|
|
await $`sudo apt-get update`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'basher') {
|
|
|
|
|
} else if (packageManager === 'binary') {
|
|
|
|
|
} else if (packageManager === 'brew' || packageManager === 'cask') {
|
2022-12-08 21:19:29 -08:00
|
|
|
|
if (!brewUpdated) {
|
|
|
|
|
brewUpdated = true
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`brew update`
|
2022-12-08 21:19:29 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'cargo') {
|
|
|
|
|
} else if (packageManager === 'choco') {
|
|
|
|
|
} else if (packageManager === 'crew') {
|
|
|
|
|
await $`crew update`
|
|
|
|
|
} else if (packageManager === 'dnf') {
|
|
|
|
|
const dnf = which.sync('dnf', { nothrow: true })
|
|
|
|
|
const yum = which.sync('yum', { nothrow: true })
|
2022-12-04 19:51:47 -08:00
|
|
|
|
if (dnf) {
|
2022-12-25 02:52:18 -08:00
|
|
|
|
await $`sudo dnf update -y`
|
2022-12-04 19:51:47 -08:00
|
|
|
|
} else if (yum) {
|
2022-12-25 02:52:18 -08:00
|
|
|
|
await $`sudo yum update -y`
|
2022-12-04 19:51:47 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'flatpak') {
|
2023-01-03 19:03:04 -08:00
|
|
|
|
await $`sudo flatpak update -y`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'gem') {
|
|
|
|
|
} else if (packageManager === 'go') {
|
|
|
|
|
} else if (packageManager === 'nix') {
|
|
|
|
|
await $`nix-channel --update`
|
|
|
|
|
} else if (packageManager === 'npm') {
|
|
|
|
|
} else if (packageManager === 'pacman') {
|
|
|
|
|
await $`sudo pacman -Syu`
|
|
|
|
|
} else if (packageManager === 'pipx') {
|
|
|
|
|
} else if (packageManager === 'pkg') {
|
|
|
|
|
await $`sudo pkg upgrade`
|
|
|
|
|
} else if (packageManager === 'port') {
|
|
|
|
|
const port = which.sync('port', { nothrow: true })
|
2022-12-04 20:12:14 -08:00
|
|
|
|
if (port) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`sudo port sync`
|
2022-12-04 20:12:14 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Port Not Installed', 'Skipping sudo port sync step because port is not installed')
|
2022-12-04 20:12:14 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'scoop') {
|
|
|
|
|
await $`scoop update`
|
|
|
|
|
} else if (packageManager === 'snap' || packageManager === 'snap-classic') {
|
2022-12-08 21:19:29 -08:00
|
|
|
|
if (!snapRefreshed) {
|
|
|
|
|
snapRefreshed = true
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`sudo snap refresh`
|
2022-12-08 21:19:29 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'whalebrew') {
|
|
|
|
|
if (osType === 'darwin') {
|
|
|
|
|
const docker = which.sync('docker', { nothrow: true })
|
2022-12-02 09:09:59 -08:00
|
|
|
|
if (!docker) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`brew install --cask docker`
|
2022-12-02 09:09:59 -08:00
|
|
|
|
}
|
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`docker run --rm hello-world`
|
2022-12-02 09:09:59 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('warn', logStage, `The command \`docker run --rm hello-world\` failed`)
|
2022-12-02 09:09:59 -08:00
|
|
|
|
try {
|
2022-12-04 21:46:23 -08:00
|
|
|
|
log(
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'info',
|
2022-12-04 21:46:23 -08:00
|
|
|
|
logStage,
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'Attempting to open `/Applications/Docker.app` (Docker Desktop for macOS). This should take about 30 seconds.'
|
|
|
|
|
)
|
|
|
|
|
const promises = [$`test -d /Applications/Docker.app`, $`open /Applications/Docker.app`]
|
|
|
|
|
await Promise.all(promises)
|
|
|
|
|
const gum = which.sync('gum', { nothrow: true })
|
2022-12-02 09:09:59 -08:00
|
|
|
|
if (gum) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
execSync('gum spin --spinner dot --title "Waiting for Docker Desktop to start up.." -- sleep 30', {
|
|
|
|
|
stdio: 'inherit',
|
|
|
|
|
shell: true
|
|
|
|
|
})
|
2022-12-02 09:09:59 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`sleep 30`
|
2022-12-02 09:09:59 -08:00
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('warn', logStage, `Docker Desktop appears to not be installed!`)
|
2022-12-02 09:09:59 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-02 09:01:47 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'winget') {
|
|
|
|
|
await $`winget source update`
|
|
|
|
|
} else if (packageManager === 'yay') {
|
|
|
|
|
} else if (packageManager === 'zypper') {
|
|
|
|
|
await $`sudo zypper update`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function ensureInstalled(bin, callback) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const logStage = 'Package Manager Install'
|
|
|
|
|
const installed = which.sync(bin, { nothrow: true })
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (installed) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', logStage, `\`${bin}\` is available`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('warn', logStage, `\`${bin}\` is not installed!`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (callback) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await callback
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', logStage, `There does not appear to be an installation method available for \`${bin}\``)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-02 09:50:31 -08:00
|
|
|
|
async function ensurePackageManagerAnsible() {
|
2022-12-25 02:03:54 -08:00
|
|
|
|
await $`pipx install ansible-core`
|
2022-12-25 01:38:17 -08:00
|
|
|
|
if (osType === 'darwin') {
|
2022-12-25 02:03:54 -08:00
|
|
|
|
await $`pipx inject ansible-core PyObjC PyObjC-core`
|
2022-12-25 01:38:17 -08:00
|
|
|
|
}
|
2022-12-25 02:03:54 -08:00
|
|
|
|
await $`pipx inject ansible-core docker lxml netaddr pexpect python-vagrant pywinrm requests-credssp watchdog`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`mkdir -p "$HOME/.cache/megabyte-labs"`
|
|
|
|
|
await $`touch "$HOME/.cache/megabyte-labs/ansible-installed"`
|
|
|
|
|
log('info', 'Package Manager Install', `Ansible and its supporting packages are now installed via pipx`)
|
2022-12-02 09:50:31 -08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 22:26:34 -08:00
|
|
|
|
// Ensure the package manager is available
|
2022-12-24 20:48:43 -08:00
|
|
|
|
let packageManagerInstalled = {}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
async function ensurePackageManager(packageManager) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const logStage = 'Package Manager Install'
|
|
|
|
|
log('info', logStage, `Ensuring \`${packageManager}\` is set up`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (packageManagerInstalled[packageManager]) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
return
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
packageManagerInstalled[packageManager] = true
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
if (packageManager === 'ansible') {
|
|
|
|
|
await ensurePackageManager('pipx')
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
if (
|
2022-12-24 20:48:43 -08:00
|
|
|
|
packageManager === 'gem' ||
|
|
|
|
|
packageManager === 'go' ||
|
|
|
|
|
packageManager === 'npm' ||
|
|
|
|
|
packageManager === 'pipx' ||
|
|
|
|
|
packageManager === 'whalebrew'
|
2022-11-29 22:26:34 -08:00
|
|
|
|
) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await ensurePackageManager('brew')
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
if (packageManager === 'appimage') {
|
2022-12-08 22:37:26 -08:00
|
|
|
|
const zap = which.sync('zap', { nothrow: true })
|
|
|
|
|
if (!zap) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Zap Installation', 'Installing Zap to handle AppImage installation')
|
2022-12-08 23:57:44 -08:00
|
|
|
|
await ensurePackage('curl')
|
2022-12-08 22:37:26 -08:00
|
|
|
|
await $`sudo curl -sSL https://github.com/srevinsaju/zap/releases/download/continuous/zap-amd64 > /usr/local/bin/zap`
|
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'ansible') {
|
2022-12-02 09:50:31 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`test -f "$HOME/.cache/megabyte-labs/ansible-installed"`
|
|
|
|
|
const ansible = which.sync('ansible', { nothrow: true })
|
2022-12-02 09:50:31 -08:00
|
|
|
|
if (ansible) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', logStage, `\`ansible\` and its supporting packages appear to be installed`)
|
2022-12-02 09:50:31 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await ensurePackageManagerAnsible()
|
2022-12-02 09:50:31 -08:00
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await ensurePackageManagerAnsible()
|
2022-12-02 09:50:31 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'apk') {
|
|
|
|
|
await ensureInstalled('apk', false)
|
|
|
|
|
} else if (packageManager === 'apt') {
|
|
|
|
|
await ensureInstalled('apt', false)
|
|
|
|
|
} else if (packageManager === 'basher') {
|
2022-12-04 21:46:23 -08:00
|
|
|
|
await ensureInstalled(
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'basher',
|
2022-12-04 21:46:23 -08:00
|
|
|
|
$`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
# TODO
|
|
|
|
|
echo "Bash script that installs basher here"
|
2022-12-04 21:46:23 -08:00
|
|
|
|
`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
|
|
|
|
} else if (packageManager === 'binary') {
|
2022-12-08 23:57:44 -08:00
|
|
|
|
await ensurePackage('curl')
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'bpkg') {
|
2022-12-04 21:46:23 -08:00
|
|
|
|
await ensureInstalled(
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'bpkg',
|
2022-12-04 21:46:23 -08:00
|
|
|
|
$`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
# TODO
|
|
|
|
|
echo "Bash script that installs bpkg here"
|
2022-12-04 21:46:23 -08:00
|
|
|
|
`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
|
|
|
|
} else if (packageManager === 'brew' || packageManager === 'cask') {
|
|
|
|
|
const brew = which.sync('brew', { nothrow: true })
|
2022-12-25 04:07:02 -08:00
|
|
|
|
if (!brew) {
|
2022-12-04 21:46:23 -08:00
|
|
|
|
await ensureInstalled(
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'brew',
|
2022-12-04 21:46:23 -08:00
|
|
|
|
$`
|
2022-12-02 06:30:38 -08:00
|
|
|
|
if command -v sudo > /dev/null && sudo -n true; then
|
|
|
|
|
echo | bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
|
|
|
|
else
|
2022-12-02 16:13:21 -08:00
|
|
|
|
log('info', logStage, 'Homebrew is not installed. Password may be required.')
|
2022-12-02 06:30:38 -08:00
|
|
|
|
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || BREW_EXIT_CODE="$?"
|
|
|
|
|
if [ -n "$BREW_EXIT_CODE" ]; then
|
|
|
|
|
if command -v brew > /dev/null; then
|
2022-12-02 16:13:21 -08:00
|
|
|
|
log('warn', logStage, 'Homebrew was installed but part of the installation failed. Attempting to fix..')
|
2022-12-02 06:30:38 -08:00
|
|
|
|
BREW_DIRS="share/man share/doc share/zsh/site-functions etc/bash_completion.d"
|
|
|
|
|
for BREW_DIR in $BREW_DIRS; do
|
|
|
|
|
if [ -d "$(brew --prefix)/$BREW_DIR" ]; then
|
|
|
|
|
sudo chown -R "$(whoami)" "$(brew --prefix)/$BREW_DIR"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
brew update --force --quiet
|
|
|
|
|
fi
|
2022-11-29 22:26:34 -08:00
|
|
|
|
fi
|
|
|
|
|
fi
|
2022-12-04 21:46:23 -08:00
|
|
|
|
`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
2022-12-02 06:30:38 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'cargo') {
|
2022-12-25 04:07:02 -08:00
|
|
|
|
const cargo = which.sync('cargo', { nothrow: true })
|
|
|
|
|
if (!cargo) {
|
|
|
|
|
if (osType === 'darwin') {
|
|
|
|
|
await $`brew install rustup`
|
|
|
|
|
await $`rustup-init`
|
|
|
|
|
} else if (osType === 'windows') {
|
|
|
|
|
} else {
|
|
|
|
|
await ensurePackage('cargo')
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'choco') {
|
2022-12-04 21:46:23 -08:00
|
|
|
|
await ensureInstalled(
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'choco',
|
2022-12-04 21:46:23 -08:00
|
|
|
|
$`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
powershell "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"
|
2022-12-04 21:46:23 -08:00
|
|
|
|
`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
|
|
|
|
} else if (packageManager === 'crew') {
|
2022-12-04 21:46:23 -08:00
|
|
|
|
await ensureInstalled(
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'crew',
|
2022-12-04 21:46:23 -08:00
|
|
|
|
$`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
# TODO Bash script that installs crew here
|
|
|
|
|
# Source: https://github.com/chromebrew/chromebrew
|
|
|
|
|
curl -Ls git.io/vddgY | bash
|
2022-12-04 21:46:23 -08:00
|
|
|
|
`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
|
|
|
|
} else if (packageManager === 'dnf') {
|
|
|
|
|
const dnf = which.sync('dnf', { nothrow: true })
|
|
|
|
|
const yum = which.sync('yum', { nothrow: true })
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (dnf) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', logStage, `\`dnf\` is available`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else if (yum) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', logStage, `\`yum\` is available`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', logStage, `Both \`dnf\` and \`yum\` are not available`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'flatpak') {
|
|
|
|
|
const flatpak = which.sync('flatpak', { nothrow: true })
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (flatpak) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', logStage, `\`flatpak\` is available`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const apk = which.sync('apk', { nothrow: true })
|
2022-12-25 03:05:03 -08:00
|
|
|
|
const apt = which.sync('apt-get', { nothrow: true })
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const dnf = which.sync('dnf', { nothrow: true })
|
|
|
|
|
const yum = which.sync('yum', { nothrow: true })
|
|
|
|
|
const pacman = which.sync('pacman', { nothrow: true })
|
|
|
|
|
const zypper = which.sync('zypper', { nothrow: true })
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (apk) {
|
2022-12-25 02:03:54 -08:00
|
|
|
|
await $`sudo apk add flatpak`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} else if (apt) {
|
2022-12-25 02:03:54 -08:00
|
|
|
|
await $`
|
2022-12-25 03:05:03 -08:00
|
|
|
|
sudo apt-get install -y flatpak
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if [ -f /usr/bin/gnome-shell ]; then
|
2022-12-25 03:05:03 -08:00
|
|
|
|
sudo apt-get install -y gnome-software-plugin-flatpak
|
2022-11-29 22:26:34 -08:00
|
|
|
|
fi
|
|
|
|
|
if [ -f /usr/bin/plasmashell ]; then
|
2022-12-25 03:05:03 -08:00
|
|
|
|
sudo apt-get install -y plasmashell
|
2022-11-29 22:26:34 -08:00
|
|
|
|
fi
|
2022-12-24 20:48:43 -08:00
|
|
|
|
`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} else if (dnf) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`sudo dnf install -y flatpak`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} else if (yum) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`sudo yum install -y flatpak`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else if (pacman) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`sudo pacman -Sy flatpak`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else if (zypper) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`sudo zypper install -y flatpak`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const flatpakPost = which.sync('flatpak', { nothrow: true })
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (flatpakPost) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', logStage, `\`flatpak\` failed to install!`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', logStage, `\`flatpak\` was installed. It may require a reboot to function correctly.`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'gem') {
|
|
|
|
|
await ensureInstalled('gem', $`brew install ruby`)
|
|
|
|
|
} else if (packageManager === 'go') {
|
|
|
|
|
await ensureInstalled('gem', $`brew install go`)
|
|
|
|
|
} else if (packageManager === 'nix') {
|
2022-12-04 21:46:23 -08:00
|
|
|
|
await ensureInstalled(
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'nix',
|
2022-12-04 21:46:23 -08:00
|
|
|
|
$`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if [ -d /Applications ] && [ -d /Library ]; then
|
|
|
|
|
sh <(curl -L https://nixos.org/nix/install)
|
|
|
|
|
else
|
|
|
|
|
sh <(curl -L https://nixos.org/nix/install) --daemon
|
|
|
|
|
fi
|
2022-12-04 21:46:23 -08:00
|
|
|
|
`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
|
|
|
|
} else if (packageManager === 'npm') {
|
2022-12-25 11:07:19 -08:00
|
|
|
|
const npm = which.sync('npm', { nothrow: true })
|
|
|
|
|
const node = which.sync('node', { nothrow: true })
|
|
|
|
|
const volta = which.sync('volta', { nothrow: true })
|
2022-11-29 22:26:34 -08:00
|
|
|
|
if (npm && node && volta) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', logStage, `\`npm\`, \`node\`, and \`volta\` are available`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
} else {
|
|
|
|
|
if (!volta) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`brew install volta`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
await $`
|
|
|
|
|
if [ -z "$VOLTA_HOME" ]; then
|
|
|
|
|
volta setup
|
|
|
|
|
fi
|
|
|
|
|
export PATH="$VOLTA_HOME/bin:$PATH"
|
|
|
|
|
volta install node
|
2022-12-24 20:48:43 -08:00
|
|
|
|
`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-25 02:19:44 -08:00
|
|
|
|
log('info', logStage, 'Ensuring Volt has Node.js runtime available')
|
|
|
|
|
await $`if ! volta list 2>1 | grep 'runtime node' > /dev/null; then volta install node; fi`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'pacman') {
|
|
|
|
|
await ensureInstalled('pacman', false)
|
|
|
|
|
} else if (packageManager === 'pipx') {
|
2022-12-25 11:07:19 -08:00
|
|
|
|
const pipx = which.sync('pipx', { nothrow: true })
|
|
|
|
|
if (!pipx) {
|
|
|
|
|
await ensureInstalled('pipx', $`brew install pipx`)
|
|
|
|
|
await $`pipx ensurepath`
|
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'pkg') {
|
|
|
|
|
await ensureInstalled('pkg', false)
|
|
|
|
|
} else if (packageManager === 'port') {
|
2022-12-05 12:25:46 -08:00
|
|
|
|
const port = which.sync('port', { nothrow: true })
|
|
|
|
|
if (!port) {
|
|
|
|
|
log('info', logStage, `Installing ${packageManager}`)
|
|
|
|
|
await ensureInstalled(
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'port',
|
2022-12-05 12:25:46 -08:00
|
|
|
|
$`
|
|
|
|
|
sudo mkdir -p /opt/mports
|
|
|
|
|
cd /opt/mports
|
2022-12-05 21:42:36 -08:00
|
|
|
|
sudo rm -rf macports-base
|
2022-12-05 12:25:46 -08:00
|
|
|
|
sudo git clone https://github.com/macports/macports-base.git
|
|
|
|
|
cd macports-base
|
|
|
|
|
sudo git checkout v2.8.0
|
2022-12-06 10:20:31 -08:00
|
|
|
|
sudo bash --noprofile --norc -c './configure --enable-readline && make && make install && make distclean'
|
|
|
|
|
sudo port selfupdate
|
2022-12-05 12:25:46 -08:00
|
|
|
|
`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
2022-12-05 12:25:46 -08:00
|
|
|
|
log('info', logStage, `${packageManager} is now installed`)
|
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', logStage, `\`port\` is available`)
|
2022-12-05 12:25:46 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'scoop') {
|
2022-12-04 21:46:23 -08:00
|
|
|
|
await ensureInstalled(
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'scoop',
|
2022-12-04 21:46:23 -08:00
|
|
|
|
$`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
powershell 'Set-ExecutionPolicy RemoteSigned -Scope CurrentUser'
|
|
|
|
|
powershell 'irm get.scoop.sh | iex
|
2022-12-04 21:46:23 -08:00
|
|
|
|
`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
|
|
|
|
} else if (packageManager === 'snap') {
|
|
|
|
|
const apk = which.sync('apk', { nothrow: true })
|
|
|
|
|
const apt = which.sync('apt-get', { nothrow: true })
|
|
|
|
|
const dnf = which.sync('dnf', { nothrow: true })
|
|
|
|
|
const yum = which.sync('yum', { nothrow: true })
|
|
|
|
|
const pacman = which.sync('pacman', { nothrow: true })
|
|
|
|
|
const zypper = which.sync('zypper', { nothrow: true })
|
2022-12-04 21:46:23 -08:00
|
|
|
|
if (apt) {
|
2022-12-25 03:05:03 -08:00
|
|
|
|
await $`if [ -f /etc/apt/preferences.d/nosnap.pref ]; then sudo mv /etc/apt/preferences.d/nosnap.pref /etc/apt/nosnap.pref.bak; fi && sudo apt-get install -y snapd`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
// TODO Following may be required on Kali -> https://snapcraft.io/docs/installing-snap-on-kali
|
|
|
|
|
// systemctl enable --now snapd apparmor
|
|
|
|
|
} else if (dnf) {
|
2022-12-25 02:52:18 -08:00
|
|
|
|
await $`sudo dnf install -y snapd && if [ ! -d /snap ]; then sudo ln -s /var/lib/snapd/snap /snap; fi`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} else if (yum) {
|
2022-12-25 02:52:18 -08:00
|
|
|
|
await $`sudo yum install -y snapd && sudo systemctl enable --now snapd.socket && if [ ! -d /snap ]; then sudo ln -s /var/lib/snapd/snap /snap; fi`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} else if (pacman) {
|
2022-12-25 02:52:18 -08:00
|
|
|
|
await $`if [ -f /etc/arch-release ]; then sudo git clone https://aur.archlinux.org/snapd.git /usr/local/src/snapd && cd /usr/local/src/snapd && sudo makepkg -si; else sudo pacman -S snapd && sudo systemctl enable --now snapd.socket && if [ ! -d /snap ]; then sudo ln -s /var/lib/snapd/snap /snap; fi; fi`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} else if (zypper) {
|
|
|
|
|
// TODO See https://snapcraft.io/docs/installing-snap-on-opensuse
|
|
|
|
|
await $`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
echo "TODO - Bash script that installs snap w/ zypper"
|
2022-12-24 20:48:43 -08:00
|
|
|
|
`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const snap = which.sync('snap', { nothrow: true })
|
2022-12-04 21:46:23 -08:00
|
|
|
|
if (snap) {
|
2022-12-25 02:03:54 -08:00
|
|
|
|
await $`sudo snap install core`
|
2022-12-08 21:19:29 -08:00
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('warn', logStage, 'Snap installation sequence completed but the snap bin is still not available')
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'script') {
|
|
|
|
|
} else if (packageManager === 'whalebrew') {
|
|
|
|
|
await ensureInstalled('whalebrew', $`brew install whalebrew`)
|
|
|
|
|
} else if (packageManager === 'winget') {
|
2022-12-04 21:46:23 -08:00
|
|
|
|
await ensureInstalled(
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'winget',
|
2022-12-04 21:46:23 -08:00
|
|
|
|
$`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
echo "TODO - Script that installs winget here"
|
2022-12-04 21:46:23 -08:00
|
|
|
|
`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
|
|
|
|
} else if (packageManager === 'yay') {
|
|
|
|
|
const yay = which.sync('yay', { nothrow: true })
|
|
|
|
|
await $`sudo pacman -S --needed base-devel git`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
await $`
|
|
|
|
|
if [ -d /usr/local/src ]; then
|
|
|
|
|
git clone https://aur.archlinux.org/yay.git /usr/local/src/yay
|
|
|
|
|
cd /usr/local/src/yay
|
|
|
|
|
makepkg -si
|
|
|
|
|
fi
|
2022-12-24 20:48:43 -08:00
|
|
|
|
`
|
|
|
|
|
} else if (packageManager === 'zypper') {
|
|
|
|
|
await ensureInstalled('zypper', false)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Installs a list of packages via the specified package manager
|
|
|
|
|
async function installPackageList(packageManager, packages) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const logStage = 'Package Install'
|
2022-11-29 22:26:34 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
if (packageManager === 'appimage') {
|
2022-12-08 22:37:26 -08:00
|
|
|
|
for (let pkg of packages) {
|
|
|
|
|
try {
|
|
|
|
|
if (pkg.substring(0, 3) === 'http' && pkg.slice(-8) === 'AppImage') {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'AppImage Install', `Installing ${pkg} from its URL`)
|
2022-12-08 22:37:26 -08:00
|
|
|
|
await $`zap install --from ${pkg}`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (pkg.includes('/')) {
|
|
|
|
|
log('info', 'AppImage Install', `Installing ${pkg} from a GitHub Release`)
|
2022-12-08 22:37:26 -08:00
|
|
|
|
await $`zap install --github --from ${pkg}`
|
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'AppImage Install', `Installing ${pkg} using the AppImage Catalog`)
|
2022-12-08 22:37:26 -08:00
|
|
|
|
await $`zap install ${pkg}`
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'AppImage / Zap Failure', `There was an error using Zap to install ${pkg}`)
|
2022-12-08 22:37:26 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'ansible') {
|
2022-12-02 15:15:45 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 16:44:43 -08:00
|
|
|
|
try {
|
2022-12-06 13:04:49 -08:00
|
|
|
|
const unbuffer = which.sync('unbuffer', { nothrow: true })
|
|
|
|
|
let unbufferPrefix = ''
|
|
|
|
|
if (unbuffer) {
|
2022-12-06 14:24:46 -08:00
|
|
|
|
unbufferPrefix = 'unbuffer'
|
2022-12-06 13:04:49 -08:00
|
|
|
|
}
|
2022-12-24 08:46:51 -08:00
|
|
|
|
const verboseMode = process.env.DEBUG_MODE === 'on' ? 'vv' : ''
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`${unbufferPrefix} ansible 127.0.0.1 -v${verboseMode} -e '{ ansible_connection: "local", ansible_user: "${process.env.USER}", install_homebrew: False }' -m include_role -a name=${pkg}`
|
2022-12-02 16:44:43 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Ansible Role Failure', `There was an error installing ${pkg} with Ansible`)
|
2022-12-02 16:44:43 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'apk') {
|
2022-12-02 15:15:45 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`sudo apk add ${pkg}`
|
2022-12-02 17:39:29 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'APK Install Failure', `There was an error installing ${pkg} with apk`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-12-02 15:15:45 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'apt') {
|
2022-12-02 15:15:45 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2023-01-03 20:39:23 -08:00
|
|
|
|
await $`sudo apt-get install -y ${pkg}`
|
2022-12-02 17:39:29 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'apt-get Failure', `There was an error installing ${pkg} with apt-get`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-12-02 15:15:45 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'basher') {
|
2022-12-04 19:51:47 -08:00
|
|
|
|
for (let pkg of packages) {
|
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`basher install ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Basher Failure', `There was an error installing ${pkg} with basher`)
|
2022-12-04 19:51:47 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'binary') {
|
2022-12-08 22:37:26 -08:00
|
|
|
|
for (let pkg of packages) {
|
|
|
|
|
try {
|
|
|
|
|
await $`TMP="$(mktemp)" && curl -sSL ${pkg} > "$TMP" && sudo mv "$TMP" /usr/local/src/${binName} && chmod +x /usr/local/src/${binName}`
|
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Binary Release Install', `There was an error installing the binary release for ${pkg}`)
|
2022-12-08 22:37:26 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'brew') {
|
2022-12-02 15:15:45 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`brew install ${pkg}`
|
2022-12-02 17:39:29 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Homebrew Failure', `There was an error installing ${pkg} with brew`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-12-02 15:15:45 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'cask') {
|
2022-12-02 15:15:45 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`brew install --cask ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Homebrew Cask Failure', `There was an error installing ${pkg} with Homebrew Cask`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-12-02 15:15:45 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'cargo') {
|
2022-12-02 06:40:47 -08:00
|
|
|
|
for (const pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`cargo install ${pkg}`
|
2022-12-02 17:39:29 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Cargo Failure', `There was an error installing ${pkg} with Cargo`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'choco') {
|
2022-12-02 15:15:45 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`choco install -y ${pkg}`
|
2022-12-02 17:39:29 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Chocolatey Failure', `There was an error installing ${pkg} with Chocolatey`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-12-02 15:15:45 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'crew') {
|
|
|
|
|
} else if (packageManager === 'dnf') {
|
|
|
|
|
const dnf = which.sync('dnf', { nothrow: true })
|
|
|
|
|
const yum = which.sync('yum', { nothrow: true })
|
2023-01-03 20:39:23 -08:00
|
|
|
|
for (let pkg of packages) {
|
|
|
|
|
if (dnf) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2023-01-03 20:39:23 -08:00
|
|
|
|
await $`sudo dnf install -y ${pkg}`
|
2022-12-02 17:39:29 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'dnf Failure', `There was an error installing ${pkg} with dnf`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2023-01-03 20:39:23 -08:00
|
|
|
|
} else if (yum) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2023-01-03 20:39:23 -08:00
|
|
|
|
await $`sudo yum install -y ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'yum Failure', `There was an error installing ${pkg} with yum`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-12-02 15:15:45 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'flatpak') {
|
2022-12-02 06:40:47 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2023-01-03 18:05:12 -08:00
|
|
|
|
await $`sudo flatpak install -y flathub ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Flatpak Failure', `There was an error installing ${pkg} with flatpak`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'gem') {
|
2022-12-02 06:40:47 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`gem install ${pkg}`
|
2022-12-02 17:39:29 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Gem Failure', `There was an error installing ${pkg} with gem`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'go') {
|
2022-12-02 06:40:47 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`go install ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Go Failure', `There was an error installing ${pkg} with go`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'nix') {
|
|
|
|
|
} else if (packageManager === 'npm') {
|
2022-12-02 06:40:47 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`volta install ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Volta Failure', `There was an error installing ${pkg} with volta`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'pacman') {
|
2022-12-02 15:15:45 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2023-01-03 20:39:23 -08:00
|
|
|
|
await $`sudo pacman -Sy --noconfirm --needed ${dep}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Pacman Failure', `There was an error installing ${pkg} with pacman`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-12-02 15:15:45 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'pipx') {
|
2022-12-02 06:40:47 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`pipx install ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'PIPX Failure', `There was an error installing ${pkg} with pipx`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'pkg') {
|
|
|
|
|
} else if (packageManager === 'port') {
|
|
|
|
|
const port = which.sync('port', { nothrow: true })
|
2022-12-04 19:39:40 -08:00
|
|
|
|
if (port) {
|
|
|
|
|
for (let pkg of packages) {
|
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`sudo port install ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Port Failure', `There was an error installing ${pkg} with port`)
|
2022-12-04 19:39:40 -08:00
|
|
|
|
}
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-12-04 19:39:40 -08:00
|
|
|
|
} else {
|
2022-12-04 21:46:23 -08:00
|
|
|
|
log(
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'error',
|
|
|
|
|
'Port Not Installed',
|
2022-12-04 21:46:23 -08:00
|
|
|
|
`Unable to install with port because it is not installed. Skipping installation of ${packages}`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'scoop') {
|
2022-12-02 06:40:47 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`scoop install ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Scoop Failure', `There was an error installing ${pkg} with scoop`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'snap') {
|
2022-12-02 06:40:47 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-25 02:06:51 -08:00
|
|
|
|
await $`sudo snap install ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Snap Failure', `There was an error installing ${pkg} with snap`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'script') {
|
2022-12-08 22:37:26 -08:00
|
|
|
|
for (let pkg of packages) {
|
|
|
|
|
try {
|
|
|
|
|
await $`${pkg}`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
log('error', 'Script Install Failure', `There was an error running the script installation method for ${pkg}`)
|
2022-12-08 22:37:26 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'snap-classic') {
|
2022-12-08 21:19:29 -08:00
|
|
|
|
for (let pkg of packages) {
|
|
|
|
|
try {
|
2022-12-25 02:06:51 -08:00
|
|
|
|
await $`sudo snap install --classic ${pkg}`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
log('error', 'Snap Failure', `There was an error installing ${pkg} with snap in classic mode`)
|
2022-12-08 21:19:29 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'whalebrew') {
|
2022-12-02 06:40:47 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`whalebrew install ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Whalebrew Failure', `There was an error installing ${pkg} with whalebrew`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'winget') {
|
2022-12-04 19:51:47 -08:00
|
|
|
|
for (let pkg of packages) {
|
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`winget install ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Winget Failure', `There was an error installing ${pkg} with winget`)
|
2022-12-04 19:51:47 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'yay') {
|
2022-12-02 06:40:47 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`yay -Sy --noconfirm --needed ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Yay Failure', `There was an error installing ${pkg} with yay`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
} else if (packageManager === 'zypper') {
|
2022-12-02 15:15:45 -08:00
|
|
|
|
for (let pkg of packages) {
|
2022-12-02 17:39:29 -08:00
|
|
|
|
try {
|
2023-01-03 20:39:23 -08:00
|
|
|
|
await $`sudo zypper install -y ${pkg}`
|
2022-12-04 21:46:23 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Zypper Failure', `There was an error installing ${pkg} with zypper`)
|
2022-12-02 17:39:29 -08:00
|
|
|
|
}
|
2022-12-02 15:15:45 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', logStage, `Possibly encountered an error while installing via \`${packageManager}\``)
|
|
|
|
|
log('info', logStage, `Proceeding with the installation..`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-08 21:19:29 -08:00
|
|
|
|
async function updateSystemd(service) {
|
|
|
|
|
const logStage = 'Systemd Service'
|
2022-12-24 20:48:43 -08:00
|
|
|
|
if (osType === 'linux') {
|
2022-12-08 21:19:29 -08:00
|
|
|
|
const systemd = which.sync('systemctl', { nothrow: true })
|
|
|
|
|
if (systemd) {
|
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', logStage, `Starting / enabling the ${service} service`)
|
2022-12-08 21:19:29 -08:00
|
|
|
|
await $`sudo systemctl enable --now ${service}`
|
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', logStage, `There was an error starting / enabling the ${service} service`)
|
2022-12-24 08:48:46 -08:00
|
|
|
|
console.error(e)
|
2022-12-08 21:19:29 -08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log(
|
|
|
|
|
'warn',
|
|
|
|
|
logStage,
|
|
|
|
|
`The systemctl command is not available so applications with services cannot be started / enabled`
|
|
|
|
|
)
|
2022-12-08 21:19:29 -08:00
|
|
|
|
}
|
2022-12-24 08:44:38 -08:00
|
|
|
|
} else if (osType === 'darwin') {
|
|
|
|
|
const brew = which.sync('brew', { nothrow: true })
|
|
|
|
|
if (brew) {
|
|
|
|
|
try {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', logStage, `Starting / enabling the ${service} service with Homebrew`)
|
2022-12-24 08:44:38 -08:00
|
|
|
|
await $`brew services start ${service}`
|
2022-12-24 08:48:46 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', logStage, `There was an error starting / enabling the ${service} Homebrew service`)
|
2022-12-24 08:48:46 -08:00
|
|
|
|
console.error(e)
|
2022-12-24 08:44:38 -08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('warn', logStage, `Homebrew is not available - skipping service start command`)
|
2022-12-24 08:44:38 -08:00
|
|
|
|
}
|
2022-12-08 21:19:29 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:39:23 -08:00
|
|
|
|
async function pruneInstallOrders(installOrders) {
|
|
|
|
|
const newOrders = Object.assign({}, installOrders)
|
|
|
|
|
for (const pkgManager in installOrders) {
|
|
|
|
|
if (pkgManager === 'apt') {
|
|
|
|
|
newOrders[pkgManager] = newOrders[pkgManager].filter(async x => {
|
|
|
|
|
try {
|
|
|
|
|
await $`dpkg -l ${pkg} | grep -E '^ii' > /dev/null`
|
|
|
|
|
return true
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-01-03 21:28:46 -08:00
|
|
|
|
} else if (pkgManager === 'brew') {
|
|
|
|
|
newOrders[pkgManager] = newOrders[pkgManager].filter(async x => {
|
|
|
|
|
try {
|
|
|
|
|
await $`brew list ${pkg}`
|
|
|
|
|
return true
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-01-03 20:39:23 -08:00
|
|
|
|
} else if (pkgManager === 'dnf') {
|
|
|
|
|
const dnf = which.sync('dnf', { nothrow: true })
|
|
|
|
|
newOrders[pkgManager] = newOrders[pkgManager].filter(async x => {
|
|
|
|
|
try {
|
|
|
|
|
if (dnf) {
|
|
|
|
|
await $`rpm -qa | grep ${pkg} > /dev/null > /dev/null`
|
|
|
|
|
} else {
|
|
|
|
|
await $`rpm -qa | grep ${pkg} > /dev/null > /dev/null`
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} else if (pkgManager === 'flatpak') {
|
|
|
|
|
newOrders[pkgManager] = newOrders[pkgManager].filter(async x => {
|
|
|
|
|
try {
|
|
|
|
|
if (dnf) {
|
|
|
|
|
await $`rpm -qa | grep ${pkg} > /dev/null > /dev/null`
|
|
|
|
|
} else {
|
|
|
|
|
await $`rpm -qa | grep ${pkg} > /dev/null > /dev/null`
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} else if (pkgManager === 'pacman') {
|
|
|
|
|
newOrders[pkgManager] = newOrders[pkgManager].filter(async x => {
|
|
|
|
|
try {
|
|
|
|
|
await $`pacman -Qs ${pkg} > /dev/null > /dev/null`
|
|
|
|
|
return true
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return newOrders
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 22:26:34 -08:00
|
|
|
|
// main process
|
2022-12-08 23:57:44 -08:00
|
|
|
|
async function installSoftware(pkgsToInstall) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
osType = await OSType()
|
|
|
|
|
osID = osType
|
|
|
|
|
if (osType === 'linux') {
|
|
|
|
|
osID = await releaseID()
|
2022-12-04 21:46:23 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Catalog Download', `Fetching the latest version of the installation map`)
|
|
|
|
|
installData = await downloadInstallData()
|
|
|
|
|
log('info', 'Install Orders', `Calculating the install orders`)
|
|
|
|
|
await generateInstallOrders(pkgsToInstall ? pkgsToInstall : process.argv.slice(3))
|
2022-12-04 21:46:23 -08:00
|
|
|
|
log(
|
2022-12-24 20:48:43 -08:00
|
|
|
|
'info',
|
|
|
|
|
'Ensure Package Manager Installed',
|
2022-12-04 21:46:23 -08:00
|
|
|
|
`Ensuring any package managers that will be used are installed / configured`
|
2022-12-24 20:48:43 -08:00
|
|
|
|
)
|
|
|
|
|
const packageManagers = Object.keys(installOrders)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
for (const packageManager of packageManagers) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await ensurePackageManager(packageManager)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 08:57:06 -08:00
|
|
|
|
try {
|
|
|
|
|
for (const key in installOrders) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
installOrders[key] = [...new Set(installOrders[key])]
|
2022-12-24 08:57:06 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Install Orders', `The install orders were generated:`)
|
2022-12-24 08:57:06 -08:00
|
|
|
|
} catch (e) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('error', 'Install Orders', `There was an error reducing the duplicates in the install orders`)
|
2022-12-24 08:57:06 -08:00
|
|
|
|
console.error(e)
|
2022-12-24 08:44:38 -08:00
|
|
|
|
}
|
2023-01-03 20:39:23 -08:00
|
|
|
|
installOrders = await pruneInstallOrders(installOrders)
|
2022-12-24 20:48:43 -08:00
|
|
|
|
console.log(installOrders)
|
|
|
|
|
log('info', 'Package Manager Pre-Install', `Running package manager pre-installation steps`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
for (const packageManager of packageManagers) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await beforeInstall(packageManager)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Package Pre-Install', `Running package-specific pre-installation steps`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
for (const script of installOrdersPre) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`${script}`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Package Install', `Installing the packages`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
for (const packageManager of packageManagers) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
const asyncOrders = []
|
|
|
|
|
asyncOrders.push(installPackageList(packageManager, installOrders[packageManager]))
|
|
|
|
|
await Promise.all(asyncOrders)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Package Post-Install', `Running package-specific post-installation steps`)
|
2022-12-08 21:19:29 -08:00
|
|
|
|
for (const service of installOrdersSystemd) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await updateSystemd(service)
|
2022-12-08 21:19:29 -08:00
|
|
|
|
}
|
2022-11-29 22:26:34 -08:00
|
|
|
|
for (const script of installOrdersPost) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await $`${script}`
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('info', 'Package Manager Post-Install', `Running package manager post-installation steps`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
for (const packageManager of packageManagers) {
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await afterInstall(packageManager)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
2022-12-24 20:48:43 -08:00
|
|
|
|
log('success', 'Installation Complete', `Done!`)
|
2022-11-29 22:26:34 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start the main process
|
2022-12-24 20:48:43 -08:00
|
|
|
|
await installSoftware(false)
|