Compare commits
220 commits
master
...
pkgng_free
Author | SHA1 | Date | |
---|---|---|---|
f994226d0e | |||
|
652c891858 | ||
84ade29ca9 | |||
|
73d6c9d469 | ||
8ab1b6a03d | |||
84a7818121 | |||
|
b6922508b9 | ||
|
0fc10749ed | ||
|
89a0080e13 | ||
139a782c96 | |||
2e6c12c27c | |||
89b6215115 | |||
decc0ad54d | |||
|
2885c6a248 | ||
|
53b91adbd8 | ||
|
6b262a61c1 | ||
a20ab63e60 | |||
b1375464cc | |||
f5b534df71 | |||
|
b5a40eb0d1 | ||
a4a3b98568 | |||
|
c17541f24c | ||
|
ba26a437be | ||
a8ea56253c | |||
2c1eca9ee7 | |||
52b75e513f | |||
d239169c4f | |||
502d753047 | |||
|
6fed178529 | ||
|
8f94a226c7 | ||
d6b44769e1 | |||
|
fa967631e3 | ||
|
74dd47c8c3 | ||
7b0a4f6831 | |||
54c525e36c | |||
4082359a2f | |||
6f021889ee | |||
17ab4bd80c | |||
|
b370b70ff4 | ||
|
7b480f4293 | ||
|
71710fa00a | ||
|
885d5a58f4 | ||
935f2395bc | |||
d37d2dc307 | |||
7e1428ab3c | |||
|
c053a2c4a0 | ||
|
f5b367dfdb | ||
|
76bb214b53 | ||
a5f25faf25 | |||
a6cd767c8f | |||
|
3a87a447d0 | ||
|
5dfc996feb | ||
|
627d215b63 | ||
5c5890d458 | |||
|
d26c36914a | ||
|
463b6cd6b5 | ||
8a8a48313c | |||
73f1937636 | |||
1b18b9487e | |||
263c7a90a8 | |||
|
70d1228dc0 | ||
|
511d8c96aa | ||
|
a923e75d9b | ||
|
cbf22f3b2c | ||
|
0ae0935afa | ||
|
630d987d5f | ||
|
0ef54a721d | ||
|
47e28fc441 | ||
|
a590504436 | ||
|
46d09392f0 | ||
|
ee71cad047 | ||
|
8b53f35ffa | ||
9df29de564 | |||
|
8654cbe466 | ||
1d5e3a5b06 | |||
|
ae5f0bba0b | ||
5d0f6caef7 | |||
|
595e43b8d5 | ||
|
fdef468f1a | ||
|
d8b5c733f6 | ||
80a0551b36 | |||
|
3965c7f738 | ||
|
8903540e91 | ||
cc089789de | |||
bc97073131 | |||
652ffea4a8 | |||
|
9fb7e151b8 | ||
|
19514662b0 | ||
c62eaa6eab | |||
|
a5ae26116b | ||
|
b8752e9ee3 | ||
506a0f3f47 | |||
|
cb9933b4a0 | ||
fde5627721 | |||
e906266286 | |||
93506d2113 | |||
|
fe193ecab8 | ||
|
88400551f9 | ||
727f3dbb03 | |||
c5a8004c9a | |||
|
3860f1feea | ||
|
6467ccbdcc | ||
|
9e33a8f42f | ||
|
999e7b0134 | ||
|
a263fdfe58 | ||
99b5dcd8f0 | |||
996e7fc09c | |||
b6bf90e3f1 | |||
85614aabd6 | |||
|
077989e8fd | ||
|
7074f9c395 | ||
684043bf37 | |||
ceedcd02f2 | |||
|
5364d3bc90 | ||
|
a9778965be | ||
|
49dde11def | ||
|
3649555f35 | ||
26dfdf37c2 | |||
d478bef8a6 | |||
e67215f93d | |||
|
6aae58dea7 | ||
|
ce07021580 | ||
|
a6a3fb40bf | ||
|
e79b26a61f | ||
|
97e48be39e | ||
|
a6543a72ad | ||
d59ba09d71 | |||
|
cdb998398d | ||
201050a9e5 | |||
|
5be8437a60 | ||
7a48b30d7a | |||
|
59b98091d7 | ||
|
57e352cd1e | ||
|
831bfc822b | ||
|
6e9e9ad557 | ||
|
eba3d0505b | ||
|
eec7ab8e45 | ||
|
4167f9f60c | ||
|
840e417eb7 | ||
|
74e5d7182a | ||
b22e09e1af | |||
7c490a703d | |||
|
955243a93b | ||
|
191f45eb7f | ||
|
58f101b8e8 | ||
|
a251e53495 | ||
|
4a81c019e3 | ||
|
7b262c0cec | ||
|
dc018fdb16 | ||
|
978e249043 | ||
|
e1ff1bfdff | ||
|
46574fc577 | ||
|
3d725f12da | ||
|
f5630297bd | ||
|
be47619b1e | ||
c8a98c02ff | |||
|
89ebd7a4f7 | ||
|
23e66e08fa | ||
|
7a570f8692 | ||
|
790c6efae9 | ||
|
89e48734bf | ||
|
cdb0d2be41 | ||
|
747c6b1076 | ||
|
6a611e556a | ||
|
48d66b0143 | ||
fc9ce280f7 | |||
|
55ebd1a4c5 | ||
|
9a4e3488c2 | ||
3fc36a67a1 | |||
ba77ea9edc | |||
|
988190363a | ||
|
b354ea6e94 | ||
b99f1eda0f | |||
29c0180204 | |||
|
abac79d4a5 | ||
|
ba64971a56 | ||
06cc20aa28 | |||
|
f4e1bbc87e | ||
|
6ba73c4be6 | ||
15e4b5ee3b | |||
b7d3da443c | |||
716d3554f3 | |||
|
66f4421089 | ||
|
226ed02c1c | ||
dab32b0cb6 | |||
d1b73dd42b | |||
3bcbd95269 | |||
bf25a18a04 | |||
|
f354d80308 | ||
cc8dcf682c | |||
ad58ea79c2 | |||
|
f9afac4dd6 | ||
8d639d54d0 | |||
2362d89976 | |||
c5454afc72 | |||
d5075b49c5 | |||
6d502f737a | |||
8b790b0a54 | |||
cf44c4a01b | |||
7ca2bfc14a | |||
086e683c99 | |||
dcfabf9268 | |||
42f2dceeb1 | |||
|
6f4649efc6 | ||
|
d4059fd29e | ||
|
f58d662b32 | ||
|
310045d9fb | ||
|
250161e42d | ||
888cf54d99 | |||
ea3bd14d8b | |||
|
515992249d | ||
cd0c811d74 | |||
965829e18a | |||
bd66b6d948 | |||
b31e13eacf | |||
56a65518ab | |||
0b3c417aef | |||
678df1ec8a | |||
fefc828780 | |||
|
64c247026a |
176 changed files with 2325 additions and 1379 deletions
MakefileREADMEREADME.md
bin
cdist
__init__.pyargparse.py
conf
explorer
type
__clean_path
__cron
__daemontools_service
__directory
__download
__file
__filesystem/explorer
__group
__hosts
__iocage_clone
__key_value
__letsencrypt_acmetiny
__letsencrypt_acmetiny_base
__letsencrypt_cert
__link
__locale_system
__motd
__openldap_server
__package_apt
__package_opkg
__package_pip
__package_pkgng_freebsd
__pf_apply
__pf_rdr
__postfix_master
__pyvenv
__ssh_authorized_key
__ssh_authorized_keys
4
Makefile
4
Makefile
|
@ -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
7
README
|
@ -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
31
README.md
Normal 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
|
|
@ -371,7 +371,6 @@ eof
|
|||
Manual steps post release:
|
||||
- cdist-web
|
||||
- send generated mailinglist.tmp mail
|
||||
- twitter
|
||||
eof
|
||||
;;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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)"
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
;;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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" )"
|
||||
|
||||
|
|
|
@ -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
|
||||
-------
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
exclude
|
||||
onchange
|
||||
path
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -40,12 +40,6 @@ run-file
|
|||
log-run
|
||||
Command to run for log consumption. Default: `multilog t ./main`
|
||||
|
||||
owner
|
||||
User to chown to.
|
||||
|
||||
group
|
||||
User to chgrp to.
|
||||
|
||||
servicedir
|
||||
Directory to install into. Default: `/service`
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@ servicedir=$(cat "$__object/parameter/servicedir")
|
|||
run=$(cat "$__object/parameter/run")
|
||||
runfile=$(cat "$__object/parameter/run-file")
|
||||
logrun=$(cat "$__object/parameter/log-run")
|
||||
owner=$(cat "$__object/parameter/owner")
|
||||
group=$(cat "$__object/parameter/group")
|
||||
|
||||
svc=$(cat "$__type/explorer/svc")
|
||||
|
||||
|
@ -27,22 +25,14 @@ badusage() {
|
|||
[ -z "$run$runfile" ] && badusage
|
||||
[ -n "$run" ] && [ -n "$runfile" ] && badusage
|
||||
|
||||
flags=""
|
||||
if [ -n "$owner" ]; then
|
||||
flags="$flags --owner $owner"
|
||||
fi
|
||||
if [ -n "$group" ]; then
|
||||
flags="$flags --group $group"
|
||||
fi
|
||||
|
||||
__directory "$servicedir/$name/log/main" --parents $flags
|
||||
__directory "$servicedir/$name/log/main" --parents
|
||||
|
||||
echo "$RUN_PREFIX$run" | require="__directory/$servicedir/$name/log/main" __config_file "$servicedir/$name/run" \
|
||||
--onchange "svc -t '$servicedir/$name' 2>/dev/null" \
|
||||
--mode 755 $flags \
|
||||
--mode 755 \
|
||||
--source "${runfile:--}"
|
||||
|
||||
echo "$RUN_PREFIX$logrun" | require="__directory/$servicedir/$name/log/main" __config_file "$servicedir/$name/log/run" \
|
||||
--onchange "svc -t '$servicedir/$name/log' 2>/dev/null" \
|
||||
--mode 755 $flags \
|
||||
--mode 755 \
|
||||
--source "-"
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
group
|
||||
log-run
|
||||
owner
|
||||
run
|
||||
run-file
|
||||
servicedir
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
19
cdist/conf/type/__download/explorer/remote_cmd
Executable file
19
cdist/conf/type/__download/explorer/remote_cmd
Executable 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"
|
72
cdist/conf/type/__download/explorer/state
Executable file
72
cdist/conf/type/__download/explorer/state
Executable 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
|
58
cdist/conf/type/__download/gencode-local
Executable file
58
cdist/conf/type/__download/gencode-local
Executable 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"
|
25
cdist/conf/type/__download/gencode-remote
Executable file
25
cdist/conf/type/__download/gencode-remote
Executable 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
|
86
cdist/conf/type/__download/man.rst
Normal file
86
cdist/conf/type/__download/man.rst
Normal 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.
|
6
cdist/conf/type/__download/manifest
Executable file
6
cdist/conf/type/__download/manifest
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
if grep -Eq '^wget' "$__object/explorer/remote_cmd"
|
||||
then
|
||||
__package wget
|
||||
fi
|
1
cdist/conf/type/__download/parameter/default/download
Normal file
1
cdist/conf/type/__download/parameter/default/download
Normal file
|
@ -0,0 +1 @@
|
|||
local
|
4
cdist/conf/type/__download/parameter/optional
Normal file
4
cdist/conf/type/__download/parameter/optional
Normal file
|
@ -0,0 +1,4 @@
|
|||
cmd-get
|
||||
cmd-sum
|
||||
download
|
||||
onchange
|
2
cdist/conf/type/__download/parameter/required
Normal file
2
cdist/conf/type/__download/parameter/required
Normal file
|
@ -0,0 +1,2 @@
|
|||
url
|
||||
sum
|
|
@ -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
|
||||
|
|
|
@ -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")"
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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}" "$@"
|
||||
|
|
1
cdist/conf/type/__hosts/parameter/optional_multiple
Normal file
1
cdist/conf/type/__hosts/parameter/optional_multiple
Normal file
|
@ -0,0 +1 @@
|
|||
alias
|
|
@ -1,152 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
state="$(cat $__object/parameter/state)"
|
||||
template="$(cat $__object/parameter/template)"
|
||||
ip4_addr="$(cat $__object/parameter/bridge)|$(cat $__object/parameter/ip)"
|
||||
interfaces="none:none"
|
||||
defaultrouter="none"
|
||||
vnet="off"
|
||||
jail_zfs_dataset="$(cat $__object/parameter/jail_zfs_dataset)"
|
||||
devfs_ruleset="$(cat $__object/parameter/devfs_ruleset)"
|
||||
allow_socket_af="$(cat $__object/parameter/allow_socket_af)"
|
||||
mount_procfs="$(cat $__object/parameter/mount_procfs)"
|
||||
mount_linprocfs="$(cat $__object/parameter/mount_linprocfs)"
|
||||
|
||||
if [ "X$state" = "Xabsent" ]; then
|
||||
cat <<EOF
|
||||
iocage stop $__object_id || true
|
||||
iocage destroy -f $__object_id || true
|
||||
rm -f /iocage/jails/$__object_id
|
||||
EOF
|
||||
else
|
||||
cat <<EOF
|
||||
get_property_zfs () {
|
||||
zfs get -H -o value \$1 "\$2"
|
||||
}
|
||||
|
||||
get_property_iocage () {
|
||||
get_property_zfs "org.freebsd.iocage:\$1" "/iocage/jails/\$2"
|
||||
}
|
||||
|
||||
create_new=0
|
||||
if [ ! -d /iocage/jails/"$__object_id" ]; then
|
||||
echo "Jail $__object_id does not exist, going to create."
|
||||
create_new=1
|
||||
else
|
||||
base=\$(get_property_zfs origin "/iocage/jails/$__object_id")
|
||||
current_template=\$(get_property_zfs org.freebsd.iocage:tag "\$base")
|
||||
if [ "X\$current_template" != "X$template" ]; then
|
||||
echo "Jail $__object_id has base \$current_template, which is not $template. " >&2
|
||||
create_new=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ \$create_new -eq 0 ]; then
|
||||
if [ "off" == "\$(get_property_iocage jail_zfs "$__object_id")" ]; then
|
||||
current_jail_zfs_dataset=""
|
||||
else
|
||||
current_jail_zfs_dataset="\$(get_property_iocage jail_zfs_dataset "$__object_id")"
|
||||
fi
|
||||
fi
|
||||
|
||||
configure=0
|
||||
if [ \$create_new -eq 1 ]; then
|
||||
configure=1
|
||||
elif [ "X$vnet" != "X\$(get_property_iocage vnet "$__object_id")" ]; then
|
||||
configure=1
|
||||
elif [ "X$ip4_addr" != "X\$(get_property_iocage ip4_addr "$__object_id")" ]; then
|
||||
configure=1
|
||||
elif [ "X$interfaces" != "X\$(get_property_iocage interfaces "$__object_id")" ]; then
|
||||
configure=1
|
||||
elif [ "X$defaultrouter" != "X\$(get_property_iocage defaultrouter "$__object_id")" ]; then
|
||||
configure=1
|
||||
elif [ "X$mount_procfs" != "X\$(get_property_iocage mount_procfs "$__object_id")" ]; then
|
||||
configure=1
|
||||
elif [ "X$devfs_ruleset" != "X\$(get_property_iocage devfs_ruleset "$__object_id")" ]; then
|
||||
configure=1
|
||||
elif [ "X$allow_socket_af" != "X\$(get_property_iocage allow_socket_af "$__object_id")" ]; then
|
||||
configure=1
|
||||
elif [ "X$jail_zfs_dataset" != "X\$current_jail_zfs_dataset" ]; then
|
||||
configure=1
|
||||
fi
|
||||
|
||||
if [ \$create_new -eq 1 ]; then
|
||||
echo "Creating jail $__object_id" >&2
|
||||
|
||||
iocage stop $__object_id || true
|
||||
iocage destroy -f $__object_id || true
|
||||
# Without VNETs, we should not need this.
|
||||
# TODO(riso): Use nicer path
|
||||
# /root/cdist/ioc deconfigure $__object_id
|
||||
|
||||
rm -f /iocage/jails/$__object_id
|
||||
|
||||
iocage clone $template tag=$__object_id
|
||||
iocage set boot=on $__object_id
|
||||
UUID=\$(iocage list | grep " $__object_id " | awk "{ print \\\$2; }")
|
||||
rm -f /iocage/jails/$__object_id
|
||||
ln -s /iocage/jails/\$UUID /iocage/jails/$__object_id
|
||||
else
|
||||
UUID=\$(iocage list | grep " $__object_id " | awk "{ print \\\$2; }")
|
||||
echo "Jail $__object_id already exists, UUID=\$UUID" >&2
|
||||
fi
|
||||
|
||||
ROOT="/iocage/jails/\$UUID/root"
|
||||
FSTAB="/iocage/jails/\$UUID/fstab"
|
||||
rm -f \$FSTAB.new
|
||||
touch \$FSTAB.new
|
||||
cat $__object/parameter/mount 2>/dev/null | \\
|
||||
while read mount; do
|
||||
src=\$(echo \$mount | awk -F: "{ print \\\$1; }")
|
||||
dst_rel=\$(echo \$mount | awk -F: "{ print \\\$2; }")
|
||||
dst="/iocage/jails/\$UUID/root/\$dst_rel"
|
||||
mkdir -p "\$dst"
|
||||
echo "\$src \$dst nullfs rw 0 0" >>\$FSTAB.new
|
||||
done
|
||||
if [ $mount_linprocfs -eq 1 ]; then
|
||||
echo "linproc /iocage/jails/\$UUID/root/compat/linux/proc linprocfs rw 0 0" >>\$FSTAB.new
|
||||
fi
|
||||
|
||||
fstab_changed=0
|
||||
if diff -q \$FSTAB \$FSTAB.new >/dev/null; then
|
||||
# pass
|
||||
else
|
||||
configure=1
|
||||
fstab_changed=1
|
||||
fi
|
||||
|
||||
if [ \$configure -eq 1 ]; then
|
||||
echo "Configuring jail $__object_id." >&2
|
||||
iocage stop $__object_id || true
|
||||
|
||||
iocage set vnet="$vnet" $__object_id
|
||||
iocage set interfaces="$interfaces" $__object_id
|
||||
iocage set hostname="$__object_id" $__object_id
|
||||
iocage set ip4_addr="$ip4_addr" $__object_id
|
||||
iocage set defaultrouter="$defaultrouter" $__object_id
|
||||
iocage set mount_procfs="$mount_procfs" $__object_id
|
||||
iocage set devfs_ruleset="$devfs_ruleset" $__object_id
|
||||
iocage set allow_socket_af="$allow_socket_af" $__object_id
|
||||
if [ -n "$jail_zfs_dataset" ]; then
|
||||
iocage set jail_zfs=on $__object_id
|
||||
iocage set jail_zfs_dataset="$jail_zfs_dataset" $__object_id
|
||||
else
|
||||
iocage set jail_zfs=off $__object_id
|
||||
fi
|
||||
|
||||
if [ \$fstab_changed -eq 1 ]; then
|
||||
umount -afF \$FSTAB || true
|
||||
mv \$FSTAB.new \$FSTAB
|
||||
fi
|
||||
|
||||
iocage start $__object_id || true
|
||||
|
||||
# Iocage creates new mac address, but arp can have an old mac cached.
|
||||
# TODO(riso): Is this true without VNETs?
|
||||
arp -d -a
|
||||
else
|
||||
echo "Jail $__object_id is already configured." >&2
|
||||
fi
|
||||
rm -f \$FSTAB.new
|
||||
EOF
|
||||
fi
|
|
@ -1 +0,0 @@
|
|||
__package iocage
|
|
@ -1 +0,0 @@
|
|||
0
|
|
@ -1 +0,0 @@
|
|||
bridge0
|
|
@ -1 +0,0 @@
|
|||
4
|
|
@ -1 +0,0 @@
|
|||
0
|
|
@ -1 +0,0 @@
|
|||
0
|
|
@ -1 +0,0 @@
|
|||
24
|
|
@ -1 +0,0 @@
|
|||
present
|
|
@ -1,7 +0,0 @@
|
|||
state
|
||||
bridge
|
||||
jail_zfs_dataset
|
||||
mount_procfs
|
||||
mount_linprocfs
|
||||
devfs_ruleset
|
||||
allow_socket_af
|
|
@ -1 +0,0 @@
|
|||
mount
|
|
@ -1,2 +0,0 @@
|
|||
ip
|
||||
template
|
|
@ -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"]
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
ACME_TINY_CERT_REQUEST_DIR="/var/acme-tiny/cert-requests"
|
||||
ACME_TINY_ACCOUNT_KEY="/var/acme-tiny/account.key"
|
||||
ACME_CHALLENGE_DIR="/srv/www/sites/acme/public/.well-known/acme-challenge"
|
||||
|
||||
REALM="${__object_id}"
|
||||
EXTRA_DOMAINS=""
|
||||
if [ -f "${__object}/parameter/extra-domain" ]; then
|
||||
EXTRA_DOMAINS="$(cat "${__object}/parameter/extra-domain")"
|
||||
fi
|
||||
|
||||
#TODO: support linux too
|
||||
REALMS_DIR="/usr/local/etc/pki/realms"
|
||||
REALM_DIR="${REALMS_DIR}/${REALM}"
|
||||
REALM_CERT="${REALM_DIR}/default.crt"
|
||||
REALM_KEY="${REALM_DIR}/default.key"
|
||||
REALM_CERT_REQUEST="${ACME_TINY_CERT_REQUEST_DIR}/${REALM}.csr"
|
||||
REALM_CERT_REQUEST_CNF="${ACME_TINY_CERT_REQUEST_DIR}/${REALM}.cnf"
|
||||
|
||||
CSR_ALT_NAMES=""
|
||||
REALM_CERT_REQUEST_CNF_LINE=""
|
||||
if [ -n "${EXTRA_DOMAINS}" ]; then
|
||||
CSR_ALT_NAMES="DNS:${REALM}"
|
||||
for domain in ${EXTRA_DOMAINS}; do
|
||||
CSR_ALT_NAMES="${CSR_ALT_NAMES},DNS:${domain}"
|
||||
done
|
||||
# CSR requests are executed always against .new, only after succeeding .new replaces the .cnf
|
||||
REALM_CERT_REQUEST_CNF_LINE="-reqexts SAN -config '${REALM_CERT_REQUEST_CNF}.new'"
|
||||
fi
|
||||
|
||||
cat << EOF
|
||||
if [ ! -d '${REALM_DIR}' ]; then
|
||||
mkdir -p '${REALM_DIR}'
|
||||
fi
|
||||
if [ ! -f '${REALM_KEY}' ]; then
|
||||
openssl genrsa 4096 > '${REALM_KEY}'
|
||||
fi
|
||||
|
||||
if [ ! -d '${ACME_TINY_CERT_REQUEST_DIR}' ]; then
|
||||
mkdir '${ACME_TINY_CERT_REQUEST_DIR}'
|
||||
fi
|
||||
|
||||
FORCE_CSR_REGEN=""
|
||||
if [ -n '${CSR_ALT_NAMES}' ]; then
|
||||
# Generate new config
|
||||
cat /etc/ssl/openssl.cnf > '${REALM_CERT_REQUEST_CNF}.new'
|
||||
printf '[SAN]\nsubjectAltName=${CSR_ALT_NAMES}' >> '${REALM_CERT_REQUEST_CNF}.new'
|
||||
# Compare to previous config if necessary
|
||||
if [ -f '${REALM_CERT_REQUEST_CNF}' ]; then
|
||||
CNF_DIFF=\$(diff -q '${REALM_CERT_REQUEST_CNF}' '${REALM_CERT_REQUEST_CNF}.new' || true)
|
||||
if [ -n "\${CNF_DIFF}" ]; then
|
||||
# Options have changed
|
||||
FORCE_CSR_REGEN="YES"
|
||||
else
|
||||
# Since they match, we won't be using this, clean it
|
||||
rm '${REALM_CERT_REQUEST_CNF}.new'
|
||||
fi
|
||||
else
|
||||
# We never used SAN here, CSR regen needed.
|
||||
FORCE_CSR_REGEN="YES"
|
||||
fi
|
||||
else
|
||||
# We used SAN at some point, not any more
|
||||
if [ -f '${REALM_CERT_REQUEST_CNF}' ]; then
|
||||
rm '${REALM_CERT_REQUEST_CNF}'
|
||||
FORCE_CSR_REGEN="YES"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create or re-create when params have changed
|
||||
if [ ! -f '${REALM_CERT_REQUEST}' -o -n "\${FORCE_CSR_REGEN}" ]; then
|
||||
openssl req -new -sha256 -key '${REALM_KEY}' -subj '/CN=${REALM}' -out '${REALM_CERT_REQUEST}' ${REALM_CERT_REQUEST_CNF_LINE}
|
||||
fi
|
||||
|
||||
# Check if cert exists, and if so whether or not it's older than a month
|
||||
if [ -f '${REALM_CERT}' ]; then
|
||||
MODIFIED_IN_30d="\$(find '${REALM_CERT}' -mtime -30d)"
|
||||
if [ -z "\${MODIFIED_IN_30d}" ]; then
|
||||
# Cert is over a month old, it's fine to regenerate
|
||||
FORCE_CRT_REGEN="YES"
|
||||
fi
|
||||
else
|
||||
# This cert doesn't exist
|
||||
FORCE_CRT_REGEN="YES"
|
||||
fi
|
||||
|
||||
|
||||
# Only request certificate when needed
|
||||
# TODO: support linux too
|
||||
if [ -n "\${FORCE_CSR_REGEN}" -o -n "\${FORCE_CRT_REGEN}" ]; then
|
||||
doas -u acme-tiny -- acme_tiny \
|
||||
--account '${ACME_TINY_ACCOUNT_KEY}' \
|
||||
--csr '${REALM_CERT_REQUEST}' \
|
||||
--acme-dir '${ACME_CHALLENGE_DIR}' > '${REALM_CERT}.new'
|
||||
|
||||
if [ -s '${REALM_CERT}.new' ]; then
|
||||
mv '${REALM_CERT}.new' '${REALM_CERT}'
|
||||
else
|
||||
echo "Failed to generate cert for realm '${REALM}'."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
cat "${REALM_CERT}" "${REALMS_DIR}/chain.pem" > ${REALM_DIR}/fullchain.pem
|
||||
|
||||
if [ -n '${REALM_CERT_REQUEST_CNF_LINE}' -a -f '${REALM_CERT_REQUEST_CNF}.new' ]; then
|
||||
# CSR and cert generation succeded with a new config, put new config in-place.
|
||||
# This is the last thing we do, so we try again next time if sth fails.
|
||||
mv '${REALM_CERT_REQUEST_CNF}.new' '${REALM_CERT_REQUEST_CNF}'
|
||||
fi
|
||||
EOF
|
|
@ -1 +0,0 @@
|
|||
#__letsencrypt_acmetiny_base
|
|
@ -1 +0,0 @@
|
|||
extra-domain
|
|
@ -1,12 +0,0 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
ACME_HOME="/var/acme-tiny"
|
||||
ACME_ACCOUNT_KEY="${ACME_HOME}/account.key"
|
||||
|
||||
cat << EOF
|
||||
if [ ! -f '${ACME_ACCOUNT_KEY}' ]; then
|
||||
openssl genrsa 4096 > '${ACME_ACCOUNT_KEY}'
|
||||
chown acme-tiny:acme-tiny '${ACME_ACCOUNT_KEY}'
|
||||
chmod 640 '${ACME_ACCOUNT_KEY}'
|
||||
fi
|
||||
EOF
|
|
@ -1,227 +0,0 @@
|
|||
# Arguments
|
||||
ACME_DOMAIN="$(cat "${__object}/parameter/acme_domain" || true)"
|
||||
|
||||
if [ -z "${ACME_DOMAIN}" ]; then
|
||||
ACME_DOMAIN="${__target_host}"
|
||||
fi
|
||||
|
||||
|
||||
# Install needed stuffz
|
||||
|
||||
## TODO: consider not depending on nginx? It is... practical though.
|
||||
## TODO: Maybe just move this out to a sepecial type?
|
||||
__package "nginx"
|
||||
|
||||
NGINX_ETC="/usr/local/etc/nginx"
|
||||
|
||||
# Setup the acme-challenge snippet
|
||||
require="__package/nginx" __directory "${NGINX_ETC}/snippets" --state present
|
||||
require="__directory${NGINX_ETC}/snippets" __file "${NGINX_ETC}/snippets/acme-challenge.conf" \
|
||||
--mode 644 \
|
||||
--source - << EOF
|
||||
# This file is managed remotely, all changes will be lost
|
||||
|
||||
# This was heavily inspired by debops.org.
|
||||
|
||||
# Automatic Certificate Management Environment (ACME) support.
|
||||
# https://tools.ietf.org/html/draft-ietf-acme-acme-01
|
||||
# https://en.wikipedia.org/wiki/Automated_Certificate_Management_Environment
|
||||
|
||||
|
||||
# Return the ACME challenge present in the server public root.
|
||||
# If not found, switch to global web server root.
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
default_type "text/plain";
|
||||
try_files \$uri @well-known-acme-challenge;
|
||||
}
|
||||
|
||||
# Return the ACME challenge present in the global server public root.
|
||||
# If not present, redirect request to a specified domain.
|
||||
location @well-known-acme-challenge {
|
||||
root /srv/www/sites/acme/public;
|
||||
default_type "text/plain";
|
||||
try_files \$uri @redirect-acme-challenge;
|
||||
}
|
||||
|
||||
# Redirect the ACME challenge to a different host. If a redirect loop is
|
||||
# detected, return 404.
|
||||
location @redirect-acme-challenge {
|
||||
if (\$arg_redirect) {
|
||||
return 404;
|
||||
}
|
||||
return 307 \$scheme://${ACME_DOMAIN}\$request_uri?redirect=yes;
|
||||
}
|
||||
|
||||
# Return 404 if ACME challenge well known path is accessed directly.
|
||||
location = /.well-known/acme-challenge/ {
|
||||
return 404;
|
||||
}
|
||||
EOF
|
||||
|
||||
require="__package/nginx" __directory "${NGINX_ETC}/sites-enabled" --state present
|
||||
require="__directory${NGINX_ETC}/sites-enabled" __file "${NGINX_ETC}/nginx.conf" \
|
||||
--mode 644 \
|
||||
--source - << EOF
|
||||
# This file is managed remotely, all changes will be lost
|
||||
|
||||
worker_processes 1;
|
||||
|
||||
# This default error log path is compiled-in to make sure configuration parsing
|
||||
# errors are logged somewhere, especially during unattended boot when stderr
|
||||
# isn't normally logged anywhere. This path will be touched on every nginx
|
||||
# start regardless of error log location configured here. See
|
||||
# https://trac.nginx.org/nginx/ticket/147 for more info.
|
||||
#
|
||||
#error_log /var/log/nginx/error.log;
|
||||
#
|
||||
|
||||
#pid logs/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
server_tokens off;
|
||||
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 5m;
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
types_hash_max_size 2048;
|
||||
gzip on;
|
||||
gzip_disable "msie6";
|
||||
gzip_comp_level 5;
|
||||
gzip_min_length 256;
|
||||
gzip_proxied any;
|
||||
gzip_vary on;
|
||||
gzip_types
|
||||
application/atom+xml
|
||||
application/javascript
|
||||
application/json
|
||||
application/ld+json
|
||||
application/manifest+json
|
||||
application/rss+xml
|
||||
application/vnd.geo+json
|
||||
application/vnd.ms-fontobject
|
||||
application/x-font-ttf
|
||||
application/x-web-app-manifest+json
|
||||
application/xhtml+xml
|
||||
application/xml
|
||||
font/opentype
|
||||
image/bmp
|
||||
image/svg+xml
|
||||
image/x-icon
|
||||
text/cache-manifest
|
||||
text/css
|
||||
text/plain
|
||||
text/vcard
|
||||
text/vnd.rim.location.xloc
|
||||
text/vtt
|
||||
text/x-component
|
||||
text/x-cross-domain-policy;
|
||||
|
||||
# Logging
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
#add_header X-Clacks-Overhead "GNU Terry Pratchett";
|
||||
|
||||
# Virtual Hosts Configs
|
||||
include ${NGINX_ETC}/sites-enabled/*.conf;
|
||||
}
|
||||
EOF
|
||||
|
||||
require="__directory${NGINX_ETC}/sites-enabled" __file "${NGINX_ETC}/sites-enabled/welcome.conf" \
|
||||
--mode 644 \
|
||||
--source - << EOF
|
||||
# This file is managed remotely, all changes will be lost
|
||||
|
||||
# nginx server configuration for:
|
||||
# - https://welcome/
|
||||
|
||||
server {
|
||||
|
||||
listen [::]:80;
|
||||
|
||||
server_name welcome;
|
||||
|
||||
root /srv/www/sites/welcome/public;
|
||||
|
||||
include snippets/acme-challenge.conf;
|
||||
|
||||
location / {
|
||||
return 301 https://\$host\$request_uri;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
## TODO: this is kinda bad, don't restart every time.
|
||||
## Otherwise this isn't idempotent.
|
||||
require="__package/nginx" __service nginx --action onerestart
|
||||
require="__package/nginx" __start_on_boot nginx
|
||||
|
||||
|
||||
__package "acme-tiny"
|
||||
|
||||
# Create acme-tiny user and secure home dir
|
||||
ACME_TINY_HOME="/var/acme-tiny"
|
||||
require="__package/acme-tiny" __user acme-tiny --system --home ${ACME_TINY_HOME} --comment "acme-tiny client"
|
||||
require="__user/acme-tiny" __directory "${ACME_TINY_HOME}" --state present --mode 0750 --owner acme-tiny --group acme-tiny
|
||||
|
||||
# Create ACME challenge dirs to be served by nginx
|
||||
ACME_PUBLIC_DIR="/srv/www/sites/acme/public"
|
||||
ACME_WELLKNOWN_DIR="${ACME_PUBLIC_DIR}/.well-known"
|
||||
ACME_CHALLENGE_DIR="${ACME_WELLKNOWN_DIR}/acme-challenge"
|
||||
__directory "${ACME_PUBLIC_DIR}" \
|
||||
--parents \
|
||||
--state present \
|
||||
--owner acme-tiny --group www \
|
||||
--mode 2750 # TODO: check whether this does require gid?
|
||||
require="__directory${ACME_PUBLIC_DIR}" __directory "${ACME_WELLKNOWN_DIR}" \
|
||||
--state present \
|
||||
--owner acme-tiny --group www \
|
||||
--mode 0750
|
||||
require="__directory${ACME_WELLKNOWN_DIR}" __directory "${ACME_CHALLENGE_DIR}" \
|
||||
--state present \
|
||||
--owner acme-tiny --group www \
|
||||
--mode 0750
|
||||
|
||||
__package doas
|
||||
DOAS_CONF="/usr/local/etc/doas.conf"
|
||||
require="__package/doas" __file "${DOAS_CONF}" --mode 0640
|
||||
require="__file${DOAS_CONF}" __line "${DOAS_CONF}" \
|
||||
--regex 'root as acme-tiny' \
|
||||
--line 'permit nopass root as acme-tiny'
|
||||
|
||||
# Setup CA
|
||||
REALMS_DIR="/usr/local/etc/pki/realms"
|
||||
__directory "${REALMS_DIR}" \
|
||||
--parents \
|
||||
--state present \
|
||||
--mode 0755
|
||||
|
||||
require="__directory${REALMS_DIR}" __file ${REALMS_DIR}/intermediate.pem \
|
||||
--mode 0644 \
|
||||
--source - << EOF
|
||||
$(curl -s https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt)
|
||||
EOF
|
||||
require="__directory${REALMS_DIR}" __file ${REALMS_DIR}/root.pem \
|
||||
--mode 0644 \
|
||||
--source - << EOF
|
||||
$(curl -s https://letsencrypt.org/certs/trustid-x3-root.pem.txt)
|
||||
EOF
|
||||
require="__directory${REALMS_DIR}" __file ${REALMS_DIR}/chain.pem \
|
||||
--mode 0644 \
|
||||
--source - << EOF
|
||||
$(curl -s https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt)
|
||||
$(curl -s https://letsencrypt.org/certs/trustid-x3-root.pem.txt)
|
||||
EOF
|
||||
|
|
@ -1 +0,0 @@
|
|||
acme_domain
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
10
cdist/conf/type/__package_pip/explorer/pip
Executable file
10
cdist/conf/type/__package_pip/explorer/pip
Executable 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
|
|
@ -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.
|
||||
|
|
|
@ -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"
|
||||
;;
|
||||
|
|
4
cdist/conf/type/__package_pkgng_freebsd/explorer/pkg_bootstrapped
Executable file
4
cdist/conf/type/__package_pkgng_freebsd/explorer/pkg_bootstrapped
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh -e
|
||||
if pkg -N >/dev/null 2>&1; then
|
||||
echo "YES"
|
||||
fi
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Consider moving to __pf_apply_anchor. Get in touch if you need __pf_apply.
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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.
|
|
@ -1,40 +0,0 @@
|
|||
#!/bin/sh -e
|
||||
#
|
||||
# 2016 Kamila Součková (coding at kamila.is)
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
# TODO it would be cool to print a warning if a generated anchor is unused in pf.conf
|
||||
|
||||
ANCHORS_DIR=/etc/pf.d
|
||||
|
||||
proto="$(cat "${__object}/parameter/proto")"
|
||||
from="$(cat "${__object}/parameter/from")"
|
||||
to="$(cat "${__object}/parameter/to")"
|
||||
state="$(cat "${__object}/parameter/state")"
|
||||
|
||||
# This breaks utterly with IPv6
|
||||
from="$(echo ${from} | sed 's/:/ port /')"
|
||||
to="$(echo ${to} | sed 's/:/ port /')"
|
||||
|
||||
anchor_name="$(echo ${__object_id} | cut -d/ -f1)"
|
||||
rule="rdr pass log proto ${proto} from any to ${from} -> ${to}"
|
||||
|
||||
__directory "${ANCHORS_DIR}" --parents
|
||||
|
||||
require="__directory/${ANCHORS_DIR}" \
|
||||
__line __pf_rdr/${__object_id} --state ${state} --line "${rule}" --file ${ANCHORS_DIR}/${anchor_name}
|
|
@ -1 +0,0 @@
|
|||
tcp
|
|
@ -1 +0,0 @@
|
|||
present
|
|
@ -1,2 +0,0 @@
|
|||
proto
|
||||
state
|
|
@ -1,2 +0,0 @@
|
|||
from
|
||||
to
|
|
@ -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
|
||||
|
|
|
@ -4,6 +4,5 @@ unpriv
|
|||
chroot
|
||||
wakeup
|
||||
maxproc
|
||||
option
|
||||
comment
|
||||
state
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
option
|
|
@ -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"
|
||||
;;
|
||||
*)
|
||||
|
|
|
@ -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+).
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
9
cdist/conf/type/__ssh_authorized_keys/explorer/keys
Executable file
9
cdist/conf/type/__ssh_authorized_keys/explorer/keys
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
file="$( . "$__type_explorer/file" )"
|
||||
|
||||
if [ -f "$file" ]
|
||||
then
|
||||
cat "$file"
|
||||
fi
|
|
@ -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..."
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
noparent
|
||||
nofile
|
||||
remove-unknown
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue