Skip to content

Instantly share code, notes, and snippets.

@eekfonky
Last active December 23, 2017 06:03
Show Gist options
  • Save eekfonky/f319e37d44ca6403908fe014f8ba9756 to your computer and use it in GitHub Desktop.
Save eekfonky/f319e37d44ca6403908fe014f8ba9756 to your computer and use it in GitHub Desktop.
Add package install to bash script
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