Created
April 9, 2013 15:27
-
-
Save compleatang/5346648 to your computer and use it in GitHub Desktop.
Install a bunch of packages. First check if they can be found in repos, then check if they are installed. If yes to first and no to second, add to an array, then install the entire array.
This file contains 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
#!/bin/bash | |
function install_a_bunch() { | |
PKGS_INST=( ) | |
for pkg in $1; do | |
CAN_WE_FIND_IT=`sudo apt-get -qq --dry-run install $pkg` | |
if [ ! "$CAN_WE_FIND_IT" == 100 ]; then | |
IS_IT_THERE=`dpkg -l | grep $pkg` | |
if [[ ! "$IS_IT_THERE" ]]; then | |
PKGS_INST=( "${PKGS_INST[@]}" "${pkg}" ) | |
fi | |
fi | |
done | |
if [[ ! ${#PKGS_INST[@]} == 0 ]]; then | |
echo "Packages to install ${PKGS_INST[@]}" | |
sudo apt-get install ${PKGS_INST[@]} | |
else | |
echo "Nothing to install" | |
fi | |
} | |
### Add the packages you'd like below those are just there for testing and illustration. | |
pkgs=(nmap asdflgk) | |
install_a_bunch $pkgs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment