upgrades-installed-check 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. elif [ -e /etc/arch-release ]; then
  25. ## Archlinux
  26. set -e
  27. set -o pipefail
  28. checkupdates_output="$(checkupdates 2>&1)"
  29. exit_code="$?"
  30. echo "$checkupdates_output" | grep -qF -- '->' && echo "false" || echo "true"
  31. else
  32. echo "Check not implemented for this distribution" >&2
  33. exit 1
  34. fi
  35. exit "$exit_code"