Compare commits

...

220 Commits

Author SHA1 Message Date
evilham f994226d0e [__package_pkgng_freebsd] Bootstrap pkg if necessary
In a pristine FreeBSD base installation, pkg is really a bootstrapper utility,
in such cases the type used to fail instead of automatically bootstrapping pkg.
2020-09-29 19:47:59 +02:00
Darko Poljak 652c891858 ++changelog 2020-09-29 05:57:54 +02:00
poljakowski 84ade29ca9 Merge branch 'docs/custom-remote-exec-copy-examples' into 'master'
Add custom remote copy/exec examples

See merge request ungleich-public/cdist!938
2020-09-29 05:56:38 +02:00
Darko Poljak 73d6c9d469 Add custom remote copy/exec examples 2020-09-27 10:17:35 +02:00
poljakowski 8ab1b6a03d Merge branch 'fix/docs-makefile' into 'master'
docs: make varaibles environment-aware

See merge request ungleich-public/cdist!937
2020-09-24 06:55:30 +02:00
matze 84a7818121 docs: make varaibles environment-aware
There are all overwriting the environment, even the comment states
otherwise. Fixes it.
2020-09-23 20:29:47 +02:00
Darko Poljak b6922508b9 Update helper script 2020-09-21 09:17:34 +02:00
Darko Poljak 0fc10749ed Fix shellcheck 2020-09-21 09:11:35 +02:00
Darko Poljak 89a0080e13 ++changelog 2020-09-21 09:09:26 +02:00
poljakowski 139a782c96 Merge branch '__package_pip_detect_pip_bin' into 'master'
[__package_pip] detect pip binary

See merge request ungleich-public/cdist!935
2020-09-21 09:06:44 +02:00
poljakowski 2e6c12c27c Merge branch 'clarify-stdin-input' into 'master'
Clarify stdin input

Closes #836

See merge request ungleich-public/cdist!934
2020-09-21 09:04:06 +02:00
poljakowski 89b6215115 Clarify stdin input
Resolve #836.
2020-09-21 09:04:05 +02:00
ander decc0ad54d [__package_pip] detect pip binary 2020-09-19 12:38:20 +03:00
Darko Poljak 2885c6a248 Release 6.8.0 2020-09-11 14:20:57 +02:00
Darko Poljak 53b91adbd8 Fix shellcheck 2020-09-11 14:20:57 +02:00
Darko Poljak 6b262a61c1 ++changelog 2020-09-10 13:24:58 +02:00
poljakowski a20ab63e60 Merge branch 'fix/__systemd_service/manpage' into 'master'
__systemd_service: fix manpage typos

See merge request ungleich-public/cdist!931
2020-09-10 13:21:19 +02:00
matze b1375464cc __systemd_service: fix manpage typos 2020-09-09 21:11:40 +02:00
poljakowski f5b534df71 Merge branch 'fix/type/__timezone/singleton' into 'master'
__timezone: Make singleton

See merge request ungleich-public/cdist!916
2020-09-08 07:20:01 +02:00
Darko Poljak b5a40eb0d1 ++changelog 2020-08-27 12:25:11 +02:00
poljakowski a4a3b98568 Merge branch 'feature/expand-require-separator' into 'master'
Expand and split by consecutive require delimiters

Closes #832

See merge request ungleich-public/cdist!930
2020-08-27 12:22:55 +02:00
Darko Poljak c17541f24c Expand and split by consecutive require delimiters
Resolves #832.
2020-08-24 07:16:28 +02:00
Darko Poljak ba26a437be ++changelog 2020-08-18 11:06:19 +02:00
poljakowski a8ea56253c Merge branch 'feature/explorer/os_version/debian-sid' into 'master'
explorer/os_version: Convert Debian sid to version number.

Closes #833

See merge request ungleich-public/cdist!927
2020-08-18 11:05:12 +02:00
poljakowski 2c1eca9ee7 Merge branch '__download_man_fix' into 'master'
[__download] fix manual: onchange parameter in wrong section

See merge request ungleich-public/cdist!929
2020-08-18 11:02:18 +02:00
poljakowski 52b75e513f Merge branch '__unpack_onchange' into 'master'
[__unpack] add --onchange

See merge request ungleich-public/cdist!928
2020-08-18 10:59:55 +02:00
ander d239169c4f [__download] fix manual: onchange parameter in wrong section 2020-08-18 00:48:58 +03:00
ander 502d753047 [__unpack] add --onchange 2020-08-18 00:46:07 +03:00
Dennis Camera 6fed178529 [explorer/os_version] Convert Debian sid to version number.
Conversion of Debian sid to versions is done based on Debian codenames.
The version number is the version number of the final release - 0.01.

It is unknown if Debian < 4.0 has any sort of version information
available (apart from maybe checking base-files package version).
But I don't think any of these systems are still alive,
so I think going with 3.99 is fine for those.
2020-08-17 09:31:40 +02:00
Darko Poljak 8f94a226c7 ++changelog 2020-08-15 21:54:07 +02:00
poljakowski d6b44769e1 Merge branch 'fix/type/__locale_system/version-cmp' into 'master'
__locale_system: Fix version comparison

See merge request ungleich-public/cdist!923
2020-08-15 21:51:52 +02:00
ssrq fa967631e3 Merge branch 'master' into 'fix/type/__locale_system/version-cmp'
# Conflicts:
#   cdist/conf/type/__locale_system/manifest
2020-08-15 21:17:25 +02:00
Darko Poljak 74dd47c8c3 ++changelog 2020-08-15 21:11:43 +02:00
poljakowski 7b0a4f6831 Merge branch 'feature/alpine-filesystem' into 'master'
Add Alpine Linux as supported for __filesystem.

See merge request ungleich-public/cdist!925
2020-08-15 21:09:37 +02:00
poljakowski 54c525e36c Merge branch '__unpack_tar_extra_args' into 'master'
[__unpack] add parameter --tar-extra-args

See merge request ungleich-public/cdist!922
2020-08-15 21:07:20 +02:00
poljakowski 4082359a2f Merge branch 'fix/explorer/os/opensuse' into 'master'
explorer/os: Fix OS detection for openSUSE

See merge request ungleich-public/cdist!924
2020-08-15 21:06:31 +02:00
poljakowski 6f021889ee Merge branch '__locale_system_debian_fix' into 'master'
[__locale_system] fix for debian and ubuntu

See merge request ungleich-public/cdist!921
2020-08-15 20:59:59 +02:00
sparrowhawk 17ab4bd80c
Add Alpine Linux as supported for __filesystem. 2020-08-06 11:45:05 +02:00
Dennis Camera b370b70ff4 [explorer/os] Fix OS detection for openSUSE
All distros with ID_LIKE suse should be treated as "suse".
My openSUSE Leap 15.1 installation has:
ID_LIKE="suse opensuse"

This patch doesn't require a strict "suse" value but only the word suse to be in
the list.
2020-08-02 22:50:06 +02:00
Dennis Camera 7b480f4293 [type/__locale_system] Fix version extraction for SuSE 2020-08-02 22:47:46 +02:00
Dennis Camera 71710fa00a [type/__locale_system] Implement "proper" version comparison
Proper in the sense that it can handle all numeric version numbers even if they
are not floating point (e.g. 16.04.6).
2020-08-02 20:59:22 +02:00
Dennis Camera 885d5a58f4 [type/__locale_system] Fix floating point version comparison 2020-08-02 17:04:06 +02:00
ander 935f2395bc [__locale_system] fix for debian and ubuntu
ubuntu 6.10 and debian etch are 10+ years old and EOL. rather than
preserving compatibility I'll just remove it. while /etc/environment
works too, correct place is /etc/default/locale (as it was before
breaking change). also /etc/debian_version (os_version explorer) may
contain minor version with dot (10.5) or string (bullseye/sid).
2020-08-02 13:54:30 +03:00
ander d37d2dc307 [__unpack] add parameter --tar-extra-args 2020-08-02 13:53:38 +03:00
poljakowski 7e1428ab3c Merge branch 'bugfix/sphinx-docs-build' into 'master'
Fix building man pages

Closes #830

See merge request ungleich-public/cdist!919
2020-07-29 16:59:26 +02:00
Darko Poljak c053a2c4a0 Fix building man pages
Resolves #830.
2020-07-29 11:31:12 +02:00
Darko Poljak f5b367dfdb Release 6.7.0 2020-07-28 07:14:26 +02:00
Darko Poljak 76bb214b53 ++changelog 2020-07-27 15:31:38 +02:00
poljakowski a5f25faf25 Merge branch 'fix/type/__sysctl/netbsd-path' into 'master'
__sysctl: Fix on NetBSD

See merge request ungleich-public/cdist!918
2020-07-27 15:30:57 +02:00
poljakowski a6cd767c8f Merge branch 'fix/explorer/netbsd' into 'master'
Fix global explorers for NetBSD

See merge request ungleich-public/cdist!917
2020-07-27 15:29:52 +02:00
Dennis Camera 3a87a447d0 [type/__sysctl] Fix on NetBSD 2020-07-27 15:22:21 +02:00
Dennis Camera 5dfc996feb Fix global explorers for NetBSD
On NetBSD sysctl is at /sbin/sysctl, but the default PATH does not
contain /sbin.
2020-07-27 15:11:02 +02:00
Darko Poljak 627d215b63 ++changelog 2020-07-27 13:09:53 +02:00
poljakowski 5c5890d458 Merge branch 'feature/type/__locale_system/os-support' into 'master'
__locale_system: Wider OS support

See merge request ungleich-public/cdist!914
2020-07-27 12:58:53 +02:00
Dennis Camera d26c36914a [__timezone] Make type singleton 2020-07-27 11:06:14 +02:00
Darko Poljak 463b6cd6b5 ++changelog 2020-07-27 06:22:25 +02:00
poljakowski 8a8a48313c Merge branch '__unpack' into 'master'
new type: __unpack

See merge request ungleich-public/cdist!893
2020-07-27 06:20:21 +02:00
ander 73f1937636 [__unpack] no mkdir by default, because destination can be file, but tar needs mkdir andrar needs slash at the end 2020-07-27 06:20:21 +02:00
poljakowski 1b18b9487e Merge branch 'fix/type/__key_value/solaris-awk' into 'master'
__key_value: Get AWK from POSIX PATH

See merge request ungleich-public/cdist!913
2020-07-27 06:01:53 +02:00
poljakowski 263c7a90a8 Merge branch 'fix/type/__package_apt/legacy-norecommends' into 'master'
__package_apt: Fix for legacy APT versions that do not support --no-install-recommends.

See merge request ungleich-public/cdist!912
2020-07-27 05:58:40 +02:00
Dennis Camera 70d1228dc0 [type/__locale_system] Add support for FreeBSD 2020-07-26 20:10:52 +02:00
Dennis Camera 511d8c96aa [type/__locale_system] Add support for Slackware 2020-07-26 20:10:52 +02:00
Dennis Camera a923e75d9b [type/__locale_system] Add support for NetBSD 2020-07-26 20:10:52 +02:00
Dennis Camera cbf22f3b2c [type/__locale_system] Add support for Solaris 2020-07-26 20:10:52 +02:00
Dennis Camera 0ae0935afa [type/__locale_system] Add support for SuSE 2020-07-26 20:10:34 +02:00
Dennis Camera 630d987d5f [type/__locale_system] Add support for Void Linux 2020-07-26 20:10:34 +02:00
Dennis Camera 0ef54a721d [type/__locale_system] Add support for Gentoo Linux 2020-07-26 20:10:34 +02:00
Dennis Camera 47e28fc441 [type/__locale_system] Support old Debian derivatives 2020-07-26 20:10:34 +02:00
Dennis Camera a590504436 [type/__locale_system] RedHat systems on systemd use /etc/locale.conf 2020-07-26 20:10:34 +02:00
Dennis Camera 46d09392f0 [type/__key_value] Get AWK from POSIX PATH
This is required here, because Solaris /usr/bin/awk does not support the
sub() function.
So xpg4 AWK needs to be used.
2020-07-26 19:36:34 +02:00
Dennis Camera ee71cad047 [type/__package_apt] Fix type for legacy APT versions
--no-install-recommends was introduced with Debian 5.
The APT::Install-Recommends option gets ignored by old versions and
produces no error.
2020-07-25 19:20:32 +02:00
Darko Poljak 8b53f35ffa ++changelog 2020-07-24 12:33:40 +02:00
poljakowski 9df29de564 Merge branch 'rm-deprecated-__pf_apply' into 'master'
Remove deprecated __pf_apply

See merge request ungleich-public/cdist!899
2020-07-24 12:30:32 +02:00
Darko Poljak 8654cbe466 ++changelog 2020-07-24 12:29:02 +02:00
poljakowski 1d5e3a5b06 Merge branch 'openldap-alpine' into 'master'
Add Alpine support to __openldap_server

See merge request ungleich-public/cdist!909
2020-07-24 12:26:36 +02:00
fnux ae5f0bba0b Add Alpine support to __openldap_server 2020-07-24 12:26:35 +02:00
poljakowski 5d0f6caef7 Merge branch 'hotfix/stat-explorer' into 'master'
Hotfix:  Fix incorrect interpretation of --mode strings with leading 0s as octal

See merge request ungleich-public/cdist!911
2020-07-23 10:59:18 +02:00
Dennis Camera 595e43b8d5 [type/{__file,__directory}] Fix incorrect interpretation of strings with leading 0s as octal 2020-07-23 09:43:40 +02:00
Darko Poljak fdef468f1a Fix OpenWrt spelling 2020-07-22 18:28:41 +02:00
Darko Poljak d8b5c733f6 ++changelog 2020-07-22 06:36:27 +02:00
poljakowski 80a0551b36 Merge branch 'fix/type/__user/openwrt-support' into 'master'
__user: Install user{add,mod,del} packages on OpenWrt

See merge request ungleich-public/cdist!910
2020-07-22 06:35:23 +02:00
Dennis Camera 3965c7f738 [type/__user] Install user{add,mod,del} packages on OpenWrt 2020-07-21 19:42:40 +02:00
Darko Poljak 8903540e91 ++changelog 2020-07-13 07:54:12 +02:00
poljakowski cc089789de Merge branch 'cherry-pick-2f433a14' into 'master'
Merge branch 'bugfix/postfix-master-option' into master

See merge request ungleich-public/cdist!907
2020-07-13 07:51:25 +02:00
poljakowski bc97073131 Merge branch 'bugfix/postfix-master-option' into '6.6'
Fix broken --option parameter in __postfix_master type

See merge request ungleich-public/cdist!905

(cherry picked from commit 2f433a1458f3a1f7f8859e9ae165178a0ec5b7a0)

9496b234 The option parameter is actually multi-valued
4009bbd7 Protect postfix variables in options
2020-07-13 07:49:49 +02:00
poljakowski 652ffea4a8 Merge branch 'fix/stat-explorer' into 'master'
type/{__file/__directory}: Support setuid,setguid,sticky bits

See merge request ungleich-public/cdist!903
2020-07-13 07:37:50 +02:00
Dennis Camera 9fb7e151b8 [type/{__file/__directory}] Remove special Solaris blocks
Solaris 11 has GNU stat (handled by *)
Solaris 10 (and older?) does not have stat (handled by failing command -v stat)

On Solaris 10 (at least on UFS), setgid cannot be set on directories.
Unlike on other systems `chmod 2400` is not `-r----S---`, but `-r----l---`.
2020-07-12 12:41:02 +02:00
Dennis Camera 19514662b0 [type/{__file/__directory}] Fix typo 2020-07-12 12:24:00 +02:00
poljakowski c62eaa6eab Merge branch 'fix/type/__hosts/no-alias' into 'master'
__hosts: Fix when used without --alias

See merge request ungleich-public/cdist!906
2020-07-12 09:31:01 +02:00
Dennis Camera a5ae26116b [type/__hosts] Fix when used without --alias 2020-07-11 18:57:47 +02:00
Darko Poljak b8752e9ee3 ++changelog 2020-07-10 21:03:35 +02:00
poljakowski 506a0f3f47 Merge branch 'bugfix/make-code-consistent' into 'master'
Make code consistent

See merge request ungleich-public/cdist!904
2020-07-10 21:01:42 +02:00
Darko Poljak cb9933b4a0 Fix state -> state_is 2020-07-08 12:43:55 +02:00
poljakowski fde5627721 Merge branch '__download_improvements' into 'master'
__download improvements

See merge request ungleich-public/cdist!895
2020-07-08 12:33:41 +02:00
ander e906266286 [__download] s/variable/format specification/ 2020-07-08 00:20:55 +03:00
ander 93506d2113 [__download] curl follow redirects 2020-07-08 00:17:12 +03:00
Darko Poljak fe193ecab8 Make code consistent
* Remove supreflous checking and warning message.
* Fix cache recording.
2020-07-01 14:08:48 +02:00
Darko Poljak 88400551f9 ++changelog 2020-06-30 23:59:45 +02:00
poljakowski 727f3dbb03 Merge branch 'fix/type/__user/openbsd-shadow' into 'master'
__user: Fix shadow explorer for OpenBSD

See merge request ungleich-public/cdist!902
2020-06-30 22:55:33 +02:00
poljakowski c5a8004c9a Merge branch 'hosts-aliases' into 'master'
__hosts: add --alias parameter

See merge request ungleich-public/cdist!901
2020-06-30 22:52:52 +02:00
Dennis Camera 3860f1feea [type/{__file/__directory}] Support setuid,setguid,sticky bits 2020-06-30 15:10:30 +02:00
Dennis Camera 6467ccbdcc [type/__user] Make shellcheck happy 2020-06-30 14:31:11 +02:00
ssrq 9e33a8f42f Merge branch 'master' into 'fix/type/__user/openbsd-shadow'
# Conflicts:
#   cdist/conf/type/__user/explorer/shadow
2020-06-30 14:26:23 +02:00
Dennis Camera 999e7b0134 [type/__user] Fix shadow explorer for OpenBSD 2020-06-30 14:23:34 +02:00
Dennis Camera a263fdfe58 [__hosts] Add --alias parameter
The --alias parameter allows to specify a hostname and multiple aliases on a
single /etc/hosts line.
2020-06-30 14:05:26 +02:00
ander 99b5dcd8f0 Merge branch 'master' into __download_improvements 2020-06-28 16:57:13 +03:00
ander 996e7fc09c Merge branch 'master' into __download_improvements 2020-06-28 16:55:11 +03:00
ander b6bf90e3f1 [__download] update manual 2020-06-28 16:43:45 +03:00
ander 85614aabd6 [__download] add --download (local|remote), update manual 2020-06-28 16:38:15 +03:00
Darko Poljak 077989e8fd Remove annoying warnings
Those warnings don't have any specail meaning and usage.
Resolve #825.
2020-06-27 15:55:57 +02:00
Darko Poljak 7074f9c395 ++changelog 2020-06-25 06:32:10 +02:00
poljakowski 684043bf37 Merge branch 'fix/type/__package_opkg/lock' into 'master'
__package_opkg: Add locking

See merge request ungleich-public/cdist!896
2020-06-25 06:31:16 +02:00
poljakowski ceedcd02f2 Merge branch 'feature/type/__locale_system/support-devuan' into 'master'
__locale_system: "Whitelist" Devuan

See merge request ungleich-public/cdist!900
2020-06-25 06:24:17 +02:00
Dennis Camera 5364d3bc90 [type/__package_opkg] Implement flock locking if available 2020-06-24 21:06:10 +02:00
Dennis Camera a9778965be [type/__package_opkg] Use mkdir(1) to lock instead of noclobber
noclobber is potentially unsafe, because it relies on the underlying shell to
implement noclobber in a safe way that avoids race conditions between multiple
processes.
mkdir is safer because it is mandated by POSIX to "fail" if the target already
exists.
2020-06-24 08:47:22 +02:00
Darko Poljak 49dde11def Remove deprecated __pf_apply 2020-06-24 07:04:32 +02:00
Dennis Camera 3649555f35 [type/__package_opkg] Do not lock execution of code-remote (revert)
Instead, rely on `nonparallel`.
In any case cdist should never run explorer and code concurrently even if the
dependency graph would allow to do so as it would result in many more
synchronization issues than this one.
2020-06-22 09:32:57 +02:00
ander 26dfdf37c2 [__download] support multiple checksum formats and download utilities, add --onchange and other minor changes 2020-06-21 23:39:53 +03:00
poljakowski d478bef8a6 Merge branch 'lint/py3-classes' into 'master'
Consequently use Python 3-style classes

See merge request ungleich-public/cdist!898
2020-06-21 17:54:56 +02:00
poljakowski e67215f93d Merge branch 'lint/no-python-shebangs' into 'master'
Remove unnecessary Python shebangs

See merge request ungleich-public/cdist!897
2020-06-21 17:53:44 +02:00
Dennis Camera 6aae58dea7 [type/__package_opkg] Mark lock variables readonly 2020-06-21 17:35:28 +02:00
Dennis Camera ce07021580 Do not subclass object 2020-06-21 16:53:47 +02:00
Dennis Camera a6a3fb40bf Remove unnecessary Python shebangs 2020-06-21 16:03:09 +02:00
Dennis Camera e79b26a61f [type/__package_opkg] Also lock execution of code-remote 2020-06-21 15:53:01 +02:00
Dennis Camera 97e48be39e [type/__package_opkg] Fix explorer running in parallel 2020-06-21 15:52:57 +02:00
Darko Poljak a6543a72ad ++changelog 2020-06-17 13:40:31 +02:00
poljakowski d59ba09d71 Merge branch '__download' into 'master'
new type: __download

See merge request ungleich-public/cdist!892
2020-06-17 13:39:07 +02:00
Darko Poljak cdb998398d Release 6.6.0 2020-06-17 12:10:58 +02:00
ander 201050a9e5 new type: __download 2020-06-16 20:53:31 +03:00
Darko Poljak 5be8437a60 ++changelog 2020-06-13 13:48:34 +02:00
poljakowski 7a48b30d7a Merge branch 'log-server-new-min-py-ver' into 'master'
Log server to capture nested logging output

See merge request ungleich-public/cdist!891
2020-06-13 13:46:05 +02:00
Darko Poljak 59b98091d7 Adapt; update docs and code style 2020-06-13 13:44:01 +02:00
Steven Armstrong 57e352cd1e log server is also usefull for cdist config
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
2020-06-13 13:44:01 +02:00
Steven Armstrong 831bfc822b remove unused code
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
2020-06-13 13:44:01 +02:00
Steven Armstrong 6e9e9ad557 implement log server to capture nested logging output
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
2020-06-13 13:44:01 +02:00
Darko Poljak eba3d0505b ++changelog 2020-06-12 06:29:39 +02:00
Darko Poljak eec7ab8e45 Increase minimum supported Python version to 3.5 2020-06-12 06:08:56 +02:00
Darko Poljak 4167f9f60c Use proper format string with name 2020-06-11 14:22:54 +02:00
Darko Poljak 840e417eb7 Fix emulator colored logging 2020-06-11 14:16:37 +02:00
Darko Poljak 74e5d7182a ++changelog 2020-06-10 10:45:20 +02:00
poljakowski b22e09e1af Merge branch '__clean_path_add_path_param' into 'master'
[__clean_path] add --path parameter

See merge request ungleich-public/cdist!889
2020-06-10 10:44:20 +02:00
ander 7c490a703d [__clean_path] add --path parameter 2020-06-10 11:38:14 +03:00
Darko Poljak 955243a93b Update cdist man page copyright years 2020-06-09 12:51:19 +02:00
Darko Poljak 191f45eb7f ++changelog 2020-06-08 13:48:37 +02:00
Darko Poljak 58f101b8e8 Merge branch 'dheule-fix_os_explorer_sles15' 2020-06-08 13:44:11 +02:00
Darko Poljak a251e53495 Merge branch 'fix_os_explorer_sles15' of https://github.com/dheule/cdist into dheule-fix_os_explorer_sles15 2020-06-08 13:43:41 +02:00
Darko Poljak 4a81c019e3 Merge branch 'jaakristioja-master' 2020-06-08 13:37:51 +02:00
Jaak Ristioja 7b262c0cec
[docs] Fixed capitalization of URLs in cdist-bootstrap.rst
Signed-off-by: Jaak Ristioja <jaak@ristioja.ee>
2020-06-08 14:12:03 +03:00
Jaak Ristioja dc018fdb16
[docs] Fixed typo in cdist-cache.rst
Signed-off-by: Jaak Ristioja <jaak@ristioja.ee>
2020-06-08 14:12:03 +03:00
Jaak Ristioja 978e249043
[docs] Fixed capitalization of POSIX in cdist-install.rst
Signed-off-by: Jaak Ristioja <jaak@ristioja.ee>
2020-06-08 14:12:03 +03:00
Jaak Ristioja e1ff1bfdff
[docs] Fixed two typos in cdist-real-world.rst
Signed-off-by: Jaak Ristioja <jaak@ristioja.ee>
2020-06-08 14:12:03 +03:00
Jaak Ristioja 46574fc577
[docs] Fixed three typos in cdist-upgrade.rst
Signed-off-by: Jaak Ristioja <jaak@ristioja.ee>
2020-06-08 14:12:03 +03:00
Jaak Ristioja 3d725f12da
[docs] Fixed a typo and s/posix/POSIX/ in cdist-why.rst
Signed-off-by: Jaak Ristioja <jaak@ristioja.ee>
2020-06-08 14:12:03 +03:00
Jaak Ristioja f5630297bd
[docs] Fixed typo in cdist-configuration.rst
Signed-off-by: Jaak Ristioja <jaak@ristioja.ee>
2020-06-08 14:11:58 +03:00
Darko Poljak be47619b1e ++changelog 2020-06-08 09:11:51 +02:00
poljakowski c8a98c02ff Merge branch 'no-color' into 'master'
Respect NO_COLOR environment variable

See merge request ungleich-public/cdist!887
2020-06-08 09:09:50 +02:00
Dennis Camera 89ebd7a4f7 cdist man page: update --colors metavar name 2020-06-07 19:20:10 +02:00
Dennis Camera 23e66e08fa Restrict colored_output value to always/never/auto. 2020-06-06 13:45:31 +02:00
Dennis Camera 7a570f8692 [cdist.cfg.skeleton] Update colored_output documentation based on cdist(1) 2020-06-05 13:59:17 +02:00
Dennis Camera 790c6efae9 Update colored output documentation 2020-06-05 13:56:30 +02:00
Dennis Camera 89e48734bf Let config file and command line override NO_COLOR envvar 2020-06-05 12:23:36 +02:00
Dennis Camera cdb0d2be41 Patch tests 2020-06-03 23:21:50 +02:00
Dennis Camera 747c6b1076 Respect NO_COLOR environment variable 2020-06-03 22:17:52 +02:00
Daniel Heule 6a611e556a fix os explorer for sles15 2020-06-02 13:40:21 +02:00
Darko Poljak 48d66b0143 ++changelog 2020-06-01 22:25:15 +02:00
poljakowski fc9ce280f7 Merge branch 'bugfix/sphinx-build-failure' into 'master'
Bugfix/sphinx build failure

Closes #814

See merge request ungleich-public/cdist!885
2020-06-01 22:23:50 +02:00
Darko Poljak 55ebd1a4c5 Fix man build failure in newer sphinx versions 2020-06-01 20:22:40 +02:00
Darko Poljak 9a4e3488c2 ++changelog 2020-06-01 19:17:02 +02:00
poljakowski 3fc36a67a1 Merge branch 'evilham-colored-output' into 'master'
[UX] Add option to enable LogLevel-based coloured output.

See merge request ungleich-public/cdist!879
2020-06-01 19:11:58 +02:00
evilham ba77ea9edc [UX] Add option to enable LogLevel-based coloured output.
This makes it easier for new and experienced users to run cdist with higher
verbosity levels, both to know that things are working as expected and to debug
issues.

Documentation has been modified accordingly and default behaviour is not
changed.
2020-06-01 19:11:58 +02:00
Darko Poljak 988190363a Resolve shellcheck SC1090 2020-05-30 15:10:13 +02:00
Darko Poljak b354ea6e94 ++changelog 2020-05-30 10:49:13 +02:00
poljakowski b99f1eda0f Merge branch '__ssh_authorized_keys_remove_unknown' into 'master'
[__ssh_authorized_keys] add --remove-unknown parameter

See merge request ungleich-public/cdist!884
2020-05-30 10:48:02 +02:00
ander 29c0180204 [__ssh_authorized_keys] add --remove-unknown parameter 2020-05-28 23:31:13 +03:00
Darko Poljak abac79d4a5 Release 6.5.6 2020-05-25 11:16:48 +02:00
Darko Poljak ba64971a56 ++changelog 2020-05-24 17:05:01 +02:00
poljakowski 06cc20aa28 Merge branch 'bugfix/multiple-log-lines' into 'master'
Fix multiple log lines

Closes #813

See merge request ungleich-public/cdist!883
2020-05-24 17:01:31 +02:00
Darko Poljak f4e1bbc87e Fix multiple log lines
Fixes #813.
2020-05-24 01:10:56 +02:00
Darko Poljak 6ba73c4be6 ++changelog 2020-05-23 19:03:13 +02:00
poljakowski 15e4b5ee3b Merge branch '__user_remove_freebsd_fix' into 'master'
[__user] fix user delete on freebsd

See merge request ungleich-public/cdist!882
2020-05-23 19:02:31 +02:00
ander b7d3da443c Merge branch 'jaakristioja-master' into github 2020-05-23 01:15:09 +03:00
ander 716d3554f3 [__user] fix user delete on freebsd 2020-05-23 00:48:35 +03:00
Jaak Ristioja 66f4421089
[docs] Fixed two typos in cdist.cfg.skeleton
Signed-off-by: Jaak Ristioja <jaak@ristioja.ee>
2020-05-22 17:14:29 +03:00
Darko Poljak 226ed02c1c ++changelog 2020-05-22 10:09:05 +02:00
poljakowski dab32b0cb6 Merge branch '__group_freebsd_fix' into 'master'
[__group] fix --gid on freebsd

See merge request ungleich-public/cdist!881
2020-05-22 10:08:29 +02:00
poljakowski d1b73dd42b Merge branch '__motd_fix_for_debians' into 'master'
[__motd] debian|ubuntu|devuan use /etc/motd

See merge request ungleich-public/cdist!880
2020-05-22 10:05:50 +02:00
ander 3bcbd95269 [__motd] debian|ubuntu|devuan use /etc/motd 2020-05-22 02:36:49 +03:00
ander bf25a18a04 [__group] fix --gid on freebsd 2020-05-22 02:31:38 +03:00
Darko Poljak f354d80308 ++changelog 2020-05-18 21:03:42 +02:00
poljakowski cc8dcf682c Merge branch 'evilham-authorized_keys-options-bug' into 'master'
[__ssh_authorized_keys] Fix bug where --option was not multiple

See merge request ungleich-public/cdist!878
2020-05-18 21:03:01 +02:00
evilham ad58ea79c2 [__ssh_authorized_keys] Fix bug where --option was not multiple
This went against both documentation and intent.
2020-05-18 20:01:01 +02:00
Darko Poljak f9afac4dd6 ++changelog 2020-05-18 19:51:08 +02:00
poljakowski 8d639d54d0 Merge branch 'evilham-authorized_keys-man' into 'master'
[__ssh_authorizedkey{,s}] Improve documentation.

See merge request ungleich-public/cdist!877
2020-05-18 19:49:50 +02:00
poljakowski 2362d89976 Merge branch 'evilham-machine_type-explorer-simplify-linux-add-openbsd' into 'master'
[explorer/machine_type] simplify linux add openbsd

See merge request ungleich-public/cdist!876
2020-05-18 19:48:47 +02:00
poljakowski c5454afc72 Merge branch 'evilham-machine_type-explorer-freebsd' into 'master'
[explorer/machine_type] Add support for FreeBSD.

See merge request ungleich-public/cdist!875
2020-05-18 19:46:47 +02:00
poljakowski d5075b49c5 Merge branch 'fix/manpages' into 'master'
Fix some type manpages

See merge request ungleich-public/cdist!874
2020-05-18 19:45:12 +02:00
evilham 6d502f737a [__ssh_authorizedkey{,s}] Improve documentation. 2020-05-18 18:37:16 +02:00
evilham 8b790b0a54 [explorer/machine_type] Make shellcheck happy! 2020-05-18 16:47:20 +02:00
evilham cf44c4a01b [explorer/machine_type] Simplify Linux + basic OpenBSD support.
By abstracting away vendor-dependent pattern matching for the linux code, we can
re-use that and be reasonably sure about OpenBSD machines being virtualised when
we can identify the undelrying virtualisation technology.
It remains to be solved how to tell if an OpenBSD machine is physical; in that
case previous cdist behaviour ("unknown") remains.

For NetBSD something similar to OpenBSD could be done, with different sysctls:
hw.machine and hw.model wary of adding those without testing though, so for
NetBSD previous cdist behaviour ("unknown") remains.
https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+7.i386+NetBSD-9.0
2020-05-18 16:35:50 +02:00
evilham 7ca2bfc14a [explorer/machine_type] Add support for FreeBSD.
More research is needed for {Net,Open}BSD support.

Indentation is left as-is for the linux code as I intend to simplify it in a
future MR, this way the diff is minimal.
2020-05-18 16:00:23 +02:00
matze 086e683c99 [__file] add "default values" in manual for group, mode and owner
Because at least the --mode default value may not be expected, the
manual lists the "default values". As they are not explicitly set in the
`__file` type, it is a bit more difficult, but should resolve to
following:
  - the mode comes from the umask set in the cdist code to protect file
    creation and uses the strongest umask possible.
  - the owner and group comes from the ssh user, which should always be
    the root user. (I think this can be swaped, too, but who will?)

At the owner and group parameter, it could be replaced with something
like "the ssh user and group", which would be more correct, but less
understandable.
2020-05-16 16:33:38 +02:00
matze dcfabf9268 [__cron] add hint for default values of time-related parameters
This should resolve some misunderstanding when leave a time-related
parameter with it's default value.
2020-05-16 14:00:02 +02:00
matze 42f2dceeb1 [__link] fix typo in the manual 2020-05-09 18:40:44 +02:00
Nico Schottelius 6f4649efc6 Reference the new cdist chat on matrix 2020-05-08 16:08:21 +02:00
Nico Schottelius d4059fd29e [__letsencrypt_cert] whitelist Ubuntu 2020-05-01 15:31:23 +02:00
Nico Schottelius f58d662b32 [__pyvenv] Switch to python3 -m venv for ubuntu 2020-05-01 15:28:01 +02:00
Darko Poljak 310045d9fb Release 6.5.5 2020-05-01 13:02:00 +02:00
Darko Poljak 250161e42d ++ 2020-04-28 23:08:03 +02:00
poljakowski 888cf54d99 Merge branch 'mute-return_output-warning' into 'master'
[logging] Mute warning on return_output=True when running scripts.

Closes #806

See merge request ungleich-public/cdist!872
2020-04-28 15:00:00 +02:00
evilham ea3bd14d8b [logging] Mute warning on return_output=True when running scripts.
This fixes #806 which contains more information about the issue.

The TL;DR: this warning is not being useful and hinders debugging types because
it creates an innecessary line for each explorer.

An alternative proposal was #807 but was abandoned in favour of just dropping
the warning.
2020-04-28 14:54:51 +02:00
Darko Poljak 515992249d ++changelog 2020-04-27 22:55:57 +02:00
poljakowski cd0c811d74 Merge branch 'evilham-explorers' into 'master'
[explorers] Improve *BSD support.

See merge request ungleich-public/cdist!869
2020-04-27 22:53:09 +02:00
poljakowski 965829e18a Merge branch 'evilham-cdist.cfg.skeleton' into 'master'
[docs] Improve cdist.cfg.skeleton

See merge request ungleich-public/cdist!868
2020-04-27 22:51:48 +02:00
nico14571 bd66b6d948 Merge branch 'update_readme' into 'master'
update README

See merge request ungleich-public/cdist!870
2020-04-27 16:48:09 +02:00
ander b31e13eacf README: add bits about cdist-contrib 2020-04-27 16:30:52 +03:00
ander 56a65518ab README: add participating section 2020-04-27 15:25:43 +03:00
ander 0b3c417aef update README 2020-04-27 15:09:40 +03:00
evilham 678df1ec8a [explorers] Improve *BSD support.
cpu_cores and memory did lacked support for other BSDs.
2020-04-27 01:29:37 +02:00
evilham fefc828780 [docs] Improve cdist.cfg.skeleton 2020-04-26 19:06:42 +02:00
Dennis Camera 64c247026a [__locale_system] Support Devuan 2019-09-30 14:20:41 +02:00
137 changed files with 2322 additions and 747 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)
################################################################################

7
README
View File

@ -1,7 +0,0 @@
cdist
-----
cdist is a usable configuration management system.
For the web documentation have a look at https://www.cdi.st/
or at docs/src for reStructuredText manual.

31
README.md Normal file
View File

@ -0,0 +1,31 @@
# cdist
**cdist** is a usable configuration management system.
It adheres to the [**KISS principle**](https://en.wikipedia.org/wiki/KISS_principle)
and is being used in small up to enterprise grade environments.
For more information have a look at [**homepage**](https://cdi.st)
or at **``docs/src``** for manual in **reStructuredText** format.
## Contributing
Merge/Pull requests can be made in both
[upstream **GitLab**](https://code.ungleich.ch/ungleich-public/cdist/merge_requests)
(managed by [**ungleich**](https://ungleich.ch))
and [**GitHub** project](https://github.com/ungleich/cdist/pulls).
Issues can be made and other project management activites happen
[**only in GitLab**](https://code.ungleich.ch/ungleich-public/cdist)
(needs [**ungleich** account](https://account.ungleich.ch)).
For community-maintained types there is
[**cdist-contrib** project](https://code.ungleich.ch/ungleich-public/cdist-contrib).
## Participating
IRC: ``#cdist`` @ freenode
Matrix: ``#cdist:ungleich.ch``
Mattermost: https://chat.ungleich.ch/ungleich/channels/cdist

View File

@ -371,7 +371,6 @@ eof
Manual steps post release:
- cdist-web
- send generated mailinglist.tmp mail
- twitter
eof
;;

View File

@ -26,6 +26,7 @@ import hashlib
import cdist.log
import cdist.version
VERSION = cdist.version.VERSION
BANNER = """
@ -48,6 +49,9 @@ REMOTE_EXEC = "ssh -o User=root"
REMOTE_CMDS_CLEANUP_PATTERN = "ssh -o User=root -O exit -S {}"
MIN_SUPPORTED_PYTHON_VERSION = '3.5'
class Error(Exception):
"""Base exception class for this project"""
pass

View File

@ -5,6 +5,7 @@ import logging
import collections
import functools
import cdist.configuration
import cdist.log
import cdist.preos
import cdist.info
@ -125,6 +126,14 @@ def get_parsers():
'value.'),
action='count', default=None)
parser['colored_output'] = argparse.ArgumentParser(add_help=False)
parser['colored_output'].add_argument(
'--colors', metavar='WHEN',
help="Colorize cdist's output based on log level; "
"WHEN is 'always', 'never', or 'auto'.",
action='store', dest='colored_output', required=False,
choices=cdist.configuration.ColoredOutputOption.CHOICES)
parser['beta'] = argparse.ArgumentParser(add_help=False)
parser['beta'].add_argument(
'-b', '--beta',
@ -197,6 +206,13 @@ def get_parsers():
'supported. Without argument CPU count is used by default. '),
action='store', dest='jobs',
const=multiprocessing.cpu_count())
parser['config_main'].add_argument(
'--log-server',
action='store_true',
help=('Start a log server for sub processes to use. '
'This is mainly useful when running cdist nested '
'from a code-local script. Log server is alwasy '
'implicitly started for \'install\' command.'))
parser['config_main'].add_argument(
'-n', '--dry-run',
help='Do not execute code.', action='store_true')
@ -257,8 +273,7 @@ def get_parsers():
'-f', '--file',
help=('Read specified file for a list of additional hosts to '
'operate on or if \'-\' is given, read stdin (one host per '
'line). If no host or host file is specified then, by '
'default, read hosts from stdin.'),
'line).'),
dest='hostfile', required=False)
parser['config_args'].add_argument(
'-p', '--parallel', nargs='?', metavar='HOST_MAX',
@ -283,6 +298,7 @@ def get_parsers():
'host', nargs='*', help='Host(s) to operate on.')
parser['config'] = parser['sub'].add_parser(
'config', parents=[parser['loglevel'], parser['beta'],
parser['colored_output'],
parser['common'],
parser['config_main'],
parser['inventory_common'],
@ -301,6 +317,7 @@ def get_parsers():
parser['add-host'] = parser['invsub'].add_parser(
'add-host', parents=[parser['loglevel'], parser['beta'],
parser['colored_output'],
parser['common'],
parser['inventory_common']])
parser['add-host'].add_argument(
@ -308,13 +325,12 @@ def get_parsers():
parser['add-host'].add_argument(
'-f', '--file',
help=('Read additional hosts to add from specified file '
'or from stdin if \'-\' (each host on separate line). '
'If no host or host file is specified then, by default, '
'read from stdin.'),
'or from stdin if \'-\' (each host on separate line). '),
dest='hostfile', required=False)
parser['add-tag'] = parser['invsub'].add_parser(
'add-tag', parents=[parser['loglevel'], parser['beta'],
parser['colored_output'],
parser['common'],
parser['inventory_common']])
parser['add-tag'].add_argument(
@ -323,20 +339,12 @@ def get_parsers():
parser['add-tag'].add_argument(
'-f', '--file',
help=('Read additional hosts to add tags from specified file '
'or from stdin if \'-\' (each host on separate line). '
'If no host or host file is specified then, by default, '
'read from stdin. If no tags/tagfile nor hosts/hostfile'
' are specified then tags are read from stdin and are'
' added to all hosts.'),
'or from stdin if \'-\' (each host on separate line). '),
dest='hostfile', required=False)
parser['add-tag'].add_argument(
'-T', '--tag-file',
help=('Read additional tags to add from specified file '
'or from stdin if \'-\' (each tag on separate line). '
'If no tag or tag file is specified then, by default, '
'read from stdin. If no tags/tagfile nor hosts/hostfile'
' are specified then tags are read from stdin and are'
' added to all hosts.'),
'or from stdin if \'-\' (each tag on separate line). '),
dest='tagfile', required=False)
parser['add-tag'].add_argument(
'-t', '--taglist',
@ -346,6 +354,7 @@ def get_parsers():
parser['del-host'] = parser['invsub'].add_parser(
'del-host', parents=[parser['loglevel'], parser['beta'],
parser['colored_output'],
parser['common'],
parser['inventory_common']])
parser['del-host'].add_argument(
@ -356,13 +365,12 @@ def get_parsers():
parser['del-host'].add_argument(
'-f', '--file',
help=('Read additional hosts to delete from specified file '
'or from stdin if \'-\' (each host on separate line). '
'If no host or host file is specified then, by default, '
'read from stdin.'),
'or from stdin if \'-\' (each host on separate line). '),
dest='hostfile', required=False)
parser['del-tag'] = parser['invsub'].add_parser(
'del-tag', parents=[parser['loglevel'], parser['beta'],
parser['colored_output'],
parser['common'],
parser['inventory_common']])
parser['del-tag'].add_argument(
@ -375,20 +383,13 @@ def get_parsers():
parser['del-tag'].add_argument(
'-f', '--file',
help=('Read additional hosts to delete tags for from specified '
'file or from stdin if \'-\' (each host on separate line). '
'If no host or host file is specified then, by default, '
'read from stdin. If no tags/tagfile nor hosts/hostfile'
' are specified then tags are read from stdin and are'
' deleted from all hosts.'),
'file or from stdin if \'-\' (each host on separate '
'line). '),
dest='hostfile', required=False)
parser['del-tag'].add_argument(
'-T', '--tag-file',
help=('Read additional tags from specified file '
'or from stdin if \'-\' (each tag on separate line). '
'If no tag or tag file is specified then, by default, '
'read from stdin. If no tags/tagfile nor'
' hosts/hostfile are specified then tags are read from'
' stdin and are added to all hosts.'),
'or from stdin if \'-\' (each tag on separate line). '),
dest='tagfile', required=False)
parser['del-tag'].add_argument(
'-t', '--taglist',
@ -398,6 +399,7 @@ def get_parsers():
parser['list'] = parser['invsub'].add_parser(
'list', parents=[parser['loglevel'], parser['beta'],
parser['colored_output'],
parser['common'],
parser['inventory_common']])
parser['list'].add_argument(
@ -430,7 +432,7 @@ def get_parsers():
# Shell
parser['shell'] = parser['sub'].add_parser(
'shell', parents=[parser['loglevel']])
'shell', parents=[parser['loglevel'], parser['colored_output']])
parser['shell'].add_argument(
'-s', '--shell',
help=('Select shell to use, defaults to current shell. Used shell'
@ -478,7 +480,12 @@ def handle_loglevel(args):
if hasattr(args, 'quiet') and args.quiet:
args.verbose = _verbosity_level_off
logging.root.setLevel(_verbosity_level[args.verbose])
logging.getLogger().setLevel(_verbosity_level[args.verbose])
def handle_log_colors(args):
if cdist.configuration.ColoredOutputOption.translate(args.colored_output):
cdist.log.CdistFormatter.USE_COLORS = True
def parse_and_configure(argv, singleton=True):
@ -492,6 +499,7 @@ def parse_and_configure(argv, singleton=True):
raise cdist.Error(str(e))
# Loglevels are handled globally in here
handle_loglevel(args)
handle_log_colors(args)
log = logging.getLogger("cdist")

View File

@ -32,6 +32,11 @@ case "$os" in
sysctl -n hw.ncpuonline
;;
"freebsd"|"netbsd")
PATH=$(getconf PATH)
sysctl -n hw.ncpu
;;
*)
if [ -r /proc/cpuinfo ]; then
cores="$(grep "core id" /proc/cpuinfo | sort | uniq | wc -l)"

View File

@ -30,9 +30,8 @@ case $uname_s in
sysctl -n hw.disknames | grep -Eo '[lsw]d[0-9]+'
;;
NetBSD)
PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
sysctl -n hw.disknames \
| awk 'BEGIN { RS = " " } /^[lsw]d[0-9]+/'
PATH=$(getconf PATH)
sysctl -n hw.disknames | awk -v RS=' ' '/^[lsw]d[0-9]+/'
;;
Linux)
# list of major device numbers toexclude:

View File

@ -2,6 +2,7 @@
#
# 2014 Daniel Heule (hda at sfs.biz)
# 2014 Thomas Oettli (otho at sfs.biz)
# 2020 Evilham (contact at evilham.com)
#
# This file is part of cdist.
#
@ -18,63 +19,91 @@
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# FIXME: other system types (not linux ...)
os=$("$__explorer/os")
if [ -d "/proc/vz" ] && [ ! -d "/proc/bc" ]; then
echo openvz
exit
fi
if [ -e "/proc/1/environ" ] &&
tr '\000' '\n' < "/proc/1/environ" | grep -Eiq '^container='; then
echo lxc
exit
fi
if [ -r /proc/cpuinfo ]; then
# this should only exist on virtual guest machines,
# tested on vmware, xen, kvm
if grep -q "hypervisor" /proc/cpuinfo; then
# this file is aviable in xen guest systems
if [ -r /sys/hypervisor/type ]; then
if grep -q -i "xen" /sys/hypervisor/type; then
echo virtual_by_xen
exit
vendor_string_to_machine_type() {
for vendor in vmware bochs kvm qemu virtualbox bhyve; do
if echo "${1}" | grep -q -i "${vendor}"; then
if [ "${vendor}" = "bochs" ] || [ "${vendor}" = "qemu" ]; then
vendor="kvm"
fi
else
if [ -r /sys/class/dmi/id/product_name ]; then
if grep -q -i 'vmware' /sys/class/dmi/id/product_name; then
echo "virtual_by_vmware"
exit
elif grep -q -i 'bochs' /sys/class/dmi/id/product_name; then
echo "virtual_by_kvm"
exit
elif grep -q -i 'virtualbox' /sys/class/dmi/id/product_name; then
echo "virtual_by_virtualbox"
exit
fi
fi
if [ -r /sys/class/dmi/id/sys_vendor ]; then
if grep -q -i 'qemu' /sys/class/dmi/id/sys_vendor; then
echo "virtual_by_kvm"
exit
fi
fi
if [ -r /sys/class/dmi/id/chassis_vendor ]; then
if grep -q -i 'qemu' /sys/class/dmi/id/chassis_vendor; then
echo "virtual_by_kvm"
exit
fi
fi
echo "virtual_by_${vendor}"
exit
fi
echo "virtual_by_unknown"
else
echo "physical"
fi
else
echo "unknown"
fi
done
}
case "$os" in
"freebsd")
# FreeBSD does not have /proc/cpuinfo even when procfs is used.
# Instead there is a sysctl kern.vm_guest.
# Which is 'none' if physical, else the virtualisation.
vm_guest="$(sysctl -n kern.vm_guest 2>/dev/null || true)"
if [ -n "${vm_guest}" ]; then
if [ "${vm_guest}" = "none" ]; then
echo "physical"
exit
fi
echo "virtual_by_${vm_guest}"
exit
fi
;;
"openbsd")
# OpenBSD can also use the sysctl's: hw.vendor or hw.product.
# Note we can be reasonably sure about a machine being virtualised
# as long as we can identify the virtualisation technology.
# But not so much about it being physical...
# Patches are welcome / reach out if you have better ideas.
for sysctl in hw.vendor hw.product; do
# This exits if we can make a reasonable judgement
vendor_string_to_machine_type "$(sysctl -n "${sysctl}")"
done
;;
*)
# Defaulting to linux for compatibility with previous cdist behaviour
if [ -d "/proc/vz" ] && [ ! -d "/proc/bc" ]; then
echo openvz
exit
fi
if [ -e "/proc/1/environ" ] &&
tr '\000' '\n' < "/proc/1/environ" | grep -Eiq '^container='; then
echo lxc
exit
fi
if [ -r /proc/cpuinfo ]; then
# this should only exist on virtual guest machines,
# tested on vmware, xen, kvm, bhyve
if grep -q "hypervisor" /proc/cpuinfo; then
# this file is aviable in xen guest systems
if [ -r /sys/hypervisor/type ]; then
if grep -q -i "xen" /sys/hypervisor/type; then
echo virtual_by_xen
exit
fi
else
for vendor_file in /sys/class/dmi/id/product_name \
/sys/class/dmi/id/sys_vendor \
/sys/class/dmi/id/chasis_vendor; do
if [ -r ${vendor_file} ]; then
# This exits if we can make a reasonable judgement
vendor_string_to_machine_type "$(cat "${vendor_file}")"
fi
done
fi
echo "virtual_by_unknown"
exit
else
echo "physical"
exit
fi
fi
;;
esac
echo "unknown"

View File

@ -29,7 +29,8 @@ case "$os" in
echo "$(sysctl -n hw.memsize)/1024" | bc
;;
"openbsd")
*"bsd")
PATH=$(getconf PATH)
echo "$(sysctl -n hw.physmem) / 1048576" | bc
;;

View File

@ -143,6 +143,13 @@ case "$uname_s" in
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
# shellcheck disable=SC1091
if (. /etc/os-release && echo "${ID_LIKE}" | grep -q '\(^\|\ \)suse\($\|\ \)')
then
echo suse
exit 0
fi
# already lowercase, according to:
# https://www.freedesktop.org/software/systemd/man/os-release.html
awk -F= '/^ID=/ { if ($2 ~ /^'"'"'(.*)'"'"'$/ || $2 ~ /^"(.*)"$/) { print substr($2, 2, length($2) - 2) } else { print $2 } }' /etc/os-release

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

View File

@ -18,7 +18,12 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
path="/$__object_id"
if [ -f "$__object/parameter/path" ]
then
path="$( cat "$__object/parameter/path" )"
else
path="/$__object_id"
fi
[ ! -d "$path" ] && exit 0

View File

@ -20,7 +20,12 @@
[ ! -s "$__object/explorer/list" ] && exit 0
path="/$__object_id"
if [ -f "$__object/parameter/path" ]
then
path="$( cat "$__object/parameter/path" )"
else
path="/$__object_id"
fi
pattern="$( cat "$__object/parameter/pattern" )"

View File

@ -10,7 +10,7 @@ DESCRIPTION
-----------
Remove files and directories which match the pattern.
Provided path (as __object_id) must be a directory.
Provided path must be a directory.
Patterns are passed to ``find``'s ``-regex`` - see ``find(1)`` for more details.
@ -29,6 +29,9 @@ pattern
OPTIONAL PARAMETERS
-------------------
path
Path which will be cleaned. Defaults to ``$__object_id``.
exclude
Pattern of files which are excluded from removal.
@ -46,6 +49,11 @@ EXAMPLES
--exclude '.+\(charset\.conf\|security\.conf\)' \
--onchange 'service apache2 restart'
__clean_path apache2-conf-enabled \
--path /etc/apache2/conf-enabled \
--pattern '.+' \
--exclude '.+\(charset\.conf\|security\.conf\)' \
--onchange 'service apache2 restart'
AUTHORS
-------

View File

@ -1,2 +1,3 @@
exclude
onchange
path

View File

@ -21,6 +21,11 @@ command
OPTIONAL PARAMETERS
-------------------
**NOTE**: All time-related parameters (``--minute``, ``--hour``, ``--day_of_month``
``--month`` and ``--day_of_week``) defaults to ``*``, which means to execute it
**always**. If you set ``--hour 0`` to execute the cronjob only at midnight, it
will execute **every** minute in the first hour of the morning all days.
state
Either present or absent. Defaults to present.
minute

View File

@ -30,10 +30,10 @@ fallback() {
gid=$(echo "$ls_line" | awk '{ print $4 }')
owner=$(awk -F: -v uid="$uid" '$3 == uid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/passwd)
group=$(awk -F: -v uid="$uid" '$3 == uid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/group)
group=$(awk -F: -v gid="$gid" '$3 == gid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/group)
mode_text=$(echo "$ls_line" | awk '{ print $1 }')
mode=$(echo "$mode_text" | awk '{ k=0; for (i=0; i<=8; i++) k += ((substr($1, i+2, 1) ~ /[rwx]/) * 2^(8-i)); printf("%0o", k) }')
mode=$(echo "$mode_text" | awk '{for(i=8;i>=0;--i){c=substr($1,10-i,1);k+=((c~/[rwxst]/)*2^i);if(!(i%3))k+=(tolower(c)~/[lst]/)*2^(9+i/3)}printf("%04o",k)}')
printf 'type: %s\nowner: %d %s\ngroup: %d %s\nmode: %s %s\n' \
"$("$__type_explorer/type")" \
@ -45,56 +45,27 @@ fallback() {
# nothing to work with, nothing we could do
[ -e "$destination" ] || exit 0
if ! command -v stat >/dev/null
then
command -v stat >/dev/null 2>&1 || {
fallback
exit
fi
}
case $("$__explorer/os") in
"freebsd"|"netbsd"|"openbsd"|"macosx")
stat -f "type: %HT
case $("$__explorer/os")
in
freebsd|netbsd|openbsd|macosx)
stat -f 'type: %HT
owner: %Du %Su
group: %Dg %Sg
mode: %Lp %Sp
" "$destination" | awk '/^type/ { print tolower($0); next } { print }'
mode: %Mp%03Lp %Sp
' "$destination" | awk '/^type/ { print tolower($0); next } { print }'
;;
solaris)
ls1="$( ls -ld "$destination" )"
ls2="$( ls -ldn "$destination" )"
if [ -f "$__object/parameter/mode" ]
then mode_should="$( cat "$__object/parameter/mode" )"
fi
# yes, it is ugly hack, but if you know better way...
if [ -z "$( find "$destination" -perm "$mode_should" )" ]
then octets=888
else octets="$( echo "$mode_should" | sed 's/^0//' )"
fi
case "$( echo "$ls1" | cut -c1-1 )" in
-) echo 'type: regular file' ;;
d) echo 'type: directory' ;;
esac
echo "owner: $( echo "$ls2" \
| awk '{print $3}' ) $( echo "$ls1" \
| awk '{print $3}' )"
echo "group: $( echo "$ls2" \
| awk '{print $4}' ) $( echo "$ls1" \
| awk '{print $4}' )"
echo "mode: $octets $( echo "$ls1" | awk '{print $1}' )"
;;
*)
# NOTE: Do not use --printf here as it is not supported by BusyBox stat.
# NOTE: BusyBox's stat might not support the "-c" option, in which case
# we fall through to the shell fallback.
stat -c "type: %F
stat -c 'type: %F
owner: %u %U
group: %g %G
mode: %a %A" "$destination" 2>/dev/null || fallback
;;
mode: %04a %A' "$destination" 2>/dev/null || fallback
;;
esac

View File

@ -97,9 +97,11 @@ case "$state_should" in
value_should="$(cat "$__object/parameter/$attribute")"
value_is="$(get_current_value "$attribute" "$value_should")"
# change 0xxx format to xxx format => same as stat returns
# format mode in four digits => same as stat returns
if [ "$attribute" = mode ]; then
value_should="$(echo "$value_should" | sed 's/^0\(...\)/\1/')"
# Convert to four-digit octal number (printf interprets
# strings with leading 0s as octal!)
value_should=$(printf '%04o' "0${value_should}")
fi
if [ "$set_attributes" = 1 ] || [ "$value_should" != "$value_is" ]; then

View File

@ -0,0 +1,19 @@
#!/bin/sh -e
if [ -f "$__object/parameter/cmd-get" ]
then
cmd="$( cat "$__object/parameter/cmd-get" )"
elif command -v curl > /dev/null
then
cmd="curl -L -o - '%s'"
elif command -v fetch > /dev/null
then
cmd="fetch -o - '%s'"
else
cmd="wget -O - '%s'"
fi
echo "$cmd"

View File

@ -0,0 +1,72 @@
#!/bin/sh -e
dst="/$__object_id"
if [ ! -f "$dst" ]
then
echo 'absent'
exit 0
fi
sum_should="$( cat "$__object/parameter/sum" )"
if [ -f "$__object/parameter/cmd-sum" ]
then
# shellcheck disable=SC2059
sum_is="$( eval "$( printf \
"$( cat "$__object/parameter/cmd-sum" )" \
"$dst" )" )"
else
os="$( "$__explorer/os" )"
if echo "$sum_should" | grep -Eq '^[0-9]+\s[0-9]+$'
then
sum_is="$( cksum "$dst" | awk '{print $1" "$2}' )"
elif echo "$sum_should" | grep -Eiq '^md5:[a-f0-9]{32}$'
then
case "$os" in
freebsd)
sum_is="md5:$( md5 -q "$dst" )"
;;
*)
sum_is="md5:$( md5sum "$dst" | awk '{print $1}' )"
;;
esac
elif echo "$sum_should" | grep -Eiq '^sha1:[a-f0-9]{40}$'
then
case "$os" in
freebsd)
sum_is="sha1:$( sha1 -q "$dst" )"
;;
*)
sum_is="sha1:$( sha1sum "$dst" | awk '{print $1}' )"
;;
esac
elif echo "$sum_should" | grep -Eiq '^sha256:[a-f0-9]{64}$'
then
case "$os" in
freebsd)
sum_is="sha256:$( sha256 -q "$dst" )"
;;
*)
sum_is="sha256:$( sha256sum "$dst" | awk '{print $1}' )"
;;
esac
fi
fi
if [ -z "$sum_is" ]
then
echo 'no checksum from target' >&2
exit 1
fi
if [ "$sum_is" = "$sum_should" ]
then
echo 'present'
else
echo 'mismatch'
fi

View File

@ -0,0 +1,58 @@
#!/bin/sh -e
download="$( cat "$__object/parameter/download" )"
state_is="$( cat "$__object/explorer/state" )"
if [ "$download" != 'local' ] || [ "$state_is" = 'present' ]
then
exit 0
fi
url="$( cat "$__object/parameter/url" )"
tmp="$( mktemp )"
dst="/$__object_id"
if [ -f "$__object/parameter/cmd-get" ]
then
cmd="$( cat "$__object/parameter/cmd-get" )"
elif command -v wget > /dev/null
then
cmd="wget -O - '%s'"
elif command -v curl > /dev/null
then
cmd="curl -L -o - '%s'"
elif command -v fetch > /dev/null
then
cmd="fetch -o - '%s'"
else
echo 'no usable locally installed utility for downloading' >&2
exit 1
fi
printf "$cmd > %s\n" \
"$url" \
"$tmp"
if echo "$__target_host" | grep -Eq '^[0-9a-fA-F:]+$'
then
target_host="[$__target_host]"
else
target_host="$__target_host"
fi
printf '%s %s %s:%s\n' \
"$__remote_copy" \
"$tmp" \
"$target_host" \
"$dst"
echo "rm -f '$tmp'"
echo 'downloaded' > "$__messages_out"

View File

@ -0,0 +1,25 @@
#!/bin/sh -e
download="$( cat "$__object/parameter/download" )"
state_is="$( cat "$__object/explorer/state" )"
if [ "$download" = 'remote' ] && [ "$state_is" != 'present' ]
then
cmd="$( cat "$__object/explorer/remote_cmd" )"
url="$( cat "$__object/parameter/url" )"
dst="/$__object_id"
printf "$cmd > %s\n" \
"$url" \
"$dst"
echo 'downloaded' > "$__messages_out"
fi
if [ -f "$__object/parameter/onchange" ] && [ "$state_is" != "present" ]
then
cat "$__object/parameter/onchange"
fi

View File

@ -0,0 +1,86 @@
cdist-type__download(7)
=======================
NAME
----
cdist-type__download - Download a file
DESCRIPTION
-----------
Destination (``$__object_id``) in target host must be persistent storage
in order to calculate checksum and decide if file must be (re-)downloaded.
By default type will try to use ``wget``, ``curl`` or ``fetch``.
If download happens in target (see ``--download``) then type will
fallback to (and install) ``wget``.
If download happens in local machine, then environment variables like
``{http,https,ftp}_proxy`` etc can be used on cdist execution
(``http_proxy=foo cdist config ...``).
REQUIRED PARAMETERS
-------------------
url
File's URL.
sum
Checksum of file going to be downloaded.
By default output of ``cksum`` without filename is expected.
Other hash formats supported with prefixes: ``md5:``, ``sha1:`` and ``sha256:``.
OPTIONAL PARAMETERS
-------------------
download
If ``local`` (default), then download file to local storage and copy
it to target host. If ``remote``, then download happens in target.
cmd-get
Command used for downloading.
Command must output to ``stdout``.
Parameter will be used for ``printf`` and must include only one
format specification ``%s`` which will become URL.
For example: ``wget -O - '%s'``.
cmd-sum
Command used for checksum calculation.
Command output and ``--sum`` parameter must match.
Parameter will be used for ``printf`` and must include only one
format specification ``%s`` which will become destination.
For example: ``md5sum '%s' | awk '{print $1}'``.
onchange
Execute this command after download.
EXAMPLES
--------
.. code-block:: sh
__directory /opt/cpma
require='__directory/opt/cpma' \
__download /opt/cpma/cnq3.zip \
--url https://cdn.playmorepromode.com/files/cnq3/cnq3-1.51.zip \
--sum md5:46da3021ca9eace277115ec9106c5b46
require='__download/opt/cpma/cnq3.zip' \
__unpack /opt/cpma/cnq3.zip \
--move-existing-destination \
--destination /opt/cpma/server
AUTHORS
-------
Ander Punnar <ander-at-kvlt-dot-ee>
COPYING
-------
Copyright \(C) 2020 Ander Punnar. 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,6 @@
#!/bin/sh -e
if grep -Eq '^wget' "$__object/explorer/remote_cmd"
then
__package wget
fi

View File

@ -0,0 +1 @@
local

View File

@ -0,0 +1,4 @@
cmd-get
cmd-sum
download
onchange

View File

@ -0,0 +1,2 @@
url
sum

View File

@ -31,10 +31,10 @@ fallback() {
gid=$(echo "$ls_line" | awk '{ print $4 }')
owner=$(awk -F: -v uid="$uid" '$3 == uid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/passwd)
group=$(awk -F: -v uid="$uid" '$3 == uid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/group)
group=$(awk -F: -v gid="$gid" '$3 == gid { print $1; f=1 } END { if (!f) print "UNKNOWN" }' /etc/group)
mode_text=$(echo "$ls_line" | awk '{ print $1 }')
mode=$(echo "$mode_text" | awk '{ k=0; for (i=0; i<=8; i++) k += ((substr($1, i+2, 1) ~ /[rwx]/) * 2^(8-i)); printf("%0o", k) }')
mode=$(echo "$mode_text" | awk '{for(i=8;i>=0;--i){c=substr($1,10-i,1);k+=((c~/[rwxst]/)*2^i);if(!(i%3))k+=(tolower(c)~/[lst]/)*2^(9+i/3)}printf("%04o",k)}')
size=$(echo "$ls_line" | awk '{ print $5 }')
links=$(echo "$ls_line" | awk '{ print $2 }')
@ -53,64 +53,32 @@ fallback() {
[ -e "$destination" ] || exit 0
if ! command -v stat >/dev/null
then
command -v stat >/dev/null 2>&1 || {
fallback
exit
fi
}
case $("$__explorer/os")
in
freebsd|netbsd|openbsd|macosx)
stat -f "type: %HT
stat -f 'type: %HT
owner: %Du %Su
group: %Dg %Sg
mode: %Lp %Sp
mode: %Mp%03Lp %Sp
size: %Dz
links: %Dl
" "$destination" | awk '/^type/ { print tolower($0); next } { print }'
' "$destination" | awk '/^type/ { print tolower($0); next } { print }'
;;
solaris)
ls1="$( ls -ld "$destination" )"
ls2="$( ls -ldn "$destination" )"
if [ -f "$__object/parameter/mode" ]
then mode_should="$( cat "$__object/parameter/mode" )"
fi
# yes, it is ugly hack, but if you know better way...
if [ -z "$( find "$destination" -perm "$mode_should" )" ]
then octets=888
else octets="$( echo "$mode_should" | sed 's/^0//' )"
fi
case "$( echo "$ls1" | cut -c1-1 )" in
-) echo 'type: regular file' ;;
d) echo 'type: directory' ;;
esac
echo "owner: $( echo "$ls2" \
| awk '{print $3}' ) $( echo "$ls1" \
| awk '{print $3}' )"
echo "group: $( echo "$ls2" \
| awk '{print $4}' ) $( echo "$ls1" \
| awk '{print $4}' )"
echo "mode: $octets $( echo "$ls1" | awk '{print $1}' )"
echo "size: $( echo "$ls1" | awk '{print $5}' )"
echo "links: $( echo "$ls1" | awk '{print $2}' )"
;;
*)
# NOTE: Do not use --printf here as it is not supported by BusyBox stat.
# NOTE: BusyBox's stat might not support the "-c" option, in which case
# we fall through to the shell fallback.
stat -c "type: %F
stat -c 'type: %F
owner: %u %U
group: %g %G
mode: %a %A
mode: %04a %A
size: %s
links: %h" "$destination" 2>/dev/null || fallback
;;
links: %h' "$destination" 2>/dev/null || fallback
;;
esac

View File

@ -68,9 +68,11 @@ case "$state_should" in
if [ -f "$__object/parameter/$attribute" ]; then
value_should="$(cat "$__object/parameter/$attribute")"
# change 0xxx format to xxx format => same as stat returns
# format mode in four digits => same as stat returns
if [ "$attribute" = mode ]; then
value_should="$(echo "$value_should" | sed 's/^0\(...\)/\1/')"
# Convert to four-digit octal number (printf interprets
# strings with leading 0s as octal!)
value_should=$(printf '%04o' "0${value_should}")
fi
value_is="$(get_current_value "$attribute" "$value_should")"

View File

@ -50,13 +50,13 @@ state
create or modify it
group
Group to chgrp to.
Group to chgrp to. Defaults to ``root``.
mode
Unix permissions, suitable for chmod.
Unix permissions, suitable for chmod. Defaults to a very secure ``0600``.
owner
User to chown to.
User to chown to. Defaults to ``root``.
source
If supplied, copy this file from the host running cdist to the target.

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

@ -88,7 +88,7 @@ if [ "$state" = "present" ]; then
fi
done
if [ "$os" = "freebsd" ]; then
echo pw groupadd "$@" "$name"
echo pw groupadd "$name" "$@"
else
echo groupadd "$@" "$name"
fi

View File

@ -25,6 +25,10 @@ ip
state is ``present``, this parameter is mandatory, if state is
``absent``, this parameter is silently ignored.
alias
An alias for the hostname.
This parameter can be specified multiple times (once per alias).
EXAMPLES
--------
@ -36,6 +40,8 @@ EXAMPLES
# previously configured via __hosts.
__hosts happy --state absent
__hosts srv1.example.com --ip 192.168.0.42 --alias srv1
SEE ALSO
--------
@ -43,13 +49,14 @@ SEE ALSO
AUTHORS
-------
Dmitry Bogatov <KAction@gnu.org>
| Dmitry Bogatov <KAction@gnu.org>
| Dennis Camera <dennis.camera--@--ssrq-sds-fds.ch>
COPYING
-------
Copyright (C) 2015,2016 Dmitry Bogatov. Free use of this software is granted
under the terms of the GNU General Public License version 3 or later
(GPLv3+).
Copyright \(C) 2015-2016 Dmitry Bogatov, 2019 Dennis Camera.
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

@ -1,29 +1,42 @@
#!/bin/sh -e
# Copyright (C) 2015 Bogatov Dmitry <KAction@gnu.org>
#
# This program is free software: you can redistribute it and/or modify
# Copyright (C) 2015 Bogatov Dmitry <KAction@gnu.org>
# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# 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 this program. If not, see <http://www.gnu.org/licenses/>.
set -ue
#
hostname="$__object_id"
state="$(cat "$__object/parameter/state")"
marker="# __hosts/$hostname"
set -e
set -- "__hosts/$hostname" --file /etc/hosts --state "$state"
hostname=$__object_id
state=$(cat "${__object}/parameter/state")
marker="# __hosts/${hostname}"
if [ "$state" = absent ] ; then
__line "$@" --regex "$marker"
if test "${state}" != 'absent'
then
ip=$(cat "${__object}/parameter/ip")
if test -s "${__object}/parameter/alias"
then
aliases=$(while read -r a; do printf '\t%s' "$a"; done <"$__object/parameter/alias")
fi
set -- --line "$(printf '%s\t%s%s %s' \
"${ip}" "${hostname}" "${aliases}" "${marker}")"
else
ip="$(cat "$__object/parameter/ip")"
__line "$@" --line "$ip $hostname $marker"
set -- --regex "$(echo "${marker}" | sed -e 's/\./\\./')$"
fi
__line "/etc/hosts:${hostname}" --file /etc/hosts --state "${state}" "$@"

View File

@ -0,0 +1 @@
alias

View File

@ -40,7 +40,9 @@ else
fi
export key state delimiter value exact_delimiter
awk -f - "$file" <<"AWK_EOF"
awk_bin=$(PATH=$(getconf PATH 2>/dev/null) && command -v awk || echo awk)
"${awk_bin}" -f - "$file" <<"AWK_EOF"
BEGIN {
state=ENVIRON["state"]
key=ENVIRON["key"]

View File

@ -24,7 +24,10 @@ if [ -f "$file" ]; then
else
touch "$file"
fi
awk -f - "$file" >"$tmpfile" <<"AWK_EOF"
awk_bin=$(PATH=$(getconf PATH 2>/dev/null) && command -v awk || echo awk)
"${awk_bin}" -f - "$file" >"$tmpfile" <<"AWK_EOF"
BEGIN {
# import variables in a secure way ..
state=ENVIRON["state"]

View File

@ -25,7 +25,7 @@ state_should="$(cat "$__object/parameter/state")"
state_is="$(cat "$__object/explorer/state")"
fire_onchange=''
if [ "$state_is" = "$state_should" ]; then
if [ "$state_is" = "$state_should" ]; then
exit 0
fi

View File

@ -91,6 +91,9 @@ if [ -z "${certbot_fullpath}" ]; then
certbot_fullpath=/usr/local/bin/certbot
;;
ubuntu)
__package certbot
;;
*)
echo "Unsupported os: $os" >&2
exit 1

View File

@ -18,7 +18,7 @@ source
Specifies the link source.
type
Specifies the link type: Either hard or symoblic.
Specifies the link type: Either hard or symbolic.
OPTIONAL PARAMETERS

View File

@ -3,6 +3,7 @@
# 2012-2016 Steven Armstrong (steven-cdist at armstrong.cc)
# 2016 Carlos Ortigoza (carlos.ortigoza at ungleich.ch)
# 2016 Nico Schottelius (nico.schottelius at ungleich.ch)
# 2020 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
#
# This file is part of cdist.
#
@ -23,17 +24,171 @@
# 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
catval() {
# shellcheck disable=SC2059
printf "$($quote_value && echo '"%s"' || echo '%s')" "$(cat "$1")"
}
state_should=$(cat "${__object}/parameter/state")
os=$(cat "$__global/explorer/os")
case "$os" in
debian|ubuntu)
case $os
in
debian)
if version_ge 4 <"${__global}/explorer/os_version"
then
# Debian 4 (etch) and later
locale_conf="/etc/default/locale"
else
locale_conf="/etc/environment"
fi
;;
devuan)
locale_conf="/etc/default/locale"
;;
ubuntu)
if version_ge 6.10 <"${__global}/explorer/os_version"
then
# Ubuntu 6.10 (edgy) and later
locale_conf="/etc/default/locale"
else
locale_conf="/etc/environment"
fi
;;
archlinux)
locale_conf="/etc/locale.conf"
;;
redhat|centos)
locale_conf="/etc/sysconfig/i18n"
centos|redhat|scientific)
# shellcheck source=/dev/null
version_id=$(. "${__global}/explorer/os_release" && echo "${VERSION_ID:-0}")
if echo "${version_id}" | version_ge 7
then
locale_conf="/etc/locale.conf"
else
locale_conf="/etc/sysconfig/i18n"
fi
;;
fedora)
# shellcheck source=/dev/null
version_id=$(. "${__global}/explorer/os_release" && echo "${VERSION_ID:-0}")
if echo "${version_id}" | version_ge 18
then
locale_conf="/etc/locale.conf"
quote_value=false
else
locale_conf="/etc/sysconfig/i18n"
fi
;;
gentoo)
case $(cat "${__global}/explorer/init")
in
(*openrc*)
locale_conf="/etc/env.d/02locale"
onchange_cmd="env-update --no-ldconfig"
quote_value=true
;;
(systemd)
locale_conf="/etc/locale.conf"
;;
esac
;;
freebsd|netbsd)
# NetBSD doesn't have a separate configuration file to set locales.
# In FreeBSD locales could be configured via /etc/login.conf but parsing
# that would be annoying, so the shell login file will have to do.
# "Non-POSIX" shells like csh will not be updated here.
locale_conf="/etc/profile"
quote_value=true
value="$(catval "${__object}/parameter/value"); export ${key}"
;;
solaris)
locale_conf="/etc/default/init"
locale_conf_group="sys"
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
locale_conf_mode=0644
# Oracle Solaris 11.2 and later uses SMF to store environment info.
# This is a hack, but I didn't feel like modifying the whole type
# just for some Oracle nonsense.
# 11.3 apparently added nlsadm(1m), but it is missing from 11.2.
# Illumos continues to use /etc/default/init
# NOTE: Remember not to use "cool" POSIX features like -q or -e with
# Solaris grep.
release_regex='Oracle Solaris 11.[2-9][0-9]*'
case $state_should
in
(present)
svccfg_cmd="svccfg -s svc:/system/environment:init setprop environment/${key} = astring: '$(cat "${__object}/parameter/value")'"
;;
(absent)
svccfg_cmd="svccfg -s svc:/system/environment:init delprop environment/${key}"
;;
esac
refresh_cmd='svcadm refresh svc:/system/environment'
onchange_cmd="grep '${release_regex}' /etc/release >&- || exit 0; ${svccfg_cmd:-:} && ${refresh_cmd}"
else
locale_conf_mode=0555
fi
;;
slackware)
# NOTE: lang.csh (csh config) is ignored here.
locale_conf="/etc/profile.d/lang.sh"
locale_conf_mode=0755
key="export ${__object_id}"
;;
suse)
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
if expr "${os_major}" '>=' 15 \& "${os_major}" != 42
then
# It seems that starting with SuSE 15 the systemd /etc/locale.conf
# is the preferred way to set locales, although
# /etc/sysconfig/language is still available.
# Older documentation doesn't mention /etc/locale.conf, even though
# is it created when localectl is used.
locale_conf="/etc/locale.conf"
else
locale_conf="/etc/sysconfig/language"
quote_value=true
key="RC_${__object_id}"
fi
;;
voidlinux)
locale_conf="/etc/locale.conf"
;;
*)
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
@ -42,14 +197,16 @@ case "$os" in
;;
esac
__file "$locale_conf" \
--owner root --group root --mode 644 \
--state exists
__file "${locale_conf}" --state exists \
--owner "${locale_conf_owner:-0}" \
--group "${locale_conf_group:-0}" \
--mode "${locale_conf_mode:-0644}"
require="__file/$locale_conf" \
__key_value "$locale_conf:$__object_id" \
--file "$locale_conf" \
--key "$__object_id" \
--delimiter = \
--state "$(cat "$__object/parameter/state")" \
--value "$(cat "$__object/parameter/value")"
require="__file/${locale_conf}" \
__key_value "${locale_conf}:${key#export }" \
--file "${locale_conf}" \
--key "${key}" \
--delimiter '=' --exact_delimiter \
--state "${state_should}" \
--value "${value:-$(catval "${__object}/parameter/value")}" \
--onchange "${onchange_cmd}"

View File

@ -22,13 +22,6 @@
os=$(cat "$__global/explorer/os")
case "$os" in
debian|ubuntu|devuan)
# Debian and Ubuntu need to be updated,
# as seen in /etc/init.d/bootlogs
echo "uname -snrvm > /var/run/motd"
echo "cat /etc/motd.tail >> /var/run/motd"
;;
freebsd)
# FreeBSD only updates /etc/motd on boot,
# as seen in /etc/rc.d/motd

View File

@ -33,10 +33,6 @@ os=$(cat "$__global/explorer/os")
case "$os" in
debian|ubuntu|devuan)
# Debian-based systems use /etc/motd.tail as a template
destination=/etc/motd.tail
;;
freebsd)
# FreeBSD uses motd.template to prepend system information on boot
# (this actually only applies starting with version 13,

View File

@ -31,8 +31,8 @@ manager-password-hash
Generate e.g. with: `slappasswd -s weneedgoodsecurity`.
See `slappasswd(8C)`, `slapd.conf(5)`.
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).
At that point, manager-password-hash should be deprecated and ignored.
to derive from the manager-password parameter and ensure idempotency (care with salts).
At that point, manager-password-hash should be deprecated and ignored.
serverid
The server for the directory.
@ -103,8 +103,8 @@ syncrepl-host
Set once per host that will replicate the directory.
module
LDAP module to load. See `slapd.conf(5)`.
Default value is OS-dependent, see manifest.
LDAP module to load. See `slapd.conf(5)`. Some dependencies might have to
be installed beforehand. Default value is OS-dependent, see manifest.
schema
Name of LDAP schema to load. Must be the name without extension of a

View File

@ -25,6 +25,7 @@ case "${os}" in
SLAPD_DATA_DIR="/var/db/openldap-data"
SLAPD_RUN_DIR="/var/run/openldap"
SLAPD_MODULE_PATH="/usr/local/libexec/openldap"
SLAPD_MODULE_TYPE="la"
if [ -z "${slapd_modules}" ]; then
# It looks like ppolicy and syncprov must be compiled
slapd_modules="back_mdb back_monitor"
@ -43,13 +44,34 @@ case "${os}" in
SLAPD_DATA_DIR="/var/lib/ldap"
SLAPD_RUN_DIR="/var/run/slapd"
SLAPD_MODULE_PATH="/usr/lib/ldap"
SLAPD_MODULE_TYPE="la"
if [ -z "${slapd_modules}" ]; then
slapd_modules="back_mdb ppolicy syncprov back_monitor"
fi
CONF_OWNER="openldap"
CONF_GROUP="openldap"
if [ -z "${tls_cipher_suite}" ]; then
tls_cipher_suite="NORMAL"
fi
;;
alpine)
PKGS="openldap openldap-clients"
ETC="/etc"
SLAPD_DIR="/etc/openldap"
SLAPD_DATA_DIR="/var/lib/openldap"
SLAPD_RUN_DIR="/var/run/openldap"
SLAPD_MODULE_PATH="/usr/lib/openldap"
SLAPD_MODULE_TYPE="so"
if [ -z "${slapd_modules}" ]; then
slapd_modules="back_mdb ppolicy syncprov back_monitor"
PKGS="$PKGS openldap-back-mdb openldap-back-monitor openldap-overlay-all"
fi
CONF_OWNER="ldap"
CONF_GROUP="$SLAPD_USER"
if [ -z "${tls_cipher_suite}" ]; then
tls_cipher_suite="DEFAULT"
fi
;;
*)
echo "Don't know the openldap defaults for: $os" >&2
exit 1
@ -156,6 +178,12 @@ case "${os}" in
--line "SLAPD_SERVICES=\"${slapd_urls}\"" \
--state present
;;
alpine)
require="__package/${PKG_MAIN}" __line add_slapd_services \
--file ${ETC}/conf.d/slapd \
--line "command_args=\"-h '${slapd_urls}'\"" \
--state present
;;
*)
# Nothing to do here, move on.
;;
@ -170,20 +198,22 @@ if [ -z "${_skip_letsencrypt_cert}" ]; then
fi
# shellcheck disable=SC2086
__letsencrypt_cert "${name}" --admin-email "${admin_email}" \
--renew-hook "cp ${ETC}/letsencrypt/live/${name}/*.pem ${SLAPD_DIR}/sasl2 && chown -R openldap:openldap ${SLAPD_DIR}/sasl2 && service slapd restart" \
--automatic-renewal ${staging}
__directory ${SLAPD_DIR}/sasl2
require="__directory/${SLAPD_DIR}/sasl2" __letsencrypt_cert "${name}" \
--admin-email "${admin_email}" \
--renew-hook "cp ${ETC}/letsencrypt/live/${name}/*.pem ${SLAPD_DIR}/sasl2 && chown -R ${CONF_OWNER}:${CONF_GROUP} ${SLAPD_DIR}/sasl2 && service slapd restart" \
--automatic-renewal "${staging}"
fi
require="__package/${PKG_MAIN}" __directory ${SLAPD_DIR}/slapd.d --state absent
if [ -z "${_skip_letsencrypt_cert}" ]; then
require="__package/${PKG_MAIN} __letsencrypt_cert/${name}" \
__file ${SLAPD_DIR}/slapd.conf --owner ${CONF_OWNER} --group ${CONF_GROUP} --mode 644 \
__file "${SLAPD_DIR}/slapd.conf" --owner "${CONF_OWNER}" --group "${CONF_GROUP}" --mode 644 \
--source "${ldapconf}"
else
require="__package/${PKG_MAIN}" \
__file ${SLAPD_DIR}/slapd.conf --owner ${CONF_OWNER} --group ${CONF_GROUP} --mode 644 \
__file "${SLAPD_DIR}/slapd.conf" --owner "${CONF_OWNER}" --group "${CONF_GROUP}" --mode 644 \
--source "${ldapconf}"
fi
@ -210,7 +240,7 @@ done
# Add specified modules
echo "modulepath ${SLAPD_MODULE_PATH}" >> "${ldapconf}"
for module in ${slapd_modules}; do
echo "moduleload ${module}.la" >> "${ldapconf}"
echo "moduleload ${module}.${SLAPD_MODULE_TYPE}" >> "${ldapconf}"
done
# Rest of the config

View File

@ -64,7 +64,7 @@ esac
# Hint if we need to avoid questions at some point:
# DEBIAN_PRIORITY=critical can reduce the number of questions
aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes --no-install-recommends -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\""
aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes -o APT::Install-Recommends=0 -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\""
if [ "$state_is" = "$state_should" ]; then
if [ -z "$version" ] || [ "$version" = "$version_is" ]; then

View File

@ -1,7 +1,8 @@
#!/bin/sh
#!/bin/sh -e
#
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
# 2012 Giel van Schijndel (giel plus cdist at mortis dot eu)
# 2020 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
#
# This file is part of cdist.
#
@ -19,21 +20,78 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Retrieve the status of a package - parsed opkg output
# Retrieve the status of a package - parses opkg output
#
if [ -f "$__object/parameter/name" ]; then
name="$(cat "$__object/parameter/name")"
readonly __type_path=${__object%%${__object_id}*}
test -d "${__type_path}" || { echo 'Cannot determine __type_path' >&2; exit 1; }
readonly LOCKFILE="${__type_path:?}/.cdist_opkg.lock"
if command -v flock >/dev/null 2>&1
then
# use flock (if available) on FD 9
_lock() {
exec 9<>"${LOCKFILE:?}"
flock -x 9
echo $$>&9
}
_unlock() {
:>"${LOCKFILE:?}"
flock -u 9
exec 9<&-
}
else
name="$__object_id"
# fallback to mkdir if flock is missing
_lock() {
until mkdir "${LOCKFILE:?}.dir" 2>/dev/null
do
while test -d "${LOCKFILE}.dir"
do
# DEBUG:
# printf 'Locked by PID: %u\n' "$(cat "${LOCKFILE}.dir/pid")"
sleep 1
done
done
echo $$ >"${LOCKFILE:?}.dir/pid"
}
_unlock() {
test -d "${LOCKFILE}.dir" || return 0
if test -s "${LOCKFILE}.dir/pid"
then
test "$(cat "${LOCKFILE}.dir/pid")" = $$ || return 1
rm "${LOCKFILE:?}.dir/pid"
fi
rmdir "${LOCKFILE:?}.dir"
}
fi
# Except dpkg failing, if package is not known / installed
if opkg status "$name" 2>/dev/null | grep -q "^Status: install user installed$"; then
echo "present"
exit 0
elif [ "$(opkg info "$name" 2> /dev/null | wc -l)" -eq 0 ]; then
echo "absent notpresent"
exit 0
if test -f "${__object}/parameter/name"
then
pkg_name=$(cat "${__object}/parameter/name")
else
pkg_name=$__object_id
fi
# NOTE: We need to lock parallel execution of type explorers and code-remote
# because opkg will try to acquire the OPKG lock (usually /var/lock/opkg.lock)
# using lockf(2) for every operation.
# It will not wait for the lock but terminate with an error.
# This leads to incorrect 'absent notpresent' statuses when parallel execution
# is enabled.
trap _unlock EXIT
_lock
# Except opkg failing, if package is not known / installed
if opkg status "${pkg_name}" 2>/dev/null \
| grep -q -e '^Status: [^ ][^ ]* [^ ][^ ]* installed$'
then
echo 'present'
elif opkg info "${pkg_name}" 2>/dev/null | grep -q .
then
echo 'absent notpresent'
else
echo 'absent'
fi
echo "absent"

View File

@ -2,6 +2,7 @@
#
# 2011,2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2012 Giel van Schijndel (giel plus cdist at mortis dot eu)
# 2020 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
#
# This file is part of cdist.
#
@ -19,41 +20,50 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Manage packages on OpenWRT and co.
# Manage packages on OpenWrt, optware, and co.
#
if [ -f "$__object/parameter/name" ]; then
name="$(cat "$__object/parameter/name")"
if test -f "${__object}/parameter/name"
then
name=$(cat "${__object}/parameter/name")
else
name="$__object_id"
name=$__object_id
fi
state_should="$(cat "$__object/parameter/state")"
state_should=$(cat "${__object}/parameter/state")
state_is=$(cat "${__object}/explorer/pkg_status")
state_is="$(cat "$__object/explorer/pkg_status")"
case "$state_is" in
absent*)
present="$(echo "$state_is" | cut -d ' ' -f 2)"
state_is="absent"
;;
case $state_is
in
(absent*)
presence=$(echo "${state_is}" | cut -d ' ' -f 2)
state_is='absent'
;;
esac
[ "$state_is" = "$state_should" ] && exit 0
if test "${state_is}" = "${state_should}"
then
exit 0
fi
case "$state_should" in
present)
if [ "$present" = "notpresent" ]; then
echo "opkg --verbosity=0 update"
fi
echo "opkg --verbosity=0 install '$name'"
echo "installed" >> "$__messages_out"
;;
absent)
echo "opkg --verbosity=0 remove '$name'"
echo "removed" >> "$__messages_out"
;;
*)
echo "Unknown state: ${state_should}" >&2
exit 1
;;
case $state_should
in
(present)
if test "${presence}" = 'notpresent'
then
echo 'opkg --verbosity=0 update'
fi
printf "opkg --verbosity=0 install '%s'\n" "${name}"
echo 'installed' >>"${__messages_out}"
;;
(absent)
printf "opkg --verbosity=0 remove '%s'" "${name}"
echo 'removed' >>"${__messages_out}"
;;
(*)
printf 'Unknown state: %s\n' "${state_should}" >&2
exit 1
;;
esac

View File

@ -0,0 +1,10 @@
#!/bin/sh -e
for bin in pip3 pip
do
if check="$( command -v "$bin" )"
then
echo "$check"
break
fi
done

View File

@ -32,7 +32,7 @@ pipparam="$__object/parameter/pip"
if [ -f "$pipparam" ]; then
pip=$(cat "$pipparam")
else
pip="pip"
pip="$( "$__type_explorer/pip" )"
fi
# If there is no pip, it may get created from somebody else.

View File

@ -38,7 +38,12 @@ pipparam="$__object/parameter/pip"
if [ -f "$pipparam" ]; then
pip=$(cat "$pipparam")
else
pip="pip"
pip="$( cat "$__object/explorer/pip" )"
if [ -z "$pip" ]
then
echo 'pip not found in path' >&2
exit 1
fi
fi
runasparam="$__object/parameter/runas"
@ -55,7 +60,7 @@ case "$state_should" in
then
echo "su -c '$pip install -q $name' $runas"
else
echo $pip install -q "$name"
echo "$pip" install -q "$name"
fi
echo "installed" >> "$__messages_out"
;;
@ -64,7 +69,7 @@ case "$state_should" in
then
echo "su -c '$pip uninstall -q -y $name' $runas"
else
echo $pip uninstall -q -y "$name"
echo "$pip" uninstall -q -y "$name"
fi
echo "removed" >> "$__messages_out"
;;

View File

@ -0,0 +1,4 @@
#!/bin/sh -e
if pkg -N >/dev/null 2>&1; then
echo "YES"
fi

View File

@ -21,6 +21,11 @@
# Retrieve the status of a package - parsed dpkg output
#
if ! pkg -N >/dev/null 2>&1; then
# Nothing to do if pkg is not bootstrapped
exit
fi
if [ -f "$__object/parameter/name" ]; then
name="$(cat "$__object/parameter/name")"
else

View File

@ -43,6 +43,7 @@ fi
repo="$(cat "$__object/parameter/repo")"
state="$(cat "$__object/parameter/state")"
curr_version="$(cat "$__object/explorer/pkg_version")"
pkg_bootstrapped="$(cat "$__object/explorer/pkg_bootstrapped")"
add_cmd="pkg install -y"
rm_cmd="pkg delete -y"
upg_cmd="pkg upgrade -y"
@ -73,6 +74,10 @@ execcmd(){
;;
esac
if [ -z "${pkg_bootstrapped}" ]; then
echo "pkg bootstrap -y >/dev/null 2>&1"
fi
echo "$_cmd >/dev/null 2>&1" # Silence the output of the command
echo "status=\$?"
echo "if [ \"\$status\" -ne \"0\" ]; then"

View File

@ -1 +0,0 @@
Consider moving to __pf_apply_anchor. Get in touch if you need __pf_apply.

View File

@ -1,36 +0,0 @@
#!/bin/sh
#
# 2012 Jake Guffey (jake.guffey at eprotex.com)
#
# 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/>.
#
#
# Get the location of the pf ruleset on the target host.
#
# Debug
#exec >&2
#set -x
# Check /etc/rc.conf for pf's configuration file name. Default to /etc/pf.conf
RC="/etc/rc.conf"
PFCONF="$(grep '^pf_rules=' ${RC} | cut -d= -f2 | sed 's/"//g')"
echo "${PFCONF:-"/etc/pf.conf"}"
# Debug
#set +x

View File

@ -1,51 +0,0 @@
#!/bin/sh -e
#
# 2012 Jake Guffey (jake.guffey at eprotex.com)
#
# 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/>.
#
#
# Apply pf(4) ruleset on *BSD
#
# Debug
#exec >&2
#set -x
rcvar=$(cat "$__object/explorer/rcvar")
cat <<EOF
if [ -f "${rcvar}.old" ]; then # rcvar.old exists, we must need to disable pf
# Disable pf
# If it already is disabled, pfctl -d returns 1, go on with life
pfctl -d || true
# Cleanup
rm -f "${rcvar}.old"
elif [ -f "${rcvar}.new" ]; then # rcvar.new exists, we must need to apply it
# Ensure that pf is enabled in the first place
# If it already is enabled, pfctl -e returns 1, go on with life
mv "${rcvar}.new" "${rcvar}"
pfctl -e || true
pfctl -f "${rcvar}"
if [ "\$?" -ne "0" ]; then # failed to configure new ruleset
echo "Failed to configure the new ruleset on ${__target_host}!" >&2
fi
fi
EOF
# Debug
#set +x

View File

@ -1,55 +0,0 @@
cdist-type__pf_apply(7)
=======================
NAME
----
cdist-type__pf_apply - Apply pf(4) ruleset on \*BSD
DESCRIPTION
-----------
This type is used on \*BSD systems to manage the pf firewall's active ruleset.
REQUIRED PARAMETERS
-------------------
NONE
OPTIONAL PARAMETERS
-------------------
NONE
EXAMPLES
--------
.. code-block:: sh
# Modify the ruleset on $__target_host:
__pf_ruleset --state present --source /my/pf/ruleset.conf
require="__pf_ruleset" \
__pf_apply
# Remove the ruleset on $__target_host (implies disabling pf(4):
__pf_ruleset --state absent
require="__pf_ruleset" \
__pf_apply
SEE ALSO
--------
:strong:`pf`\ (4), :strong:`cdist-type__pf_ruleset`\ (7)
AUTHORS
-------
Jake Guffey <jake.guffey--@--eprotex.com>
COPYING
-------
Copyright \(C) 2012 Jake Guffey. 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

@ -67,7 +67,7 @@ case "$state_should" in
remove_entry
fi
cat << DONE
cat >> "$config" << ${__type##*/}_DONE
cat >> "$config" << "${__type##*/}_DONE"
$(cat "$entry")
${__type##*/}_DONE
DONE

View File

@ -4,6 +4,5 @@ unpriv
chroot
wakeup
maxproc
option
comment
state

View File

@ -0,0 +1 @@
option

View File

@ -1,6 +1,7 @@
#!/bin/sh -e
#
# 2016 Darko Poljak (darko.poljak at gmail.com)
# 2020 Nico Schotetlius (nico.schottelius at ungleich.ch)
#
# This file is part of cdist.
#
@ -45,7 +46,7 @@ then
pyvenv=$(cat "$pyvenvparam")
else
case "$os" in
alpine) # no pyvenv on alpine - I assume others will follow
alpine|ubuntu) # no pyvenv on alpine - I assume others will follow
pyvenv="python3 -m venv"
;;
*)

View File

@ -9,7 +9,7 @@ cdist-type__pyvenv - Create or remove python virtual environment
DESCRIPTION
-----------
This cdist type allows you to create or remove python virtual
environment using pyvenv.
environment using pyvenv on python3 -m venv.
It assumes pyvenv is already installed. Concrete package depends
on concrete OS and/or OS version/distribution.
Ensure this for e.g. in your init manifest as in the following example:
@ -57,7 +57,7 @@ EXAMPLES
__pyvenv /home/services/djangoenv
# Use specific pyvenv
# Use specific pyvenv
__pyvenv /home/foo/fooenv --pyvenv /usr/local/bin/pyvenv-3.4
# Create python virtualenv for user foo.
@ -76,4 +76,3 @@ COPYING
-------
Copyright \(C) 2016 Darko Poljak. Free use of this software is
granted under the terms of the GNU General Public License v3 or later (GPLv3+).

View File

@ -15,25 +15,27 @@ This type was created to be used by the __ssh_authorized_keys type.
REQUIRED PARAMETERS
-------------------
file
the authorized_keys file to which the given key should be added
The authorized_keys file where the given key should be managed.
key
a string containing the ssh keytype, base 64 encoded key and optional
trailing comment which shall be added to the given authorized_keys file.
The ssh key which shall be managed in this authorized_keys file.
Must be a string containing the ssh keytype, base 64 encoded key and
optional trailing comment which shall be added to the given
authorized_keys file.
OPTIONAL PARAMETERS
-------------------
comment
explicit comment instead of the one which may be trailing the given key
Use this comment instead of the one which may be trailing in the key.
option
an option to set for this authorized_key entry.
An option to set for this authorized_key entry.
Can be specified multiple times.
See sshd(8) for available options.
state
if the given keys should be 'present' or 'absent', defaults to 'present'.
If the managed key should be 'present' or 'absent', defaults to 'present'.
MESSAGES
@ -64,7 +66,7 @@ EXAMPLES
SEE ALSO
--------
:strong:`cdist__ssh_authorized_keys`\ (7), :strong:`sshd`\ (8)
:strong:`cdist-type__ssh_authorized_keys`\ (7), :strong:`sshd`\ (8)
AUTHORS

View File

@ -0,0 +1,9 @@
#!/bin/sh -e
# shellcheck disable=SC1090
file="$( . "$__type_explorer/file" )"
if [ -f "$file" ]
then
cat "$file"
fi

View File

@ -20,42 +20,48 @@ then left to the user to ensure that the file exists and that ownership and
permissions work with ssh.
REQUIRED PARAMETERS
-------------------
REQUIRED MULTIPLE PARAMETERS
----------------------------
key
the ssh key which shall be added to this authorized_keys file.
Must be a string and can be specified multiple times.
An ssh key which shall be managed in this authorized_keys file.
Must be a string containing the ssh keytype, base 64 encoded key and
optional trailing comment which shall be added to the given
authorized_keys file.
Can be specified multiple times.
OPTIONAL PARAMETERS
-------------------
comment
explicit comment instead of the one which may be trailing the given key
Use this comment instead of the one which may be trailing in each key.
file
an alternative destination file, defaults to ~$owner/.ssh/authorized_keys
An alternative destination file, defaults to ~$owner/.ssh/authorized_keys.
option
an option to set for all created authorized_key entries.
An option to set for all authorized_key entries in the key parameter.
Can be specified multiple times.
See sshd(8) for available options.
owner
the user owning the authorized_keys file, defaults to object_id.
The user owning the authorized_keys file, defaults to object_id.
state
if the given keys should be 'present' or 'absent', defaults to 'present'.
If the given keys should be 'present' or 'absent', defaults to 'present'.
BOOLEAN PARAMETERS
------------------
noparent
don't create or change ownership and permissions of the directory containing
the authorized_keys file
Don't create or change ownership and permissions of the directory containing
the authorized_keys file.
nofile
don't manage existence, ownership and permissions of the the authorized_keys
file
Don't manage existence, ownership and permissions of the the authorized_keys
file.
remove-unknown
Remove undefined keys.
EXAMPLES
@ -67,6 +73,12 @@ EXAMPLES
__ssh_authorized_keys root \
--key "$(cat ~/.ssh/id_rsa.pub)"
# same as above, but make sure your key is only key in
# root's authorized_keys file
__ssh_authorized_keys root \
--key "$(cat ~/.ssh/id_rsa.pub)" \
--remove-unknown
# allow key to login as user-name
__ssh_authorized_keys user-name \
--key "ssh-rsa AXYZAAB3NzaC1yc2..."

View File

@ -55,8 +55,12 @@ _cksum() {
echo "$1" | cksum | cut -d' ' -f 1
}
_type_and_key() {
echo "$1" | tr ' ' '\n' | awk '/^(ssh|ecdsa)-[^ ]+/ { printf $1" "; getline; printf $1 }'
}
while read -r key; do
type_and_key="$(echo "$key" | tr ' ' '\n' | awk '/^(ssh|ecdsa)-[^ ]+/ { printf $1" "; getline; printf $1 }')"
type_and_key="$( _type_and_key "$key" )"
object_id="$(_cksum "$file")-$(_cksum "$type_and_key")"
set -- "$object_id"
set -- "$@" --file "$file"
@ -72,3 +76,24 @@ while read -r key; do
# Ensure __ssh_authorized_key does not read stdin
__ssh_authorized_key "$@" < /dev/null
done < "$__object/parameter/key"
if [ -f "$__object/parameter/remove-unknown" ] &&
[ -s "$__object/explorer/keys" ]
then
while read -r key
do
type_and_key="$( _type_and_key "$key" )"
if grep -Fq "$type_and_key" "$__object/parameter/key"
then
continue
fi
__ssh_authorized_key "remove-$( _cksum "$file$key" )" \
--file "$file" \
--key "$key" \
--state absent \
< /dev/null
done \
< "$__object/explorer/keys"
fi

View File

@ -1,2 +1,3 @@
noparent
nofile
remove-unknown

View File

@ -1,5 +1,4 @@
comment
file
option
owner
state

View File

@ -0,0 +1 @@
option

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/sh -e
#
# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
@ -18,5 +18,10 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
if test "$(uname -s)" = NetBSD
then
PATH=$(getconf PATH)
fi
# get the current runtime value
sysctl -n "$__object_id" || true
sysctl -n "${__object_id}" || true

View File

@ -44,6 +44,8 @@ case "$os" in
flag='-w'
;;
netbsd)
# shellcheck disable=SC2016
echo 'PATH=$(getconf PATH)'
flag='-w'
;;
freebsd|openbsd)

View File

@ -26,6 +26,13 @@ EXAMPLES
__sysctl net.ipv4.ip_forward --value 1
# On some operating systems, e.g. NetBSD, to prevent an error if the
# MIB style name does not exist (e.g. optional kernel components),
# name and value can be separated by `?=`. The same effect can be achieved
# in cdist by appending a `?` to the key:
__sysctl ddb.onpanic? --value -1
AUTHORS
-------

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
@ -27,19 +28,24 @@ EXAMPLES
.. code-block:: sh
#Set up Europe/Andorra as our timezone.
__timezone Europe/Andorra
# Set up Europe/Andorra as our timezone.
__timezone --tz Europe/Andorra
#Set up US/Central as our timezone.
__timezone US/Central
# Set up US/Central as our timezone.
__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

@ -0,0 +1,37 @@
#!/bin/sh -e
src="/$__object_id"
if [ -f "$__object/parameter/sum-file" ]
then
src_sum_was_file="$( cat "$__object/parameter/sum-file" )"
else
src_sum_was_file="$src.cdist__unpack_sum"
fi
if [ ! -f "$src" ]
then
if [ -n "$__cdist_dry_run" ]
then
echo 'mismatch'
else
echo 'missing'
fi
else
if [ ! -f "$src_sum_was_file" ]
then
echo 'mismatch'
exit 0
fi
src_sum_was="$( cat "$src_sum_was_file" )"
src_sum_is="$( cksum "$src" | awk '{ print $1$2 }' )"
if [ "$src_sum_was" = "$src_sum_is" ]
then
echo 'match'
else
echo 'mismatch'
fi
fi

View File

@ -0,0 +1,87 @@
#!/bin/sh -e
if grep -Eq '^(missing|match)$' "$__object/explorer/state"
then
exit 0
fi
os="$( cat "$__global/explorer/os" )"
src="/$__object_id"
dst="$( sed 's/\/$//' "$__object/parameter/destination" )"
cmd=''
case "$src" in
*.tar|*.tgz|*.tar.*)
cmd="mkdir -p '$dst' && tar --directory='$dst' --extract --file='$src'"
if [ -f "$__object/parameter/tar-strip" ]
then
tar_strip="$( cat "$__object/parameter/tar-strip" )"
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
centos|fedora|redhat)
cmd='7za'
;;
*)
cmd='7zr'
;;
esac
cmd="$cmd e -aoa -o'$dst' '$src'"
;;
*.bz2)
cmd="bunzip2 --stdout '$src' > '$dst'"
;;
*.gz)
cmd="gunzip --stdout '$src' > '$dst'"
;;
*.lzma|*.xz)
cmd="xz --uncompress --stdout '$src' > '$dst'"
;;
*.rar)
cmd="unrar x -o+ '$src' '$dst/'"
;;
*.zip)
cmd="unzip -o '$src' -d '$dst'"
;;
esac
if [ -f "$__object/parameter/backup-destination" ]
then
echo "if [ -e '$dst' ]; then mv '$dst' '$dst.cdist__unpack_backup_$( date +%s )'; fi"
fi
echo "$cmd"
if [ -f "$__object/parameter/sum-file" ]
then
sum_file="$( cat "$__object/parameter/sum-file" )"
else
sum_file="$src.cdist__unpack_sum"
fi
echo "cksum '$src' | awk '{ print \$1\$2 }' > '$sum_file'"
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

@ -0,0 +1,93 @@
cdist-type__unpack(7)
=====================
NAME
----
cdist-type__unpack - Unpack archives
DESCRIPTION
-----------
Unpack ``.tar``, ``.tgz``, ``.tar.*``, ``.7z``, ``.bz2``, ``.gz``,
``.lzma``, ``.xz``, ``.rar`` and ``.zip`` archives. Archive type is
detected by extension.
To achieve idempotency, checksum file will be created in target. See
``--sum-file`` parameter for details.
REQUIRED PARAMETERS
-------------------
destination
Depending on archive format file or directory to where archive
contents will be written.
OPTIONAL PARAMETERS
-------------------
sum-file
Override archive's checksum file in target. By default
``XXX.cdist__unpack_sum`` will be used, where ``XXX`` is source
archive path. This file must be kept in target's persistent storage.
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
---------------------------
backup-destination
By default destination file will be overwritten. In case destination
is directory, files from archive will be added to or overwritten in
directory. This parameter moves existing destination to
``XXX.cdist__unpack_backup_YYY``, where ``XXX`` is destination and
``YYY`` current UNIX timestamp.
preserve-archive
Don't delete archive after unpacking.
onchange
Execute this command after unpack.
EXAMPLES
--------
.. code-block:: sh
__directory /opt/cpma
require='__directory/opt/cpma' \
__download /opt/cpma/cnq3.zip \
--url https://cdn.playmorepromode.com/files/cnq3/cnq3-1.51.zip \
--sum md5:46da3021ca9eace277115ec9106c5b46
require='__download/opt/cpma/cnq3.zip' \
__unpack /opt/cpma/cnq3.zip \
--backup-destination \
--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
-------
Ander Punnar <ander-at-kvlt-dot-ee>
COPYING
-------
Copyright \(C) 2020 Ander Punnar. 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,41 @@
#!/bin/sh -e
os="$( cat "$__global/explorer/os" )"
src="/$__object_id"
case "$src" in
*.7z)
__package p7zip
;;
*.bz2)
case "$os" in
freebsd)
# bzip2 is part of freebsd base system
;;
*)
__package bzip2
;;
esac
;;
*.lzma|*.xz|*.txz)
case "$os" in
debian|ubuntu|devuan)
__package xz-utils
;;
alpine|centos)
__package xz
;;
esac
;;
*.rar)
case "$os" in
debian|ubuntu|devuan|alpine|freebsd)
__package unrar
;;
esac
;;
*.zip)
__package unzip
;;
esac

View File

@ -0,0 +1,2 @@
backup-destination
preserve-archive

View File

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

View File

@ -0,0 +1 @@
destination

View File

@ -0,0 +1,3 @@
./make-test-files.sh
./make-init-manifest.sh | cdist config -i - localhost
sudo find /tmp/cdist__unpack_test/ -type f -exec cat {} \; | sort

View File

@ -0,0 +1,22 @@
#!/bin/sh -e
p="$( pwd )"
d=/tmp/cdist__unpack_test
echo 'export CDIST_ORDER_DEPENDENCY=1'
echo "__directory $d"
find "$p" -name 'test.*' -and -not -name '*.cdist__unpack_sum' \
| sort \
| while read -r l
do
n="$( basename "$l" )"
printf '__unpack %s --destination %s/%s\n' \
"$l" \
"$d" \
"$n"
done
echo "__clean_path $p --pattern '.+/test\..+'"

View File

@ -0,0 +1,44 @@
#!/bin/sh -ex
echo test.7z > test
7z a test.7z test > /dev/null
echo test.bz2 > test
bzip2 test
echo test.gz > test
gzip test
echo test.lzma > test
lzma test
echo test.rar > test
rar a test.rar test > /dev/null
echo test.tar.bz2 > test
tar cf test.tar test
bzip2 test.tar
echo test.tar.xz > test
tar cf test.tar test
xz test.tar
echo test.tgz > test
tar cf test.tar test
gzip test.tar
mv test.tar.gz test.tgz
echo test.tar.gz > test
tar cf test.tar test
gzip test.tar
echo test.tar > test
tar cf test.tar test
echo test.xz > test
xz test
echo test.zip > test
zip test.zip test > /dev/null
rm test

View File

@ -23,18 +23,25 @@
name=$__object_id
case $("$__explorer/os") in
'freebsd'|'netbsd'|'openbsd'|'alpine')
case $("${__explorer}/os") in
freebsd|netbsd)
database='passwd'
;;
# Default to using shadow passwords
openbsd)
database='master.passwd'
;;
*)
# Default to using shadow passwords
database='shadow'
;;
esac
if command -v getent >/dev/null; then
getent "$database" "$name" || true
elif [ -f /etc/shadow ]; then
grep "^${name}:" /etc/shadow || true
if command -v getent >/dev/null 2>&1
then
# shellcheck disable=SC2015
getent "${database}" "${name}" 2>/dev/null && exit || true # fallback to file
fi
if test -n "${database}" -a -f "/etc/${database}"
then
grep -e "^${name}:" "/etc/${database}" || true # ignore failure
fi

View File

@ -135,11 +135,19 @@ elif [ "$state" = "absent" ]; then
if grep -q "^${name}:" "$__object/explorer/passwd"; then
#user exists, but state != present, so delete it
if [ -f "$__object/parameter/remove-home" ]; then
printf "userdel -r '%s' >/dev/null 2>&1\\n" "${name}"
echo "userdel -r" >> "$__messages_out"
if [ "$os" = "freebsd" ]; then
printf "pw userdel '%s' -r >/dev/null 2>&1\\n" "${name}"
else
printf "userdel -r '%s' >/dev/null 2>&1\\n" "${name}"
fi
echo "userdel -r" >> "$__messages_out"
else
printf "userdel '%s' >/dev/null 2>&1\\n" "${name}"
echo "userdel" >> "$__messages_out"
if [ "$os" = "freebsd" ]; then
printf "pw userdel '%s' >/dev/null 2>&1\\n" "${name}"
else
printf "userdel '%s' >/dev/null 2>&1\\n" "${name}"
fi
echo "userdel" >> "$__messages_out"
fi
fi
else

View File

@ -1,6 +1,7 @@
#!/bin/sh -e
#
# 2019 Nico Schottelius (nico-cdist at schottelius.org)
# 2020 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
#
# This file is part of cdist.
#
@ -17,16 +18,37 @@
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Manage users.
#
os=$(cat "$__global/explorer/os")
case "$os" in
alpine)
__package shadow
;;
*)
:
;;
case $(cat "${__global}/explorer/os")
in
(alpine)
__package shadow
;;
(openwrt)
case $(cat "${__object}/parameter/state")
in
(present)
if test -s "${__object}/explorer/passwd"
then
# NOTE: The package might not be required if no changes
# are required, but determining if changes are required is
# out of scope here, and 40k should be okay, I hope.
__package shadow-usermod
else
__package shadow-useradd
fi
;;
(absent)
if test -s "${__object}/explorer/passwd"
then
__package shadow-userdel
fi
;;
esac
;;
(*)
:
;;
esac

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 2010-2015 Nico Schottelius (nico-cdist at schottelius.org)
@ -29,18 +28,20 @@ import time
import itertools
import tempfile
import multiprocessing
from cdist.mputil import mp_pool_run, mp_sig_handler
import atexit
import shutil
import socket
from cdist.mputil import mp_pool_run, mp_sig_handler
from cdist import core, inventory
from cdist.util.remoteutil import inspect_ssh_mux_opts
import cdist
import cdist.hostsource
import cdist.exec.local
import cdist.exec.remote
import cdist.util.ipaddr as ipaddr
import cdist.configuration
from cdist import core, inventory
from cdist.util.remoteutil import inspect_ssh_mux_opts
def graph_check_cycle(graph):
@ -70,7 +71,7 @@ def _graph_dfs_cycle(graph, node, path):
return False
class Config(object):
class Config:
"""Cdist main class to hold arbitrary data"""
# list of paths (files and/or directories) that will be removed on finish
@ -174,9 +175,11 @@ class Config(object):
raise cdist.Error(("Cannot read both, manifest and host file, "
"from stdin"))
# if no host source is specified then read hosts from stdin
if not (args.hostfile or args.host):
args.hostfile = '-'
if args.tag or args.all_tagged_hosts:
raise cdist.Error(("Target host tag(s) missing"))
else:
raise cdist.Error(("Target host(s) missing"))
if args.manifest == '-':
# read initial manifest from stdin
@ -195,7 +198,6 @@ class Config(object):
@classmethod
def commandline(cls, args):
"""Configure remote system"""
if (args.parallel and args.parallel != 1) or args.jobs:
if args.timestamp:
cdist.log.setupTimestampingParallelLogging()
@ -203,6 +205,7 @@ class Config(object):
cdist.log.setupParallelLogging()
elif args.timestamp:
cdist.log.setupTimestampingLogging()
log = logging.getLogger("config")
# No new child process if only one host at a time.
@ -381,10 +384,16 @@ class Config(object):
If operating in parallel then return tuple (host, True|False, )
so that main process knows for which host function was successful.
"""
log = logging.getLogger(host)
try:
if args.log_server:
# Start a log server so that nested `cdist config` runs
# have a place to send their logs to.
log_server_socket_dir = tempfile.mkdtemp()
cls._register_path_for_removal(log_server_socket_dir)
cdist.log.setupLogServer(log_server_socket_dir, log)
remote_exec, remote_copy, cleanup_cmd = cls._resolve_remote_cmds(
args)
log.debug("remote_exec for host \"{}\": {}".format(

View File

@ -27,6 +27,7 @@ import cdist.argparse
import re
import multiprocessing
import logging
import sys
class Singleton(type):
@ -246,9 +247,33 @@ class LogLevelOption(OptionBase):
return VerbosityOption().translate(val)
class ColoredOutputOption(BooleanOption):
CHOICES = ('always', 'never', 'auto')
DEFAULT = 'auto'
def get_converter(self):
return self.translate
@staticmethod
def translate(val):
if isinstance(val, bool):
return val
elif val == 'always':
return True
elif val == 'never':
return False
elif val == 'auto':
return 'NO_COLOR' not in os.environ and sys.stdout.isatty()
ColoredOutputOption.DEFAULT = ColoredOutputOption.translate(
ColoredOutputOption.DEFAULT)
_ARG_OPTION_MAPPING = {
'beta': 'beta',
'cache_path_pattern': 'cache_path_pattern',
'colored_output': 'colored_output',
'conf_dir': 'conf_dir',
'manifest': 'init_manifest',
'out_path': 'out_path',
@ -294,6 +319,7 @@ class Configuration(metaclass=Singleton):
'remote_shell': StringOption('remote_shell'),
'cache_path_pattern': StringOption('cache_path_pattern'),
'conf_dir': ConfDirOption(),
'colored_output': ColoredOutputOption('colored_output'),
'init_manifest': StringOption('init_manifest'),
'out_path': StringOption('out_path'),
'remote_out_path': StringOption('remote_out_path'),
@ -319,6 +345,7 @@ class Configuration(metaclass=Singleton):
'CDIST_REMOTE_COPY': 'remote_copy',
'CDIST_INVENTORY_DIR': 'inventory_dir',
'CDIST_CACHE_PATH_PATTERN': 'cache_path_pattern',
'CDIST_COLORED_OUTPUT': 'colored_output',
'__cdist_log_level': 'verbosity',
}
ENV_VAR_BOOLEAN_OPTIONS = ('CDIST_BETA', )
@ -327,11 +354,10 @@ class Configuration(metaclass=Singleton):
}
ARG_OPTION_MAPPING = _ARG_OPTION_MAPPING
ADJUST_ARG_OPTION_MAPPING = {
_ARG_OPTION_MAPPING[key]: key for key in _ARG_OPTION_MAPPING
}
ADJUST_ARG_OPTION_MAPPING = {v: k for k, v in _ARG_OPTION_MAPPING.items()}
REQUIRED_DEFAULT_CONFIG_VALUES = {
'GLOBAL': {
'colored_output': 'auto',
'verbosity': 0,
},
}
@ -484,8 +510,7 @@ class Configuration(metaclass=Singleton):
newconfig = self._read_config_file(config_file)
self._update_config_dict(config, newconfig)
# command line config file
if (self.args and 'config_file' in self.args and
self.args['config_file']):
if (self.args and self.args.get('config_file', None)):
newconfig = self._read_config_file(self.args['config_file'])
self._update_config_dict(config, newconfig)
# command line

View File

@ -47,7 +47,7 @@ class MissingObjectIdError(cdist.Error):
return '%s' % (self.message)
class CdistObject(object):
class CdistObject:
"""Represents a cdist object.
All interaction with objects in cdist should be done through this class.

View File

@ -38,7 +38,7 @@ class InvalidTypeError(cdist.Error):
self.type_path, self.type_absolute_path, self.source_path)
class CdistType(object):
class CdistType:
"""Represents a cdist type.
All interaction with types in cdist should be done through this class.

View File

@ -92,7 +92,7 @@ code-remote
'''
class Code(object):
class Code:
"""Generates and executes cdist code scripts.
"""
@ -116,6 +116,10 @@ class Code(object):
if dry_run:
self.env['__cdist_dry_run'] = '1'
if '__cdist_log_server_socket_export' in os.environ:
self.env['__cdist_log_server_socket'] = os.environ[
'__cdist_log_server_socket_export']
def _run_gencode(self, cdist_object, which):
cdist_type = cdist_object.cdist_type
script = os.path.join(self.local.type_path,

View File

@ -63,7 +63,7 @@ type explorer is:
'''
class Explorer(object):
class Explorer:
"""Executes cdist explorers.
"""

View File

@ -92,7 +92,7 @@ class NoInitialManifestError(cdist.Error):
return repr(self.message)
class Manifest(object):
class Manifest:
"""Executes cdist manifests.
"""
@ -119,6 +119,8 @@ class Manifest(object):
'__cdist_log_level': util.log_level_env_var_val(self.log),
'__cdist_log_level_name': util.log_level_name_env_var_val(
self.log),
'__cdist_colored_log': str(
cdist.log.CdistFormatter.USE_COLORS).lower(),
}
if dry_run:

Some files were not shown because too many files have changed in this diff Show More