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

View File

@ -144,7 +144,9 @@ esac
if [ -f /etc/os-release ]; then 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 # 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 echo suse
exit 0 exit 0
fi fi

View File

@ -31,7 +31,32 @@ case "$("$__explorer/os")" in
cat /etc/arch-release cat /etc/arch-release
;; ;;
debian) 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) devuan)
cat /etc/devuan_version cat /etc/devuan_version
@ -73,4 +98,4 @@ case "$("$__explorer/os")" in
alpine) alpine)
cat /etc/alpine-release cat /etc/alpine-release
;; ;;
esac esac

View File

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

View File

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

View File

@ -24,6 +24,22 @@
# Configure system-wide locale by modifying i18n file. # 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 key=$__object_id
onchange_cmd= # none, by default onchange_cmd= # none, by default
quote_value=false quote_value=false
@ -40,8 +56,7 @@ os=$(cat "$__global/explorer/os")
case $os case $os
in in
debian) debian)
os_version=$(cat "${__global}/explorer/os_version") if version_ge 4 <"${__global}/explorer/os_version"
if expr "${os_version}" '>=' 4 >/dev/null
then then
# Debian 4 (etch) and later # Debian 4 (etch) and later
locale_conf="/etc/default/locale" locale_conf="/etc/default/locale"
@ -53,8 +68,7 @@ in
locale_conf="/etc/default/locale" locale_conf="/etc/default/locale"
;; ;;
ubuntu) ubuntu)
os_version=$(cat "${__global}/explorer/os_version") if version_ge 6.10 <"${__global}/explorer/os_version"
if expr "${os_version}" '>=' 6.10 >/dev/null
then then
# Ubuntu 6.10 (edgy) and later # Ubuntu 6.10 (edgy) and later
locale_conf="/etc/default/locale" locale_conf="/etc/default/locale"
@ -68,7 +82,7 @@ in
centos|redhat|scientific) centos|redhat|scientific)
# shellcheck source=/dev/null # shellcheck source=/dev/null
version_id=$(. "${__global}/explorer/os_release" && echo "${VERSION_ID:-0}") 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 then
locale_conf="/etc/locale.conf" locale_conf="/etc/locale.conf"
else else
@ -78,7 +92,7 @@ in
fedora) fedora)
# shellcheck source=/dev/null # shellcheck source=/dev/null
version_id=$(. "${__global}/explorer/os_release" && echo "${VERSION_ID:-0}") 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 then
locale_conf="/etc/locale.conf" locale_conf="/etc/locale.conf"
quote_value=false quote_value=false
@ -113,7 +127,7 @@ in
locale_conf="/etc/default/init" locale_conf="/etc/default/init"
locale_conf_group="sys" 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 then
# mode on Oracle Solaris 11 is actually 0444, # mode on Oracle Solaris 11 is actually 0444,
# but the write bit makes sense, IMO # but the write bit makes sense, IMO
@ -149,7 +163,13 @@ in
key="export ${__object_id}" key="export ${__object_id}"
;; ;;
suse) 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,\}\)') os_major=$(expr "${os_version}" : '\([0-9]\{1,\}\)')
# https://documentation.suse.com/sles/15-SP2/html/SLES-all/cha-suse.html#sec-suse-l10n # https://documentation.suse.com/sles/15-SP2/html/SLES-all/cha-suse.html#sec-suse-l10n

View File

@ -31,8 +31,8 @@ manager-password-hash
Generate e.g. with: `slappasswd -s weneedgoodsecurity`. Generate e.g. with: `slappasswd -s weneedgoodsecurity`.
See `slappasswd(8C)`, `slapd.conf(5)`. See `slappasswd(8C)`, `slapd.conf(5)`.
TODO: implement this: http://blog.adamsbros.org/2015/06/09/openldap-ssha-salted-hashes-by-hand/ TODO: implement this: http://blog.adamsbros.org/2015/06/09/openldap-ssha-salted-hashes-by-hand/
to derive from the manager-password parameter and ensure idempotency (care with salts). to derive from the manager-password parameter and ensure idempotency (care with salts).
At that point, manager-password-hash should be deprecated and ignored. At that point, manager-password-hash should be deprecated and ignored.
serverid serverid
The server for the directory. The server for the directory.

View File

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

View File

@ -22,7 +22,7 @@
# This type allows to configure the desired localtime timezone. # This type allows to configure the desired localtime timezone.
timezone_is=$(cat "$__object/explorer/timezone_is") timezone_is=$(cat "$__object/explorer/timezone_is")
timezone_should="$__object_id" timezone_should=$(cat "$__object/parameter/tz")
os=$(cat "$__global/explorer/os") os=$(cat "$__global/explorer/os")
if [ "$timezone_is" = "$timezone_should" ]; then 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 REQUIRED PARAMETERS
------------------- -------------------
None. tz
The name of timezone to set.
OPTIONAL PARAMETERS OPTIONAL PARAMETERS
@ -27,19 +28,24 @@ EXAMPLES
.. code-block:: sh .. code-block:: sh
#Set up Europe/Andorra as our timezone. # Set up Europe/Andorra as our timezone.
__timezone Europe/Andorra __timezone --tz Europe/Andorra
#Set up US/Central as our timezone. # Set up US/Central as our timezone.
__timezone US/Central __timezone --tz US/Central
AUTHORS 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 COPYING
------- -------
Free use of this software is Copyright \(C) 2012-2020 the `AUTHORS`_. You can redistribute it
granted under the terms of the GNU General Public License version 3 (GPLv3). 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. # This type allows to configure the desired localtime timezone.
timezone="$__object_id" timezone=$(cat "$__object/parameter/tz")
os=$(cat "$__global/explorer/os") os=$(cat "$__global/explorer/os")
case "$os" in 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" cmd="$cmd --strip-components=$tar_strip"
fi 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) *.7z)
case "$os" in case "$os" in
@ -73,3 +80,8 @@ if [ ! -f "$__object/parameter/preserve-archive" ]
then then
echo "rm -f '$src'" echo "rm -f '$src'"
fi fi
if [ -f "$__object/parameter/onchange" ]
then
cat "$__object/parameter/onchange"
fi

View File

@ -33,6 +33,10 @@ sum-file
tar-strip tar-strip
Tarball specific. See ``man tar`` for ``--strip-components``. 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 OPTIONAL BOOLEAN PARAMETERS
--------------------------- ---------------------------
@ -46,6 +50,9 @@ backup-destination
preserve-archive preserve-archive
Don't delete archive after unpacking. Don't delete archive after unpacking.
onchange
Execute this command after unpack.
EXAMPLES EXAMPLES
-------- --------
@ -65,6 +72,13 @@ EXAMPLES
--preserve-archive \ --preserve-archive \
--destination /opt/cpma/server --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 AUTHORS
------- -------

View File

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

View File

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

View File

@ -685,6 +685,16 @@ class EmulatorAlreadyExistingRequirementsWarnTestCase(test.CdistTestCase):
self.env['require'] = '__directory/spam' self.env['require'] = '__directory/spam'
emu = emulator.Emulator(argv, env=self.env) 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__': if __name__ == '__main__':
import unittest import unittest

View File

@ -5,6 +5,19 @@ next:
* Core: Add trigger functionality (Nico Schottelius, Darko Poljak) * Core: Add trigger functionality (Nico Schottelius, Darko Poljak)
* Core: Implement core support for python types (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 6.7.0: 2020-07-28
* Delete deprecated type: __pf_apply (Darko Poljak) * Delete deprecated type: __pf_apply (Darko Poljak)
* New type: __download (Ander Punnar) * New type: __download (Ander Punnar)

View File

@ -95,7 +95,8 @@ Dependencies
------------ ------------
If you want to describe that something requires something else, just If you want to describe that something requires something else, just
setup the variable "require" to contain the requirements. Multiple 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.
:: ::