Detect package manager
This commit is contained in:
22
sh/custom-scripts/pkg-mgr.sh
Executable file
22
sh/custom-scripts/pkg-mgr.sh
Executable file
@ -0,0 +1,22 @@
|
||||
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 $1
|
||||
elif [ "$PACKAGE_MANAGER" == "pacman" ]; then pacman -S --noconfirm $1
|
||||
elif [ "$PACKAGE_MANAGER" == "emerge" ]; then emerge $1
|
||||
elif [ "$PACKAGE_MANAGER" == "zypp" ]; then zypper install $1
|
||||
elif [ "$PACKAGE_MANAGER" == "apt-get" ]; then apt-get install -y $1
|
||||
elif [ "$PACKAGE_MANAGER" == "apk" ]; then apk add $1; fi
|
||||
}
|
Reference in New Issue
Block a user