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.

51 lines
1.3 KiB

9 months ago
9 months ago
9 months ago
7 months ago
9 months ago
7 months ago
9 months ago
7 months ago
9 months ago
7 months ago
7 months ago
7 months ago
  1. #!/bin/bash
  2. function usage {
  3. local BASECMD
  4. BASECMD=$(basename "$0")
  5. echo "usage: $BASECMD <packages...>"
  6. case $(os-release) in
  7. debian)
  8. echo 'idempotent debian package installation : update if necessary, install only if not yet done'
  9. ;;
  10. arch)
  11. echo 'idempotent archlinux package installation : update if necessary, install only if not yet done'
  12. ;;
  13. esac
  14. exit 1
  15. }
  16. source "$MIAOU_BASH_DIR"/lib/functions.sh
  17. [ "$(id -u)" -ne 0 ] && echo 'root privilege required' && exit 2
  18. [[ $# -lt 1 ]] && usage
  19. case $(os-release) in
  20. debian)
  21. if [ "$(date --date='-12 hours' +%s)" -gt "$(date -d "$(stat -c %y /var/lib/apt/lists/partial)" +%s)" ]; then
  22. echo "updating repositoring..."
  23. apt-get update
  24. fi
  25. for i in "$@"; do
  26. if ! dpkg -l "$i" 2>/dev/null | grep -q ^ii; then
  27. sudo apt-get install -y "$i"
  28. elif [ -n "${VERBOSE+x}" ] && $VERBOSE; then
  29. echo "apt package <$i> already installed!"
  30. fi
  31. done
  32. ;;
  33. arch)
  34. for i in "$@"; do
  35. if ! pacman -Ql "$i" &>/dev/null; then
  36. sudo pacman -S --noconfirm "$i"
  37. elif [ -n "${VERBOSE+x}" ] && $VERBOSE; then
  38. echo "pacman package <$i> already installed!"
  39. fi
  40. done
  41. ;;
  42. *)
  43. echo "unknown os release <$(os-release)>!" && exit 2
  44. ;;
  45. esac