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.

53 lines
1.4 KiB

8 months ago
8 months ago
8 months ago
6 months ago
8 months ago
6 months ago
8 months ago
6 months ago
8 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 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. BASEDIR=$(dirname "$0")
  17. source "$BASEDIR"/../lib/functions.sh
  18. [ "$(id -u)" -ne 0 ] && echo 'root privilege required' && exit 2
  19. [[ $# -lt 1 ]] && usage
  20. case $(os-release) in
  21. debian)
  22. if [ "$(date --date='-12 hours' +%s)" -gt "$(date -d "$(stat -c %y /var/lib/apt/lists/partial)" +%s)" ]; then
  23. echo "updating repositoring..."
  24. apt-get update
  25. fi
  26. for i in "$@"; do
  27. if ! dpkg -l "$i" 2>/dev/null | grep -q ^ii; then
  28. sudo apt-get install -y "$i"
  29. elif [ -n "${VERBOSE+x}" ] && $VERBOSE; then
  30. echo "apt package <$i> already installed!"
  31. fi
  32. done
  33. ;;
  34. arch)
  35. sudo pacman -Syyu --noconfirm
  36. for i in "$@"; do
  37. if ! pacman -Ql "$i" &>/dev/null; then
  38. sudo pacman -S --noconfirm "$i"
  39. elif [ -n "${VERBOSE+x}" ] && $VERBOSE; then
  40. echo "pacman package <$i> already installed!"
  41. fi
  42. done
  43. ;;
  44. *)
  45. echo "unknown os release <$(os-release)>!" && exit 2
  46. ;;
  47. esac