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
|
2018-12-05 05:46:51 +01:00
|
|
|
## Fedora
|
2018-12-05 05:48:00 +01:00
|
|
|
if command -v dnf >/dev/null; then
|
|
|
|
yum=dnf
|
|
|
|
else
|
|
|
|
yum=yum
|
|
|
|
fi
|
2018-12-05 05:46:51 +01:00
|
|
|
# shellcheck disable=SC2034
|
2020-12-21 16:25:45 +01:00
|
|
|
yum_output="$($yum -yq check-update 2>&1)"
|
2018-12-05 05:46:51 +01:00
|
|
|
exit_code="$?"
|
|
|
|
[ "$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
|
2018-12-05 05:46:51 +01:00
|
|
|
## Debian
|
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
apt_get_update_output="$(apt-get -q update 2>&1)"
|
|
|
|
apt_get_upgrade_output="$(LANG="C" apt-get -s upgrade 2>&1)"
|
|
|
|
exit_code="$?"
|
|
|
|
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="$?"
|
2020-11-28 23:54:56 +01:00
|
|
|
[ "$exit_code" -eq 2 ] && echo "true" && exit 0
|
|
|
|
echo "false"
|
2020-07-26 14:20:57 +02:00
|
|
|
elif [ -e /etc/gentoo-release ]; then
|
|
|
|
## Gentoo
|
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
emerge_output="$(emerge -puDv @world 2>&1)"
|
|
|
|
exit_code="$?"
|
|
|
|
echo "$emerge_output" | grep -qF -- '[ebuild' && echo "false" || echo "true"
|
2015-11-12 00:36:43 +01:00
|
|
|
else
|
2018-12-05 05:46:51 +01:00
|
|
|
echo "Check not implemented for this distribution" >&2
|
|
|
|
exit 1
|
2015-10-22 17:26:24 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit "$exit_code"
|