Merge pull request #629 from tom-ee/feature/improve__package_dpkg

add `--state`-parameter and messaging to __package_dpkg
This commit is contained in:
Darko Poljak 2018-02-21 21:19:07 +01:00 committed by GitHub
commit ef7304499a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 95 additions and 7 deletions

View file

@ -0,0 +1,11 @@
#!/bin/sh -e
package=$( basename "$__object_id" )
dpkg_status="$(dpkg-query --show --showformat='${db:Status-Abbrev} ${binary:Package}_${Version}_${Architecture}.deb\n' "${package%%_*}" 2>/dev/null || true)"
if echo "$dpkg_status" | grep -q '^ii'; then
echo "${dpkg_status##* }"
fi

View file

@ -1,6 +1,7 @@
#!/bin/sh -e
#
# 2013 Tomas Pospisek (tpo_deb sourcepole.ch)
# 2018 Thomas Eckert (tom at it-eckert.de)
#
# This file is based on cdist's __file/gencode-local and part of cdist.
#
@ -26,5 +27,25 @@
# to conflict with dpkg's --force options). But currently we don't
# do any checks or --force'ing.
#
state=$( cat "$__object/parameter/state" )
package=$( basename "$__object_id" )
state_is="$(cat "$__object/explorer/pkg_state")"
state_should=""
echo "dpkg -i /var/cache/apt/archives/$__object_id"
[ "$state" = "absent" ] || state_should="$package"
[ "$state_is" = "$state_should" ] && exit 0
case "$state" in
present)
echo "dpkg --install /var/cache/apt/archives/$__object_id"
echo "installed" >> "$__messages_out"
;;
absent)
[ -f "$__object/parameter/purge-if-absent" ] \
&& action="--purge" \
|| action="--remove"
echo "dpkg $action ${__object_id%%_*}"
echo "removed ($action)" >> "$__messages_out"
;;
*) echo "ERROR: unknown state '$state'" >&2 ;;
esac

View file

@ -12,30 +12,77 @@ This type is used on Debian and variants (like Ubuntu) to
install packages that are provided locally as \*.deb files.
The object given to this type must be the name of the deb package.
The filename of the deb package has to follow Debian naming conventions, i.e.
`${binary:Package}_${Version}_${Architecture}.deb` (see `dpkg-query(1)` for
details).
OPTIONAL PARAMETERS
-------------------
state
`present` or `absent`, defaults to `present`.
REQUIRED PARAMETERS
-------------------
source
path to the \*.deb package
BOOLEAN PARAMETERS
------------------
purge-if-absent
If this parameter is given when state is `absent`, the package is
purged from the system (using `--purge`).
EXPLORER
--------
pkg_state
Returns the full package name if package is installed, empty otherwise.
MESSAGES
--------
installed
The deb-file was installed.
removed (--remove)
The package was removed, keeping config.
removed (--purge)
The package was removed including config (purged).
EXAMPLES
--------
.. code-block:: sh
# Install foo and bar packages
__package_dpkg --source /tmp/foo_0.1_all.deb foo_0.1_all.deb
__package_dpkg --source $__type/files/bar_1.4.deb bar_1.4.deb
__package_dpkg foo_0.1_all.deb --source /tmp/foo_0.1_all.deb
__package_dpkg bar_1.4.deb --source $__type/files/bar_1.4.deb
# uninstall baz:
__package_dpkg baz_1.4_amd64.deb \
--source $__type/files/baz_1.4_amd64.deb \
--state "absent"
# uninstall baz and also purge config-files:
__package_dpkg baz_1.4_amd64.deb \
--source $__type/files/baz_1.4_amd64.deb \
--purge-if-absent \
--state "absent"
SEE ALSO
--------
:strong:`cdist-type__package`\ (7)
:strong:`cdist-type__package`\ (7), :strong:`dpkg-query`\ (1)
AUTHORS
-------
Tomas Pospisek <tpo_deb--@--sourcepole.ch>
| Tomas Pospisek <tpo_deb--@--sourcepole.ch>
| Thomas Eckert <tom--@--it-eckert.de>
COPYING
-------

View file

@ -25,10 +25,16 @@
# do any checks or --force'ing.
state=$( cat "$__object/parameter/state" )
package_path=$( cat "$__object/parameter/source" )
package=$( basename "$__object_id" )
state_is="$(cat "$__object/explorer/pkg_state")"
state_should=""
[ "$state" = "absent" ] || state_should="$package"
[ "$state_is" = "$state_should" ] && exit 0
__file "/var/cache/apt/archives/$package" \
--source "$package_path" \
--state present
--source "$package_path" \
--state "$state"

View file

@ -0,0 +1 @@
purge-if-absent

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1 @@
state