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.

52 lines
1.4 KiB

10 months ago
10 months ago
10 months ago
8 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
8 months ago
8 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. sudo pacman -Syyu --noconfirm
  35. for i in "$@"; do
  36. if ! pacman -Ql "$i" &>/dev/null; then
  37. sudo pacman -S --noconfirm "$i"
  38. elif [ -n "${VERBOSE+x}" ] && $VERBOSE; then
  39. echo "pacman package <$i> already installed!"
  40. fi
  41. done
  42. ;;
  43. *)
  44. echo "unknown os release <$(os-release)>!" && exit 2
  45. ;;
  46. esac