2015-10-22 17:26:24 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
## `echo`s:
|
|
|
|
## * 'true' - if all upgrades have been installed
|
|
|
|
## * 'false' - if there are pending upgrades
|
|
|
|
## * nothing - if apt-get is currently locked
|
|
|
|
##
|
|
|
|
## Forwards the exit code of the package manager.
|
|
|
|
|
|
|
|
if [ -e /etc/system-release ]; then
|
|
|
|
## Fedora
|
2017-09-30 04:55:24 +02:00
|
|
|
# shellcheck disable=SC2034
|
2015-10-22 17:26:24 +02:00
|
|
|
yum_output="$(yum -q check-update 2>&1)"
|
|
|
|
exit_code="$?"
|
2015-11-11 17:10:23 +01:00
|
|
|
[ "$exit_code" -eq 100 ] && echo "false" && exit 0
|
|
|
|
[ "$exit_code" -eq 0 ] && echo "true"
|
2015-11-12 00:36:43 +01:00
|
|
|
elif [ -e /etc/debian_version ]; then
|
2015-10-22 17:26:24 +02:00
|
|
|
## Debian
|
2015-11-11 22:13:17 +01:00
|
|
|
set -e
|
|
|
|
set -o pipefail
|
2017-09-30 04:55:24 +02:00
|
|
|
# shellcheck disable=SC2034
|
2016-04-02 17:00:10 +02:00
|
|
|
apt_get_update_output="$(apt-get -q update 2>&1)"
|
|
|
|
apt_get_upgrade_output="$(LANG="C" apt-get -s upgrade 2>&1)"
|
2015-10-22 17:26:24 +02:00
|
|
|
exit_code="$?"
|
2016-04-02 17:00:10 +02:00
|
|
|
echo "$apt_get_upgrade_output" | awk "/^Inst/{ print $2 }" | [ "$(wc -L)" -eq 0 ] && echo "true" || echo "false"
|
2017-02-03 03:37:49 +01:00
|
|
|
elif [ -e /etc/arch-release ]; then
|
|
|
|
## Archlinux
|
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
checkupdates_output="$(checkupdates 2>&1)"
|
|
|
|
exit_code="$?"
|
2017-10-06 14:01:57 +02:00
|
|
|
echo "$checkupdates_output" | grep -qF -- '->' && echo "false" || echo "true"
|
2015-11-12 00:36:43 +01:00
|
|
|
else
|
|
|
|
echo "Check not implemented for this distribution" >&2
|
|
|
|
exit 1
|
2015-10-22 17:26:24 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit "$exit_code"
|