MIAOU-BASH is a collection of settings and helpers for leveraging BASH. Developer-friendly, it may be used as solo package with or without the miaou project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
714 B

10 months ago
10 months ago
10 months ago
  1. #!/bin/bash
  2. function usage {
  3. local BASECMD
  4. BASECMD=$(basename "$0")
  5. echo "usage: $BASECMD <packages...>"
  6. echo 'idempotent debian package installation : update if necessary, install only if not yet done'
  7. exit 1
  8. }
  9. [ "$(id -u)" -ne 0 ] && echo 'root privilege required' && exit 2
  10. [[ $# -lt 1 ]] && usage
  11. if [ "$(date --date='-12 hours' +%s)" -gt "$(date -d "$(stat -c %y /var/lib/apt/lists/partial)" +%s)" ]; then
  12. echo "updating repositoring..."
  13. apt-get update
  14. fi
  15. for i in "$@"; do
  16. if ! dpkg -l "$i" 2>/dev/null | grep -q ^ii; then
  17. sudo apt-get install -y "$i"
  18. elif [ -n "${VERBOSE+x}" ] && $VERBOSE; then
  19. echo "apt package <$i> already installed!"
  20. fi
  21. done