puppet: make check for installed packages more reliable

"dpkg-query -s" doesn't necessarily provide the desired answer,
it includes packages known to dpkg for different reasons, but
does not exactly reply whether they are installed or not.

Starting with dpkg version 1.17.11 the ${db:Status-Status} +
${db:Status-Eflag} flags can be used for checking the current
state. While I don't think the puppet script is relevant for
Debian/wheezy systems (or even older) let's still be backwards
compatible.

Thanks: Manuel Montecelo for reporting
Thanks: Guillem Jover for feedback and code review

Development sponsored by Sipwise GmbH, recorded as
TT#25551 in customers' ticket system.
master
Michael Prokop 8 years ago
parent 3529ae6bc2
commit d27375db70

@ -97,8 +97,28 @@ $IP $(hostname).example.org $(hostname)
exit 1
fi
if dpkg --compare-versions "$(dpkg-query -f "\${Version}\n" -W dpkg 2>/dev/null)" ge '1.17.11' 2>/dev/null ; then
package_check() {
[ "$(dpkg-query -f "\${db:Status-Status} \${db:Status-Eflag}" -W "$package" 2>/dev/null)" = 'installed ok' ]
}
else # dpkg versions older than 1.17.11 (e.g. Debian/wheezy) don't support db:Status* flags, so fall back then
package_check() {
dpkg --list "$package" 2>/dev/null | grep -q '^.i'
}
fi
package_installed() {
local packages="$*"
for package in $packages ; do
if ! package_check "$package" ; then
return 1
fi
done
}
if puppet apply jenkins_debian_glue.pp ; then
if ! dpkg-query -s jenkins jenkins-debian-glue >/dev/null 2>&1 ; then
if ! package_installed jenkins jenkins-debian-glue; then
echo "While puppet reported a successful run, jenkins and/or jenkins-debian-glue aren't successfully installed. :(" >&2
echo "Please re-execute this script and if the problem persists please report this at" >&2
echo "https://github.com/mika/jenkins-debian-glue/issues" >&2

Loading…
Cancel
Save