Add package manager detection (partially)

This commit is contained in:
askiiart 2023-08-23 21:25:12 -05:00
parent d34792d34d
commit 36a1d3395d
No known key found for this signature in database
GPG key ID: 85505F3A2264FA01
2 changed files with 45 additions and 16 deletions

View file

@ -1,21 +1,31 @@
#!/bin/bash
#!/usr/bin/env bash
# Exit if there's an error
set -e
declare -A osInfo;
osInfo[/etc/redhat-release]=yum
osInfo[/etc/arch-release]=pacman
osInfo[/etc/gentoo-release]=emerge
osInfo[/etc/SuSE-release]=zypp
osInfo[/etc/debian_version]=apt-get
osInfo[/etc/alpine-release]=apk
for f in ${!osInfo[@]}
do
if [[ -f $f ]];then
PACKAGE_MANAGER=${osInfo[$f]}
fi
done
if [ $(whoami) != "root" ]; then
$SUDO = "sudo"
exit 1
fi
exit 0
command_exists() { type "$1" &> /dev/null; }
sudo ${PACKAGE_MANAGER} install zsh -y
if command_exists "apt-get"; then
$SUDO apt-get install zsh -y
elif command_exists "yum"; then
$SUDO apt-get install zsh -y
elif command_exists "pacman"; then
$SUDO pacman -S zsh --noconfirm --needed
elif command_exists "zypper"; then
$SUDO zypper install zsh -y
elif command_exists "emerge"; then
$SUDO emerge --ask app-shells/zsh
$SUDO emerge --ask app-shells/zsh-completions
$SUDO emerge --ask app-shells/gentoo-zsh-completions
elif command_exists "apk"; then
$SUDO apk add zsh -y;
else
>&2 echo "Unsupported: unknown package manager"
exit 1
fi
cp -r zsh-files/* ~/