Merge branch 'master' into beta

This commit is contained in:
Darko Poljak 2020-09-11 14:33:27 +02:00
commit 9e89088e61
20 changed files with 160 additions and 43 deletions

View file

@ -81,7 +81,7 @@ version:
}
# Manpages #3: generic part
man: version $(MANTYPES) $(DOCSREF)
man: version configskel $(MANTYPES) $(DOCSREF) $(DOCSTYPESREF)
$(SPHINXM)
html: version configskel $(MANTYPES) $(DOCSREF) $(DOCSTYPESREF)
@ -104,7 +104,7 @@ DOTMANTYPES=$(subst /man.rst,.rst,$(DOTMANTYPEPREFIX))
$(DOTMAN7DSTDIR)/cdist-type%.rst: $(DOTTYPEDIR)/%/man.rst
ln -sf "$^" $@
dotman: version $(DOTMANTYPES)
dotman: version configskel $(DOTMANTYPES) $(DOCSREF) $(DOCSTYPESREF)
$(SPHINXM)
################################################################################

View file

@ -144,7 +144,9 @@ esac
if [ -f /etc/os-release ]; then
# after sles15, suse don't provide an /etc/SuSE-release anymore, but there is almost no difference between sles and opensuse leap, so call it suse
if grep -q ^ID_LIKE=\"suse\" /etc/os-release 2>/dev/null; then
# shellcheck disable=SC1091
if (. /etc/os-release && echo "${ID_LIKE}" | grep -q '\(^\|\ \)suse\($\|\ \)')
then
echo suse
exit 0
fi

View file

@ -31,7 +31,32 @@ case "$("$__explorer/os")" in
cat /etc/arch-release
;;
debian)
cat /etc/debian_version
debian_version=$(cat /etc/debian_version)
case $debian_version
in
testing/unstable)
# previous to Debian 4.0 testing/unstable was used
# cf. https://metadata.ftp-master.debian.org/changelogs/main/b/base-files/base-files_11_changelog
echo 3.99
;;
*/sid)
# sid versions don't have a number, so we decode by codename:
case $(expr "$debian_version" : '\([a-z]\{1,\}\)/')
in
bullseye) echo 10.99 ;;
buster) echo 9.99 ;;
stretch) echo 8.99 ;;
jessie) echo 7.99 ;;
wheezy) echo 6.99 ;;
squeeze) echo 5.99 ;;
lenny) echo 4.99 ;;
*) exit 1
esac
;;
*)
echo "$debian_version"
;;
esac
;;
devuan)
cat /etc/devuan_version

View file

@ -30,9 +30,6 @@ sum
By default output of ``cksum`` without filename is expected.
Other hash formats supported with prefixes: ``md5:``, ``sha1:`` and ``sha256:``.
onchange
Execute this command after download.
OPTIONAL PARAMETERS
-------------------
@ -54,6 +51,9 @@ cmd-sum
format specification ``%s`` which will become destination.
For example: ``md5sum '%s' | awk '{print $1}'``.
onchange
Execute this command after download.
EXAMPLES
--------

View file

@ -18,16 +18,16 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
os=$("$__explorer/os")
os=$("${__explorer:?}/os")
if [ -f "$__object/parameter/device" ]; then
if [ -f "${__object:?}/parameter/device" ]; then
blkdev="$(cat "$__object/parameter/device")"
else
blkdev="$__object_id"
blkdev="${__object_id:?}"
fi
case "$os" in
centos|fedora|redhat|suse|gentoo)
alpine|centos|fedora|redhat|suse|gentoo)
if [ ! -x "$(command -v lsblk)" ]; then
echo "lsblk is required for __filesystem type" >&2
exit 1

View file

@ -24,6 +24,22 @@
# Configure system-wide locale by modifying i18n file.
#
version_ge() {
awk -F '[^0-9.]' -v target="${1:?}" '
function max(x, y) { return x > y ? x : y }
BEGIN {
getline
nx = split($1, x, ".")
ny = split(target, y, ".")
for (i = 1; i <= max(nx, ny); ++i) {
diff = int(x[i]) - int(y[i])
if (diff == 0) continue
exit (diff < 0)
}
}'
}
key=$__object_id
onchange_cmd= # none, by default
quote_value=false
@ -40,8 +56,7 @@ os=$(cat "$__global/explorer/os")
case $os
in
debian)
os_version=$(cat "${__global}/explorer/os_version")
if expr "${os_version}" '>=' 4 >/dev/null
if version_ge 4 <"${__global}/explorer/os_version"
then
# Debian 4 (etch) and later
locale_conf="/etc/default/locale"
@ -53,8 +68,7 @@ in
locale_conf="/etc/default/locale"
;;
ubuntu)
os_version=$(cat "${__global}/explorer/os_version")
if expr "${os_version}" '>=' 6.10 >/dev/null
if version_ge 6.10 <"${__global}/explorer/os_version"
then
# Ubuntu 6.10 (edgy) and later
locale_conf="/etc/default/locale"
@ -68,7 +82,7 @@ in
centos|redhat|scientific)
# shellcheck source=/dev/null
version_id=$(. "${__global}/explorer/os_release" && echo "${VERSION_ID:-0}")
if expr "${version_id}" '>=' 7 >/dev/null
if echo "${version_id}" | version_ge 7
then
locale_conf="/etc/locale.conf"
else
@ -78,7 +92,7 @@ in
fedora)
# shellcheck source=/dev/null
version_id=$(. "${__global}/explorer/os_release" && echo "${VERSION_ID:-0}")
if expr "${version_id}" '>=' 18 >/dev/null
if echo "${version_id}" | version_ge 18
then
locale_conf="/etc/locale.conf"
quote_value=false
@ -113,7 +127,7 @@ in
locale_conf="/etc/default/init"
locale_conf_group="sys"
if expr "$(cat "${__global}/explorer/os_version")" '>=' 5.11 >/dev/null
if version_ge 5.11 <"${__global}/explorer/os_version"
then
# mode on Oracle Solaris 11 is actually 0444,
# but the write bit makes sense, IMO
@ -149,7 +163,13 @@ in
key="export ${__object_id}"
;;
suse)
os_version=$(cat "${__global}/explorer/os_version")
if test -s "${__global}/explorer/os_release"
then
# shellcheck source=/dev/null
os_version=$(. "${__global}/explorer/os_release" && echo "${VERSION}")
else
os_version=$(sed -n 's/^VERSION\ *=\ *//p' "${__global}/explorer/os_version")
fi
os_major=$(expr "${os_version}" : '\([0-9]\{1,\}\)')
# https://documentation.suse.com/sles/15-SP2/html/SLES-all/cha-suse.html#sec-suse-l10n

View file

@ -1,9 +1,10 @@
cdist-type__systemd-service(7)
cdist-type__systemd_service(7)
==============================
NAME
----
cdist-type__systemd-service - Controls a systemd service state
cdist-type__systemd_service - Controls a systemd service state
DESCRIPTION
-----------
@ -14,11 +15,12 @@ service after configuration applied or shutdown one service.
The activation or deactivation is out of scope. Look for the
:strong:`cdist-type__systemd_util`\ (7) type instead.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
@ -31,12 +33,12 @@ state
running
Service should run (default)
stoppend
Service should stopped
stopped
Service should be stopped
action
Executes an action on on the service. It will only execute it if the
service keeps the state **running**. There are following actions, where:
service keeps the state ``running``. There are following actions, where:
reload
Reloads the service
@ -48,11 +50,12 @@ BOOLEAN PARAMETERS
------------------
if-required
Only execute the action if minimum one required type outputs a message to
**$__messages_out**. Through this, the action should only executed if a
Only execute the action if at minimum one required type outputs a message
to ``$__messages_out``. Through this, the action should only executed if a
dependency did something. The action will not executed if no dependencies
given.
MESSAGES
--------
@ -68,12 +71,14 @@ restart
reload
Reloaded the service
ABORTS
------
Aborts in following cases:
systemd or the service does not exist
EXAMPLES
--------
.. code-block:: sh
@ -95,13 +100,15 @@ EXAMPLES
# reload the service for a modified configuration file
# only reloads the service if the file really changed
require="__config_file/etc/foo.conf" __systemd_service foo \
require="__file/etc/foo.conf" __systemd_service foo \
--action reload --if-required
AUTHORS
-------
Matthias Stecher <matthiasstecher at gmx.de>
COPYRIGHT
---------
Copyright \(C) 2020 Matthias Stecher. You can redistribute it

View file

@ -22,7 +22,7 @@
# This type allows to configure the desired localtime timezone.
timezone_is=$(cat "$__object/explorer/timezone_is")
timezone_should="$__object_id"
timezone_should=$(cat "$__object/parameter/tz")
os=$(cat "$__global/explorer/os")
if [ "$timezone_is" = "$timezone_should" ]; then

View file

@ -14,7 +14,8 @@ This type creates a symlink (/etc/localtime) to the selected timezone
REQUIRED PARAMETERS
-------------------
None.
tz
The name of timezone to set.
OPTIONAL PARAMETERS
@ -28,18 +29,23 @@ EXAMPLES
.. code-block:: sh
# Set up Europe/Andorra as our timezone.
__timezone Europe/Andorra
__timezone --tz Europe/Andorra
# Set up US/Central as our timezone.
__timezone US/Central
__timezone --tz US/Central
AUTHORS
-------
Ramon Salvadó <rsalvado--@--gnuine--dot--com>
| Steven Armstrong <steven-cdist--@--armstrong.cc>
| Nico Schottelius <nico-cdist--@--schottelius.org>
| Ramon Salvadó <rsalvado--@--gnuine--dot--com>
| Dennis Camera <dennis.camera--@--ssrq-sds-fds.ch>
COPYING
-------
Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).
Copyright \(C) 2012-2020 the `AUTHORS`_. 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

@ -22,7 +22,7 @@
#
# This type allows to configure the desired localtime timezone.
timezone="$__object_id"
timezone=$(cat "$__object/parameter/tz")
os=$(cat "$__global/explorer/os")
case "$os" in

View file

@ -0,0 +1 @@
tz

View file

View file

@ -23,6 +23,13 @@ case "$src" in
cmd="$cmd --strip-components=$tar_strip"
fi
if [ -f "$__object/parameter/tar-extra-args" ]
then
tar_extra_args="$( cat "$__object/parameter/tar-extra-args" )"
cmd="$cmd $tar_extra_args"
fi
;;
*.7z)
case "$os" in
@ -73,3 +80,8 @@ if [ ! -f "$__object/parameter/preserve-archive" ]
then
echo "rm -f '$src'"
fi
if [ -f "$__object/parameter/onchange" ]
then
cat "$__object/parameter/onchange"
fi

View file

@ -33,6 +33,10 @@ sum-file
tar-strip
Tarball specific. See ``man tar`` for ``--strip-components``.
tar-extra-args
Tarball sepcific. Append additional arguments to ``tar`` command.
See ``man tar`` for possible arguments.
OPTIONAL BOOLEAN PARAMETERS
---------------------------
@ -46,6 +50,9 @@ backup-destination
preserve-archive
Don't delete archive after unpacking.
onchange
Execute this command after unpack.
EXAMPLES
--------
@ -65,6 +72,13 @@ EXAMPLES
--preserve-archive \
--destination /opt/cpma/server
# example usecase for --tar-* args
__unpack /root/strelaysrv.tar.gz \
--preserve-archive \
--destination /usr/local/bin \
--tar-strip 1 \
--tar-extra-args '--wildcards "*/strelaysrv"'
AUTHORS
-------

View file

@ -1,2 +1,4 @@
sum-file
tar-strip
tar-extra-args
onchange

View file

@ -25,6 +25,7 @@ import argparse
import logging
import os
import sys
import re
import cdist
from cdist import core
@ -412,12 +413,15 @@ class Emulator:
if "require" in self.env:
requirements = self.env['require']
self.log.debug("reqs = " + requirements)
for requirement in requirements.split(" "):
for requirement in self._parse_require(requirements):
# Ignore empty fields - probably the only field anyway
if len(requirement) == 0:
continue
self.record_requirement(requirement)
def _parse_require(self, require):
return re.split(r'[ \t\n]+', require)
def record_auto_requirements(self):
"""An object shall automatically depend on all objects that it
defined in it's type manifest.

View file

@ -685,6 +685,16 @@ class EmulatorAlreadyExistingRequirementsWarnTestCase(test.CdistTestCase):
self.env['require'] = '__directory/spam'
emu = emulator.Emulator(argv, env=self.env)
def test_parse_require(self):
require = " \t \n \t\t\n\t\na\tb\nc d \te\t\nf\ng\t "
expected = ['', 'a', 'b', 'c', 'd', 'e', 'f', 'g', '', ]
argv = ['__directory', 'spam']
emu = emulator.Emulator(argv, env=self.env)
requirements = emu._parse_require(require)
self.assertEqual(expected, requirements)
if __name__ == '__main__':
import unittest

View file

@ -5,6 +5,19 @@ next:
* Core: Add trigger functionality (Nico Schottelius, Darko Poljak)
* Core: Implement core support for python types (Darko Poljak)
6.8.0: 2020-09-11
* Type __locale_system: Fix for debian and ubuntu (Ander Punnar)
* Type __unpack: Add --tar-extra-args parameter (Ander Punnar)
* Explorer os: Fix OS detection for openSUSE (Dennis Camera)
* Type __filesystem: Support Alpine Linux (Joachim Desroches)
* Type __locale_system: Fix version comparison (Dennis Camera)
* Type __unpack: Add --onchange parameter (Ander Punnar)
* Type __download: Fix manual (Ander Punnar)
* Explorer os_version: Convert Debian sid to version number (Dennis Camera)
* Core: Expand require delimiter characters, split by consecutive delimiters (Darko Poljak)
* Type __timezone: Make singleton (Dennis Camera)
* Type __systemd_service: Fix manpage typos (Matthias Stecher)
6.7.0: 2020-07-28
* Delete deprecated type: __pf_apply (Darko Poljak)
* New type: __download (Ander Punnar)

View file

@ -95,7 +95,8 @@ Dependencies
------------
If you want to describe that something requires something else, just
setup the variable "require" to contain the requirements. Multiple
requirements can be added white space separated.
requirements can be added separated with (optionally consecutive)
delimiters including space, tab and newline.
::