Update home/.local/bin/installx
Update home/.local/bin/package.json
This commit is contained in:
parent
baf7a0d2e7
commit
f7ae2f35da
2 changed files with 64 additions and 29 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env zx
|
#!/usr/bin/env zx
|
||||||
import osInfo from 'linux-os-info'
|
import osInfo from 'linux-os-info'
|
||||||
import { parallelLimit } from 'async'
|
import { Queue } from 'modern-async'
|
||||||
|
|
||||||
$.verbose = false
|
$.verbose = false
|
||||||
// Preserves color from subshells
|
// Preserves color from subshells
|
||||||
|
@ -275,6 +275,8 @@ async function forEachSeries(iterable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function installPackages(pkgInstructions) {
|
async function installPackages(pkgInstructions) {
|
||||||
|
const queue = new Queue(3)
|
||||||
|
|
||||||
const combined = {}
|
const combined = {}
|
||||||
const promises = []
|
const promises = []
|
||||||
log(`Populating install order lists`)
|
log(`Populating install order lists`)
|
||||||
|
@ -286,7 +288,9 @@ async function installPackages(pkgInstructions) {
|
||||||
}
|
}
|
||||||
log(`Running Homebrew installation via Brewfile`)
|
log(`Running Homebrew installation via Brewfile`)
|
||||||
if ((combined.brew && combined.brew.length) || (combined.cask && combined.cask.length)) {
|
if ((combined.brew && combined.brew.length) || (combined.cask && combined.cask.length)) {
|
||||||
promises.push(bundleInstall(combined.brew ? combined.brew.flatMap(x => x.installList.flatMap(i => i)) : [], combined.cask ? combined.cask.flatMap(x => x.installList.flatMap(i => i)) : [], combined.cask))
|
promises.push(queue.exec(async () => {
|
||||||
|
await bundleInstall(combined.brew ? combined.brew.flatMap(x => x.installList.flatMap(i => i)) : [], combined.cask ? combined.cask.flatMap(x => x.installList.flatMap(i => i)) : [], combined.cask)
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
for (const key of Object.keys(combined)) {
|
for (const key of Object.keys(combined)) {
|
||||||
if (key !== 'script') {
|
if (key !== 'script') {
|
||||||
|
@ -294,24 +298,32 @@ async function installPackages(pkgInstructions) {
|
||||||
}
|
}
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'ansible':
|
case 'ansible':
|
||||||
promises.push(forEachSeries(combined[key].flatMap(x => x.installList.flatMap(i => $`${key} 127.0.0.1 -v${process.env.DEBUG && 'vv'} -e '{ ansible_connection: "local", ansible_become_user: "root", ansible_user: "${process.env.USER}", ansible_family: "${osId.charAt(0).toUpperCase() + osId.slice(1)}", install_homebrew: False }' -m include_role -a name=${i}`))))
|
promises.push(
|
||||||
|
forEachSeries(combined[key].flatMap(x => x.installList.flatMap(i => queue.exec(async () => {
|
||||||
|
await $`${key} 127.0.0.1 -v${process.env.DEBUG && 'vv'} -e '{ ansible_connection: "local", ansible_become_user: "root", ansible_user: "${process.env.USER}", ansible_family: "${osId.charAt(0).toUpperCase() + osId.slice(1)}", install_homebrew: False }' -m include_role -a name=${i}`
|
||||||
|
}))))
|
||||||
|
)
|
||||||
break
|
break
|
||||||
case 'apk':
|
case 'apk':
|
||||||
promises.push($`sudo ${key} add ${combined[key].flatMap(x => x.installList).split(' ')}`)
|
promises.push(queue.exec(async () => {
|
||||||
|
await $`sudo ${key} add ${combined[key].flatMap(x => x.installList).split(' ')}`
|
||||||
|
}))
|
||||||
break
|
break
|
||||||
case 'appimage':
|
case 'appimage':
|
||||||
promises.push(...combined[key].flatMap(x => x.installList.flatMap(i => {
|
promises.push(...combined[key].flatMap(x => x.installList.flatMap(i => {
|
||||||
if (x.substring(0, 4) === 'http') {
|
if (x.substring(0, 4) === 'http') {
|
||||||
return $`zap install --select-first -q --from ${i}`
|
return queue.exec(async () => { await $`zap install --select-first -q --from ${i}` })
|
||||||
} else if ((x.match(/\//g) || []).length === 1) {
|
} else if ((x.match(/\//g) || []).length === 1) {
|
||||||
return $`zap install --select-first -q --github --from ${i}`
|
return queue.exec(async () => { await $`zap install --select-first -q --github --from ${i}` })
|
||||||
} else {
|
} else {
|
||||||
return $`zap install --select-first -q ${i}`
|
return queue.exec(async () => { $`zap install --select-first -q ${i}` })
|
||||||
}
|
}
|
||||||
})))
|
})))
|
||||||
break
|
break
|
||||||
case 'apt':
|
case 'apt':
|
||||||
promises.push($`DEBIAN_FRONTEND=noninteractive sudo apt-get -o DPkg::Options::=--force-confdef install -y ${combined[key].flatMap(x => x.installList).split(' ')}`)
|
promises.push(queue.exec(async () => {
|
||||||
|
await $`DEBIAN_FRONTEND=noninteractive sudo apt-get -o DPkg::Options::=--force-confdef install -y ${combined[key].flatMap(x => x.installList).split(' ')}`
|
||||||
|
}))
|
||||||
break
|
break
|
||||||
case 'basher':
|
case 'basher':
|
||||||
case 'baulk':
|
case 'baulk':
|
||||||
|
@ -323,29 +335,47 @@ async function installPackages(pkgInstructions) {
|
||||||
case 'pipx':
|
case 'pipx':
|
||||||
case 'scoop': // Maybe needs forEachSeries
|
case 'scoop': // Maybe needs forEachSeries
|
||||||
case 'winget': // Maybe needs forEachSeries
|
case 'winget': // Maybe needs forEachSeries
|
||||||
promises.push(...combined[key].flatMap(x => x.installList.flatMap(i => $`${key} install ${i}`)))
|
promises.push(
|
||||||
|
...combined[key].flatMap(x => x.installList.flatMap(i => queue.exec(async () => {
|
||||||
|
await $`${key} install ${i}`
|
||||||
|
})))
|
||||||
|
)
|
||||||
break
|
break
|
||||||
case 'npm':
|
case 'npm':
|
||||||
promises.push(...combined[key].flatMap(x => x.installList.flatMap(i => $`volta install ${i}`)))
|
promises.push(
|
||||||
|
...combined[key].flatMap(x => x.installList.flatMap(i => queue.exec(async () => {
|
||||||
|
await $`volta install ${i}`
|
||||||
|
})))
|
||||||
|
)
|
||||||
break
|
break
|
||||||
case 'binary':
|
case 'binary':
|
||||||
// TODO
|
// TODO
|
||||||
promises.push(...combined[key].flatMap(x => x.installList.flatMap(i => $`TMP="$(mktemp)" && curl -sSL ${i} > "$TMP" && sudo mv "$TMP" /usr/local/src/${x._bin} && chmod +x /usr/local/src/${x._bin}`)))
|
promises.push(
|
||||||
|
...combined[key].flatMap(x => x.installList.flatMap(i => queue.exec(async () => {
|
||||||
|
await $`TMP="$(mktemp)" && curl -sSL ${i} > "$TMP" && sudo mv "$TMP" /usr/local/src/${x._bin} && chmod +x /usr/local/src/${x._bin}`
|
||||||
|
})))
|
||||||
|
)
|
||||||
break
|
break
|
||||||
case 'brew':
|
case 'brew':
|
||||||
case 'cask': // Handled above
|
case 'cask': // Handled above
|
||||||
break
|
break
|
||||||
case 'choco':
|
case 'choco':
|
||||||
promises.push($`${key} install -y ${combined[key].flatMap(x => x.installList).join(' ')}`)
|
promises.push(queue.exec(async () => {
|
||||||
|
await $`${key} install -y ${combined[key].flatMap(x => x.installList).join(' ')}`
|
||||||
|
}))
|
||||||
break
|
break
|
||||||
case 'dnf':
|
case 'dnf':
|
||||||
case 'yum':
|
case 'yum':
|
||||||
case 'zypper':
|
case 'zypper':
|
||||||
promises.push($`sudo ${key} install -y ${combined[key].flatMap(x => x.installList).join(' ')}`)
|
promises.push(queue.exec(async () => {
|
||||||
|
await $`sudo ${key} install -y ${combined[key].flatMap(x => x.installList).join(' ')}`
|
||||||
|
}))
|
||||||
break
|
break
|
||||||
case 'emerge':
|
case 'emerge':
|
||||||
case 'pkg_add':
|
case 'pkg_add':
|
||||||
promises.push($`sudo ${key} ${combined[key].flatMap(x => x.installList).join(' ')}`)
|
promises.push(queue.exec(async () => {
|
||||||
|
await $`sudo ${key} ${combined[key].flatMap(x => x.installList).join(' ')}`
|
||||||
|
}))
|
||||||
break
|
break
|
||||||
case 'eopkg':
|
case 'eopkg':
|
||||||
case 'pkg-freebsd':
|
case 'pkg-freebsd':
|
||||||
|
@ -353,10 +383,14 @@ async function installPackages(pkgInstructions) {
|
||||||
case 'pkgin':
|
case 'pkgin':
|
||||||
case 'port':
|
case 'port':
|
||||||
case 'snap': // TODO - snap testing.. combine with snap-classic and add appropriate logic
|
case 'snap': // TODO - snap testing.. combine with snap-classic and add appropriate logic
|
||||||
promises.push($`sudo ${key === 'pkg-freebsd' || key === 'pkg-termux' ? 'pkg' : key} install ${combined[key].flatMap(x => x.installList).join(' ')}`)
|
promises.push(queue.exec(async () => {
|
||||||
|
await $`sudo ${key === 'pkg-freebsd' || key === 'pkg-termux' ? 'pkg' : key} install ${combined[key].flatMap(x => x.installList).join(' ')}`
|
||||||
|
}))
|
||||||
break
|
break
|
||||||
case 'flatpak':
|
case 'flatpak':
|
||||||
promises.push(forEachSeries(combined[key].flatMap(x => x.installList.flatMap(i => $`sudo ${key} install -y flathub ${i}`))))
|
promises.push(queue.exec(async () => {
|
||||||
|
await forEachSeries(combined[key].flatMap(x => x.installList.flatMap(i => $`sudo ${key} install -y flathub ${i}`)))
|
||||||
|
}))
|
||||||
break
|
break
|
||||||
case 'github': // TODO
|
case 'github': // TODO
|
||||||
break
|
break
|
||||||
|
@ -365,22 +399,30 @@ async function installPackages(pkgInstructions) {
|
||||||
case 'nix-shell': // TODO
|
case 'nix-shell': // TODO
|
||||||
break
|
break
|
||||||
case 'pacman':
|
case 'pacman':
|
||||||
promises.push($`sudo ${key} -Sy --noconfirm --needed ${combined[key].flatMap(x => x.installList).join(' ')}`)
|
promises.push(queue.exec(async () => {
|
||||||
|
await $`sudo ${key} -Sy --noconfirm --needed ${combined[key].flatMap(x => x.installList).join(' ')}`
|
||||||
|
}))
|
||||||
break
|
break
|
||||||
case 'pkg-darwin':
|
case 'pkg-darwin':
|
||||||
break
|
break
|
||||||
case 'sbopkg': // TODO
|
case 'sbopkg': // TODO
|
||||||
break
|
break
|
||||||
case 'script':
|
case 'script':
|
||||||
promises.push(...combined[key].flatMap(x => x.installList.flatMap(i => runScript(x.listKey, i))))
|
promises.push(
|
||||||
|
...combined[key].flatMap(x => x.installList.flatMap(i => queue.exec(async () => await runScript(x.listKey, i))))
|
||||||
|
)
|
||||||
break
|
break
|
||||||
case 'whalebrew': // TODO
|
case 'whalebrew': // TODO
|
||||||
break
|
break
|
||||||
case 'xbps':
|
case 'xbps':
|
||||||
promises.push($`sudo xbps-install -S ${combined[key].flatMap(x => x.installList).join(' ')}`)
|
promises.push(queue.exec(async () => {
|
||||||
|
await $`sudo xbps-install -S ${combined[key].flatMap(x => x.installList).join(' ')}`
|
||||||
|
}))
|
||||||
break
|
break
|
||||||
case 'yay':
|
case 'yay':
|
||||||
promises.push($`yay -Sy --noconfirm --needed ${combined[key].flatMap(x => x.installList).join(' ')}`)
|
promises.push(queue.exec(async () => {
|
||||||
|
await $`yay -Sy --noconfirm --needed ${combined[key].flatMap(x => x.installList).join(' ')}`
|
||||||
|
}))
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
log(`Unable to find install key instructions for ${key}`)
|
log(`Unable to find install key instructions for ${key}`)
|
||||||
|
@ -388,14 +430,7 @@ async function installPackages(pkgInstructions) {
|
||||||
}
|
}
|
||||||
log(`Performing ${promises.length} installations`)
|
log(`Performing ${promises.length} installations`)
|
||||||
process.env.DEBUG && console.log('Queued installs:', promises)
|
process.env.DEBUG && console.log('Queued installs:', promises)
|
||||||
// const installs = await Promise.allSettled(promises)
|
const insalls = await Promise.allSettled(promises)
|
||||||
|
|
||||||
let installs = []
|
|
||||||
for (const cmd of promises) {
|
|
||||||
const res = await cmd
|
|
||||||
installs.push(res)
|
|
||||||
}
|
|
||||||
|
|
||||||
log(`All of the installations have finished`)
|
log(`All of the installations have finished`)
|
||||||
process.env.DEBUG && console.log('Completed installs:', installs)
|
process.env.DEBUG && console.log('Completed installs:', installs)
|
||||||
await postInstall(combined)
|
await postInstall(combined)
|
||||||
|
|
|
@ -13,6 +13,6 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"linux-os-info": "2.0.0",
|
"linux-os-info": "2.0.0",
|
||||||
"async": "3.2.6"
|
"modern-async": "2.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue