Update .local/bin/install-program

This commit is contained in:
Brian Zalewski 2022-12-02 18:31:20 +00:00
parent b5433569b1
commit ff8bfefc88

View file

@ -214,17 +214,8 @@ async function afterInstall(packageManager) {
async function beforeInstall(packageManager) { async function beforeInstall(packageManager) {
if (packageManager === 'appimage') { if (packageManager === 'appimage') {
} else if (packageManager === 'ansible') { } else if (packageManager === 'ansible') {
try { await $`logg info 'Temporarily enabling passwordless sudo for Ansible role installations'`
await $`test -f "$HOME/.cache/megabytelabs/ansible-installed"` await $`sudo echo "$(whoami) ALL=(ALL:ALL) NOPASSWD: ALL # TEMPORARY FOR ANSIBLE INSTALL" > /etc/sudoers`
const ansible = which.sync('ansible', { nothrow: true })
if (ansible) {
await $`logg info '\`ansible\` and its supporting packages appear to be installed'`
} else {
await ensurePackageManagerAnsible()
}
} catch (e) {
await ensurePackageManagerAnsible()
}
} else if (packageManager === 'apk') { } else if (packageManager === 'apk') {
} else if (packageManager === 'apt') { } else if (packageManager === 'apt') {
await $`sudo apt-get update` await $`sudo apt-get update`
@ -294,6 +285,13 @@ async function ensureInstalled(bin, callback) {
} }
} }
async function ensurePackageManagerAnsible() {
await $`pipx install ansible`
await $`pipx inject ansible PyObjC PyObjC-core docker lxml netaddr pexpect python-vagrant pywinrm requests-credssp watchdog`
await $`touch "$HOME/.cache/megabytelabs/ansible-installed"`
await $`logg info 'Ansible and its supporting packages are now installed via pipx'`
}
// Ensure the package manager is available // Ensure the package manager is available
let packageManagerInstalled = {}; let packageManagerInstalled = {};
async function ensurePackageManager(packageManager) { async function ensurePackageManager(packageManager) {
@ -317,15 +315,17 @@ async function ensurePackageManager(packageManager) {
} }
if (packageManager === 'appimage') { if (packageManager === 'appimage') {
} else if (packageManager === 'ansible') { } else if (packageManager === 'ansible') {
$` try {
if [ ! -f "$HOME/.cache/megabytelabs/ansible-installed" ] || ! command -v ansible > /dev/null; then await $`test -f "$HOME/.cache/megabytelabs/ansible-installed"`
pipx install ansible const ansible = which.sync('ansible', { nothrow: true })
pipx inject ansible PyObjC PyObjC-core docker lxml netaddr pexpect python-vagrant pywinrm requests-credssp watchdog if (ansible) {
touch "$HOME/.cache/megabytelabs/ansible-installed" await $`logg info '\`ansible\` and its supporting packages appear to be installed'`
else } else {
logg info '\`ansible\` and its supporting packages appear to be installed' await ensurePackageManagerAnsible()
fi }
` } catch (e) {
await ensurePackageManagerAnsible()
}
} else if (packageManager === 'apk') { } else if (packageManager === 'apk') {
await ensureInstalled('apk', false) await ensureInstalled('apk', false)
} else if (packageManager === 'apt') { } else if (packageManager === 'apt') {
@ -342,26 +342,29 @@ async function ensurePackageManager(packageManager) {
echo "Bash script that installs bpkg here" echo "Bash script that installs bpkg here"
`) `)
} else if (packageManager === 'brew' || packageManager === 'cask') { } else if (packageManager === 'brew' || packageManager === 'cask') {
await ensureInstalled('brew', $` const brew = which.sync('brew', { nothrow: true })
if command -v sudo > /dev/null && sudo -n true; then if (!brew) {
echo | bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" await ensureInstalled('brew', $`
else if command -v sudo > /dev/null && sudo -n true; then
logg info 'Homebrew is not installed. Password may be required.' echo | bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || BREW_EXIT_CODE="$?" else
if [ -n "$BREW_EXIT_CODE" ]; then logg info 'Homebrew is not installed. Password may be required.'
if command -v brew > /dev/null; then bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || BREW_EXIT_CODE="$?"
logg warn 'Homebrew was installed but part of the installation failed. Attempting to fix..' if [ -n "$BREW_EXIT_CODE" ]; then
BREW_DIRS="share/man share/doc share/zsh/site-functions etc/bash_completion.d" if command -v brew > /dev/null; then
for BREW_DIR in $BREW_DIRS; do logg warn 'Homebrew was installed but part of the installation failed. Attempting to fix..'
if [ -d "$(brew --prefix)/$BREW_DIR" ]; then BREW_DIRS="share/man share/doc share/zsh/site-functions etc/bash_completion.d"
sudo chown -R "$(whoami)" "$(brew --prefix)/$BREW_DIR" for BREW_DIR in $BREW_DIRS; do
fi if [ -d "$(brew --prefix)/$BREW_DIR" ]; then
done sudo chown -R "$(whoami)" "$(brew --prefix)/$BREW_DIR"
brew update --force --quiet fi
done
brew update --force --quiet
fi
fi fi
fi fi
fi `)
`) }
} else if (packageManager === 'cargo') { } else if (packageManager === 'cargo') {
await ensureInstalled('cargo', $` await ensureInstalled('cargo', $`
# TODO Bash script that installs cargo # TODO Bash script that installs cargo
@ -549,6 +552,7 @@ async function ensurePackageManager(packageManager) {
// Installs a list of packages via the specified package manager // Installs a list of packages via the specified package manager
async function installPackageList(packageManager, packages) { async function installPackageList(packageManager, packages) {
let pkg = packages
try { try {
if (packageManager === 'appimage') { if (packageManager === 'appimage') {
} else if (packageManager === 'ansible') { } else if (packageManager === 'ansible') {
@ -566,8 +570,8 @@ async function installPackageList(packageManager, packages) {
} else if (packageManager === 'cask') { } else if (packageManager === 'cask') {
await $`brew install --cask ${packages}` await $`brew install --cask ${packages}`
} else if (packageManager === 'cargo') { } else if (packageManager === 'cargo') {
for (const cargoPkg of packages) { for (const pkg of packages) {
await $`cargo install ${cargoPkg}` await $`cargo install ${pkg}`
} }
} else if (packageManager === 'choco') { } else if (packageManager === 'choco') {
await $`choco install -y ${packages}` await $`choco install -y ${packages}`
@ -581,55 +585,56 @@ async function installPackageList(packageManager, packages) {
await $`yum install -y ${packages}` await $`yum install -y ${packages}`
} }
} else if (packageManager === 'flatpak') { } else if (packageManager === 'flatpak') {
for (const flatPkg of packages) { for (let pkg of packages) {
await $`sudo flatpak install flathub ${flatPkg}` await $`sudo flatpak install flathub ${pkg}`
} }
} else if (packageManager === 'gem') { } else if (packageManager === 'gem') {
for (const gem of packages) { for (let pkg of packages) {
await $`gem install ${gem}` await $`gem install ${pkg}`
} }
} else if (packageManager === 'go') { } else if (packageManager === 'go') {
for (const goPkg of packages) { for (let pkg of packages) {
await $`go install ${goPkg}` await $`go install ${pkg}`
} }
} else if (packageManager === 'nix') { } else if (packageManager === 'nix') {
} else if (packageManager === 'npm') { } else if (packageManager === 'npm') {
for (const npmPkg of packages) { for (let pkg of packages) {
await $`volta install ${npmPkg}` await $`volta install ${pkg}`
} }
} else if (packageManager === 'pacman') { } else if (packageManager === 'pacman') {
await $`sudo pacman -Sy --noconfirm --needed ${packages}` await $`sudo pacman -Sy --noconfirm --needed ${packages}`
} else if (packageManager === 'pipx') { } else if (packageManager === 'pipx') {
for (const pipxPkg of packages) { for (let pkg of packages) {
await $`pipx install ${pipxPkg}` await $`pipx install ${pkg}`
} }
} else if (packageManager === 'pkg') { } else if (packageManager === 'pkg') {
} else if (packageManager === 'port') { } else if (packageManager === 'port') {
for (const portPkg of packages) { for (let pkg of packages) {
// TODO await $`sudo port install ${portPkg}` await $`sudo port install ${pkg}`
} }
} else if (packageManager === 'scoop') { } else if (packageManager === 'scoop') {
for (const scoopPkg of packages) { for (let pkg of packages) {
await $`scoop install ${scoopPkg}` await $`scoop install ${pkg}`
} }
} else if (packageManager === 'snap') { } else if (packageManager === 'snap') {
for (const snapPkg of packages) { for (let pkg of packages) {
await $`sudo snap install -y ${snapPkg}` await $`sudo snap install -y ${pkg}`
} }
} else if (packageManager === 'whalebrew') { } else if (packageManager === 'whalebrew') {
for (const whalePkg of packages) { for (let pkg of packages) {
await $`whalebrew install ${snapPkg}` await $`whalebrew install ${pkg}`
} }
} else if (packageManager === 'winget') { } else if (packageManager === 'winget') {
} else if (packageManager === 'yay') { } else if (packageManager === 'yay') {
for (const yayPkg of packages) { for (let pkg of packages) {
await $`yay -Sy --noconfirm --needed ${yayPkg}` await $`yay -Sy --noconfirm --needed ${pkg}`
} }
} else if (packageManager === 'zypper') { } else if (packageManager === 'zypper') {
await $`sudo zypper install -y ${zypPkg}` await $`sudo zypper install -y ${packages}`
} }
} catch (e) { } catch (e) {
await $`logg error 'Failed to install via \`${packageManager}\`'` await $`logg error 'Possibly encountered an error while installing via \`${packageManager}\`'`
await $`logg info 'Error was encountered while installing: ${pkg}'`
await $`logg info 'Proceeding with the installation..'` await $`logg info 'Proceeding with the installation..'`
} }
} }