Compare commits

..

1 commit

Author SHA1 Message Date
a9dcd061bc introduce dnf as package manager 2024-04-11 21:44:14 +02:00
13 changed files with 179 additions and 24 deletions

View file

@ -534,8 +534,7 @@ eof
;;
version)
target_version="$(git describe | sed 's/-/.dev/; s/-/+/g')"
printf "VERSION = \"%s\"\n" "${target_version}" > cdist/version.py
printf "VERSION = \"%s\"\n" "$(git describe)" > cdist/version.py
;;
target-version)

View file

@ -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. Defaults to 500. (To match the default target distro's priority)
The priority value to assign to matching packages. Deafults 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.

View file

@ -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 <http://www.gnu.org/licenses/>.
#
#
# 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

View file

@ -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 <http://www.gnu.org/licenses/>.
#
#
# 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

View file

@ -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.

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,3 @@
name
state
url

View file

@ -34,12 +34,3 @@ case "$os" in
echo "echo \"$timezone_should\" > /etc/timezone"
;;
esac
case "$os" in
openwrt)
cat <<EOF
uci set system.@system[0].timezone="$timezone_should"
uci commit
EOF
;;
esac

View file

@ -53,10 +53,7 @@ case "$os" in
--file /etc/sysconfig/clock \
--delimiter '=' \
--value "\"$timezone\""
;;
openwrt)
: # Uses gencode-remote
;;
;;
*)
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
echo "Please contribute an implementation for it if you can." >&2

View file

@ -20,4 +20,4 @@
user="$(cat "$__object/parameter/user" 2>/dev/null || echo "$__object_id")"
(id -G -n "$user" | tr ' ' '\n') 2>/dev/null || true
(id -G -n "$user" | tr ' ' '\n' | sort) 2>/dev/null || true

View file

@ -26,15 +26,13 @@ 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/files/group-remote.sorted" "$__object/files/group.sorted")"
changed_groups="$(comm -13 "$__object/explorer/group" "$__object/files/group.sorted")"
;;
absent)
changed_groups="$(comm -12 "$__object/files/group-remote.sorted" "$__object/files/group.sorted")"
changed_groups="$(comm -12 "$__object/explorer/group" "$__object/files/group.sorted")"
;;
esac

View file

@ -1,9 +1,6 @@
Changelog
---------
next:
* Type __timezone: Add support for OpenWRT (Nico Schottelius)
7.0.1:
* Core: Remove double definition of scan parser (Nico Schottelius)
* Type __apt_mark: Narrow down grep for hold packages (marcoduif)