| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 | #! /bin/bash
main() {
  drivers_dir=""
  while getopts "hd:" arg; do
    case "${arg}" in
    h)
      echo '--help'
      ;;
    d)
      drivers_dir="${OPTARG}"
      ;;
    *)
      echo '??'
      ;;
    esac
  done
  shopt -s nullglob
  set -e
  echo "==== Driver dir: ${drivers_dir}"
  for file in "${drivers_dir}"/*; do
    echo "==== Processing ${file}..."
    case "${file}" in
    *.deb)
      dpkg -i "${file}" || :
      ;;
    *.sh)
      "${file}"
      ;;
    *.ppd)
      cp "${file}" /usr/share/ppd/
      ;;
    *)
      echo "==== Ignoring ${file}"
      ;;
    esac
  done
  if ! apt-get install; then
    echo "==== Apt seems broken. Fixing..."
    apt-get update &&
      DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -yqf &&
      apt-get clean &&
      rm -rf /var/lib/apt/lists/*
  fi
}
main "${@}"
 |