#!/bin/bash install_package() { # These stacked ifs are just a stopgap until proper trapping. echo -n "# Installing package $PACKAGE... " apt-get $INSTALLOPTIONS install ${PACKAGE} ERR=$? if [ "$ERR" -ne 0 ]; then echo echo "# Could not install package $PACKAGE - Error number $ERR!" echo -n "# Trying an apt-get update..." apt-get update 2>/dev/null 1>&2 ERR=$? if [ "$ERR" -ne 0 ]; then echo echo "# apt-get update has thrown error number $ERR. You need to take care" echo "# of this by hand. Commencing installation." else echo " ok." echo -n "# Retrying installing package $PACKAGE... " apt-get $INSTALLOPTIONS install ${PACKAGE} 2>/dev/null 1>&2 ERR=$? if [ "$ERR" -ne 0 ]; then perror "Could not install $PACKAGE. Giving up." else echo "ok." fi fi else echo "ok." fi } install_packages() { local NEEDED_PACKAGES="$2" echo "#" echo "# Installing packages. This may take a while." echo "#" case "$1" in NOREC) INSTALLOPTIONS="-qq -y --no-install-recommends" for PACKAGE in $NEEDED_PACKAGES; do install_package done ;; RECOM) INSTALLOPTIONS="-qq -y" for PACKAGE in $NEEDED_PACKAGES; do install_package done esac }