Last active
December 23, 2017 06:03
-
-
Save eekfonky/f319e37d44ca6403908fe014f8ba9756 to your computer and use it in GitHub Desktop.
Add package install to bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package_to_install () { | |
# enter the package you want installed in PKG_NAME below | |
PKG_NAME="<PACKAGE_NAME>" | |
if ! type $PKG_NAME > /dev/null 2>&1; then | |
# check Linux package manager (yum or apt) | |
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 | |
osInfo[/etc/lsb-release]=apt | |
for f in "${!osInfo[@]}" | |
do | |
if [[ -f $f ]];then | |
sudo ${osInfo[$f]} install "$PKG_NAME" | |
fi | |
done | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment