core-agent-linux/package-managers/upgrades-installed-check
Marek Marczykowski-Górecki f95f08e15f
Merge remote-tracking branch 'origin/pr/267'
* origin/pr/267:
  fix for ArchLinux: notify dom0 about installed updates The launch of the qubes-update-check service failed on ArchLinux, because the qubes-rpc uses the `service` command which isn't available for this OS.
  fix archlinux detection of available upgrades note: checkupdates return 2 when no updates are available (source: man page and source code)
  upgrades-installed-check requires pacman-contrib for checkupdates
2021-01-03 05:25:57 +01:00

52 lines
1.4 KiB
Bash
Executable File

#!/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
if command -v dnf >/dev/null; then
yum=dnf
else
yum=yum
fi
# shellcheck disable=SC2034
yum_output="$($yum -yq check-update 2>&1)"
exit_code="$?"
[ "$exit_code" -eq 100 ] && echo "false" && exit 0
[ "$exit_code" -eq 0 ] && echo "true"
elif [ -e /etc/debian_version ]; then
## 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"
elif [ -e /etc/arch-release ]; then
## Archlinux
set -e
set -o pipefail
checkupdates_output="$(checkupdates 2>&1)"
exit_code="$?"
[ "$exit_code" -eq 2 ] && echo "true" && exit 0
echo "false"
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"
else
echo "Check not implemented for this distribution" >&2
exit 1
fi
exit "$exit_code"