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

10 months ago
8 months ago
10 months ago
10 months ago
8 months ago
10 months ago
8 months ago
10 months ago
8 months ago
8 months ago
8 months ago
  1. #!/bin/bash
  2. source "$MIAOU_BASH_DIR"/lib/functions.sh
  3. function usage {
  4. local BASECMD
  5. BASECMD=$(basename "$0")
  6. echo "usage: $BASECMD <packages...>"
  7. case $(os-release) in
  8. debian)
  9. echo 'idempotent debian package installation : update if necessary, install only if not yet done'
  10. ;;
  11. arch)
  12. echo 'idempotent archlinux package installation : update if necessary, install only if not yet done'
  13. ;;
  14. esac
  15. exit 1
  16. }
  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" 2>/dev/null | grep -q ^ii; then
  36. sudo pacman -Sy "$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