__package_apt: add --install-recommends parameter

For a good reason, __package_apt doesn't install recommended packages as
default. But the option --install-recommends comes handy if you want to
install a package where you want to install all recommended packages
(and not to install all of them separately).

Also, the manpage now explains that the type won't install recommended
packages by default.
This commit is contained in:
matze 2020-11-08 13:14:13 +01:00
parent 348c6eedc9
commit 9fc6ee0948
3 changed files with 26 additions and 7 deletions

View file

@ -42,6 +42,13 @@ else
target_release="" target_release=""
fi fi
if [ -f "$__object/parameter/install-recommends" ]; then
# required if __apt_norecommends is used
recommendsparam="-o APT::Install-Recommends=1"
else
recommendsparam="-o APT::Install-Recommends=0"
fi
if [ -f "$__object/parameter/purge-if-absent" ]; then if [ -f "$__object/parameter/purge-if-absent" ]; then
purgeparam="--purge" purgeparam="--purge"
else else
@ -62,16 +69,16 @@ case "$state_is" in
;; ;;
esac esac
# Hint if we need to avoid questions at some point:
# DEBIAN_PRIORITY=critical can reduce the number of questions
aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes -o APT::Install-Recommends=0 -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\""
if [ "$state_is" = "$state_should" ]; then if [ "$state_is" = "$state_should" ]; then
if [ -z "$version" ] || [ "$version" = "$version_is" ]; then if [ -z "$version" ] || [ "$version" = "$version_is" ]; then
exit 0; exit 0;
fi fi
fi fi
# Hint if we need to avoid questions at some point:
# DEBIAN_PRIORITY=critical can reduce the number of questions
aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\""
case "$state_should" in case "$state_should" in
present) present)
# following is bit ugly, but important hack. # following is bit ugly, but important hack.
@ -85,7 +92,7 @@ EOF
if [ -n "$version" ]; then if [ -n "$version" ]; then
name="${name}=${version}" name="${name}=${version}"
fi fi
echo "$aptget install $target_release '$name'" echo "$aptget $recommendsparam install $target_release '$name'"
echo "installed" >> "$__messages_out" echo "installed" >> "$__messages_out"
;; ;;
absent) absent)

View file

@ -9,7 +9,9 @@ cdist-type__package_apt - Manage packages with apt-get
DESCRIPTION DESCRIPTION
----------- -----------
apt-get is usually used on Debian and variants (like Ubuntu) to apt-get is usually used on Debian and variants (like Ubuntu) to
manage packages. manage packages. The package will be installed without recommended
or suggested packages. If such packages are required, install them
separatly or use the parameter ``--install-recommends``.
This type will also update package index, if it is older This type will also update package index, if it is older
than one day, to avoid missing package error messages. than one day, to avoid missing package error messages.
@ -23,7 +25,7 @@ None
OPTIONAL PARAMETERS OPTIONAL PARAMETERS
------------------- -------------------
name name
If supplied, use the name and not the object id as the package name. If supplied, use the name and not the object id as the package name.
state state
Either "present" or "absent", defaults to "present" Either "present" or "absent", defaults to "present"
@ -39,6 +41,15 @@ version
BOOLEAN PARAMETERS BOOLEAN PARAMETERS
------------------ ------------------
install-recommends
If the package will be installed, it also installs recommended packages
with it. It will not install recommended packages if the original package
is already installed.
In most cases, it is recommended to install recommended packages separatly
to control which additional packages will be installed to avoid useless
installed packages.
purge-if-absent purge-if-absent
If this parameter is given when state is `absent`, the package is If this parameter is given when state is `absent`, the package is
purged from the system (using `--purge`). purged from the system (using `--purge`).

View file

@ -1 +1,2 @@
install-recommends
purge-if-absent purge-if-absent