upgrades-installed-check 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. elif [ -e /etc/gentoo-release ]; then
  37. ## Gentoo
  38. set -e
  39. set -o pipefail
  40. emerge_output="$(emerge -puDv @world 2>&1)"
  41. exit_code="$?"
  42. echo "$emerge_output" | grep -qF -- '[ebuild' && echo "false" || echo "true"
  43. else
  44. echo "Check not implemented for this distribution" >&2
  45. exit 1
  46. fi
  47. exit "$exit_code"