Compare commits

...

1 commit

Author SHA1 Message Date
pedro
1c2a5d7ac6 __package_dpkg: improve local deb info retrieval
this type forces you to put a correct object id name in order to get
idempotency. dpkg-deb command, when available, makes that work for you,
facilitating the usage of this type
2021-10-25 01:54:26 +02:00
3 changed files with 21 additions and 9 deletions

View file

@ -28,7 +28,12 @@
# do any checks or --force'ing.
#
state=$( cat "$__object/parameter/state" )
package=$( basename "$__object_id" )
package_path=$( cat "$__object/parameter/source" )
if command -v dpkg-deb 2>&1 > /dev/null; then
package="$(dpkg-deb --show --showformat='${binary:Package}_${Version}_${Architecture}.deb\n' ${package_path})"
else
package="$( basename "$__object_id" )"
fi
state_is="$(cat "$__object/explorer/pkg_state")"
state_should=""
@ -37,7 +42,7 @@ state_should=""
case "$state" in
present)
echo "dpkg --install /var/cache/apt/archives/$__object_id"
echo "dpkg --install /var/cache/apt/archives/${package}"
echo "installed" >> "$__messages_out"
;;
absent)

View file

@ -11,7 +11,8 @@ DESCRIPTION
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.
If the command `dpkg-deb(1)` is not available locally,
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).

View file

@ -27,14 +27,20 @@
state=$( cat "$__object/parameter/state" )
package_path=$( cat "$__object/parameter/source" )
package=$( basename "$__object_id" )
if command -v dpkg-deb 2>&1 > /dev/null; then
package="$(dpkg-deb --show --showformat='${binary:Package}_${Version}_${Architecture}.deb\n' ${package_path})"
else
package="$( basename "$__object_id" )"
fi
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" \
if [ "$state_is" = "$state_should" ]; then
exit 0
else
__file "/var/cache/apt/archives/$package" \
--source "$package_path" \
--state "$state"
fi