upgrades-installed-check 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. ## `echo`s:
  3. ## * 'true' - if all upgrades have been installed
  4. ## * 'false' - if there are pending upgrades
  5. ## * nothing - if apt-get is currently locked
  6. ##
  7. ## Forwards the exit code of the package manager.
  8. if [ -e /etc/system-release ]; then
  9. ## Fedora
  10. if command -v dnf >/dev/null; then
  11. yum=dnf
  12. else
  13. yum=yum
  14. fi
  15. # shellcheck disable=SC2034
  16. yum_output="$($yum -yq check-update)"
  17. exit_code="$?"
  18. [ "$exit_code" -eq 100 ] && echo "false" && exit 0
  19. [ "$exit_code" -eq 0 ] && echo "true"
  20. elif [ -e /etc/debian_version ]; then
  21. ## Debian
  22. set -e
  23. set -o pipefail
  24. # shellcheck disable=SC2034
  25. apt_get_update_output="$(apt-get -q update 2>&1)"
  26. apt_get_upgrade_output="$(LANG="C" apt-get -s upgrade 2>&1)"
  27. exit_code="$?"
  28. echo "$apt_get_upgrade_output" | awk "/^Inst/{ print $2 }" | [ "$(wc -L)" -eq 0 ] && echo "true" || echo "false"
  29. elif [ -e /etc/arch-release ]; then
  30. ## Archlinux
  31. set -e
  32. set -o pipefail
  33. checkupdates >/dev/null 2>&1
  34. exit_code="$?"
  35. [ "$exit_code" -eq 2 ] && echo "true" && exit 0
  36. echo "false"
  37. elif [ -e /etc/gentoo-release ]; then
  38. ## Gentoo
  39. set -e
  40. set -o pipefail
  41. emerge_output="$(emerge -puDv @world 2>&1)"
  42. exit_code="$?"
  43. echo "$emerge_output" | grep -qF -- '[ebuild' && echo "false" || echo "true"
  44. else
  45. echo "Check not implemented for this distribution" >&2
  46. exit 1
  47. fi
  48. exit "$exit_code"