forked from ungleich-public/cdist
add --state
-parameter and messaging to __package_dpkg
- `--state` allows to remove a deb-package, if `--purge-if-absent` is specified the package is purged instead of "only" removed - messaging was added - man-page updated accordingly
This commit is contained in:
parent
c0dc26a577
commit
a545b10538
7 changed files with 101 additions and 6 deletions
11
cdist/conf/type/__package_dpkg/explorer/pkg_state
Normal file
11
cdist/conf/type/__package_dpkg/explorer/pkg_state
Normal 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
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
@ -12,30 +12,84 @@ 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
|
||||
use `--purge` instead of just `--remove` for state=absent.
|
||||
|
||||
|
||||
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:`dpkg-query`\ (1)
|
||||
|
||||
|
||||
AUTHORS
|
||||
-------
|
||||
Tomas Pospisek <tpo_deb--@--sourcepole.ch>
|
||||
| Tomas Pospisek <tpo_deb--@--sourcepole.ch>
|
||||
| Thomas Eckert <tom--@--it-eckert.de>
|
||||
|
||||
|
||||
COPYING
|
||||
-------
|
||||
|
|
|
@ -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
|
||||
--state "$state"
|
||||
|
||||
|
|
1
cdist/conf/type/__package_dpkg/parameter/boolean
Normal file
1
cdist/conf/type/__package_dpkg/parameter/boolean
Normal file
|
@ -0,0 +1 @@
|
|||
purge-if-absent
|
1
cdist/conf/type/__package_dpkg/parameter/default/state
Normal file
1
cdist/conf/type/__package_dpkg/parameter/default/state
Normal file
|
@ -0,0 +1 @@
|
|||
present
|
1
cdist/conf/type/__package_dpkg/parameter/optional
Normal file
1
cdist/conf/type/__package_dpkg/parameter/optional
Normal file
|
@ -0,0 +1 @@
|
|||
state
|
Loading…
Reference in a new issue