upgrades-installed-check 914 B

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