upgrades-installed-check 783 B

12345678910111213141516171819202122232425262728
  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. yum_output="$(yum -q check-update 2>&1)"
  11. exit_code="$?"
  12. [ "$exit_code" -eq 100 ] && echo "false" && exit 0
  13. [ "$exit_code" -eq 0 ] && echo "true"
  14. elif [ -e /etc/debian_version ]; then
  15. ## Debian
  16. set -e
  17. set -o pipefail
  18. apt_get_output="$(LANG="C" apt-get -s upgrade 2>&1)"
  19. exit_code="$?"
  20. echo "$apt_get_output" | awk "/^Inst/{ print $2 }" | [ "$(wc -L)" -eq 0 ] && echo "true" || echo "false"
  21. else
  22. echo "Check not implemented for this distribution" >&2
  23. exit 1
  24. fi
  25. exit "$exit_code"