Un exemple:
if ! dpkg-query -l “your_package” | grep -r ‘^ ii’ 2>&1 > /dev/null ; then apt-get install -y “your_package” fi
Un altre exemple:
$ dpkg -s libasound2| grep installed
Sinó està instal·lat, instal·lar-lo:
problem=$(dpkg -s xulrunner-1.9|grep installed) echo Checking for libxul: $problem if [ "" == "$problem" ]; then echo "No libxul. Setting up libxul" sudo apt-get --force-yes --yes install xulrunner-1.9 fi
Més exemples:
function dpkgstatins { echo "checking if $dpkgof is installed" 2>&1 if [[ $(dpkg-query -f'${Status}' --show $dpkgof 2>/dev/null) = *\ installed ]]; then echo "$dpkgof found!" else echo "$dpkgof was not found, installing..." 2>&1 apt-get --force-yes -yqq install $dpkgof 2>/dev/null fi }
PACKAGES_DEPENDENCIES="wget mount hello" #Install dependencies: #Activate verbose VERBOSE=true; [ ! -z "$VERBOSE" ] && echo "Verbose is active..." [ ! -z "$VERBOSE" ] && echo "Checking dependencies..." for package in $PACKAGES_DEPENDENCIES; do [ ! -z "$VERBOSE" ] && echo -n "Checking if $package is installed... " if ! dpkg-query -l $package | grep -r "^ii" 2>&1 > /dev/null ; then [ ! -z "$VERBOSE" ] && echo " NOT INSTALLED. Installing..." /usr/bin/apt-get install --force-yes --yes $package else [ ! -z "$VERBOSE" ] && echo " INSTALLED." fi done