From d1ae8942da10fce06121a23127e4ca8694d117d7 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Sat, 10 Feb 2024 18:02:53 +0100 Subject: [PATCH] introduce swupd package manager --- .../conf/type/__package_swupd/explorer/state | 29 ++++++++ .../conf/type/__package_swupd/gencode-remote | 50 ++++++++++++++ cdist/conf/type/__package_swupd/man.rst | 66 +++++++++++++++++++ cdist/conf/type/__package_swupd/nonparallel | 0 .../type/__package_swupd/parameter/boolean | 1 + .../__package_swupd/parameter/default/state | 1 + .../type/__package_swupd/parameter/optional | 2 + 7 files changed, 149 insertions(+) create mode 100644 cdist/conf/type/__package_swupd/explorer/state create mode 100755 cdist/conf/type/__package_swupd/gencode-remote create mode 100644 cdist/conf/type/__package_swupd/man.rst create mode 100644 cdist/conf/type/__package_swupd/nonparallel create mode 100644 cdist/conf/type/__package_swupd/parameter/boolean create mode 100644 cdist/conf/type/__package_swupd/parameter/default/state create mode 100644 cdist/conf/type/__package_swupd/parameter/optional diff --git a/cdist/conf/type/__package_swupd/explorer/state b/cdist/conf/type/__package_swupd/explorer/state new file mode 100644 index 00000000..598da85a --- /dev/null +++ b/cdist/conf/type/__package_swupd/explorer/state @@ -0,0 +1,29 @@ +#!/bin/sh -e +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Retrieve the status of a package on Clear Linux OS +# + +if [ -f "$__object/parameter/name" ] +then name="$(cat "$__object/parameter/name")" +else name="$__object_id" +fi + +if swupd bundle-list --status --quiet | grep -q "^${name}: .*installed" +then echo present +else echo absent +fi diff --git a/cdist/conf/type/__package_swupd/gencode-remote b/cdist/conf/type/__package_swupd/gencode-remote new file mode 100755 index 00000000..a74ac671 --- /dev/null +++ b/cdist/conf/type/__package_swupd/gencode-remote @@ -0,0 +1,50 @@ +#!/bin/sh -e +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Manage packages on Clear Linux OS +# + +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name="$__object_id" +fi + +state_should="$(cat "$__object/parameter/state")" +state_is="$(cat "$__object/explorer/state")" + +# Nothing to be done +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + if [ -f "$__object/parameter/install-optional" ] + then swupd_opts="" + else swupd_opts="--skip-optional" + fi + echo "swupd bundle-add $swupd_opts -y --quiet '$name'" + echo "installed" >> "$__messages_out" + ;; + absent) + echo "swupd bundle-remove '$name'" + echo "removed" >> "$__messages_out" + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__package_swupd/man.rst b/cdist/conf/type/__package_swupd/man.rst new file mode 100644 index 00000000..ae11b130 --- /dev/null +++ b/cdist/conf/type/__package_swupd/man.rst @@ -0,0 +1,66 @@ +cdist-type__package_swupd(7) +============================ + +NAME +---- +cdist-type__package_swupd - Manage packages with swupd + + +DESCRIPTION +----------- +swupd (software update program) is the package manager used on Clear Linux OS to +manage packages. The package will be installed without optional +packages. If such packages are required, install them +separately or use the parameter ``--install-optional``. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +name + If supplied, use the name and not the object id as the package name. + +state + Either "present" or "absent", defaults to "present" + + +BOOLEAN PARAMETERS +------------------ +install-optional + If the package will be installed, it also installs optional packages + with it. It will not install optional packages if the original package + is already installed. + + +EXAMPLES +-------- + +.. code-block:: sh + + # Ensure zsh in installed + __package_swupd zsh --state present + + # Remove package + __package_swupd zsh --state absent + + +SEE ALSO +-------- +:strong:`cdist-type__package`\ (7) + + +AUTHORS +------- +Romain Dartigues + + +COPYING +------- +Copyright \(C) 2024 Romain Dartigues. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/cdist/conf/type/__package_swupd/nonparallel b/cdist/conf/type/__package_swupd/nonparallel new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__package_swupd/parameter/boolean b/cdist/conf/type/__package_swupd/parameter/boolean new file mode 100644 index 00000000..9bb00783 --- /dev/null +++ b/cdist/conf/type/__package_swupd/parameter/boolean @@ -0,0 +1 @@ +install-optional \ No newline at end of file diff --git a/cdist/conf/type/__package_swupd/parameter/default/state b/cdist/conf/type/__package_swupd/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_swupd/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__package_swupd/parameter/optional b/cdist/conf/type/__package_swupd/parameter/optional new file mode 100644 index 00000000..1b423dc4 --- /dev/null +++ b/cdist/conf/type/__package_swupd/parameter/optional @@ -0,0 +1,2 @@ +name +state