Files
linux-toolkit/scripts/util/pkg-mgr.sh

24 lines
738 B
Bash
Executable File

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 key val in "${(@kv)osInfo}"; do
if [[ -f $key ]]; then
PACKAGE_MANAGER=$val
fi
done
install_package() {
if [ "$PACKAGE_MANAGER" == "yum" ]; then yum install -y "$@"
elif [ "$PACKAGE_MANAGER" == "pacman" ]; then pacman -S --noconfirm "$@"
elif [ "$PACKAGE_MANAGER" == "emerge" ]; then emerge "$@"
elif [ "$PACKAGE_MANAGER" == "zypp" ]; then zypper install "$@"
elif [ "$PACKAGE_MANAGER" == "apt-get" ]; then apt-get install -y "$@"
elif [ "$PACKAGE_MANAGER" == "apk" ]; then apk add "$@"; fi
}