From a9dcd061bc9c9c39234d7d21c0d8863525f03664 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Tue, 26 Mar 2024 20:57:55 +0100 Subject: [PATCH 1/6] introduce dnf as package manager --- .../type/__package_dnf/explorer/pkg_version | 29 ++++++++ cdist/conf/type/__package_dnf/gencode-remote | 70 +++++++++++++++++++ cdist/conf/type/__package_dnf/man.rst | 70 +++++++++++++++++++ cdist/conf/type/__package_dnf/nonparallel | 0 .../__package_dnf/parameter/default/state | 1 + .../type/__package_dnf/parameter/optional | 3 + 6 files changed, 173 insertions(+) create mode 100755 cdist/conf/type/__package_dnf/explorer/pkg_version create mode 100755 cdist/conf/type/__package_dnf/gencode-remote create mode 100644 cdist/conf/type/__package_dnf/man.rst create mode 100644 cdist/conf/type/__package_dnf/nonparallel create mode 100644 cdist/conf/type/__package_dnf/parameter/default/state create mode 100644 cdist/conf/type/__package_dnf/parameter/optional diff --git a/cdist/conf/type/__package_dnf/explorer/pkg_version b/cdist/conf/type/__package_dnf/explorer/pkg_version new file mode 100755 index 00000000..9b3df108 --- /dev/null +++ b/cdist/conf/type/__package_dnf/explorer/pkg_version @@ -0,0 +1,29 @@ +#!/bin/sh +# +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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 +# + +if [ -f "$__object/parameter/name" ] +then name="$(cat "$__object/parameter/name")" +else name="$__object_id" +fi + +rpm -q "$name" 2>/dev/null || rpm -q --whatprovides "$name" 2>/dev/null || true diff --git a/cdist/conf/type/__package_dnf/gencode-remote b/cdist/conf/type/__package_dnf/gencode-remote new file mode 100755 index 00000000..c9f217fe --- /dev/null +++ b/cdist/conf/type/__package_dnf/gencode-remote @@ -0,0 +1,70 @@ +#!/bin/sh -e +# +# 2024 Romain Dartigues +# +# 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 with DNF (Fedora ≥ 18, RHEL ≥ 8, OpenMandriva) +# + +if [ -f "$__object/parameter/name" ] +then name="$(cat "$__object/parameter/name")" +else name="$__object_id" +fi + +# Support installing from an URL +if [ -f "$__object/parameter/url" ] +then install_name="$(cat "$__object/parameter/url")" +else install_name="$name" +fi + + +state_should="$(cat "$__object/parameter/state")" + +if grep -q -E "(scientific|centos|redhat|amazon)" "$__global/explorer/os" +then opts="-y --quiet" +else opts="--assumeyes --quiet" +fi + +not_provided="^no package provides" +not_installed='is not installed$' + +if grep -q "$not_provided" "$__object/explorer/pkg_version" +then + if grep -q "$not_installed" "$__object/explorer/pkg_version" + then state_is="absent" + else state_is="present" + fi +else state_is="present" +fi + +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + echo "dnf $opts install '$install_name'" + echo "installed" >> "$__messages_out" + ;; + absent) + echo "dnf $opts remove '$name'" + echo "removed" >> "$__messages_out" + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__package_dnf/man.rst b/cdist/conf/type/__package_dnf/man.rst new file mode 100644 index 00000000..1ca1d88c --- /dev/null +++ b/cdist/conf/type/__package_dnf/man.rst @@ -0,0 +1,70 @@ +cdist-type__package_dnf(7) +========================== + +NAME +---- +cdist-type__package_dnf - Manage packages with dnf + + +DESCRIPTION +----------- +:abbr:`dnf (Dandified YUM)` is the next-generation version of the :abbr:`YUM (Yellowdog Updated Manager)` +used on the Fedora (≥ 18), :abbr:`RHEL (Red Hat Enterprise Linux)` ≥ 8 and derivated, OpenMandriva, …) +distributions to manage packages. + +If ``dnf`` is not available on the platform, it will automatically try to fallback to ``yum``. + + +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" + +url + URL to use for the package + + +EXAMPLES +-------- + +.. code-block:: sh + + # Ensure zsh in installed + __package_dnf zsh --state present + + # If you don't want to follow pythonX packages, but always use python + __package_dnf python --state present --name python3 + + # Remove obsolete package + __package_dnf puppet --state absent + + __package epel-release \ + --url https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm + + +SEE ALSO +-------- +:strong:`cdist-type__package`\ (7), +:strong:`cdist-type__package_yum`\ (7) + + +AUTHORS +------- +Romain Dartigues, +based on Nico Schottelius work on :strong:`cdist-type__package_man`\ (7) + + +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_dnf/nonparallel b/cdist/conf/type/__package_dnf/nonparallel new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__package_dnf/parameter/default/state b/cdist/conf/type/__package_dnf/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__package_dnf/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__package_dnf/parameter/optional b/cdist/conf/type/__package_dnf/parameter/optional new file mode 100644 index 00000000..9293119d --- /dev/null +++ b/cdist/conf/type/__package_dnf/parameter/optional @@ -0,0 +1,3 @@ +name +state +url From 61fc5e5de8adeb6d2e49c37b2cbb64c750edcb0b Mon Sep 17 00:00:00 2001 From: Daniel Fancsali Date: Fri, 8 Jul 2022 16:50:54 +0100 Subject: [PATCH 2/6] Fix typo in __apt_pin docs --- cdist/conf/type/__apt_pin/man.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__apt_pin/man.rst b/cdist/conf/type/__apt_pin/man.rst index 4229c0cd..e6ec8b51 100644 --- a/cdist/conf/type/__apt_pin/man.rst +++ b/cdist/conf/type/__apt_pin/man.rst @@ -23,7 +23,7 @@ package Package name, glob or regular expression to match (multiple) packages. If not specified `__object_id` is used. priority - The priority value to assign to matching packages. Deafults to 500. (To match the default target distro's priority) + The priority value to assign to matching packages. Defaults to 500. (To match the default target distro's priority) state Will be passed to underlying `__file` type; see there for valid values and defaults. From b7394ff4c25846be5ad8bd4fa793ceda9efae5f3 Mon Sep 17 00:00:00 2001 From: Mark Verboom Date: Thu, 2 Nov 2023 11:01:45 +0100 Subject: [PATCH 3/6] Locally sort remote group information, to prevent differences in sort output. --- cdist/conf/type/__user_groups/explorer/group | 2 +- cdist/conf/type/__user_groups/gencode-remote | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__user_groups/explorer/group b/cdist/conf/type/__user_groups/explorer/group index 5bad9a0b..8a02f219 100755 --- a/cdist/conf/type/__user_groups/explorer/group +++ b/cdist/conf/type/__user_groups/explorer/group @@ -20,4 +20,4 @@ user="$(cat "$__object/parameter/user" 2>/dev/null || echo "$__object_id")" -(id -G -n "$user" | tr ' ' '\n' | sort) 2>/dev/null || true +(id -G -n "$user" | tr ' ' '\n') 2>/dev/null || true diff --git a/cdist/conf/type/__user_groups/gencode-remote b/cdist/conf/type/__user_groups/gencode-remote index 8120761a..0585e90f 100755 --- a/cdist/conf/type/__user_groups/gencode-remote +++ b/cdist/conf/type/__user_groups/gencode-remote @@ -26,13 +26,15 @@ os=$(cat "$__global/explorer/os") mkdir "$__object/files" # file has to be sorted for comparison with `comm` sort "$__object/parameter/group" > "$__object/files/group.sorted" +# Use local sort for remote groups +sort "$__object/explorer/group" > "$__object/files/group-remote.sorted" case "$state_should" in present) - changed_groups="$(comm -13 "$__object/explorer/group" "$__object/files/group.sorted")" + changed_groups="$(comm -13 "$__object/files/group-remote.sorted" "$__object/files/group.sorted")" ;; absent) - changed_groups="$(comm -12 "$__object/explorer/group" "$__object/files/group.sorted")" + changed_groups="$(comm -12 "$__object/files/group-remote.sorted" "$__object/files/group.sorted")" ;; esac From 3e82b0085b693e6b23f2b613e2f1dd975d67e6dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=BDubom=C3=ADr=20Ku=C4=8Dera?= Date: Wed, 1 May 2024 12:11:07 +0000 Subject: [PATCH 4/6] Make development version strings PEP 440 compliant (#366) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With current pip (23.1.2) and setuptools (67.7.2) versions, installation from Git was failing with "Invalid version: '7.0.0-17-ge57cf1e7'" message. The issue can be reproduced by running the following command with the latest pip and setuptools installed: $ pip install git+https://code.ungleich.ch/ungleich-public/cdist.git@e57cf1e70a3818180b3f54e1e0364ff3b6bbd9cc#egg=cdist Reviewed-on: https://code.ungleich.ch/ungleich-public/cdist/pulls/366 Co-authored-by: Ľubomír Kučera Co-committed-by: Ľubomír Kučera --- bin/cdist-build-helper | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/cdist-build-helper b/bin/cdist-build-helper index cadddae7..6f514ef5 100755 --- a/bin/cdist-build-helper +++ b/bin/cdist-build-helper @@ -534,7 +534,8 @@ eof ;; version) - printf "VERSION = \"%s\"\n" "$(git describe)" > cdist/version.py + target_version="$(git describe | sed 's/-/.dev/; s/-/+/g')" + printf "VERSION = \"%s\"\n" "${target_version}" > cdist/version.py ;; target-version) From 27471a4a82ac29c1a1f3062178a509660d55e732 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 2 Aug 2024 12:05:37 +0200 Subject: [PATCH 5/6] [__timezone] add support for openwrt --- cdist/conf/type/__timezone/gencode-remote | 9 +++++++++ cdist/conf/type/__timezone/manifest | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__timezone/gencode-remote b/cdist/conf/type/__timezone/gencode-remote index b685c990..d8612986 100755 --- a/cdist/conf/type/__timezone/gencode-remote +++ b/cdist/conf/type/__timezone/gencode-remote @@ -34,3 +34,12 @@ case "$os" in echo "echo \"$timezone_should\" > /etc/timezone" ;; esac + +case "$os" in + openwrt) + cat <