upgrades-installed-check 852 B

1234567891011121314151617181920212223242526272829
  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_update_output="$(apt-get -q update 2>&1)"
  19. apt_get_upgrade_output="$(LANG="C" apt-get -s upgrade 2>&1)"
  20. exit_code="$?"
  21. echo "$apt_get_upgrade_output" | awk "/^Inst/{ print $2 }" | [ "$(wc -L)" -eq 0 ] && echo "true" || echo "false"
  22. else
  23. echo "Check not implemented for this distribution" >&2
  24. exit 1
  25. fi
  26. exit "$exit_code"