upgrades-installed-check 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 -q check-update 2>&1)"
  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_output="$(checkupdates 2>&1)"
  34. exit_code="$?"
  35. echo "$checkupdates_output" | grep -qF -- '->' && echo "false" || echo "true"
  36. else
  37. echo "Check not implemented for this distribution" >&2
  38. exit 1
  39. fi
  40. exit "$exit_code"