diff --git a/cdist/__init__.py b/cdist/__init__.py index 9068ae69..6ea02d41 100644 --- a/cdist/__init__.py +++ b/cdist/__init__.py @@ -59,16 +59,24 @@ class UnresolvableRequirementsError(cdist.Error): class CdistBetaRequired(cdist.Error): """Beta functionality is used but beta is not enabled""" - def __init__(self, command, arg): + def __init__(self, command, arg=None): self.command = command self.arg = arg def __str__(self): - err_msg = ("\'{}\' argument of \'{}\' command is beta, but beta is " - "not enabled. If you want to use it please enable beta " - "functionalities by using the -b/--enable-beta command " - "line flag.") - return err_msg.format(self.arg, self.command) + if self.arg is None: + err_msg = ("\'{}\' command is beta, but beta is " + "not enabled. If you want to use it please enable beta " + "functionalities by using the -b/--beta command " + "line flag or setting CDIST_BETA env var.") + fmt_args = [self.command, ] + else: + err_msg = ("\'{}\' argument of \'{}\' command is beta, but beta " + "is not enabled. If you want to use it please enable " + "beta functionalities by using the -b/--beta " + "command line flag or setting CDIST_BETA env var.") + fmt_args = [self.arg, self.command, ] + return err_msg.format(*fmt_args) class CdistObjectError(Error): diff --git a/cdist/argparse.py b/cdist/argparse.py new file mode 100644 index 00000000..e2a13c38 --- /dev/null +++ b/cdist/argparse.py @@ -0,0 +1,210 @@ +import argparse +import cdist +import multiprocessing +import os +import logging +import collections + + +# set of beta sub-commands +BETA_COMMANDS = set(('install', )) +# set of beta arguments for sub-commands +BETA_ARGS = { + 'config': set(('jobs', )), +} +EPILOG = "Get cdist at http://www.nico.schottelius.org/software/cdist/" +# Parser others can reuse +parser = None + + +_verbosity_level = { + 0: logging.ERROR, + 1: logging.WARNING, + 2: logging.INFO, +} +_verbosity_level = collections.defaultdict( + lambda: logging.DEBUG, _verbosity_level) + + +def add_beta_command(cmd): + BETA_COMMANDS.add(cmd) + + +def add_beta_arg(cmd, arg): + if cmd in BETA_ARGS: + if arg not in BETA_ARGS[cmd]: + BETA_ARGS[cmd].append(arg) + else: + BETA_ARGS[cmd] = set((arg, )) + + +def check_beta(args_dict): + if 'beta' not in args_dict: + args_dict['beta'] = False + # Check only if beta is not enabled: if beta option is specified then + # raise error. + if not args_dict['beta']: + cmd = args_dict['command'] + # first check if command is beta + if cmd in BETA_COMMANDS: + raise cdist.CdistBetaRequired(cmd) + # then check if some command's argument is beta + if cmd in BETA_ARGS: + for arg in BETA_ARGS[cmd]: + if arg in args_dict and args_dict[arg]: + raise cdist.CdistBetaRequired(cmd, arg) + + +def check_positive_int(value): + import argparse + + try: + val = int(value) + except ValueError: + raise argparse.ArgumentTypeError( + "{} is invalid int value".format(value)) + if val <= 0: + raise argparse.ArgumentTypeError( + "{} is invalid positive int value".format(val)) + return val + + +def get_parsers(): + global parser + + # Construct parser others can reuse + if parser: + return parser + else: + parser = {} + # Options _all_ parsers have in common + parser['loglevel'] = argparse.ArgumentParser(add_help=False) + parser['loglevel'].add_argument( + '-d', '--debug', + help=('Set log level to debug (deprecated, use -vvv instead)'), + action='store_true', default=False) + parser['loglevel'].add_argument( + '-v', '--verbose', + help=('Increase the verbosity level. Every instance of -v ' + 'increments the verbosity level by one. Its default value is ' + '0. There are 4 levels of verbosity. The order of levels ' + 'from the lowest to the highest are: ERROR (0), WARNING (1), ' + 'INFO (2) and DEBUG (3 or higher).'), + action='count', default=0) + + parser['beta'] = argparse.ArgumentParser(add_help=False) + parser['beta'].add_argument( + '-b', '--beta', + help=('Enable beta functionalities. ' + 'Can also be enabled using CDIST_BETA env var.'), + action='store_true', dest='beta', + default='CDIST_BETA' in os.environ) + + # Main subcommand parser + parser['main'] = argparse.ArgumentParser( + description='cdist ' + cdist.VERSION, parents=[parser['loglevel']]) + parser['main'].add_argument( + '-V', '--version', help='Show version', action='version', + version='%(prog)s ' + cdist.VERSION) + parser['sub'] = parser['main'].add_subparsers( + title="Commands", dest="command") + + # Banner + parser['banner'] = parser['sub'].add_parser( + 'banner', parents=[parser['loglevel']]) + parser['banner'].set_defaults(func=cdist.banner.banner) + + # Config + parser['config_main'] = argparse.ArgumentParser(add_help=False) + parser['config_main'].add_argument( + '-c', '--conf-dir', + help=('Add configuration directory (can be repeated, ' + 'last one wins)'), action='append') + parser['config_main'].add_argument( + '-i', '--initial-manifest', + help='path to a cdist manifest or \'-\' to read from stdin.', + dest='manifest', required=False) + parser['config_main'].add_argument( + '-j', '--jobs', nargs='?', + type=check_positive_int, + help=('Specify the maximum number of parallel jobs, currently ' + 'only global explorers are supported'), + action='store', dest='jobs', + const=multiprocessing.cpu_count()) + parser['config_main'].add_argument( + '-n', '--dry-run', + help='do not execute code', action='store_true') + parser['config_main'].add_argument( + '-o', '--out-dir', + help='directory to save cdist output in', dest="out_path") + + # remote-copy and remote-exec defaults are environment variables + # if set; if not then None - these will be futher handled after + # parsing to determine implementation default + parser['config_main'].add_argument( + '--remote-copy', + help='Command to use for remote copy (should behave like scp)', + action='store', dest='remote_copy', + default=os.environ.get('CDIST_REMOTE_COPY')) + parser['config_main'].add_argument( + '--remote-exec', + help=('Command to use for remote execution ' + '(should behave like ssh)'), + action='store', dest='remote_exec', + default=os.environ.get('CDIST_REMOTE_EXEC')) + + # Config + parser['config_args'] = argparse.ArgumentParser(add_help=False) + parser['config_args'].add_argument( + 'host', nargs='*', help='host(s) to operate on') + parser['config_args'].add_argument( + '-f', '--file', + help=('Read additional hosts to operate on from specified file ' + 'or from stdin if \'-\' (each host on separate line). ' + 'If no host or host file is specified then, by default, ' + 'read hosts from stdin.'), + dest='hostfile', required=False) + parser['config_args'].add_argument( + '-p', '--parallel', + help='operate on multiple hosts in parallel', + action='store_true', dest='parallel') + parser['config_args'].add_argument( + '-s', '--sequential', + help='operate on multiple hosts sequentially (default)', + action='store_false', dest='parallel') + parser['config'] = parser['sub'].add_parser( + 'config', parents=[parser['loglevel'], parser['beta'], + parser['config_main'], + parser['config_args']]) + parser['config'].set_defaults(func=cdist.config.Config.commandline) + + # Install + parser['install'] = parser['sub'].add_parser('install', add_help=False, + parents=[parser['config']]) + parser['install'].set_defaults(func=cdist.install.Install.commandline) + + # Shell + parser['shell'] = parser['sub'].add_parser( + 'shell', parents=[parser['loglevel']]) + parser['shell'].add_argument( + '-s', '--shell', + help=('Select shell to use, defaults to current shell. Used shell' + ' should be POSIX compatible shell.')) + parser['shell'].set_defaults(func=cdist.shell.Shell.commandline) + + for p in parser: + parser[p].epilog = EPILOG + + return parser + + +def handle_loglevel(args): + if args.debug: + retval = "-d/--debug is deprecated, use -vvv instead" + args.verbose = 3 + else: + retval = None + + logging.root.setLevel(_verbosity_level[args.verbose]) + + return retval diff --git a/cdist/conf/explorer/disks b/cdist/conf/explorer/disks new file mode 100644 index 00000000..52fef81e --- /dev/null +++ b/cdist/conf/explorer/disks @@ -0,0 +1,2 @@ +cd /dev +echo sd? hd? vd? diff --git a/cdist/conf/explorer/os b/cdist/conf/explorer/os index 550192d4..094685ea 100755 --- a/cdist/conf/explorer/os +++ b/cdist/conf/explorer/os @@ -39,6 +39,11 @@ if [ -f /etc/cdist-preos ]; then exit 0 fi +if [ -d /gnu/store ]; then + echo guixsd + exit 0 +fi + ### Debian and derivatives if grep -q ^DISTRIB_ID=Ubuntu /etc/lsb-release 2>/dev/null; then echo ubuntu diff --git a/cdist/conf/explorer/os_version b/cdist/conf/explorer/os_version index 58f750b0..380782cc 100755 --- a/cdist/conf/explorer/os_version +++ b/cdist/conf/explorer/os_version @@ -61,7 +61,11 @@ case "$($__explorer/os)" in cat /etc/slackware-version ;; suse) - cat /etc/SuSE-release + if [ -f /etc/os-release ]; then + cat /etc/os-release + else + cat /etc/SuSE-release + fi ;; ubuntu) lsb_release -sr diff --git a/cdist/conf/type/__apt_mark/explorer/apt_version b/cdist/conf/type/__apt_mark/explorer/apt_version new file mode 100644 index 00000000..32a0a58f --- /dev/null +++ b/cdist/conf/type/__apt_mark/explorer/apt_version @@ -0,0 +1,31 @@ +#!/bin/sh +# +# 2016 Ander Punnar (cdist at kvlt.ee) +# +# 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 . +# + +apt_version_is=$(dpkg-query --show --showformat '${Version}' apt) + +# from APT changelog: +# apt (0.8.14.2) UNRELEASED; urgency=low +# provide a 'dpkg --set-selections' wrapper to set/release holds + +apt_version_should=0.8.14.2 + +dpkg --compare-versions $apt_version_should le $apt_version_is \ + && echo 0 \ + || echo 1 diff --git a/cdist/conf/type/__apt_mark/explorer/package_installed b/cdist/conf/type/__apt_mark/explorer/package_installed new file mode 100644 index 00000000..c78ac3a9 --- /dev/null +++ b/cdist/conf/type/__apt_mark/explorer/package_installed @@ -0,0 +1,30 @@ +#!/bin/sh +# +# 2016 Ander Punnar (cdist at kvlt.ee) +# +# 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 . +# + +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name="$__object_id" +fi + +dpkg-query --show --showformat '${Status}' $name 2>/dev/null \ + | grep -q 'ok installed' \ + && echo 0 \ + || echo 1 diff --git a/cdist/conf/type/__apt_mark/explorer/state b/cdist/conf/type/__apt_mark/explorer/state new file mode 100644 index 00000000..3b70003a --- /dev/null +++ b/cdist/conf/type/__apt_mark/explorer/state @@ -0,0 +1,27 @@ +#!/bin/sh +# +# 2016 Ander Punnar (cdist at kvlt.ee) +# +# 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 . +# + +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name="$__object_id" +fi + +apt-mark showhold | grep -q $name && echo hold || echo unhold diff --git a/cdist/conf/type/__apt_mark/gencode-remote b/cdist/conf/type/__apt_mark/gencode-remote new file mode 100644 index 00000000..c1ac58b3 --- /dev/null +++ b/cdist/conf/type/__apt_mark/gencode-remote @@ -0,0 +1,56 @@ +#!/bin/sh +# +# 2016 Ander Punnar (cdist at kvlt.ee) +# +# 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 . +# + +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name="$__object_id" +fi + +apt_version="$(cat "$__object/explorer/apt_version")" + +if [ "$apt_version" != '0' ]; then + echo 'APT version not supported' >&2 + exit 1 +fi + +package_installed="$(cat "$__object/explorer/package_installed")" + +if [ "$package_installed" != '0' ]; then + exit 0 +fi + +state_should="$(cat "$__object/parameter/state")" + +state_is="$(cat "$__object/explorer/state")" + +if [ "$state_should" = "$state_is" ]; then + exit 0 +fi + +case "$state_should" in + hold|unhold) + echo "apt-mark $state_should $name > /dev/null" + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__apt_mark/man.rst b/cdist/conf/type/__apt_mark/man.rst new file mode 100644 index 00000000..7aa2a519 --- /dev/null +++ b/cdist/conf/type/__apt_mark/man.rst @@ -0,0 +1,47 @@ +cdist-type__apt_mark(7) +======================= + +NAME +---- +cdist-type__apt_mark - set package state as 'hold' or 'unhold' + + +DESCRIPTION +----------- +See apt-mark(8) for details. + + +REQUIRED PARAMETERS +------------------- +state + Either "hold" or "unhold". + + +OPTIONAL PARAMETERS +------------------- +name + If supplied, use the name and not the object id as the package name. + + +EXAMPLES +-------- + +.. code-block:: sh + + # hold package + __apt_mark quagga --state hold + # unhold package + __apt_mark quagga --state unhold + + +AUTHORS +------- +Ander Punnar + + +COPYING +------- +Copyright \(C) 2016 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. diff --git a/cdist/conf/type/__apt_mark/parameter/optional b/cdist/conf/type/__apt_mark/parameter/optional new file mode 100644 index 00000000..f121bdbf --- /dev/null +++ b/cdist/conf/type/__apt_mark/parameter/optional @@ -0,0 +1 @@ +name diff --git a/cdist/conf/type/__apt_mark/parameter/required b/cdist/conf/type/__apt_mark/parameter/required new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/cdist/conf/type/__apt_mark/parameter/required @@ -0,0 +1 @@ +state diff --git a/cdist/conf/type/__cdist/man.rst b/cdist/conf/type/__cdist/man.rst index f02f848a..9e1c72cb 100644 --- a/cdist/conf/type/__cdist/man.rst +++ b/cdist/conf/type/__cdist/man.rst @@ -30,7 +30,7 @@ username source Select the source from which to clone cdist from. - Defaults to "git://github.com/telmich/cdist.git". + Defaults to "git://github.com/ungleich/cdist.git". branch @@ -47,7 +47,7 @@ EXAMPLES __cdist /home/cdist/cdist # Use alternative source - __cdist --source "git://git.schottelius.org/cdist" /home/cdist/cdist + __cdist --source "git://github.com/ungleich/cdist" /home/cdist/cdist AUTHORS diff --git a/cdist/conf/type/__cdist/parameter/default/source b/cdist/conf/type/__cdist/parameter/default/source index d669308f..3f8e31ad 100644 --- a/cdist/conf/type/__cdist/parameter/default/source +++ b/cdist/conf/type/__cdist/parameter/default/source @@ -1 +1 @@ -git://github.com/telmich/cdist.git +git://github.com/ungleich/cdist.git diff --git a/cdist/conf/type/__cdistmarker/gencode-remote b/cdist/conf/type/__cdistmarker/gencode-remote index 92ea582b..5e889e52 100755 --- a/cdist/conf/type/__cdistmarker/gencode-remote +++ b/cdist/conf/type/__cdistmarker/gencode-remote @@ -2,7 +2,7 @@ # # Copyright (C) 2011 Daniel Maher (phrawzty+cdist at gmail.com) # -# This file is part of cdist (https://github.com/telmich/cdist/). +# 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 diff --git a/cdist/conf/type/__chroot_mount/gencode-remote b/cdist/conf/type/__chroot_mount/gencode-remote new file mode 100755 index 00000000..6d855f41 --- /dev/null +++ b/cdist/conf/type/__chroot_mount/gencode-remote @@ -0,0 +1,48 @@ +#!/bin/sh +# +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +chroot="/$__object_id" + +cat << DONE +# Prepare chroot +[ -d "${chroot}/proc" ] || mkdir "${chroot}/proc" +mountpoint -q "${chroot}/proc" \ + || mount -t proc -o nosuid,noexec,nodev proc "${chroot}/proc" + +[ -d "${chroot}/sys" ] || mkdir "${chroot}/sys" +mountpoint -q "${chroot}/sys" \ + || mount -t sysfs -o nosuid,noexec,nodev sys "${chroot}/sys" + +[ -d "${chroot}/dev" ] || mkdir "${chroot}/dev" +mountpoint -q "${chroot}/dev" \ + || mount -t devtmpfs -o mode=0755,nosuid udev "${chroot}/dev" + +[ -d "${chroot}/dev/pts" ] || mkdir "${chroot}/dev/pts" +mountpoint -q "${chroot}/dev/pts" \ + || mount -t devpts -o mode=0620,gid=5,nosuid,noexec devpts "${chroot}/dev/pts" + +[ -d "${chroot}/tmp" ] || mkdir -m 1777 "${chroot}/tmp" +mountpoint -q "${chroot}/tmp" \ + || mount -t tmpfs -o mode=1777,strictatime,nodev,nosuid tmpfs "${chroot}/tmp" + +if [ ! -f "${chroot}/etc/resolv.conf" ]; then + cp /etc/resolv.conf "${chroot}/etc/" +fi +DONE diff --git a/cdist/conf/type/__chroot_mount/man.rst b/cdist/conf/type/__chroot_mount/man.rst new file mode 100644 index 00000000..0d7cdce3 --- /dev/null +++ b/cdist/conf/type/__chroot_mount/man.rst @@ -0,0 +1,42 @@ +cdist-type__chroot_mount(7) +=================================== + +NAME +---- +cdist-type__chroot_mount - mount a chroot + + +DESCRIPTION +----------- +Mount and prepare a chroot for running commands within it. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +None + + +EXAMPLES +-------- + +.. code-block:: sh + + __chroot_mount /path/to/chroot + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2012 Steven Armstrong. 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. diff --git a/cdist/conf/type/__chroot_umount/gencode-remote b/cdist/conf/type/__chroot_umount/gencode-remote new file mode 100755 index 00000000..caf2c40c --- /dev/null +++ b/cdist/conf/type/__chroot_umount/gencode-remote @@ -0,0 +1,36 @@ +#!/bin/sh +# +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +chroot="/$__object_id" + +cat << DONE +umount -l "${chroot}/tmp" +umount -l "${chroot}/dev/pts" +umount -l "${chroot}/dev" +umount -l "${chroot}/sys" +umount -l "${chroot}/proc" +rm -f "${chroot}/etc/resolv.conf" +if [ -d "${chroot}/etc/resolvconf/resolv.conf.d" ]; then + # ensure /etc/resolvconf/resolv.conf.d/tail is not linked to \ + # e.g. /etc/resolvconf/resolv.conf.d/original + rm -f "${chroot}/etc/resolvconf/resolv.conf.d/tail" + touch "${chroot}/etc/resolvconf/resolv.conf.d/tail" +fi +DONE diff --git a/cdist/conf/type/__chroot_umount/man.rst b/cdist/conf/type/__chroot_umount/man.rst new file mode 100644 index 00000000..ff116da5 --- /dev/null +++ b/cdist/conf/type/__chroot_umount/man.rst @@ -0,0 +1,47 @@ +cdist-type__chroot_umount(7) +============================ + +NAME +---- +cdist-type__chroot_umount - unmount a chroot mounted by __chroot_mount + + +DESCRIPTION +----------- +Undo what __chroot_mount did. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +None + + +EXAMPLES +-------- + +.. code-block:: sh + + __chroot_umount /path/to/chroot + + +SEE ALSO +-------- +:strong:`cdist-type__chroot_mount`\ (7) + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2012 Steven Armstrong. 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. diff --git a/cdist/conf/type/__consul/files/versions/0.7.0/cksum b/cdist/conf/type/__consul/files/versions/0.7.0/cksum new file mode 100644 index 00000000..3bffeedb --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.7.0/cksum @@ -0,0 +1 @@ +695240564 24003648 consul diff --git a/cdist/conf/type/__consul/files/versions/0.7.0/source b/cdist/conf/type/__consul/files/versions/0.7.0/source new file mode 100644 index 00000000..ad610fc7 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.7.0/source @@ -0,0 +1 @@ +https://releases.hashicorp.com/consul/0.7.0/consul_0.7.0_linux_amd64.zip diff --git a/cdist/conf/type/__consul/files/versions/0.7.1/cksum b/cdist/conf/type/__consul/files/versions/0.7.1/cksum new file mode 100644 index 00000000..476bd9f6 --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.7.1/cksum @@ -0,0 +1 @@ +3128343188 28402769 consul diff --git a/cdist/conf/type/__consul/files/versions/0.7.1/source b/cdist/conf/type/__consul/files/versions/0.7.1/source new file mode 100644 index 00000000..6ba2e7bf --- /dev/null +++ b/cdist/conf/type/__consul/files/versions/0.7.1/source @@ -0,0 +1 @@ +https://releases.hashicorp.com/consul/0.7.1/consul_0.7.1_linux_amd64.zip diff --git a/cdist/conf/type/__consul_agent/man.rst b/cdist/conf/type/__consul_agent/man.rst index 0f4aa12c..966abc60 100644 --- a/cdist/conf/type/__consul_agent/man.rst +++ b/cdist/conf/type/__consul_agent/man.rst @@ -107,7 +107,7 @@ rejoin-after-leave server used to control if an agent is in server or client mode -syslog +enable-syslog enables logging to syslog verify-incoming diff --git a/cdist/conf/type/__consul_agent/manifest b/cdist/conf/type/__consul_agent/manifest index 7f180494..07bf3b26 100755 --- a/cdist/conf/type/__consul_agent/manifest +++ b/cdist/conf/type/__consul_agent/manifest @@ -98,7 +98,7 @@ for param in $(ls "$__object/parameter/"); do key="$(echo "${param%-*}" | tr '-' '_')" printf ' ,"%s": "%s"\n' "$key" "$destination" ;; - disable-remote-exec|disable-update-check|leave-on-terminate|rejoin-after-leave|server|syslog|verify-incoming|verify-outgoing) + disable-remote-exec|disable-update-check|leave-on-terminate|rejoin-after-leave|server|enable-syslog|verify-incoming|verify-outgoing) # handle boolean parameters key="$(echo "$param" | tr '-' '_')" printf ' ,"%s": true\n' "$key" diff --git a/cdist/conf/type/__consul_agent/parameter/boolean b/cdist/conf/type/__consul_agent/parameter/boolean index 9efecf49..91f7f17e 100644 --- a/cdist/conf/type/__consul_agent/parameter/boolean +++ b/cdist/conf/type/__consul_agent/parameter/boolean @@ -3,6 +3,6 @@ disable-update-check leave-on-terminate rejoin-after-leave server -syslog +enable-syslog verify-incoming verify-outgoing diff --git a/cdist/conf/type/__consul_check/man.rst b/cdist/conf/type/__consul_check/man.rst index dc7895de..9694c7af 100644 --- a/cdist/conf/type/__consul_check/man.rst +++ b/cdist/conf/type/__consul_check/man.rst @@ -11,7 +11,7 @@ DESCRIPTION Generate and deploy check definitions for a consul agent. See http://www.consul.io/docs/agent/checks.html for parameter documentation. -Use either script toghether with interval, or use ttl. +Use either script together with interval, or use ttl. REQUIRED PARAMETERS diff --git a/cdist/conf/type/__cron/explorer/entry b/cdist/conf/type/__cron/explorer/entry index c3bf02d2..2167e045 100644 --- a/cdist/conf/type/__cron/explorer/entry +++ b/cdist/conf/type/__cron/explorer/entry @@ -22,4 +22,9 @@ name="$__object_name" user="$(cat "$__object/parameter/user")" -crontab -u $user -l 2>/dev/null | grep "# $name\$" || true +if [ -f "$__object/parameter/raw_command" ]; then + command="$(cat "$__object/parameter/command")" + crontab -u $user -l 2>/dev/null | grep "^$command\$" || true +else + crontab -u $user -l 2>/dev/null | grep "# $name\$" || true +fi diff --git a/cdist/conf/type/__cron/gencode-remote b/cdist/conf/type/__cron/gencode-remote old mode 100755 new mode 100644 index 77a63b9b..3c3ed6b3 --- a/cdist/conf/type/__cron/gencode-remote +++ b/cdist/conf/type/__cron/gencode-remote @@ -3,6 +3,7 @@ # 2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2013 Nico Schottelius (nico-cdist at schottelius.org) # 2013 Thomas Oettli (otho at sfs.biz) +# 2017 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -26,7 +27,7 @@ command="$(cat "$__object/parameter/command")" if [ -f "$__object/parameter/raw" ]; then raw="$(cat "$__object/parameter/raw")" - entry="$raw $command" + entry="$raw $command # $name" elif [ -f "$__object/parameter/raw_command" ]; then entry="$command" else @@ -35,10 +36,9 @@ else day_of_month="$(cat "$__object/parameter/day_of_month" 2>/dev/null || echo "*")" month="$(cat "$__object/parameter/month" 2>/dev/null || echo "*")" day_of_week="$(cat "$__object/parameter/day_of_week" 2>/dev/null || echo "*")" - entry="$minute $hour $day_of_month $month $day_of_week $command" + entry="$minute $hour $day_of_month $month $day_of_week $command # $name" fi -entry="$entry # $name" mkdir "$__object/files" echo "$entry" > "$__object/files/entry" @@ -58,7 +58,7 @@ state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")" # These are the old markers prefix="#cdist:__cron/$__object_id" suffix="#/cdist:__cron/$__object_id" -filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V" +filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V|^# \(Cronie version .\..\)$" cat << DONE crontab -u $user -l 2>/dev/null | grep -v -E "$filter" | awk -v prefix="$prefix" -v suffix="$suffix" ' { @@ -85,7 +85,12 @@ case "$state_should" in echo ") | crontab -u $user -" ;; absent) - echo "( crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" 2>/dev/null || true ) | \\" - echo "grep -v \"# $name\\$\" | crontab -u $user -" + if [ -f "$__object/parameter/raw_command" ]; then + echo "( crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" 2>/dev/null || true ) | \\" + echo "grep -v \"^$entry\\$\" | crontab -u $user -" + else + echo "( crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" 2>/dev/null || true ) | \\" + echo "grep -v \"# $name\\$\" | crontab -u $user -" + fi ;; esac diff --git a/cdist/conf/type/__docker/man.rst b/cdist/conf/type/__docker/man.rst new file mode 100644 index 00000000..70b92cc7 --- /dev/null +++ b/cdist/conf/type/__docker/man.rst @@ -0,0 +1,56 @@ +cdist-type__docker(7) +===================== + +NAME +---- +cdist-type__docker - install docker-engine + + +DESCRIPTION +----------- +Installs latest docker-engine package from dockerproject.org. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +None. + + +BOOLEAN PARAMETERS +------------------ +experimental + Install the experimental docker-engine package instead of the latest stable release. + +state + 'present' or 'absent', defaults to 'present' + + +EXAMPLES +-------- + +.. code-block:: sh + + # Install docker + __docker + + # Install experimental + __docker --experimental + + # Remove docker + __docker --state absent + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2016 Steven Armstrong. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__docker/manifest b/cdist/conf/type/__docker/manifest new file mode 100755 index 00000000..1f473afb --- /dev/null +++ b/cdist/conf/type/__docker/manifest @@ -0,0 +1,83 @@ +#!/bin/sh +# +# 2016 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + + +os=$(cat "$__global/explorer/os") +state=$(cat "$__object/parameter/state") + +case "$os" in + centos) + component="main" + if [ -f "$__object/parameter/experimental" ]; then + component="experimental" + fi + __yum_repo docker \ + --name 'Docker Repository' \ + --baseurl "https://yum.dockerproject.org/repo/$component/centos/\$releasever/" \ + --enabled \ + --gpgcheck 1 \ + --gpgkey 'https://yum.dockerproject.org/gpg' \ + --state ${state} + require="__yum_repo/docker" __package docker-engine --state ${state} + ;; + ubuntu) + component="main" + if [ -f "$__object/parameter/experimental" ]; then + component="experimental" + fi + __package apparmor --state ${state} + __package ca-certificates --state ${state} + __package apt-transport-https --state ${state} + __apt_key docker --keyid 58118E89F3A912897C070ADBF76221572C52609D --state ${state} + export CDIST_ORDER_DEPENDENCY=on + __apt_source docker \ + --uri https://apt.dockerproject.org/repo \ + --distribution "ubuntu-$(cat "$__global/explorer/lsb_codename")" \ + --state ${state} \ + --component "$component" + __package docker-engine --state ${state} + unset CDIST_ORDER_DEPENDENCY + ;; + debian) + component="main" + if [ -f "$__object/parameter/experimental" ]; then + component="experimental" + fi + + __package apt-transport-https --state ${state} + __package ca-certificates --state ${state} + __package gnupg2 --state ${state} + __apt_key docker --keyid 58118E89F3A912897C070ADBF76221572C52609D --state ${state} + export CDIST_ORDER_DEPENDENCY=on + __apt_source docker \ + --uri https://apt.dockerproject.org/repo \ + --distribution "debian-$(cat "$__global/explorer/lsb_codename")" \ + --state ${state} \ + --component "$component" + __package docker-engine --state ${state} + unset CDIST_ORDER_DEPENDENCY + + ;; + *) + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__docker/parameter/boolean b/cdist/conf/type/__docker/parameter/boolean new file mode 100644 index 00000000..9839eb20 --- /dev/null +++ b/cdist/conf/type/__docker/parameter/boolean @@ -0,0 +1 @@ +experimental diff --git a/cdist/conf/type/__docker/parameter/default/state b/cdist/conf/type/__docker/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__docker/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__docker/parameter/optional b/cdist/conf/type/__docker/parameter/optional new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/cdist/conf/type/__docker/parameter/optional @@ -0,0 +1 @@ +state diff --git a/cdist/conf/type/__docker/singleton b/cdist/conf/type/__docker/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__docker_compose/gencode-remote b/cdist/conf/type/__docker_compose/gencode-remote new file mode 100644 index 00000000..bd1ad452 --- /dev/null +++ b/cdist/conf/type/__docker_compose/gencode-remote @@ -0,0 +1,31 @@ +#!/bin/sh +# +# 2016 Dominique Roux (dominique.roux at ungleich.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. +# +# 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 . +# + +# Variables +version="$(cat "$__object/parameter/version")" +state="$(cat "$__object/parameter/state")" + +if [ ${state} = "present" ]; then + # Download docker-compose file + echo 'curl -L "https://github.com/docker/compose/releases/download/'${version}'/docker-compose-$(uname -s)-$(uname -m)" -o /tmp/docker-compose' + echo 'mv /tmp/docker-compose /usr/local/bin/docker-compose' + # Change permissions + echo 'chmod +x /usr/local/bin/docker-compose' +fi diff --git a/cdist/conf/type/__docker_compose/man.rst b/cdist/conf/type/__docker_compose/man.rst new file mode 100644 index 00000000..7386e737 --- /dev/null +++ b/cdist/conf/type/__docker_compose/man.rst @@ -0,0 +1,58 @@ +cdist-type__docker_compose(7) +============================= + +NAME +---- +cdist-type__docker_compose - install docker-compose + + +DESCRIPTION +----------- +Installs docker-compose package. +State 'absent' will not remove docker binary itself, +only docker-compose binary will be removed + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +version + Define docker_compose version, defaults to "1.9.0" + +state + 'present' or 'absent', defaults to 'present' + + +BOOLEAN PARAMETERS +------------------ +None. + + +EXAMPLES +-------- + +.. code-block:: sh + + # Install docker-compose + __docker_compose + + # Install version 1.9.0-rc4 + __docker_compose --version 1.9.0-rc4 + + # Remove docker-compose + __docker_compose --state absent + + +AUTHORS +------- +Dominique Roux + + +COPYING +------- +Copyright \(C) 2016 Dominique Roux. Free use of this software is +granted under the terms of the GNU General Public License version 3 or later (GPLv3+). diff --git a/cdist/conf/type/__docker_compose/manifest b/cdist/conf/type/__docker_compose/manifest new file mode 100644 index 00000000..559375ef --- /dev/null +++ b/cdist/conf/type/__docker_compose/manifest @@ -0,0 +1,33 @@ +#!/bin/sh +# +# 2016 Dominique Roux (dominique.roux at ungleich.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. +# +# 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 . +# +# + +state="$(cat "$__object/parameter/state")" + +# Needed packages +if [ ${state} = "present" ]; then + __docker + __package curl +elif [ ${state} = "absent" ]; then + __file /usr/local/bin/docker-compose --state absent +else + echo "Unknown state: ${state}" >&2 + exit 1 +fi diff --git a/cdist/conf/type/__docker_compose/parameter/default/state b/cdist/conf/type/__docker_compose/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__docker_compose/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__docker_compose/parameter/default/version b/cdist/conf/type/__docker_compose/parameter/default/version new file mode 100644 index 00000000..f8e233b2 --- /dev/null +++ b/cdist/conf/type/__docker_compose/parameter/default/version @@ -0,0 +1 @@ +1.9.0 diff --git a/cdist/conf/type/__docker_compose/parameter/optional b/cdist/conf/type/__docker_compose/parameter/optional new file mode 100644 index 00000000..4d595ed7 --- /dev/null +++ b/cdist/conf/type/__docker_compose/parameter/optional @@ -0,0 +1,2 @@ +state +version diff --git a/cdist/conf/type/__docker_compose/singleton b/cdist/conf/type/__docker_compose/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__file/gencode-local b/cdist/conf/type/__file/gencode-local index ed7482cb..4caa6df6 100755 --- a/cdist/conf/type/__file/gencode-local +++ b/cdist/conf/type/__file/gencode-local @@ -66,8 +66,15 @@ destination_upload="\$($__remote_exec $__target_host "mktemp $tempfile_template" DONE if [ "$upload_file" ]; then echo upload >> "$__messages_out" + # IPv6 fix + if $(echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$') + then + my_target_host="[${__target_host}]" + else + my_target_host="${__target_host}" + fi cat << DONE -$__remote_copy "$source" "${__target_host}:\$destination_upload" +$__remote_copy "$source" "${my_target_host}:\$destination_upload" DONE fi # move uploaded file into place diff --git a/cdist/conf/type/__filesystem/man.rst b/cdist/conf/type/__filesystem/man.rst index d88e27c1..1c103ac9 100644 --- a/cdist/conf/type/__filesystem/man.rst +++ b/cdist/conf/type/__filesystem/man.rst @@ -13,7 +13,7 @@ This cdist type allows you to create filesystems on devices. If the device is mounted on target, it refuses to do anything. If the device has a filesystem other then the specified and/or -the label is not correct, it only makes a new filesystem +the label is not correct, it only makes a new filesystem if you have specified --force option. @@ -30,14 +30,14 @@ device Blockdevice for filesystem, Defaults to object_id. On linux, it can be any lsblk accepted device notation. - | + | | For example: - | /dev/sdx + | /dev/sdx | or /dev/disk/by-xxxx/xxx | or /dev/mapper/xxxx label - Label which sould apply on the filesystem. + Label which should be applied on the filesystem. mkfsoptions Additional options which are inserted to the mkfs.xxx call. @@ -46,15 +46,15 @@ mkfsoptions BOOLEAN PARAMETERS ------------------ force - Normaly, this type does nothing if a filesystem is found - on the target device. If you specify force, it's formated + Normally, this type does nothing if a filesystem is found + on the target device. If you specify force, it's formatted if the filesystem type or label differs from parameters. Warning: This option can easily lead into data loss! MESSAGES -------- filesystem on \: created - Filesytem was created on + Filesystem was created on EXAMPLES @@ -62,7 +62,7 @@ EXAMPLES .. code-block:: sh - # Ensures that device /dev/sdb is formated with xfs + # Ensures that device /dev/sdb is formatted with xfs __filesystem /dev/sdb --fstype xfs --label Testdisk1 # The same thing with btrfs and disk spezified by pci path to disk 1:0 on vmware __filesystem dev_sdb --fstype btrfs --device /dev/disk/by-path/pci-0000:0b:00.0-scsi-0:0:0:0 --label Testdisk2 diff --git a/cdist/conf/type/__firewalld_start/gencode-remote b/cdist/conf/type/__firewalld_start/gencode-remote new file mode 100644 index 00000000..7a3b6298 --- /dev/null +++ b/cdist/conf/type/__firewalld_start/gencode-remote @@ -0,0 +1,84 @@ +#!/bin/sh +# +# 2016 Darko Poljak(darko.poljak at ungleich.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. +# +# 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 . +# +# + +startstate="$(cat "$__object/parameter/startstate")" +init=$(cat "$__global/explorer/init") + +os=$(cat "$__global/explorer/os") +os_version=$(cat "$__global/explorer/os_version") +name="firewalld" + +case "${startstate}" in + present) + cmd="start" + ;; + absent) + cmd="stop" + ;; + *) + echo "Unknown startstate: ${startstate}" >&2 + exit 1 + ;; +esac + +if [ "$init" = 'systemd' ]; then + # this handles ALL linux distros with systemd + # e.g. archlinux, gentoo in some cases, new RHEL and SLES versions + echo "systemctl \"$cmd\" \"$name\"" +else + case "$os" in + debian) + case "$os_version" in + [1-7]*) + echo "service \"$name\" \"$cmd\"" + ;; + 8*) + echo "systemctl \"$cmd\" \"$name\"" + ;; + *) + echo "Unsupported version $os_version of $os" >&2 + exit 1 + ;; + esac + ;; + + gentoo) + echo service \"$name\" \"$cmd\" + ;; + + amazon|scientific|centos|fedora|owl|redhat|suse) + echo service \"$name\" \"$cmd\" + ;; + + openwrt) + echo "/etc/init.d/\"$name\" \"$cmd\"" + ;; + + ubuntu) + echo "service \"$name\" \"$cmd\"" + ;; + + *) + echo "Unsupported os: $os" >&2 + exit 1 + ;; + esac +fi diff --git a/cdist/conf/type/__firewalld_start/man.rst b/cdist/conf/type/__firewalld_start/man.rst new file mode 100644 index 00000000..74199cd6 --- /dev/null +++ b/cdist/conf/type/__firewalld_start/man.rst @@ -0,0 +1,53 @@ +cdist-type__firewalld_start(7) +============================== + +NAME +---- +cdist-type__firewalld_start - start and enable firewalld + + +DESCRIPTION +----------- +This cdist type allows you to start and enable firewalld. + + +REQUIRED PARAMETERS +------------------- +None + +OPTIONAL PARAMETERS +------------------- +startstate + 'present' or 'absent', start/stop firewalld. Default is 'present'. +bootstate + 'present' or 'absent', enable/disable firewalld on boot. Default is 'present'. + + +EXAMPLES +-------- + +.. code-block:: sh + + # start and enable firewalld + __firewalld_start + + # only enable firewalld to start on boot + __firewalld_start --startstate present --bootstate absent + + +SEE ALSO +-------- +:strong:`firewalld`\ (8) + + +AUTHORS +------- +Darko Poljak + + +COPYING +------- +Copyright \(C) 2016 Darko Poljak. 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. diff --git a/cdist/conf/type/__firewalld_start/manifest b/cdist/conf/type/__firewalld_start/manifest new file mode 100644 index 00000000..2c6a0219 --- /dev/null +++ b/cdist/conf/type/__firewalld_start/manifest @@ -0,0 +1,23 @@ +#!/bin/sh +# +# 2016 Darko Poljak (darko.poljak at ungleich.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. +# +# 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 . + +bootstate="$(cat "$__object/parameter/bootstate")" + +__package firewalld +require="__package/firewalld" __start_on_boot firewalld --state "${bootstate}" diff --git a/cdist/conf/type/__firewalld_start/parameter/default/bootstate b/cdist/conf/type/__firewalld_start/parameter/default/bootstate new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__firewalld_start/parameter/default/bootstate @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__firewalld_start/parameter/default/startstate b/cdist/conf/type/__firewalld_start/parameter/default/startstate new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__firewalld_start/parameter/default/startstate @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__firewalld_start/parameter/optional b/cdist/conf/type/__firewalld_start/parameter/optional new file mode 100644 index 00000000..934c7d0d --- /dev/null +++ b/cdist/conf/type/__firewalld_start/parameter/optional @@ -0,0 +1,2 @@ +bootstate +startstate diff --git a/cdist/conf/type/__firewalld_start/singleton b/cdist/conf/type/__firewalld_start/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__git/man.rst b/cdist/conf/type/__git/man.rst index 64adfd2f..17e9c623 100644 --- a/cdist/conf/type/__git/man.rst +++ b/cdist/conf/type/__git/man.rst @@ -44,7 +44,7 @@ EXAMPLES __git /home/services/dokuwiki --source git://github.com/splitbrain/dokuwiki.git # Checkout cdist, stay on branch 2.1 - __git /home/nico/cdist --source git://github.com/telmich/cdist.git --branch 2.1 + __git /home/nico/cdist --source git://github.com/ungleich/cdist.git --branch 2.1 AUTHORS diff --git a/cdist/conf/type/__hostname/gencode-remote b/cdist/conf/type/__hostname/gencode-remote index c1808de0..4eb08723 100755 --- a/cdist/conf/type/__hostname/gencode-remote +++ b/cdist/conf/type/__hostname/gencode-remote @@ -40,7 +40,7 @@ case "$os" in exit 0 fi ;; - scientific|centos) + scientific|centos|openbsd) if [ "$name_sysconfig" = "$name_should" -a "$name_running" = "$name_should" ]; then exit 0 fi @@ -64,7 +64,7 @@ else echo "hostname '$name_should'" echo "printf '%s\n' '$name_should' > /etc/hostname" ;; - centos) + centos|openbsd) echo "hostname '$name_should'" ;; suse) diff --git a/cdist/conf/type/__hostname/manifest b/cdist/conf/type/__hostname/manifest index 842075e0..823d2f7e 100755 --- a/cdist/conf/type/__hostname/manifest +++ b/cdist/conf/type/__hostname/manifest @@ -23,7 +23,14 @@ os=$(cat "$__global/explorer/os") if [ -f "$__object/parameter/name" ]; then name_should="$(cat "$__object/parameter/name")" else - name_should="$(echo "${__target_host%%.*}")" + case "$os" in + openbsd) + name_should="$(echo "${__target_host}")" + ;; + *) + name_should="$(echo "${__target_host%%.*}")" + ;; + esac fi @@ -45,6 +52,9 @@ case "$os" in --key HOSTNAME \ --value "$name_should" --exact_delimiter ;; + openbsd) + echo "$name_should" | __file /etc/myname --source - + ;; *) not_supported ;; diff --git a/cdist/conf/type/__install_bootloader_grub/gencode-remote b/cdist/conf/type/__install_bootloader_grub/gencode-remote new file mode 100755 index 00000000..ed57331a --- /dev/null +++ b/cdist/conf/type/__install_bootloader_grub/gencode-remote @@ -0,0 +1,73 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +device="$(cat "$__object/parameter/device")" +chroot="$(cat "$__object/parameter/chroot")" + + +cat << DONE +os=\$( +if grep -q ^DISTRIB_ID=Ubuntu ${chroot}/etc/lsb-release 2>/dev/null; then + echo ubuntu + exit 0 +fi + +if [ -f ${chroot}/etc/arch-release ]; then + echo archlinux + exit 0 +fi + +if [ -f ${chroot}/etc/debian_version ]; then + echo debian + exit 0 +fi +) + +# Ensure /tmp exists +[ -d "${chroot}/tmp" ] || mkdir -m 1777 "${chroot}/tmp" +# Generate script to run in chroot +script=\$(mktemp "${chroot}/tmp/__install_bootloader_grub.XXXXXXXXXX") +# Link file descriptor #6 with stdout +exec 6>&1 +# Link stdout with \$script +exec > \$script + +echo "#!/bin/sh -l" +echo "grub-install $device" +case \$os in + archlinux) + # bugfix/workarround: rebuild initramfs + # FIXME: doesn't belong here + echo "mkinitcpio -p linux" + echo "grub-mkconfig -o /boot/grub/grub.cfg" + ;; + ubuntu|debian) echo "update-grub" ;; +esac + +# Restore stdout and close file descriptor #6. +exec 1>&6 6>&- + +# Make script executable +chmod +x "\$script" + +# Run script in chroot +relative_script="\${script#$chroot}" +chroot "$chroot" "\$relative_script" +DONE diff --git a/cdist/conf/type/__install_bootloader_grub/install b/cdist/conf/type/__install_bootloader_grub/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_bootloader_grub/man.rst b/cdist/conf/type/__install_bootloader_grub/man.rst new file mode 100644 index 00000000..625db1d2 --- /dev/null +++ b/cdist/conf/type/__install_bootloader_grub/man.rst @@ -0,0 +1,48 @@ +cdist-type__install_bootloader_grub(7) +====================================== + +NAME +---- +cdist-type__install_bootloader_grub - install grub2 bootloader on given disk + + +DESCRIPTION +----------- +This cdist type allows you to install grub2 bootloader on given disk. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +device + The device to install grub to. Defaults to object_id + +chroot + where to chroot before running grub-install. Defaults to /target. + + +EXAMPLES +-------- + +.. code-block:: sh + + __install_bootloader_grub /dev/sda + + __install_bootloader_grub /dev/sda --chroot /mnt/foobar + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_bootloader_grub/manifest b/cdist/conf/type/__install_bootloader_grub/manifest new file mode 100755 index 00000000..4c7c4955 --- /dev/null +++ b/cdist/conf/type/__install_bootloader_grub/manifest @@ -0,0 +1,25 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +# set defaults +device="$(cat "$__object/parameter/device" 2>/dev/null \ + || echo "/$__object_id" | tee "$__object/parameter/device")" +chroot="$(cat "$__object/parameter/chroot" 2>/dev/null \ + || echo "/target" | tee "$__object/parameter/chroot")" diff --git a/cdist/conf/type/__install_bootloader_grub/parameter/optional b/cdist/conf/type/__install_bootloader_grub/parameter/optional new file mode 100644 index 00000000..0bd1ce46 --- /dev/null +++ b/cdist/conf/type/__install_bootloader_grub/parameter/optional @@ -0,0 +1,2 @@ +device +chroot diff --git a/cdist/conf/type/__install_chroot_mount/gencode-remote b/cdist/conf/type/__install_chroot_mount/gencode-remote new file mode 120000 index 00000000..b1a5485e --- /dev/null +++ b/cdist/conf/type/__install_chroot_mount/gencode-remote @@ -0,0 +1 @@ +../__chroot_mount/gencode-remote \ No newline at end of file diff --git a/cdist/conf/type/__install_chroot_mount/install b/cdist/conf/type/__install_chroot_mount/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_chroot_mount/man.rst b/cdist/conf/type/__install_chroot_mount/man.rst new file mode 100644 index 00000000..4054c4c4 --- /dev/null +++ b/cdist/conf/type/__install_chroot_mount/man.rst @@ -0,0 +1,42 @@ +cdist-type__install_chroot_mount(7) +=================================== + +NAME +---- +cdist-type__install_chroot_mount - mount a chroot with install command + + +DESCRIPTION +----------- +Mount and prepare a chroot for running commands within it. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +None + + +EXAMPLES +-------- + +.. code-block:: sh + + __install_chroot_mount /path/to/chroot + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2012 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_chroot_umount/gencode-remote b/cdist/conf/type/__install_chroot_umount/gencode-remote new file mode 120000 index 00000000..f2bd2681 --- /dev/null +++ b/cdist/conf/type/__install_chroot_umount/gencode-remote @@ -0,0 +1 @@ +../__chroot_umount/gencode-remote \ No newline at end of file diff --git a/cdist/conf/type/__install_chroot_umount/install b/cdist/conf/type/__install_chroot_umount/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_chroot_umount/man.rst b/cdist/conf/type/__install_chroot_umount/man.rst new file mode 100644 index 00000000..2e020c01 --- /dev/null +++ b/cdist/conf/type/__install_chroot_umount/man.rst @@ -0,0 +1,47 @@ +cdist-type__install_chroot_umount(7) +==================================== + +NAME +---- +cdist-type__install_chroot_umount - unmount a chroot mounted by __install_chroot_mount + + +DESCRIPTION +----------- +Undo what __install_chroot_mount did. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +None + + +EXAMPLES +-------- + +.. code-block:: sh + + __install_chroot_umount /path/to/chroot + + +SEE ALSO +-------- +:strong:`cdist-type__install_chroot_mount`\ (7) + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2012 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_config/files/remote/copy b/cdist/conf/type/__install_config/files/remote/copy new file mode 100755 index 00000000..5b6f555c --- /dev/null +++ b/cdist/conf/type/__install_config/files/remote/copy @@ -0,0 +1,48 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# +# +# __remote_copy script to run cdist against a chroot on a remote host via ssh. +# +# Usage: +# __remote_copy="/path/to/this/script /path/to/your/chroot" cdist config target-id +# + +log() { + echo "$@" | logger -t "__install_config copy" + : +} + +chroot="$1"; shift +target_host="$__target_host" + +scp="scp -o User=root -q" + +# postfix target_host with chroot location +code="$(echo "$@" | sed "s|$target_host:|$target_host:$chroot|g")" + +log "target_host: $target_host" +log "chroot: $chroot" +log "@: $@" +log "code: $code" + +# copy files into chroot +$scp $code + +log "-----" diff --git a/cdist/conf/type/__install_config/files/remote/exec b/cdist/conf/type/__install_config/files/remote/exec new file mode 100755 index 00000000..58e6b162 --- /dev/null +++ b/cdist/conf/type/__install_config/files/remote/exec @@ -0,0 +1,48 @@ +#!/bin/sh +# +# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# +# +# __remote_exec script to run cdist against a chroot on a remote host via ssh. +# +# Usage: +# __remote_exec="/path/to/this/script /path/to/your/chroot" cdist config target-id +# + +log() { + echo "$@" | logger -t "__install_config exec" + : +} + +chroot="$1"; shift +target_host="$__target_host" +# In exec mode the first argument is the __target_host which we already got from env. Get rid of it. +shift + +ssh="ssh -o User=root -q $target_host" +code="$ssh chroot $chroot sh -c '$@'" + +log "target_host: $target_host" +log "chroot: $chroot" +log "@: $@" +log "code: $code" + +# Run the code +$code + +log "-----" diff --git a/cdist/conf/type/__install_config/gencode-local b/cdist/conf/type/__install_config/gencode-local new file mode 100755 index 00000000..674dec25 --- /dev/null +++ b/cdist/conf/type/__install_config/gencode-local @@ -0,0 +1,50 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +chroot="$(cat "$__object/parameter/chroot")" +remote_exec="$__type/files/remote/exec" +remote_copy="$__type/files/remote/copy" + +cdist_args="-v" +[ "$__debug" = "yes" ] && cdist_args="$cdist_args -d" + +cat << DONE +#echo "__apt_noautostart --state present" \ +# | cdist $cdist_args \ +# config \ +# --initial-manifest - \ +# --remote-exec="$remote_exec $chroot" \ +# --remote-copy="$remote_copy $chroot" \ +# $__target_host + +cdist $cdist_args \ + config \ + --remote-exec="$remote_exec $chroot" \ + --remote-copy="$remote_copy $chroot" \ + $__target_host + +#echo "__apt_noautostart --state absent" \ +# | cdist $cdist_args \ +# config \ +# --initial-manifest - \ +# --remote-exec="$remote_exec $chroot" \ +# --remote-copy="$remote_copy $chroot" \ +# $__target_host +DONE diff --git a/cdist/conf/type/__install_config/install b/cdist/conf/type/__install_config/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_config/man.rst b/cdist/conf/type/__install_config/man.rst new file mode 100644 index 00000000..0034e85d --- /dev/null +++ b/cdist/conf/type/__install_config/man.rst @@ -0,0 +1,47 @@ +cdist-type__install_config(7) +============================= + +NAME +---- +cdist-type__install_config - run cdist config as part of the installation + + +DESCRIPTION +----------- +This cdist type allows you to run cdist config as part of the installation. +It does this by using a custom __remote_{copy,exec} prefix which runs +cdist config against the /target chroot on the remote host. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +chroot + where to chroot before running grub-install. Defaults to /target. + + +EXAMPLES +-------- + +.. code-block:: sh + + __install_config + + __install_config --chroot /mnt/somewhere + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_config/manifest b/cdist/conf/type/__install_config/manifest new file mode 100755 index 00000000..f26297b4 --- /dev/null +++ b/cdist/conf/type/__install_config/manifest @@ -0,0 +1,23 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +# set defaults +chroot="$(cat "$__object/parameter/chroot" 2>/dev/null \ + || echo "/target" | tee "$__object/parameter/chroot")" diff --git a/cdist/conf/type/__install_config/parameter/optional b/cdist/conf/type/__install_config/parameter/optional new file mode 100644 index 00000000..fa32393d --- /dev/null +++ b/cdist/conf/type/__install_config/parameter/optional @@ -0,0 +1 @@ +chroot diff --git a/cdist/conf/type/__install_config/singleton b/cdist/conf/type/__install_config/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_file/explorer b/cdist/conf/type/__install_file/explorer new file mode 120000 index 00000000..8479ee44 --- /dev/null +++ b/cdist/conf/type/__install_file/explorer @@ -0,0 +1 @@ +../__file/explorer \ No newline at end of file diff --git a/cdist/conf/type/__install_file/gencode-local b/cdist/conf/type/__install_file/gencode-local new file mode 120000 index 00000000..9ce4e805 --- /dev/null +++ b/cdist/conf/type/__install_file/gencode-local @@ -0,0 +1 @@ +../__file/gencode-local \ No newline at end of file diff --git a/cdist/conf/type/__install_file/gencode-remote b/cdist/conf/type/__install_file/gencode-remote new file mode 120000 index 00000000..f390bba4 --- /dev/null +++ b/cdist/conf/type/__install_file/gencode-remote @@ -0,0 +1 @@ +../__file/gencode-remote \ No newline at end of file diff --git a/cdist/conf/type/__install_file/install b/cdist/conf/type/__install_file/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_file/man.rst b/cdist/conf/type/__install_file/man.rst new file mode 100644 index 00000000..c5409167 --- /dev/null +++ b/cdist/conf/type/__install_file/man.rst @@ -0,0 +1,112 @@ +cdist-type__install_file(7) +=========================== + +NAME +---- +cdist-type__install_file - Manage files with install command. + + +DESCRIPTION +----------- +This cdist type allows you to create files, remove files and set file +attributes on the target. + +If the file already exists on the target, then if it is a: + +regular file, and state is: + present + replace it with the source file if they are not equal + exists + do nothing +symlink + replace it with the source file +directory + replace it with the source file + +In any case, make sure that the file attributes are as specified. + + +REQUIRED PARAMETERS +------------------- +None. + +OPTIONAL PARAMETERS +------------------- +state + 'present', 'absent' or 'exists', defaults to 'present' where: + + present + the file is exactly the one from source + absent + the file does not exist + exists + the file from source but only if it doesn't already exist + +group + Group to chgrp to. + +mode + Unix permissions, suitable for chmod. + +owner + User to chown to. + +source + If supplied, copy this file from the host running cdist to the target. + If not supplied, an empty file or directory will be created. + If source is '-' (dash), take what was written to stdin as the file content. + +MESSAGES +-------- +chgrp + Changed group membership +chown + Changed owner +chmod + Changed mode +create + Empty file was created (no --source specified) +remove + File exists, but state is absent, file will be removed by generated code. +upload + File was uploaded + + +EXAMPLES +-------- + +.. code-block:: sh + + # Create /etc/cdist-configured as an empty file + __install_file /etc/cdist-configured + # The same thing + __install_file /etc/cdist-configured --state present + # Use __file from another type + __install_file /etc/issue --source "$__type/files/archlinux" --state present + # Delete existing file + __install_file /etc/cdist-configured --state absent + # Supply some more settings + __install_file /etc/shadow --source "$__type/files/shadow" \ + --owner root --group shadow --mode 0640 \ + --state present + # Provide a default file, but let the user change it + __install_file /home/frodo/.bashrc --source "/etc/skel/.bashrc" \ + --state exists \ + --owner frodo --mode 0600 + # Take file content from stdin + __install_file /tmp/whatever --owner root --group root --mode 644 --source - << DONE + Here goes the content for /tmp/whatever + DONE + + +AUTHORS +------- +Nico Schottelius + + +COPYING +------- +Copyright \(C) 2011-2013 Nico Schottelius. 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. diff --git a/cdist/conf/type/__install_file/parameter b/cdist/conf/type/__install_file/parameter new file mode 120000 index 00000000..e5099e86 --- /dev/null +++ b/cdist/conf/type/__install_file/parameter @@ -0,0 +1 @@ +../__file/parameter \ No newline at end of file diff --git a/cdist/conf/type/__install_fstab/install b/cdist/conf/type/__install_fstab/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_fstab/man.rst b/cdist/conf/type/__install_fstab/man.rst new file mode 100644 index 00000000..5562c139 --- /dev/null +++ b/cdist/conf/type/__install_fstab/man.rst @@ -0,0 +1,53 @@ +cdist-type__install_fstab(7) +============================ + +NAME +---- +cdist-type__install_fstab - generate /etc/fstab during installation + + +DESCRIPTION +----------- +Uses __install_generate_fstab to generate a /etc/fstab file and uploads it +to the target machine at ${prefix}/etc/fstab. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +prefix + The prefix under which to generate the /etc/fstab file. + Defaults to /target. + + +EXAMPLES +-------- + +.. code-block:: sh + + __install_fstab + + __install_fstab --prefix /mnt/target + + +SEE ALSO +-------- +:strong:`cdist-type__install_generate_fstab`\ (7), +:strong:`cdist-type__install_mount`\ (7) + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_fstab/manifest b/cdist/conf/type/__install_fstab/manifest new file mode 100755 index 00000000..74af53c0 --- /dev/null +++ b/cdist/conf/type/__install_fstab/manifest @@ -0,0 +1,29 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +prefix="$(cat "$__object/parameter/prefix" 2>/dev/null || echo "/target")" + +[ -d "$__object/files" ] || mkdir "$__object/files" +__install_generate_fstab --uuid --destination "$__object/files/fstab" +require="__install_generate_fstab" \ + __install_file "${prefix}/etc/fstab" --source "$__object/files/fstab" \ + --mode 644 \ + --owner root \ + --group root diff --git a/cdist/conf/type/__install_fstab/parameter/optional b/cdist/conf/type/__install_fstab/parameter/optional new file mode 100644 index 00000000..f73f3093 --- /dev/null +++ b/cdist/conf/type/__install_fstab/parameter/optional @@ -0,0 +1 @@ +file diff --git a/cdist/conf/type/__install_fstab/singleton b/cdist/conf/type/__install_fstab/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_generate_fstab/files/fstab.header b/cdist/conf/type/__install_generate_fstab/files/fstab.header new file mode 100644 index 00000000..7653cc78 --- /dev/null +++ b/cdist/conf/type/__install_generate_fstab/files/fstab.header @@ -0,0 +1 @@ +# Generated by cdist __install_generate_fstab diff --git a/cdist/conf/type/__install_generate_fstab/gencode-local b/cdist/conf/type/__install_generate_fstab/gencode-local new file mode 100755 index 00000000..d10e5b92 --- /dev/null +++ b/cdist/conf/type/__install_generate_fstab/gencode-local @@ -0,0 +1,59 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +destination="$(cat "$__object/parameter/destination")" +cat "$__type/files/fstab.header" > "$destination" + +mkdir "$__object/files" +# get current UUID's from target_host +$__remote_exec $__target_host blkid > "$__object/files/blkid" + +for object in $(find "$__global/object/__install_mount" -path "*.cdist"); do + device="$(cat "$object/parameter/device")" + dir="$(cat "$object/parameter/dir")" + prefix="$(cat "$object/parameter/prefix")" + type="$(cat "$object/parameter/type")" + if [ -f "$object/parameter/options" ]; then + options="$(cat "$object/parameter/options")" + else + options="defaults" + fi + dump=0 + case "$type" in + swap) + pass=0 + dir="$type" + ;; + tmpfs) + pass=0 + ;; + *) + pass=1 + ;; + esac + if [ -f "$__object/parameter/uuid" ]; then + uuid="$(grep -w $device "$__object/files/blkid" | awk '{print $2}')" + if [ -n "$uuid" ]; then + echo "# $dir was on $device during installation" >> "$destination" + device="$uuid" + fi + fi + echo "$device $dir $type $options $dump $pass" >> "$destination" +done diff --git a/cdist/conf/type/__install_generate_fstab/install b/cdist/conf/type/__install_generate_fstab/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_generate_fstab/man.rst b/cdist/conf/type/__install_generate_fstab/man.rst new file mode 100644 index 00000000..b38f8876 --- /dev/null +++ b/cdist/conf/type/__install_generate_fstab/man.rst @@ -0,0 +1,53 @@ +cdist-type__install_generate_fstab(7) +===================================== + +NAME +---- +cdist-type__install_generate_fstab - generate /etc/fstab during installation + + +DESCRIPTION +----------- +Generates a /etc/fstab file from information retrieved from +__install_mount definitions. + + +REQUIRED PARAMETERS +------------------- +destination + The path where to store the generated fstab file. + Note that this is a path on the server, where cdist is running, not the target host. + + +OPTIONAL PARAMETERS +------------------- +None + + +BOOLEAN PARAMETERS +------------------- +uuid + use UUID instead of device in fstab + + +EXAMPLES +-------- + +.. code-block:: sh + + __install_generate_fstab --destination /path/where/you/want/fstab + + __install_generate_fstab --uuid --destination /path/where/you/want/fstab + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2012 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_generate_fstab/parameter/boolean b/cdist/conf/type/__install_generate_fstab/parameter/boolean new file mode 100644 index 00000000..43ab6159 --- /dev/null +++ b/cdist/conf/type/__install_generate_fstab/parameter/boolean @@ -0,0 +1 @@ +uuid diff --git a/cdist/conf/type/__install_generate_fstab/parameter/required b/cdist/conf/type/__install_generate_fstab/parameter/required new file mode 100644 index 00000000..ac459b09 --- /dev/null +++ b/cdist/conf/type/__install_generate_fstab/parameter/required @@ -0,0 +1 @@ +destination diff --git a/cdist/conf/type/__install_generate_fstab/singleton b/cdist/conf/type/__install_generate_fstab/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_mkfs/gencode-remote b/cdist/conf/type/__install_mkfs/gencode-remote new file mode 100755 index 00000000..2fe680e5 --- /dev/null +++ b/cdist/conf/type/__install_mkfs/gencode-remote @@ -0,0 +1,53 @@ +#!/bin/sh +# +# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +device="$(cat "$__object/parameter/device")" +type="$(cat "$__object/parameter/type")" + +case "$type" in + swap) + echo "mkswap $device" + ;; + xfs) + command="mkfs.xfs -f -q" + if [ -f "$__object/parameter/options" ]; then + options="$(cat "$__object/parameter/options")" + command="$command $options" + fi + command="$command $device" + if [ -f "$__object/parameter/blocks" ]; then + blocks="$(cat "$__object/parameter/blocks")" + command="$command $blocks" + fi + echo "$command" + ;; + *) + command="mkfs -t $type -q" + if [ -f "$__object/parameter/options" ]; then + options="$(cat "$__object/parameter/options")" + command="$command $options" + fi + command="$command $device" + if [ -f "$__object/parameter/blocks" ]; then + blocks="$(cat "$__object/parameter/blocks")" + command="$command $blocks" + fi + echo "$command" +esac diff --git a/cdist/conf/type/__install_mkfs/install b/cdist/conf/type/__install_mkfs/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_mkfs/man.rst b/cdist/conf/type/__install_mkfs/man.rst new file mode 100644 index 00000000..6e5c9aa9 --- /dev/null +++ b/cdist/conf/type/__install_mkfs/man.rst @@ -0,0 +1,62 @@ +cdist-type__install_mkfs(7) +=========================== + +NAME +---- +cdist-type__install_mkfs - build a linux file system + + +DESCRIPTION +----------- +This cdist type is a wrapper for the mkfs command. + + +REQUIRED PARAMETERS +------------------- +type + The filesystem type to use. Same as used with mkfs -t. + + +OPTIONAL PARAMETERS +------------------- +device + defaults to object_id + +options + file system-specific options to be passed to the mkfs command + +blocks + the number of blocks to be used for the file system + + +EXAMPLES +-------- + +.. code-block:: sh + + # reiserfs /dev/sda5 + __install_mkfs /dev/sda5 --type reiserfs + + # same thing with explicit device + __install_mkfs whatever --device /dev/sda5 --type reiserfs + + # jfs with journal on /dev/sda2 + __install_mkfs /dev/sda1 --type jfs --options "-j /dev/sda2" + + +SEE ALSO +-------- +:strong:`mkfs`\ (8) + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_mkfs/manifest b/cdist/conf/type/__install_mkfs/manifest new file mode 100755 index 00000000..e9d275a4 --- /dev/null +++ b/cdist/conf/type/__install_mkfs/manifest @@ -0,0 +1,31 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +# set defaults +if [ -f "$__object/parameter/device" ]; then + device="(cat "$__object/parameter/device")" +else + device="/$__object_id" + echo "$device" > "$__object/parameter/device" +fi + +type="(cat "$__object/parameter/type")" + +options="(cat "$__object/parameter/options")" diff --git a/cdist/conf/type/__install_mkfs/parameter/optional b/cdist/conf/type/__install_mkfs/parameter/optional new file mode 100644 index 00000000..86aeae30 --- /dev/null +++ b/cdist/conf/type/__install_mkfs/parameter/optional @@ -0,0 +1,3 @@ +device +options +blocks diff --git a/cdist/conf/type/__install_mkfs/parameter/required b/cdist/conf/type/__install_mkfs/parameter/required new file mode 100644 index 00000000..aa80e646 --- /dev/null +++ b/cdist/conf/type/__install_mkfs/parameter/required @@ -0,0 +1 @@ +type diff --git a/cdist/conf/type/__install_mount/gencode-remote b/cdist/conf/type/__install_mount/gencode-remote new file mode 100755 index 00000000..3a35c139 --- /dev/null +++ b/cdist/conf/type/__install_mount/gencode-remote @@ -0,0 +1,59 @@ +#!/bin/sh +# +# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +get_type_from_mkfs() { + _device="$1" + for mkfs_object in $(find "$__global/object/__install_mkfs" -path "*.cdist"); do + mkfs_device="$(cat "$mkfs_object/parameter/device")" + if [ "$_device" = "$mkfs_device" ]; then + cat "$mkfs_object/parameter/type" + break + fi + done + unset _device + unset mkfs_device + unset mkfs_object +} + +device="$(cat "$__object/parameter/device")" +dir="$(cat "$__object/parameter/dir")" +prefix="$(cat "$__object/parameter/prefix")" +if [ -f "$__object/parameter/type" ]; then + type="$(cat "$__object/parameter/type")" +else + type="$(get_type_from_mkfs "$device")" + # store for later use by others + echo "$type" > "$__object/parameter/type" +fi +[ -n "$type" ] || die "Can't determine type for $__object" +if [ "$type" = "swap" ]; then + echo "swapon \"$device\"" +else + if [ -f "$__object/parameter/options" ]; then + options="$(cat "$__object/parameter/options")" + else + options="" + fi + [ -n "$options" ] && options="-o $options" + mount_point="${prefix}${dir}" + + echo "[ -d \"$mount_point\" ] || mkdir -p \"$mount_point\"" + echo "mount -t \"$type\" $options \"$device\" \"$mount_point\"" +fi diff --git a/cdist/conf/type/__install_mount/install b/cdist/conf/type/__install_mount/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_mount/man.rst b/cdist/conf/type/__install_mount/man.rst new file mode 100644 index 00000000..256cef53 --- /dev/null +++ b/cdist/conf/type/__install_mount/man.rst @@ -0,0 +1,65 @@ +cdist-type__install_mount(7) +============================ + +NAME +---- +cdist-type__install_mount - mount filesystems in the installer + + +DESCRIPTION +----------- +Mounts filesystems in the installer. Collects data to generate /etc/fstab. + + +REQUIRED PARAMETERS +------------------- +device + the device to mount + + +OPTIONAL PARAMETERS +------------------- +dir + where to mount device. Defaults to object_id. + +options + mount options passed to mount(8) and used in /etc/fstab + +type + filesystem type passed to mount(8) and used in /etc/fstab. + If type is swap, 'dir' is ignored. + Defaults to the filesystem used in __install_mkfs for the same 'device'. + +prefix + the prefix to prepend to 'dir' when mounting in the installer. + Defaults to /target. + + +EXAMPLES +-------- + +.. code-block:: sh + + __install_mount slash --dir / --device /dev/sda5 --options noatime + require="__install_mount/slash" __install_mount /boot --device /dev/sda1 + __install_mount swap --device /dev/sda2 --type swap + require="__install_mount/slash" __install_mount /tmp --device tmpfs --type tmpfs + + +SEE ALSO +-------- +:strong:`cdist-type__install_mkfs`\ (7), +:strong:`cdist-type__install_mount_apply` (7) + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_mount/manifest b/cdist/conf/type/__install_mount/manifest new file mode 100755 index 00000000..5afae7fc --- /dev/null +++ b/cdist/conf/type/__install_mount/manifest @@ -0,0 +1,29 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +# set defaults +if [ ! -f "$__object/parameter/dir" ]; then + dir="/$__object_id" + echo "$dir" > "$__object/parameter/dir" +fi +if [ ! -f "$__object/parameter/prefix" ]; then + prefix="/target" + echo "$prefix" > "$__object/parameter/prefix" +fi diff --git a/cdist/conf/type/__install_mount/parameter/optional b/cdist/conf/type/__install_mount/parameter/optional new file mode 100644 index 00000000..08b6ad04 --- /dev/null +++ b/cdist/conf/type/__install_mount/parameter/optional @@ -0,0 +1,3 @@ +dir +type +options diff --git a/cdist/conf/type/__install_mount/parameter/required b/cdist/conf/type/__install_mount/parameter/required new file mode 100644 index 00000000..f89ee6a8 --- /dev/null +++ b/cdist/conf/type/__install_mount/parameter/required @@ -0,0 +1 @@ +device diff --git a/cdist/conf/type/__install_partition_msdos/install b/cdist/conf/type/__install_partition_msdos/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_partition_msdos/man.rst b/cdist/conf/type/__install_partition_msdos/man.rst new file mode 100644 index 00000000..5ebb9218 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos/man.rst @@ -0,0 +1,64 @@ +cdist-type__install_partition_msdos(7) +====================================== + +NAME +---- +cdist-type__install_partition_msdos - creates msdos partitions + + +DESCRIPTION +----------- +This cdist type allows you to create msdos paritions. + + +REQUIRED PARAMETERS +------------------- +type + the partition type used in fdisk (such as 82 or 83) or "extended" + + +OPTIONAL PARAMETERS +------------------- +partition + defaults to object_id + +bootable + mark partition as bootable, true or false, defaults to false + +size + the size of the partition (such as 32M or 15G, whole numbers + only), '+' for remaining space, or 'n%' for percentage of remaining + (these should only be used after all specific partition sizes are + specified). Defaults to +. + + +EXAMPLES +-------- + +.. code-block:: sh + + # 128MB, linux, bootable + __install_partition_msdos /dev/sda1 --type 83 --size 128M --bootable true + # 512MB, swap + __install_partition_msdos /dev/sda2 --type 82 --size 512M + # 100GB, extended + __install_partition_msdos /dev/sda3 --type extended --size 100G + # 10GB, linux + __install_partition_msdos /dev/sda5 --type 83 --size 10G + # 50% of the free space of the extended partition, linux + __install_partition_msdos /dev/sda6 --type 83 --size 50% + # rest of the extended partition, linux + __install_partition_msdos /dev/sda7 --type 83 --size + + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_partition_msdos/manifest b/cdist/conf/type/__install_partition_msdos/manifest new file mode 100755 index 00000000..e55d3f24 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos/manifest @@ -0,0 +1,41 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +# set defaults +if [ -f "$__object/parameter/partition" ]; then + partition="(cat "$__object/parameter/partition")" +else + partition="/$__object_id" + echo "$partition" > "$__object/parameter/partition" +fi +device="$(echo "$partition" | sed 's/[0-9]//g')" +echo "$device" > "$__object/parameter/device" +minor="$(echo "$partition" | sed 's/[^0-9]//g')" +echo "$minor" > "$__object/parameter/minor" + +if [ ! -f "$__object/parameter/bootable" ]; then + echo "false" > "$__object/parameter/bootable" +fi +if [ ! -f "$__object/parameter/size" ]; then + echo "+" > "$__object/parameter/size" +fi + +# pull in the type that actually does something with the above parameters +require="$__object_name" __install_partition_msdos_apply diff --git a/cdist/conf/type/__install_partition_msdos/parameter/optional b/cdist/conf/type/__install_partition_msdos/parameter/optional new file mode 100644 index 00000000..b2b0a4c2 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos/parameter/optional @@ -0,0 +1,3 @@ +partition +bootable +size diff --git a/cdist/conf/type/__install_partition_msdos/parameter/required b/cdist/conf/type/__install_partition_msdos/parameter/required new file mode 100644 index 00000000..aa80e646 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos/parameter/required @@ -0,0 +1 @@ +type diff --git a/cdist/conf/type/__install_partition_msdos_apply/explorer/partitions b/cdist/conf/type/__install_partition_msdos_apply/explorer/partitions new file mode 100755 index 00000000..6be61af4 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos_apply/explorer/partitions @@ -0,0 +1,3 @@ +#!/bin/sh + +cat /proc/partitions diff --git a/cdist/conf/type/__install_partition_msdos_apply/files/lib.sh b/cdist/conf/type/__install_partition_msdos_apply/files/lib.sh new file mode 100644 index 00000000..cddc575d --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos_apply/files/lib.sh @@ -0,0 +1,68 @@ +die() { + echo "[__install_partition_msdos_apply] $@" >&2 + exit 1 +} +debug() { + #echo "[__install_partition_msdos_apply] $@" >&2 + : +} + +fdisk_command() { + local device="$1" + local cmd="$2" + + debug fdisk_command "running fdisk command '${cmd}' on device ${device}" + printf "${cmd}\nw\n" | fdisk -c -u "$device" + ret=$? + # give disk some time + sleep 1 + return $ret +} + +create_disklabel() { + local device=$1 + + debug create_disklabel "creating new msdos disklabel" + fdisk_command ${device} "o" + return $? +} + +toggle_bootable() { + local device="$1" + local minor="$2" + fdisk_command ${device} "a\n${minor}\n" + return $? +} + +create_partition() { + local device="$1" + local minor="$2" + local size="$3" + local type="$4" + local primary_count="$5" + + if [ "$type" = "extended" -o "$type" = "5" ]; then + # Extended partition + primary_extended="e\n" + first_minor="${minor}\n" + [ "${minor}" = "4" ] && first_minor="" + type_minor="${minor}\n" + [ "${minor}" = "1" ] && type_minor="" + type="5" + elif [ "${minor}" -lt "5" ]; then + primary_extended="p\n" + first_minor="${minor}\n" + [ "${minor}" = "4" ] && first_minor="" + type_minor="${minor}\n" + [ "${minor}" = "1" ] && type_minor="" + else + # Logical partitions + first_minor="${minor}\n" + type_minor="${minor}\n" + primary_extended="l\n" + [ "$primary_count" -gt "3" ] && primary_extended="" + fi + [ -n "${size}" ] && size="+${size}M" + fdisk_command ${device} "n\n${primary_extended}${first_minor}\n${size}\nt\n${type_minor}${type}\n" + return $? +} diff --git a/cdist/conf/type/__install_partition_msdos_apply/gencode-remote b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote new file mode 100755 index 00000000..a1547296 --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos_apply/gencode-remote @@ -0,0 +1,159 @@ +#!/bin/sh +# +# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +die() { + echo "[__install_partition_msdos_apply] $@" >&2 + exit 1 +} +debug() { + #echo "[__install_partition_msdos_apply] $@" >&2 + : +} + +# Convert a size specifier 1G 100M or 50% into the corresponding numeric MB. +size_to_mb() { + local size=$1 + local available_size="$2" + + local number_suffix="$(echo ${size} | sed -e 's:\.[0-9]\+::' -e 's:\([0-9]\+\)\([KkMmGg%]\)[Bb]\?:\1|\2:')" + local number="$(echo ${number_suffix} | cut -d '|' -f1)" + local suffix="$(echo ${number_suffix} | cut -d '|' -f2)" + + case "$suffix" in + K|k) + size="$(( $number / 1024 ))" + ;; + M|m) + size="$number" + ;; + G|g) + size="$(( $number * 1024 ))" + ;; + %) + size="$(( $available_size * $number / 100 ))" + ;; + *) + size="-1" + esac + echo "$size" +} + +get_objects() { + objects_file=$(mktemp) + for object in $(find "$__global/object/__install_partition_msdos" -path "*.cdist"); do + object_device="$(cat "$object/parameter/device")" + object_minor="$(cat "$object/parameter/minor")" + echo "$object_device $object_minor $object" >> $objects_file + done + sort -k 1,2 $objects_file | cut -d' ' -f 3 + rm $objects_file + unset objects_file + unset object + unset object_device + unset object_minor +} + +# include function library for use on target +cat "$__type/files/lib.sh" + +partitions="$__object/explorer/partitions" +objects=$(get_objects) +current_device="" +available_device_size= +available_extended_size= +available_size= +primary_count=0 +for object in $objects; do + device="$(cat "$object/parameter/device")" + if [ "$current_device" != "$device" ]; then + echo "create_disklabel \"$device\" || die 'Failed to create disklabel for $device'" + current_device="$device" + device_name=$(echo ${device} | sed -e 's:^/dev/::;s:/:\\/:g') + available_device_size=$(( $(awk "/${device_name}\$/ { print \$3; }" "$partitions") / 1024)) + # make sure we don't go past the end of the drive + available_device_size=$((available_device_size - 2)) + available_extended_size=0 + primary_count=0 + debug "----- $device" + debug "current_device=$current_device" + debug "available_device_size=$available_device_size" + fi + + type="$(cat "$object/parameter/type")" + partition="$(cat "$object/parameter/partition")" + minor="$(cat "$object/parameter/minor")" + + bootable="$(cat "$object/parameter/bootable")" + size="$(cat "$object/parameter/size")" + + + if [ "${minor}" -lt "5" ]; then + # Primary partitions + primary_count=$(( $primary_count + 1 )) + available_size=$available_device_size + else + # Logical partitions + available_size=$available_extended_size + fi + + if [ "$size" = "+" ]; then + # use rest of device + partition_size="" + available_size=0 + else + partition_size=$(size_to_mb "$size" "$available_size") + available_size="$(( $available_size - $partition_size ))" + fi + + if [ "${minor}" -lt "5" ]; then + # Primary partitions + available_device_size=$available_size + if [ "$type" = "extended" -o "$type" = "5" ]; then + # Extended partition + available_extended_size=$partition_size + fi + else + # Logical paritions + available_extended_size=$available_size + fi + + [ "$partition_size" = "-1" ] && die "could not translate size '$size' to a usable value" + debug "----- $partition" + debug "primary_count=$primary_count" + debug "current_device=$current_device" + debug "device=$device" + debug "type=$type" + debug "partition=$partition" + debug "minor=$minor" + debug "bootable=$bootable" + debug "size=$size" + debug "partition_size=$partition_size" + debug "available_size=$available_size" + debug "available_device_size=$available_device_size" + debug "available_extended_size=$available_extended_size" + debug "----------" + + echo "create_partition '$device' '$minor' '$partition_size' '$type' '$primary_count' \ + || die 'Failed to create partition: $partition'" + + if [ "$bootable" = "true" ]; then + echo "toggle_bootable '$device' '$minor' || die 'Failed to toogle bootable flag for partition: $partition'" + fi +done diff --git a/cdist/conf/type/__install_partition_msdos_apply/install b/cdist/conf/type/__install_partition_msdos_apply/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_partition_msdos_apply/man.rst b/cdist/conf/type/__install_partition_msdos_apply/man.rst new file mode 100644 index 00000000..80740fde --- /dev/null +++ b/cdist/conf/type/__install_partition_msdos_apply/man.rst @@ -0,0 +1,47 @@ +cdist-type__install_partition_msdos_apply(7) +============================================ + +NAME +---- +cdist-type__install_partition_msdos_apply - Apply dos partition settings + + +DESCRIPTION +----------- +Create the partitions defined with __install_partition_msdos + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +None + + +EXAMPLES +-------- + +.. code-block:: sh + + __install_partition_msdos_apply + + +SEE ALSO +-------- +:strong:`cdist-type__install_partition_msdos_apply`\ (7) + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_partition_msdos_apply/singleton b/cdist/conf/type/__install_partition_msdos_apply/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_reboot/gencode-remote b/cdist/conf/type/__install_reboot/gencode-remote new file mode 100755 index 00000000..4358347d --- /dev/null +++ b/cdist/conf/type/__install_reboot/gencode-remote @@ -0,0 +1,23 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +options="$(cat "$__object/parameter/options")" + +echo "reboot $options" diff --git a/cdist/conf/type/__install_reboot/install b/cdist/conf/type/__install_reboot/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_reboot/man.rst b/cdist/conf/type/__install_reboot/man.rst new file mode 100644 index 00000000..ecf78ca7 --- /dev/null +++ b/cdist/conf/type/__install_reboot/man.rst @@ -0,0 +1,43 @@ +cdist-type__install_reboot(7) +============================= + +NAME +---- +cdist-type__install_reboot - run reboot + + +DESCRIPTION +----------- +This cdist type allows you to reboot a machine. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +options + options to pass to the reboot command. e.g. -f + + +EXAMPLES +-------- + +.. code-block:: sh + + __install_reboot + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_reboot/manifest b/cdist/conf/type/__install_reboot/manifest new file mode 100755 index 00000000..fab80a1e --- /dev/null +++ b/cdist/conf/type/__install_reboot/manifest @@ -0,0 +1,23 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +# set defaults +options="$(cat "$__object/parameter/options" 2>/dev/null \ + || echo "" | tee "$__object/parameter/options")" diff --git a/cdist/conf/type/__install_reboot/singleton b/cdist/conf/type/__install_reboot/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_reset_disk/gencode-remote b/cdist/conf/type/__install_reset_disk/gencode-remote new file mode 100755 index 00000000..e8e9cf8c --- /dev/null +++ b/cdist/conf/type/__install_reset_disk/gencode-remote @@ -0,0 +1,65 @@ +#!/bin/sh +# +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +disk="/$__object_id" +disk_name="${disk##*/}" + +cat << DONE +# stop lvm's if any +if find /sys/class/block/$disk_name*/holders/ -mindepth 1 | grep -q holders/dm; then + if command -v vgchange >/dev/null; then + vgchange -a n + else + echo "WARNING: vgchange command not found" >&2 + fi +fi + +# stop mdadm raids if any +if [ -r /proc/mdstat ]; then + md_name="\$(awk "/$disk_name/ {print \$1}" /proc/mdstat)" + if [ -n "\$md_name" ]; then + if command -v mdadm >/dev/null; then + mdadm --stop "/dev/\$md_name" + else + echo "WARNING: mdadm command not found" >&2 + echo "WARNING: could not stop active mdadm raid for disk $disk" >&2 + fi + fi +fi + +if command -v pvremove >/dev/null; then + pvremove --force --force --yes "$disk" || true +else + echo "WARNING: pvremove command not found" >&2 +fi +if command -v mdadm >/dev/null; then + mdadm --zero-superblock --force "$disk" || true +else + echo "WARNING: mdadm command not found" >&2 +fi +# clean disks from any legacy signatures +if command -v wipefs >/dev/null; then + wipefs -a "$disk" || true +fi + +# erase partition table +dd if=/dev/zero of=$disk bs=512 count=1 +printf 'w\n' | fdisk -u -c $disk || true +DONE diff --git a/cdist/conf/type/__install_reset_disk/install b/cdist/conf/type/__install_reset_disk/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_reset_disk/man.rst b/cdist/conf/type/__install_reset_disk/man.rst new file mode 100644 index 00000000..fadeec71 --- /dev/null +++ b/cdist/conf/type/__install_reset_disk/man.rst @@ -0,0 +1,43 @@ +cdist-type__install_reset_disk(7) +================================= + +NAME +---- +cdist-type__install_reset_disk - reset a disk + + +DESCRIPTION +----------- +Remove partition table. +Remove all lvm labels. +Remove mdadm superblock. + + +REQUIRED PARAMETERS +------------------- +None + +OPTIONAL PARAMETERS +------------------- +None + + +EXAMPLES +-------- + +.. code-block:: sh + + __install_reset_disk /dev/sdb + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2012 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_stage/gencode-remote b/cdist/conf/type/__install_stage/gencode-remote new file mode 100755 index 00000000..3b83ea61 --- /dev/null +++ b/cdist/conf/type/__install_stage/gencode-remote @@ -0,0 +1,32 @@ +#!/bin/sh +# +# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +uri="$(cat "$__object/parameter/uri" 2>/dev/null \ + || echo "$__object_id")" +target="$(cat "$__object/parameter/target")" + +[ "$__debug" = "yes" ] && curl="curl" || curl="curl -s" +[ "$__debug" = "yes" ] && tar="tar -xvzp" || tar="tar -xzp" + +if [ -f "$__object/parameter/insecure" ] ; then + curl="$curl -k" +fi + +echo "$curl '$uri' | $tar -C '$target'" diff --git a/cdist/conf/type/__install_stage/install b/cdist/conf/type/__install_stage/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_stage/man.rst b/cdist/conf/type/__install_stage/man.rst new file mode 100644 index 00000000..6c68c543 --- /dev/null +++ b/cdist/conf/type/__install_stage/man.rst @@ -0,0 +1,58 @@ +cdist-type__install_stage(7) +============================ + +NAME +---- +cdist-type__install_stage - download and unpack a stage file + + +DESCRIPTION +----------- +Downloads a operating system stage using curl and unpacks it to /target +using tar. The stage tarball is expected to be gzip compressed. + + +REQUIRED PARAMETERS +------------------- +uri + The uri from which to fetch the tarball. + Can be anything understood by curl, e.g: + | http://path/to/stage.tgz + | tftp:///path/to/stage.tgz + | file:///local/path/stage.tgz + + +OPTIONAL PARAMETERS +------------------- +target + where to unpack the tarball to. Defaults to /target. + + +BOOLEAN PARAMETERS +------------------ +insecure + run curl in insecure mode so it does not check the servers ssl certificate + + +EXAMPLES +-------- + +.. code-block:: sh + + __install_stage --uri tftp:///path/to/stage.tgz + __install_stage --uri http://path/to/stage.tgz --target /mnt/foobar + __install_stage --uri file:///path/to/stage.tgz --target /target + __install_stage --uri https://path/to/stage.tgz --target /mnt/foobar --insecure + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2011 - 2013 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_stage/parameter/boolean b/cdist/conf/type/__install_stage/parameter/boolean new file mode 100644 index 00000000..e86bf3fc --- /dev/null +++ b/cdist/conf/type/__install_stage/parameter/boolean @@ -0,0 +1 @@ +insecure diff --git a/cdist/conf/type/__install_stage/parameter/default/target b/cdist/conf/type/__install_stage/parameter/default/target new file mode 100644 index 00000000..ea8c4bf7 --- /dev/null +++ b/cdist/conf/type/__install_stage/parameter/default/target @@ -0,0 +1 @@ +/target diff --git a/cdist/conf/type/__install_stage/parameter/optional b/cdist/conf/type/__install_stage/parameter/optional new file mode 100644 index 00000000..eb5a316c --- /dev/null +++ b/cdist/conf/type/__install_stage/parameter/optional @@ -0,0 +1 @@ +target diff --git a/cdist/conf/type/__install_stage/parameter/required b/cdist/conf/type/__install_stage/parameter/required new file mode 100644 index 00000000..c7954952 --- /dev/null +++ b/cdist/conf/type/__install_stage/parameter/required @@ -0,0 +1 @@ +uri diff --git a/cdist/conf/type/__install_stage/singleton b/cdist/conf/type/__install_stage/singleton new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_umount/gencode-remote b/cdist/conf/type/__install_umount/gencode-remote new file mode 100755 index 00000000..c275fe5d --- /dev/null +++ b/cdist/conf/type/__install_umount/gencode-remote @@ -0,0 +1,25 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +target="$(cat "$__object/parameter/target")" + +echo "swapoff -a" +echo "umount -l ${target}/* || true" +echo "umount -l ${target}" diff --git a/cdist/conf/type/__install_umount/install b/cdist/conf/type/__install_umount/install new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__install_umount/man.rst b/cdist/conf/type/__install_umount/man.rst new file mode 100644 index 00000000..59f63449 --- /dev/null +++ b/cdist/conf/type/__install_umount/man.rst @@ -0,0 +1,43 @@ +cdist-type__install_umount(7) +============================= + +NAME +---- +cdist-type__install_umount - umount target directory + + +DESCRIPTION +----------- +This cdist type allows you to recursively umount the given target directory. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +target + the mount point to umount. Defaults to object_id + + +EXAMPLES +-------- + +.. code-block:: sh + + __install_umount /target + + +AUTHORS +------- +Steven Armstrong + + +COPYING +------- +Copyright \(C) 2011 Steven Armstrong. 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. diff --git a/cdist/conf/type/__install_umount/manifest b/cdist/conf/type/__install_umount/manifest new file mode 100755 index 00000000..c547e167 --- /dev/null +++ b/cdist/conf/type/__install_umount/manifest @@ -0,0 +1,23 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# + +# set defaults +target="$(cat "$__object/parameter/target" 2>/dev/null \ + || echo "/target" | tee "$__object/parameter/target")" diff --git a/cdist/conf/type/__jail_freebsd10/gencode-local b/cdist/conf/type/__jail_freebsd10/gencode-local index d4b89730..8c1687a9 100755 --- a/cdist/conf/type/__jail_freebsd10/gencode-local +++ b/cdist/conf/type/__jail_freebsd10/gencode-local @@ -43,7 +43,14 @@ basepresent="$(cat "$__object/explorer/basepresent")" if [ "$state" = "present" ]; then if [ "$basepresent" = "NONE" ]; then - echo "$__remote_copy" "${jailbase}" "$__target_host:${remotebase}" + # IPv6 fix + if $(echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$') + then + my_target_host="[${__target_host}]" + else + my_target_host="${__target_host}" + fi + echo "$__remote_copy" "${jailbase}" "${my_target_host}:${remotebase}" fi # basepresent=NONE fi # state=present diff --git a/cdist/conf/type/__jail_freebsd9/gencode-local b/cdist/conf/type/__jail_freebsd9/gencode-local index 08c7b7bf..67420a6f 100755 --- a/cdist/conf/type/__jail_freebsd9/gencode-local +++ b/cdist/conf/type/__jail_freebsd9/gencode-local @@ -39,7 +39,14 @@ basepresent="$(cat "$__object/explorer/basepresent")" if [ "$state" = "present" ]; then if [ "$basepresent" = "NONE" ]; then - echo "$__remote_copy" "${jailbase}" "$__target_host:${remotebase}" + # IPv6 fix + if $(echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$') + then + my_target_host="[${__target_host}]" + else + my_target_host="${__target_host}" + fi + echo "$__remote_copy" "${jailbase}" "${my_target_host}:${remotebase}" fi # basepresent=NONE fi # state=present diff --git a/cdist/conf/type/__package/manifest b/cdist/conf/type/__package/manifest index c745f85f..525691bb 100755 --- a/cdist/conf/type/__package/manifest +++ b/cdist/conf/type/__package/manifest @@ -43,6 +43,7 @@ else gentoo) type="emerge" ;; suse) type="zypper" ;; openwrt) type="opkg" ;; + openbsd) type="pkg_openbsd" ;; *) echo "Don't know how to manage packages on: $os" >&2 exit 1 diff --git a/cdist/conf/type/__package_dpkg/gencode-remote b/cdist/conf/type/__package_dpkg/gencode-remote new file mode 100755 index 00000000..d4186e66 --- /dev/null +++ b/cdist/conf/type/__package_dpkg/gencode-remote @@ -0,0 +1,30 @@ +#!/bin/sh +# +# 2013 Tomas Pospisek (tpo_deb sourcepole.ch) +# +# This file is based on cdist's __file/gencode-local and 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 . +# +# +# This __package_dpkg type does not check whether a *.deb package is +# allready installed. It just copies the *.deb package over to the +# destination and installs it. We could use __package_apt to check +# whether a *.deb package is allready installed and only install it +# if we're given a --force argument or similar (would be clever not +# to conflict with dpkg's --force options). But currently we don't +# do any checks or --force'ing. +# + +echo "dpkg -i /var/cache/apt/archives/$__object_id" diff --git a/cdist/conf/type/__package_dpkg/man.rst b/cdist/conf/type/__package_dpkg/man.rst new file mode 100644 index 00000000..65a695b5 --- /dev/null +++ b/cdist/conf/type/__package_dpkg/man.rst @@ -0,0 +1,46 @@ +cdist-type__package_dpkg(7) +=========================== + +NAME +---- +cdist-type__package_dpkg - Manage packages with dpkg + + +DESCRIPTION +----------- +__package_dpkg is used on Debian and variants (like Ubuntu) to +install packages that are provided locally as *.deb files. + +The object given to __package_dpkg must be the name of the deb package. + + +REQUIRED PARAMETERS +------------------- +source + path to the *.deb package + +EXAMPLES +-------- + +.. code-block:: sh + + # Install foo and bar packages + __package_dpkg --source /tmp/foo_0.1_all.deb foo_0.1_all.deb + __package_dpkg --source $__type/files/bar_1.4.deb bar_1.4.deb + + +SEE ALSO +-------- +:strong:`cdist-type__package`\ (7) + +AUTHORS +------- +Tomas Pospisek + +COPYING +------- +Copyright \(C) 2013 Tomas Pospisek. 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 type is based on __package_apt. diff --git a/cdist/conf/type/__package_dpkg/manifest b/cdist/conf/type/__package_dpkg/manifest new file mode 100644 index 00000000..ff477c2d --- /dev/null +++ b/cdist/conf/type/__package_dpkg/manifest @@ -0,0 +1,34 @@ +#!/bin/sh +# +# 2013 Tomas Pospisek (tpo_deb sourcepole.ch) +# +# 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 . +# +# +# This __package_dpkg type does not check whether a *.deb package is +# allready installed. It just copies the *.deb package over to the +# destination and installs it. We could use __package_apt to check +# whether a *.deb package is allready installed and only install it +# if we're given a --force argument or similar (would be clever not +# to conflict with dpkg's --force options). But currently we don't +# do any checks or --force'ing. + + +package_path=$( cat "$__object/parameter/source" ) +package=$( basename "$__object_id" ) + +__file "/var/cache/apt/archives/$package" \ + --source "$package_path" \ + --state present + diff --git a/cdist/conf/type/__package_dpkg/parameter/required b/cdist/conf/type/__package_dpkg/parameter/required new file mode 100644 index 00000000..5a18cd2f --- /dev/null +++ b/cdist/conf/type/__package_dpkg/parameter/required @@ -0,0 +1 @@ +source diff --git a/cdist/conf/type/__package_pkg_openbsd/gencode-remote b/cdist/conf/type/__package_pkg_openbsd/gencode-remote index dea7f711..5ba5f7ef 100755 --- a/cdist/conf/type/__package_pkg_openbsd/gencode-remote +++ b/cdist/conf/type/__package_pkg_openbsd/gencode-remote @@ -29,6 +29,10 @@ os_version="$(cat "$__global/explorer/os_version")" machine="$(cat "$__global/explorer/machine")" +if [ -f "$__object/parameter/version" ]; then + version="$(cat "$__object/parameter/version")" +fi + if [ -f "$__object/parameter/flavor" ]; then flavor="$(cat "$__object/parameter/flavor")" fi @@ -42,6 +46,16 @@ else name="$__object_id" fi +if [ -n "$version" -a -n "$flavor" ]; then + pkgid="$name-$version-$flavor" +elif [ -n "$version" ]; then + pkgid="$name-$version" +elif [ -n "$flavor" ]; then + pkgid="$name--$flavor" +else + pkgid="$name" +fi + state_should="$(cat "$__object/parameter/state")" pkg_version="$(cat "$__object/explorer/pkg_version")" @@ -65,8 +79,8 @@ case "$state_should" in # use this because pkg_add doesn't properly handle errors cat << eof export PKG_PATH="$pkg_path" -status=\$(pkg_add "$pkgopts" "$name--$flavor" 2>&1) -pkg_info | grep "^${name}.*${flavor}" > /dev/null 2>&1 +status=\$(pkg_add "$pkgopts" "$pkgid" 2>&1) +pkg_info | grep "^${name}.*${version}.*${flavor}" > /dev/null 2>&1 # We didn't find the package in the list of 'installed packages', so it failed # This is necessary because pkg_add doesn't return properly @@ -83,8 +97,8 @@ eof absent) # use this because pkg_add doesn't properly handle errors cat << eof -status=\$(pkg_delete "$pkgopts" "$name--$flavor") -pkg_info | grep "^${name}.*${flavor}" > /dev/null 2>&1 +status=\$(pkg_delete "$pkgopts" "$pkgid") +pkg_info | grep "^${name}.*${version}.*${flavor}" > /dev/null 2>&1 # We found the package in the list of 'installed packages' # This would indicate that pkg_delete failed, send the output of pkg_delete diff --git a/cdist/conf/type/__package_pkg_openbsd/man.rst b/cdist/conf/type/__package_pkg_openbsd/man.rst index 0814029f..dcfd0719 100644 --- a/cdist/conf/type/__package_pkg_openbsd/man.rst +++ b/cdist/conf/type/__package_pkg_openbsd/man.rst @@ -24,6 +24,9 @@ name flavor If supplied, use to avoid ambiguity. +version + If supplied, use to avoid ambiguity. + state Either "present" or "absent", defaults to "present" diff --git a/cdist/conf/type/__package_pkg_openbsd/parameter/optional b/cdist/conf/type/__package_pkg_openbsd/parameter/optional index 43278d16..6a5f9277 100644 --- a/cdist/conf/type/__package_pkg_openbsd/parameter/optional +++ b/cdist/conf/type/__package_pkg_openbsd/parameter/optional @@ -1,4 +1,5 @@ name +version flavor state pkg_path diff --git a/cdist/conf/type/__package_upgrade_all/gencode-remote b/cdist/conf/type/__package_upgrade_all/gencode-remote index 9dd3ddf6..3e25f45f 100755 --- a/cdist/conf/type/__package_upgrade_all/gencode-remote +++ b/cdist/conf/type/__package_upgrade_all/gencode-remote @@ -24,6 +24,10 @@ type="$__object/parameter/type" +apt_clean="$__object/parameter/apt-clean" + +apt_dist_upgrade="$__object/parameter/apt-dist-upgrade" + if [ -f "$type" ]; then type="$(cat "$type")" else @@ -48,8 +52,15 @@ case "$type" in echo "yum --quiet clean all" ;; apt) - echo $aptget dist-upgrade - echo "apt-get --quiet autoclean" + if [ -f "$apt_dist_upgrade" ] + then echo $aptget dist-upgrade + else echo $aptget upgrade + fi + + if [ -f "$apt_clean" ] + then echo "apt-get --quiet clean" + else echo "apt-get --quiet autoclean" + fi ;; pacman) echo "pacman --noprogressbar --noconfirm --sync --sysupgrade" diff --git a/cdist/conf/type/__package_upgrade_all/man.rst b/cdist/conf/type/__package_upgrade_all/man.rst index 62cbc43d..e9e2b8ce 100644 --- a/cdist/conf/type/__package_upgrade_all/man.rst +++ b/cdist/conf/type/__package_upgrade_all/man.rst @@ -28,6 +28,15 @@ type * pacman for Arch Linux +BOOLEAN PARAMETERS +------------------ +apt-dist-upgrade + Do dist-upgrade instead of upgrade. + +apt-clean + Clean out the local repository of retrieved package files. + + EXAMPLES -------- diff --git a/cdist/conf/type/__package_upgrade_all/parameter/boolean b/cdist/conf/type/__package_upgrade_all/parameter/boolean new file mode 100644 index 00000000..7a56a34b --- /dev/null +++ b/cdist/conf/type/__package_upgrade_all/parameter/boolean @@ -0,0 +1,2 @@ +apt-clean +apt-dist-upgrade diff --git a/cdist/conf/type/__pf_ruleset/gencode-local b/cdist/conf/type/__pf_ruleset/gencode-local index c2495509..2db2ae06 100644 --- a/cdist/conf/type/__pf_ruleset/gencode-local +++ b/cdist/conf/type/__pf_ruleset/gencode-local @@ -59,12 +59,20 @@ case $uname in ;; esac +# IPv6 fix +if $(echo "${__target_host}" | grep -q -E '^[0-9a-fA-F:]+$') +then + my_target_host="[${__target_host}]" +else + my_target_host="${__target_host}" +fi + if [ -n "${cksum}" ]; then if [ ! "\${currentSum}" = "${cksum}" ]; then - $__remote_copy "${source}" "$__target_host:${rcvar}.new" + $__remote_copy "${source}" "${my_target_host}:${rcvar}.new" fi else # File just doesn't exist yet - $__remote_copy "${source}" "$__target_host:${rcvar}.new" + $__remote_copy "${source}" "${my_target_host}:${rcvar}.new" fi EOF diff --git a/cdist/conf/type/__postgres_extension/gencode-remote b/cdist/conf/type/__postgres_extension/gencode-remote new file mode 100755 index 00000000..3408df86 --- /dev/null +++ b/cdist/conf/type/__postgres_extension/gencode-remote @@ -0,0 +1,39 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2013 Tomas Pospisek (tpo_deb at sourcepole.ch) +# +# This type was created by Tomas Pospisek based on the +#__postgres_role type by Steven Armstrong +# +# 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 . +# + +dbname=$( echo "$__object_id" | cut -d":" -f1 ) +extension=$( echo "$__object_id" | cut -d":" -f2 ) + +state_should=$( cat "$__object/parameter/state" ) + +case "$state_should" in + present) + cmd="CREATE EXTENSION IF NOT EXISTS $extension" + echo "su - postgres -c 'psql -c \"$cmd\" \"$dbname\"'" + ;; + absent) + cmd="DROP EXTENSION IF EXISTS $extenstion" + echo "su - postgres -c 'psql -c \"$cmd\" \"$dbname\"'" + ;; +esac diff --git a/cdist/conf/type/__postgres_extension/man.rst b/cdist/conf/type/__postgres_extension/man.rst new file mode 100644 index 00000000..ead51c83 --- /dev/null +++ b/cdist/conf/type/__postgres_extension/man.rst @@ -0,0 +1,59 @@ +cdist-type__postgres_extension(7) +================================= + +NAME +---- +cdist-type__postgres_extension - manage postgres extensions + + +DESCRIPTION +----------- +This cdist type allows you to create or drop postgres extensions. + +The object you need to pass to __postgres_extension consists of +the database name and the extension name joined by a colon in the +following form: + +.. code-block:: + + dbname:extension + +f.ex. + +.. code-block:: + + rails_test:unaccent + + +OPTIONAL PARAMETERS +------------------- +state + either "present" or "absent", defaults to "present" + + +EXAMPLES +-------- + +.. code-block:: sh + + __postgres_extension rails_test:unaccent + __postgres_extension --present rails_test:unaccent + __postgres_extension --absent rails_test:unaccent + + +SEE ALSO +-------- +:strong:`cdist-type__postgre_database`\ (7) + +Postgres "Create Extension" documentation at: . + +AUTHOR +------- +Tomas Pospisek + +COPYING +------- +Copyright \(C) 2014 Tomas Pospisek. 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. diff --git a/cdist/conf/type/__postgres_extension/parameter/default/state b/cdist/conf/type/__postgres_extension/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__postgres_extension/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__postgres_extension/parameter/optional b/cdist/conf/type/__postgres_extension/parameter/optional new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/cdist/conf/type/__postgres_extension/parameter/optional @@ -0,0 +1 @@ +state diff --git a/cdist/conf/type/__user/gencode-remote b/cdist/conf/type/__user/gencode-remote index 463fbe49..223d4d46 100755 --- a/cdist/conf/type/__user/gencode-remote +++ b/cdist/conf/type/__user/gencode-remote @@ -104,7 +104,7 @@ if [ "$state" = "present" ]; then if [ $# -gt 0 ]; then echo mod >> "$__messages_out" if [ "$os" = "freebsd" ]; then - echo pw usermod "$@" "$name" + echo pw usermod "$@" -n "$name" else echo usermod "$@" "$name" fi @@ -125,7 +125,7 @@ if [ "$state" = "present" ]; then done if [ "$os" = "freebsd" ]; then - echo pw useradd "$@" "$name" + echo pw useradd "$@" -n "$name" else echo useradd "$@" "$name" fi diff --git a/cdist/conf/type/__user_groups/explorer/oldusermod b/cdist/conf/type/__user_groups/explorer/oldusermod index bf43fcec..6ef25b13 100644 --- a/cdist/conf/type/__user_groups/explorer/oldusermod +++ b/cdist/conf/type/__user_groups/explorer/oldusermod @@ -18,11 +18,4 @@ # along with cdist. If not, see . # -os="$($__explorer/os)" - -if [ "$os" = "netbsd" ]; then - echo netbsd - exit -fi - usermod --help | grep -q -- '-A group' && echo true || echo false diff --git a/cdist/conf/type/__user_groups/gencode-remote b/cdist/conf/type/__user_groups/gencode-remote index 8b13f32c..6728228c 100755 --- a/cdist/conf/type/__user_groups/gencode-remote +++ b/cdist/conf/type/__user_groups/gencode-remote @@ -23,19 +23,6 @@ state_should="$(cat "$__object/parameter/state")" oldusermod="$(cat "$__object/explorer/oldusermod")" os=$(cat "$__global/explorer/os") -if [ "$os" = "netbsd" ]; then - # NetBSD does not have a command to remove a user from a group - oldusermod="true" - addparam="-G" - delparam=";;#" -elif [ "$oldusermod" = "true" ]; then - addparam="-A" - delparam="-R" -else - addparam="-a" - delparam="-d" -fi - mkdir "$__object/files" # file has to be sorted for comparison with `comm` sort "$__object/parameter/group" > "$__object/files/group.sorted" @@ -43,11 +30,9 @@ sort "$__object/parameter/group" > "$__object/files/group.sorted" case "$state_should" in present) changed_groups="$(comm -13 "$__object/explorer/group" "$__object/files/group.sorted")" - action="$addparam" ;; absent) changed_groups="$(comm -12 "$__object/explorer/group" "$__object/files/group.sorted")" - action="$delparam" ;; esac @@ -57,9 +42,25 @@ if [ -z "$changed_groups" ]; then fi for group in $changed_groups; do - if [ "$oldusermod" = "true" ]; then - echo "usermod $action \"$group\" \"$user\"" + if [ "$os" = "netbsd" ]; then + case "$state_should" in + present) echo "usermod -G \"$group\" \"$user\"" ;; + absent) echo 'NetBSD does not have a command to remove a user from a group' >&2 ; exit 1 ;; + esac + elif [ "$os" = "freebsd" ]; then + case "$state_should" in + present) echo "pw groupmod \"$group\" -m \"$user\"" ;; + absent) echo "pw groupmod \"$group\" -d \"$user\"" ;; + esac + elif [ "$oldusermod" = "true" ]; then + case "$state_should" in + present) echo "usermod -A \"$group\" \"$user\"" ;; + absent) echo "usermod -R \"$group\" \"$user\"" ;; + esac else - echo "gpasswd $action \"$user\" \"$group\"" + case "$state_should" in + present) echo "gpasswd -a \"$group\" \"$user\"" ;; + absent) echo "gpasswd -d \"$group\" \"$user\"" ;; + esac fi done diff --git a/cdist/config.py b/cdist/config.py index 31b41781..6b57e7bf 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -22,50 +22,21 @@ import logging import os -import shutil import sys import time -import pprint import itertools import tempfile import socket import cdist +import cdist.hostsource import cdist.exec.local import cdist.exec.remote +import cdist.util.ipaddr as ipaddr from cdist import core - - -def inspect_ssh_mux_opts(): - """Inspect whether or not ssh supports multiplexing options. - - Return string containing multiplexing options if supported. - If ControlPath is supported then placeholder for that path is - specified and can be used for final string formatting. - For example, this function can return string: - "-o ControlMaster=auto -o ControlPersist=125 -o ControlPath={}". - Then it can be formatted: - mux_opts_string.format('/tmp/tmpxxxxxx/ssh-control-path'). - """ - import subprocess - - wanted_mux_opts = { - "ControlPath": "{}", - "ControlMaster": "auto", - "ControlPersist": "125", - } - mux_opts = " ".join([" -o {}={}".format( - x, wanted_mux_opts[x]) for x in wanted_mux_opts]) - try: - subprocess.check_output("ssh {}".format(mux_opts), - stderr=subprocess.STDOUT, shell=True) - except subprocess.CalledProcessError as e: - subproc_output = e.output.decode().lower() - if "bad configuration option" in subproc_output: - return "" - return mux_opts +from cdist.util.remoteutil import inspect_ssh_mux_opts class Config(object): @@ -91,32 +62,15 @@ class Config(object): @staticmethod def hosts(source): - """Yield hosts from source. - Source can be a sequence or filename (stdin if \'-\'). - In case of filename each line represents one host. - """ - if isinstance(source, str): - import fileinput - try: - for host in fileinput.input(files=(source)): - # remove leading and trailing whitespace - yield host.strip() - except (IOError, OSError) as e: - raise cdist.Error("Error reading hosts from \'{}\'".format( - source)) - else: - if source: - for host in source: - yield host + try: + yield from cdist.hostsource.HostSource(source)() + except (IOError, OSError, UnicodeError) as e: + raise cdist.Error( + "Error reading hosts from \'{}\': {}".format( + source, e)) @classmethod - def commandline(cls, args): - """Configure remote system""" - import multiprocessing - - # FIXME: Refactor relict - remove later - log = logging.getLogger("cdist") - + def _check_and_prepare_args(cls, args): if args.manifest == '-' and args.hostfile == '-': raise cdist.Error(("Cannot read both, manifest and host file, " "from stdin")) @@ -141,10 +95,6 @@ class Config(object): import atexit atexit.register(lambda: os.remove(initial_manifest_temp_path)) - process = {} - failed_hosts = [] - time_start = time.time() - # default remote cmd patterns args.remote_exec_pattern = None args.remote_copy_pattern = None @@ -161,10 +111,29 @@ class Config(object): if args_dict['remote_copy'] is None: args.remote_copy_pattern = cdist.REMOTE_COPY + mux_opts + @classmethod + def _base_root_path(cls, args): if args.out_path: base_root_path = args.out_path else: base_root_path = tempfile.mkdtemp() + return base_root_path + + @classmethod + def commandline(cls, args): + """Configure remote system""" + import multiprocessing + + # FIXME: Refactor relict - remove later + log = logging.getLogger("cdist") + + cls._check_and_prepare_args(args) + + process = {} + failed_hosts = [] + time_start = time.time() + + base_root_path = cls._base_root_path(args) hostcnt = 0 for host in itertools.chain(cls.hosts(args.host), @@ -206,6 +175,24 @@ class Config(object): raise cdist.Error("Failed to configure the following hosts: " + " ".join(failed_hosts)) + @classmethod + def _resolve_remote_cmds(cls, args, host_base_path): + control_path = os.path.join(host_base_path, "ssh-control-path") + # If we constructed patterns for remote commands then there is + # placeholder for ssh ControlPath, format it and we have unique + # ControlPath for each host. + # + # If not then use args.remote_exec/copy that user specified. + if args.remote_exec_pattern: + remote_exec = args.remote_exec_pattern.format(control_path) + else: + remote_exec = args.remote_exec + if args.remote_copy_pattern: + remote_copy = args.remote_copy_pattern.format(control_path) + else: + remote_copy = args.remote_copy + return (remote_exec, remote_copy, ) + @classmethod def onehost(cls, host, host_base_path, host_dir_name, args, parallel): """Configure ONE system""" @@ -213,56 +200,15 @@ class Config(object): log = logging.getLogger(host) try: - control_path = os.path.join(host_base_path, "ssh-control-path") - # If we constructed patterns for remote commands then there is - # placeholder for ssh ControlPath, format it and we have unique - # ControlPath for each host. - # - # If not then use args.remote_exec/copy that user specified. - if args.remote_exec_pattern: - remote_exec = args.remote_exec_pattern.format(control_path) - else: - remote_exec = args.remote_exec - if args.remote_copy_pattern: - remote_copy = args.remote_copy_pattern.format(control_path) - else: - remote_copy = args.remote_copy + remote_exec, remote_copy = cls._resolve_remote_cmds( + args, host_base_path) log.debug("remote_exec for host \"{}\": {}".format( host, remote_exec)) log.debug("remote_copy for host \"{}\": {}".format( host, remote_copy)) - try: - # getaddrinfo returns a list of 5-tuples: - # (family, type, proto, canonname, sockaddr) - # where sockaddr is: - # (address, port) for AF_INET, - # (address, port, flow_info, scopeid) for AF_INET6 - ip_addr = socket.getaddrinfo( - host, None, type=socket.SOCK_STREAM)[0][4][0] - # gethostbyaddr returns triple - # (hostname, aliaslist, ipaddrlist) - host_name = socket.gethostbyaddr(ip_addr)[0] - log.debug("derived host_name for host \"{}\": {}".format( - host, host_name)) - except socket.gaierror as e: - log.warn("host_name: {}".format(e)) - # in case of error provide empty value - host_name = '' - except socket.herror as e: - log.warn("host_name: {}".format(e)) - # in case of error provide empty value - host_name = '' - - try: - host_fqdn = socket.getfqdn(host) - log.debug("derived host_fqdn for host \"{}\": {}".format( - host, host_fqdn)) - except socket.herror as e: - log.warn("host_fqdn: {}".format(e)) - # in case of error provide empty value - host_fqdn = '' - target_host = (host, host_name, host_fqdn) + target_host = ipaddr.resolve_target_addresses(host) + log.debug("target_host: {}".format(target_host)) local = cdist.exec.local.Local( target_host=target_host, diff --git a/cdist/core/code.py b/cdist/core/code.py index cfc1316a..e9e2edf0 100644 --- a/cdist/core/code.py +++ b/cdist/core/code.py @@ -100,9 +100,7 @@ class Code(object): """ # target_host is tuple (target_host, target_hostname, target_fqdn) def __init__(self, target_host, local, remote): - self.target_host = target_host[0] - self.target_hostname = target_host[1] - self.target_fqdn = target_host[2] + self.target_host = target_host self.local = local self.remote = remote self.env = { diff --git a/cdist/core/explorer.py b/cdist/core/explorer.py index ef85431c..23996240 100644 --- a/cdist/core/explorer.py +++ b/cdist/core/explorer.py @@ -149,14 +149,9 @@ class Explorer(object): def transfer_global_explorers(self): """Transfer the global explorers to the remote side.""" self.remote.mkdir(self.remote.global_explorer_path) - if self.jobs is None: - self.remote.transfer(self.local.global_explorer_path, - self.remote.global_explorer_path) - else: - self.remote.transfer_dir_parallel( - self.local.global_explorer_path, - self.remote.global_explorer_path, - self.jobs) + self.remote.transfer(self.local.global_explorer_path, + self.remote.global_explorer_path, + self.jobs) self.remote.run(["chmod", "0700", "%s/*" % (self.remote.global_explorer_path)]) diff --git a/cdist/core/manifest.py b/cdist/core/manifest.py index a16e9346..574884a0 100644 --- a/cdist/core/manifest.py +++ b/cdist/core/manifest.py @@ -138,7 +138,8 @@ class Manifest(object): message_prefix = "initialmanifest" self.local.run_script(initial_manifest, env=self.env_initial_manifest(initial_manifest), - message_prefix=message_prefix) + message_prefix=message_prefix, + save_output=False) def env_type_manifest(self, cdist_object): type_manifest = os.path.join(self.local.type_path, @@ -163,4 +164,5 @@ class Manifest(object): if os.path.isfile(type_manifest): self.local.run_script(type_manifest, env=self.env_type_manifest(cdist_object), - message_prefix=message_prefix) + message_prefix=message_prefix, + save_output=False) diff --git a/cdist/emulator.py b/cdist/emulator.py index 2c5e567b..cdbe5b08 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2011-2015 Nico Schottelius (nico-cdist at schottelius.org) -# 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012-2013 Steven Armstrong (steven-cdist at armstrong.cc) # 2014 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. @@ -84,6 +84,10 @@ class Emulator(object): self.type_name = os.path.basename(argv[0]) self.cdist_type = core.CdistType(self.type_base_path, self.type_name) + # If set then object alreay exists and this var holds existing + # requirements. + self._existing_reqs = None + self.__init_log() def run(self): @@ -166,8 +170,9 @@ class Emulator(object): self.parameters[key] = value if self.cdist_object.exists and 'CDIST_OVERRIDE' not in self.env: - # make existing requirements a set, so we can compare it - # later with new requirements + # Make existing requirements a set so that we can compare it + # later with new requirements. + self._existing_reqs = set(self.cdist_object.requirements) if self.cdist_object.parameters != self.parameters: errmsg = ("Object %s already exists with conflicting " "parameters:\n%s: %s\n%s: %s" % ( @@ -245,7 +250,7 @@ class Emulator(object): return cdist_object.name def record_requirements(self): - """record requirements""" + """Record requirements.""" # Inject the predecessor, but not if its an override # (this would leed to an circular dependency) @@ -269,6 +274,7 @@ class Emulator(object): # so do not set a requirement pass + reqs = set() if "require" in self.env: requirements = self.env['require'] self.log.debug("reqs = " + requirements) @@ -276,7 +282,23 @@ class Emulator(object): # Ignore empty fields - probably the only field anyway if len(requirement) == 0: continue - self.record_requirement(requirement) + object_name = self.record_requirement(requirement) + reqs.add(object_name) + if self._existing_reqs is not None: + # If object exists then compare existing and new requirements. + if self._existing_reqs != reqs: + warnmsg = ("Object {} already exists with requirements:\n" + "{}: {}\n" + "{}: {}\n" + "Dependency resolver could not handle dependencies " + "as expected.".format( + self.cdist_object.name, + " ".join(self.cdist_object.source), + self._existing_reqs, + self.object_source, + reqs + )) + self.log.warning(warnmsg) def record_auto_requirements(self): """An object shall automatically depend on all objects that it diff --git a/cdist/exec/local.py b/cdist/exec/local.py index c6e25be3..ec7a6ee8 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -212,7 +212,7 @@ class Local(object): try: if save_output: output, errout = exec_util.call_get_output(command, env=env) - self.log.debug("Local stdout: {}".format(output)) + self.log.info("Local stdout: {}".format(output)) # Currently, stderr is not captured. # self.log.debug("Local stderr: {}".format(errout)) if return_output: @@ -231,7 +231,7 @@ class Local(object): message.merge_messages() def run_script(self, script, env=None, return_output=False, - message_prefix=None): + message_prefix=None, save_output=True): """Run the given script with the given environment. Return the output as a string. @@ -240,7 +240,7 @@ class Local(object): command.append(script) return self.run(command=command, env=env, return_output=return_output, - message_prefix=message_prefix) + message_prefix=message_prefix, save_output=save_output) def save_cache(self): destination = os.path.join(self.cache_path, self.hostdir) @@ -254,6 +254,10 @@ class Local(object): "Cannot delete old cache %s: %s" % (destination, e)) shutil.move(self.base_path, destination) + # add target_host since cache dir can be hash-ed target_host + host_cache_path = os.path.join(destination, "target_host") + with open(host_cache_path, 'w') as hostf: + print(self.target_host[0], file=hostf) def _create_messages(self): """Create empty messages""" diff --git a/cdist/exec/remote.py b/cdist/exec/remote.py index 9c70bdf4..440aafa7 100644 --- a/cdist/exec/remote.py +++ b/cdist/exec/remote.py @@ -30,6 +30,16 @@ import multiprocessing import cdist import cdist.exec.util as exec_util +import cdist.util.ipaddr as ipaddr + + +def _wrap_addr(addr): + """If addr is IPv6 then return addr wrapped between '[' and ']', + otherwise return it intact.""" + if ipaddr.is_ipv6(addr): + return "".join(("[", addr, "]", )) + else: + return addr class DecodeError(cdist.Error): @@ -108,57 +118,59 @@ class Remote(object): self.log.debug("Remote mkdir: %s", path) self.run(["mkdir", "-p", path]) - def transfer(self, source, destination): + def transfer(self, source, destination, jobs=None): """Transfer a file or directory to the remote side.""" self.log.debug("Remote transfer: %s -> %s", source, destination) self.rmdir(destination) if os.path.isdir(source): self.mkdir(destination) + if jobs: + self._transfer_dir_parallel(source, destination, jobs) + else: + self._transfer_dir_sequential(source, destination) + elif jobs: + raise cdist.Error("Source {} is not a directory".format(source)) + else: + command = self._copy.split() + command.extend([source, '{0}:{1}'.format( + _wrap_addr(self.target_host[0]), destination)]) + self._run_command(command) + + def _transfer_dir_sequential(self, source, destination): + for f in glob.glob1(source, '*'): + command = self._copy.split() + path = os.path.join(source, f) + command.extend([path, '{0}:{1}'.format( + _wrap_addr(self.target_host[0]), destination)]) + self._run_command(command) + + def _transfer_dir_parallel(self, source, destination, jobs): + """Transfer a directory to the remote side in parallel mode.""" + self.log.info("Remote transfer in {} parallel jobs".format( + jobs)) + self.log.debug("Multiprocessing start method is {}".format( + multiprocessing.get_start_method())) + self.log.debug(("Starting multiprocessing Pool for parallel " + "remote transfer")) + with multiprocessing.Pool(jobs) as pool: + self.log.debug("Starting async for parallel transfer") + commands = [] for f in glob.glob1(source, '*'): command = self._copy.split() path = os.path.join(source, f) command.extend([path, '{0}:{1}'.format( - self.target_host[0], destination)]) - self._run_command(command) - else: - command = self._copy.split() - command.extend([source, '{0}:{1}'.format( - self.target_host[0], destination)]) - self._run_command(command) + _wrap_addr(self.target_host[0]), destination)]) + commands.append(command) + results = [ + pool.apply_async(self._run_command, (cmd,)) + for cmd in commands + ] - def transfer_dir_parallel(self, source, destination, jobs): - """Transfer a directory to the remote side in parallel mode.""" - self.log.debug("Remote transfer: %s -> %s", source, destination) - self.rmdir(destination) - if os.path.isdir(source): - self.mkdir(destination) - self.log.info("Remote transfer in {} parallel jobs".format( - jobs)) - self.log.debug("Multiprocessing start method is {}".format( - multiprocessing.get_start_method())) - self.log.debug(("Starting multiprocessing Pool for parallel " - "remote transfer")) - with multiprocessing.Pool(jobs) as pool: - self.log.debug("Starting async for parallel transfer") - commands = [] - for f in glob.glob1(source, '*'): - command = self._copy.split() - path = os.path.join(source, f) - command.extend([path, '{0}:{1}'.format( - self.target_host[0], destination)]) - commands.append(command) - results = [ - pool.apply_async(self._run_command, (cmd,)) - for cmd in commands - ] - - self.log.debug("Waiting async results for parallel transfer") - for r in results: - r.get() # self._run_command returns None - self.log.debug(("Multiprocessing for parallel transfer " - "finished")) - else: - raise cdist.Error("Source {} is not a directory".format(source)) + self.log.debug("Waiting async results for parallel transfer") + for r in results: + r.get() # self._run_command returns None + self.log.debug(("Multiprocessing for parallel transfer " + "finished")) def run_script(self, script, env=None, return_output=False): """Run the given script with the given environment on the remote side. diff --git a/cdist/hostsource.py b/cdist/hostsource.py new file mode 100644 index 00000000..9c2c0616 --- /dev/null +++ b/cdist/hostsource.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# +# 2016 Darko Poljak (darko.poljak at gmail.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 . +# +# + +import fileinput + + +class HostSource(object): + """ + Host source object. + Source can be a sequence or filename (stdin if \'-\'). + In case of filename each line represents one host. + """ + def __init__(self, source): + self.source = source + + def _process_file_line(self, line): + """Return host from read line or None if no host present.""" + if not line: + return None + # remove comment if present + comment_index = line.find('#') + if comment_index >= 0: + host = line[:comment_index] + else: + host = line + # remove leading and trailing whitespaces + host = host.strip() + # skip empty lines + if host: + return host + else: + return None + + def _hosts_from_sequence(self): + for host in self.source: + yield host + + def _hosts_from_file(self): + for line in fileinput.input(files=(self.source)): + host = self._process_file_line(line) + if host: + yield host + + def hosts(self): + if not self.source: + return + + if isinstance(self.source, str): + yield from self._hosts_from_file() + else: + yield from self._hosts_from_sequence() + + def __call__(self): + yield from self.hosts() diff --git a/cdist/install.py b/cdist/install.py new file mode 100644 index 00000000..b88ad016 --- /dev/null +++ b/cdist/install.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# 2013 Steven Armstrong (steven-cdist at armstrong.cc) +# +# 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 . +# +# + +import cdist.config +import cdist.core + + +class Install(cdist.config.Config): + def object_list(self): + """Short name for object list retrieval. + In install mode, we only care about install objects. + """ + for cdist_object in cdist.core.CdistObject.list_objects( + self.local.object_path, self.local.type_path, + self.local.object_marker_name): + if cdist_object.cdist_type.is_install: + yield cdist_object + else: + self.log.debug("Running in install mode, ignoring non install" + "object: {0}".format(cdist_object)) diff --git a/cdist/test/cdist_type/__init__.py b/cdist/test/cdist_type/__init__.py index feb5fa15..6ed3f87c 100644 --- a/cdist/test/cdist_type/__init__.py +++ b/cdist/test/cdist_type/__init__.py @@ -113,6 +113,16 @@ class TypeTestCase(test.CdistTestCase): cdist_type = core.CdistType(base_path, '__not_singleton') self.assertFalse(cdist_type.is_singleton) + def test_install_is_install(self): + base_path = fixtures + cdist_type = core.CdistType(base_path, '__install') + self.assertTrue(cdist_type.is_install) + + def test_not_install_is_install(self): + base_path = fixtures + cdist_type = core.CdistType(base_path, '__not_install') + self.assertFalse(cdist_type.is_install) + def test_with_explorers(self): base_path = fixtures cdist_type = core.CdistType(base_path, '__with_explorers') diff --git a/cdist/test/config/__init__.py b/cdist/test/config/__init__.py index db753f41..af1aa38f 100644 --- a/cdist/test/config/__init__.py +++ b/cdist/test/config/__init__.py @@ -177,6 +177,22 @@ class ConfigRunTestCase(test.CdistTestCase): dryrun.run() # if we are here, dryrun works like expected + def test_desp_resolver(self): + """Test to show dependency resolver warning message.""" + local = cdist.exec.local.Local( + target_host=self.target_host, + base_root_path=self.host_base_path, + host_dir_name=self.hostdir, + exec_path=os.path.abspath(os.path.join( + my_dir, '../../../scripts/cdist')), + initial_manifest=os.path.join( + fixtures, 'manifest/init-deps-resolver'), + add_conf_dirs=[fixtures]) + + # dry_run is ok for dependency testing + config = cdist.config.Config(local, self.remote, dry_run=True) + config.run() + # Currently the resolving code will simply detect that this object does # not exist. It should probably check if the type is a singleton as well diff --git a/cdist/test/config/fixtures/manifest/init-deps-resolver b/cdist/test/config/fixtures/manifest/init-deps-resolver new file mode 100644 index 00000000..f67ab61c --- /dev/null +++ b/cdist/test/config/fixtures/manifest/init-deps-resolver @@ -0,0 +1,8 @@ +__a a +require="__e/e" __b b +require="__f/f" __c c +__e e +__f f +require="__c/c" __d d +__g g +__h h diff --git a/cdist/test/config/fixtures/type/__a/.keep b/cdist/test/config/fixtures/type/__a/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/config/fixtures/type/__b/.keep b/cdist/test/config/fixtures/type/__b/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/config/fixtures/type/__c/.keep b/cdist/test/config/fixtures/type/__c/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/config/fixtures/type/__d/.keep b/cdist/test/config/fixtures/type/__d/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/config/fixtures/type/__e/.keep b/cdist/test/config/fixtures/type/__e/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/config/fixtures/type/__f/.keep b/cdist/test/config/fixtures/type/__f/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/config/fixtures/type/__g/.keep b/cdist/test/config/fixtures/type/__g/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/config/fixtures/type/__g/manifest b/cdist/test/config/fixtures/type/__g/manifest new file mode 100644 index 00000000..107dbda4 --- /dev/null +++ b/cdist/test/config/fixtures/type/__g/manifest @@ -0,0 +1 @@ +require="__c/c __d/d" __a a diff --git a/cdist/test/config/fixtures/type/__h/.keep b/cdist/test/config/fixtures/type/__h/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/config/fixtures/type/__h/manifest b/cdist/test/config/fixtures/type/__h/manifest new file mode 100644 index 00000000..ce3d8fb7 --- /dev/null +++ b/cdist/test/config/fixtures/type/__h/manifest @@ -0,0 +1,3 @@ +# require="__b/b" __a a +require="__j/j" __i i +__j j diff --git a/cdist/test/config/fixtures/type/__i/.keep b/cdist/test/config/fixtures/type/__i/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/config/fixtures/type/__j/.keep b/cdist/test/config/fixtures/type/__j/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index 4fd0ed40..51de3180 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -499,6 +499,60 @@ class StdinTestCase(test.CdistTestCase): self.assertEqual(random_string, stdin_saved_by_emulator) +class EmulatorAlreadyExistingRequirementsWarnTestCase(test.CdistTestCase): + + def setUp(self): + self.temp_dir = self.mkdtemp() + handle, self.script = self.mkstemp(dir=self.temp_dir) + os.close(handle) + base_path = self.temp_dir + hostdir = cdist.str_hash(self.target_host[0]) + host_base_path = os.path.join(base_path, hostdir) + + self.local = local.Local( + target_host=self.target_host, + base_root_path=host_base_path, + host_dir_name=hostdir, + exec_path=test.cdist_exec_path, + add_conf_dirs=[conf_dir]) + self.local.create_files_dirs() + + self.manifest = core.Manifest(self.target_host, self.local) + self.env = self.manifest.env_initial_manifest(self.script) + self.env['__cdist_object_marker'] = self.local.object_marker_name + + def tearDown(self): + shutil.rmtree(self.temp_dir) + + def test_object_existing_requirements_req_none(self): + """Test to show dependency resolver warning message.""" + argv = ['__directory', 'spam'] + emu = emulator.Emulator(argv, env=self.env) + emu.run() + argv = ['__file', 'eggs'] + self.env['require'] = '__directory/spam' + emu = emulator.Emulator(argv, env=self.env) + emu.run() + argv = ['__file', 'eggs'] + if 'require' in self.env: + del self.env['require'] + emu = emulator.Emulator(argv, env=self.env) + + def test_object_existing_requirements_none_req(self): + """Test to show dependency resolver warning message.""" + argv = ['__directory', 'spam'] + emu = emulator.Emulator(argv, env=self.env) + emu.run() + argv = ['__file', 'eggs'] + if 'require' in self.env: + del self.env['require'] + emu = emulator.Emulator(argv, env=self.env) + emu.run() + argv = ['__file', 'eggs'] + self.env['require'] = '__directory/spam' + emu = emulator.Emulator(argv, env=self.env) + + if __name__ == '__main__': import unittest unittest.main() diff --git a/cdist/test/exec/remote.py b/cdist/test/exec/remote.py index 45dabb18..371d17e3 100644 --- a/cdist/test/exec/remote.py +++ b/cdist/test/exec/remote.py @@ -136,8 +136,8 @@ class RemoteTestCase(test.CdistTestCase): source_file_name = os.path.split(source_file)[-1] filenames.append(source_file_name) target = self.mkdtemp(dir=self.temp_dir) - self.remote.transfer_dir_parallel(source, target, - multiprocessing.cpu_count()) + self.remote.transfer(source, target, + multiprocessing.cpu_count()) # test if the payload files are in the target directory for filename in filenames: self.assertTrue(os.path.isfile(os.path.join(target, filename))) diff --git a/cdist/util/ipaddr.py b/cdist/util/ipaddr.py new file mode 100644 index 00000000..71477682 --- /dev/null +++ b/cdist/util/ipaddr.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +# +# 2016 Darko Poljak (darko.poljak at gmail.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 . +# +# + +import socket +import logging + + +def resolve_target_addresses(host): + log = logging.getLogger(host) + try: + # getaddrinfo returns a list of 5-tuples: + # (family, type, proto, canonname, sockaddr) + # where sockaddr is: + # (address, port) for AF_INET, + # (address, port, flow_info, scopeid) for AF_INET6 + ip_addr = socket.getaddrinfo( + host, None, type=socket.SOCK_STREAM)[0][4][0] + # gethostbyaddr returns triple + # (hostname, aliaslist, ipaddrlist) + host_name = socket.gethostbyaddr(ip_addr)[0] + log.debug("derived host_name for host \"{}\": {}".format( + host, host_name)) + except (socket.gaierror, socket.herror) as e: + log.warn("Could not derive host_name for {}" + ", $host_name will be empty. Error is: {}".format(host, e)) + # in case of error provide empty value + host_name = '' + + try: + host_fqdn = socket.getfqdn(host) + log.debug("derived host_fqdn for host \"{}\": {}".format( + host, host_fqdn)) + except socket.herror as e: + log.warn("Could not derive host_fqdn for {}" + ", $host_fqdn will be empty. Error is: {}".format(host, e)) + # in case of error provide empty value + host_fqdn = '' + + return (host, host_name, host_fqdn) + + +# check whether addr is IPv6 +try: + # python 3.3+ + import ipaddress + + def is_ipv6(addr): + try: + return ipaddress.ip_address(addr).version == 6 + except ValueError: + return False +except ImportError: + # fallback for older python versions + def is_ipv6(addr): + try: + socket.inet_aton(addr) + return False + except socket.error: + pass + try: + socket.inet_pton(socket.AF_INET6, addr) + return True + except socket.error: + pass + return False diff --git a/cdist/util/remoteutil.py b/cdist/util/remoteutil.py new file mode 100644 index 00000000..c18d6705 --- /dev/null +++ b/cdist/util/remoteutil.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# +# 2016 Darko Poljak (darko.poljak at gmail.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 . +# +# + + +def inspect_ssh_mux_opts(): + """Inspect whether or not ssh supports multiplexing options. + + Return string containing multiplexing options if supported. + If ControlPath is supported then placeholder for that path is + specified and can be used for final string formatting. + For example, this function can return string: + "-o ControlMaster=auto -o ControlPersist=125 -o ControlPath={}". + Then it can be formatted: + mux_opts_string.format('/tmp/tmpxxxxxx/ssh-control-path'). + """ + import subprocess + + wanted_mux_opts = { + "ControlPath": "{}", + "ControlMaster": "auto", + "ControlPersist": "125", + } + mux_opts = " ".join([" -o {}={}".format( + x, wanted_mux_opts[x]) for x in wanted_mux_opts]) + try: + subprocess.check_output("ssh {}".format(mux_opts), + stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as e: + subproc_output = e.output.decode().lower() + if "bad configuration option" in subproc_output: + return "" + return mux_opts diff --git a/completions/bash/cdist-completion.bash b/completions/bash/cdist-completion.bash index c756fca8..1c4226c2 100644 --- a/completions/bash/cdist-completion.bash +++ b/completions/bash/cdist-completion.bash @@ -6,7 +6,7 @@ _cdist() prev="${COMP_WORDS[COMP_CWORD-1]}" prevprev="${COMP_WORDS[COMP_CWORD-2]}" opts="-h --help -d --debug -v --verbose -V --version" - cmds="banner shell config" + cmds="banner shell config install" case "${prevprev}" in shell) @@ -35,8 +35,8 @@ _cdist() COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; - config) - opts="-h --help -d --debug -v --verbose -b --enable-beta \ + config|install) + opts="-h --help -d --debug -v --verbose -b --beta \ -c --conf-dir -f --file -i --initial-manifest -j --jobs \ -n --dry-run -o --out-dir -p --parallel -s --sequential \ --remote-copy --remote-exec" diff --git a/completions/zsh/_cdist b/completions/zsh/_cdist index 18fda0f0..001356d4 100644 --- a/completions/zsh/_cdist +++ b/completions/zsh/_cdist @@ -11,7 +11,7 @@ _cdist() case $state in opts_cmds) - _arguments '1:Options and commands:(banner config shell -h --help -d --debug -v --verbose -V --version)' + _arguments '1:Options and commands:(banner config shell install -h --help -d --debug -v --verbose -V --version)' ;; *) case $words[2] in @@ -35,8 +35,8 @@ _cdist() ;; esac ;; - config) - opts=(-h --help -d --debug -v --verbose -b --enable-beta -c --conf-dir -f --file -i --initial-manifest -j --jobs -n --dry-run -o --out-dir -p --parallel -s --sequential --remote-copy --remote-exec) + config|install) + opts=(-h --help -d --debug -v --verbose -b --beta -c --conf-dir -f --file -i --initial-manifest -j --jobs -n --dry-run -o --out-dir -p --parallel -s --sequential --remote-copy --remote-exec) compadd "$@" -- $opts ;; *) diff --git a/docs/changelog b/docs/changelog index 4d6efbc7..6b869256 100644 --- a/docs/changelog +++ b/docs/changelog @@ -3,6 +3,47 @@ Changelog next: * New type: __hosts: manage entries in /etc/hosts (Dmitry Bogatov) + * Core: Fix suppression of manifests' outputs (Darko Poljak) + * Type __user_groups: Support FreeBSD (Andres Erbsen) + * Type __cron: Fix filter for new cron on sles12 sp2 (Daniel Heule) + * Type __docker: Support absent state (Dominique Roux) + * Type __docker_compose: Support absent state (Dominique Roux) + +4.4.1: 2016-12-17 + * Documentation: Update docs for types that used man.rst as symbolic links (Darko Poljak) + * Type __cron: Remove '# marker' for raw_command due to cron security (Daniel Heule) + * New type: __docker_compose (Dominique Roux) + * Type __apt_mark: Check supported apt version and if package is installed (Ander Punnar) + * New type: __docker (Steven Armstrong) + * New type: __package_dpkg (Tomas Pospisek) + +4.4.0: 2016-12-03 + * Core: Deprecate -d option and make -v option log level counter (Darko Poljak) + * New type: __postgres_extension (Tomas Pospisek) + * Core, types: Support IPv6 (Darko Poljak) + * Type __consul: Add source and cksum files for Consul 0.7.0 and 0.7.1 (Carlos Ortigoza) + * Type __user: FreeBSD fix (Kamila Souckova) + * New type: __apt_mark (Ander Punnar) + * Type __package_upgrade_all: Do not dist-upgrade by default, add apt-clean and apt-dist-upgrade options (Ander Punnar) + * Core: Correct target_host var in code.py (Darko Poljak) + * All: Merge install feature from 4.0-pre-not-stable (Darko Poljak) + +4.3.2: 2016-10-13 + * Documentation: Update no longer existing links (Simon Walter) + * Core: Add warning message for faulty dependencies case (Darko Poljak) + * Explorer os_version: Use /etc/os-release instead of /etc/SuSE-release (Daniel Heule) + * Type __package: Call __package_pkg_openbsd on openbsd (Andres Erbsen) + * Type __package_pkg_openbsd: Support --version (Andres Erbsen) + * Type __hostname: Support openbsd (Andres Erbsen) + * New type: __firewalld_start: start/stop firewalld and/or enable/disable start on boot (Darko Poljak) + * Bugfix __consul_agent: Config option was misnamed 'syslog' instead of 'enable_syslog' (Steven Armstrong) + +4.3.1: 2016-08-22 + * Documentation: Spelling fixes (Darko Poljak) + * Type __filesystem: Spelling fixes (Dmitry Bogatov) + * Core: Add target_host file to cache since cache dir name can be hash (Darko Poljak) + * Core: Improve hostfile: support comments, skip empty lines (Darko Poljak) +>>>>>>> ungleich/master 4.3.0: 2016-08-19 * Documentation: Add Parallelization chapter (Darko Poljak) @@ -79,7 +120,7 @@ next: * Type __consul_agent: Use systemd for Debian 8 (Nico Schottelius) * Type __firewalld_rule: Ensure firewalld package is present (David Hürlimann) * Type __locale: Support CentOS (David Hürlimann) - * Type __staged_file: Fix comparision operator (Nico Schottelius) + * Type __staged_file: Fix comparison operator (Nico Schottelius) * Type __user_groups: Support old Linux versions (Daniel Heule) 3.1.12: 2015-03-19 @@ -266,7 +307,7 @@ next: 3.0.1: 2014-01-14 * Core: Copy only files, not directories (Steven Armstrong) * Core: Allow hostnames to start with / (Nico Schottelius) - * Type __line: Remove unecessary backslash escape (Nico Schottelius) + * Type __line: Remove unnecessary backslash escape (Nico Schottelius) * Type __directory: Add messaging support (Daniel Heule) * Type __directory: Do not generate code if mode is 0xxx (Daniel Heule) * Type __package: Fix typo in optional parameter ptype (Daniel Heule) diff --git a/docs/dev/logs/2013-11-28.preos b/docs/dev/logs/2013-11-28.preos new file mode 100644 index 00000000..f8561135 --- /dev/null +++ b/docs/dev/logs/2013-11-28.preos @@ -0,0 +1,2 @@ +- debootstrap for the moment +- add triggers: https://github.com/telmich/cdist/issues/214 diff --git a/docs/dev/logs/2014-01-09.preos b/docs/dev/logs/2014-01-09.preos new file mode 100644 index 00000000..1a3f2ddc --- /dev/null +++ b/docs/dev/logs/2014-01-09.preos @@ -0,0 +1,109 @@ +- debootstrap + x setup arch + x allow cdist to configure debootstrapped directory using cdist + x include sshd + x configure network (eth0, dhcp) + x various mkfs variants + - various fdisk tools + + x add option for different initial manifest + x allow -, stdin usage + x allow to replace current manifest (later) + + x trigger + - can be handled in the manifest of the user + + - remove /var/cache/apt/archives/* ? + - later, optimisation level + + + - bug: cdist config als root! + + - fix linux-image name (amd64) + + - ln -s /sbin/init /init + + - blog! + - self configuring + + x pxe + /pxe/ + - pxelinux.0 + - linux + - initramfs + - pxelinux.cfg/ + - default + + - iso + - later + - usb stick (+efi version) + - later + + - add unit tests + +- testing with qemu + [22:43] bento:vm-tests% qemu-system-x86_64 -m 2G -boot order=cn -drive file=testhd1,if=virtio -net nic -net user,tftp=$(pwd -P)/tftp,bootfile=/pxelinux.0,hostfwd=tcp::7777-:22 -enable-kvm + +- create preos + [22:43] bento:preos-tests% echo __panter_root_ssh_keys | sudo cdist preos -vp /home/users/nico/vm-tests/tftp -c /home/users/nico/preos-tests/preos03/ -i - + + +-------------------------------------------------------------------------------- + +[1:16] bento:~% sudo cdist preos -vc ~nico/preos-tests/preos03 +INFO: cdist: version 3.0.0-38-gea286c6 +INFO: /home/users/nico/preos-tests/preos03: Running global explorers +INFO: /home/users/nico/preos-tests/preos03: Running initial manifest /tmp/tmpxbquwe/manifest +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __file/etc/network/interfaces +INFO: /home/users/nico/preos-tests/preos03: Generating code for __file/etc/network/interfaces +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/xfsprogs +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/reiser4progs +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/jfsutils +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/e2fsprogs +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/btrfs-tools +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/file +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/syslinux +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/openssh-server +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package/linux-image-amd64 +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/linux-image-amd64 +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/linux-image-amd64 +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/openssh-server +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/openssh-server +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/syslinux +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/syslinux +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/file +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/file +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/btrfs-tools +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/btrfs-tools +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/e2fsprogs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/e2fsprogs +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/jfsutils +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/jfsutils +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/reiser4progs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/reiser4progs +INFO: /home/users/nico/preos-tests/preos03: Running manifest and explorers for __package_apt/xfsprogs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package_apt/xfsprogs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/xfsprogs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/reiser4progs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/jfsutils +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/e2fsprogs +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/btrfs-tools +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/file +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/syslinux +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/openssh-server +INFO: /home/users/nico/preos-tests/preos03: Generating code for __package/linux-image-amd64 +INFO: /home/users/nico/preos-tests/preos03: Finished successful run in 2.546635866165161 seconds +[1:16] bento:~% + +-------------------------------------------------------------------------------- +[21:14] bento:vm-tests% qemu-system-x86_64 -m 2G -boot order=cn -drive file=testhd1,if=virtio -net nic -net user,tftp=$(pwd -P)/tftp,bootfile=/pxelinux.0 + +-------------------------------------------------------------------------------- +[21:16] bento:preos-tests% sudo cdist preos -vp /home/users/nico/vm-tests/tftp /home/users/nico/preos-tests/preos03/ +INFO: cdist: version 3.0.0-42-g0d78ab3 +INFO: cdist.preos: Creating kernel ... +INFO: cdist.preos: Creating initramfs ... +760780 blocks +INFO: cdist.preos: Creating pxe configuration ... +INFO: cdist.preos: Creating pxelinux.0 ... + diff --git a/docs/dev/logs/2015-02-10.installation_from_usb_stick b/docs/dev/logs/2015-02-10.installation_from_usb_stick new file mode 100644 index 00000000..b655bc18 --- /dev/null +++ b/docs/dev/logs/2015-02-10.installation_from_usb_stick @@ -0,0 +1,49 @@ +Objective: + + Create a bootable media that contains everything to install and configure a system. + +Ideas: + +* usb stick +** uefi vs. bios +** contains cdist config +** static ip (?) (if at all) +** hostname setup to localhost +** install and config support +* preos from existing OS? +** requires kernel +** requires initramfs (self build) +** missing tools: cdist preos --config hostname... +* testing with qemu +* syslinux/isolinux? + +Program: + +- get tools +- get kernel + - provide fallback on cdist page + - archlinux: /boot/vmlinuz-linux +- create initramfs? +- create bootable media + - iso + - uefi-usb + - bios-usb + +Tasks: + +- Setup test environment + - qemu launcher + /usr/bin/qemu-system-x86_64 -boot d -m 256 -cdrom '/home/users/nico/oeffentlich/rechner/projekte/cdist/cdist/cdist-preos.iso' +- Create bootable image +- Test image + +Log: + +mkdir iso +cp /boot/vmlinuz-linux iso/ +cp /usr/lib/syslinux/bios/isolinux.bin iso/ + +[22:36] freiheit:cdist% genisoimage -v -V "cdist preos v0.1" -cache-inodes -J -l -no-emul-boot -boot-load-size 4 -b isolinux.bin -c boot.cat -o cdist-preos.iso iso + +[22:38] freiheit:cdist% genisoimage -r -V "cdist preos v0.2" -cache-inodes -J -l -no-emul-boot -boot-load-size 4 -b isolinux.bin -c boot.cat -o cdist-preos.iso iso + diff --git a/docs/dev/logs/2015-03-28.preos-from-os b/docs/dev/logs/2015-03-28.preos-from-os new file mode 100644 index 00000000..93dc9e79 --- /dev/null +++ b/docs/dev/logs/2015-03-28.preos-from-os @@ -0,0 +1,32 @@ +- basics of config + - wrapping to config + - testbed for CaaS! +- allow to include .cdist +- generate + - pxe + - iso +- package... + - mkfs + - fdisk* + - kernel + +- types (?) + - iso? + - + +- based on Arch Linux + +- new types for iso? + +- change __cdistmarker to accept prefix + +- ISO / USB + genisoimage -r -V "cdist preos v0.2" -cache-inodes -J -l -no-emul-boot -boot-load-size 4 -b isolinux.bin -c boot.cat -o cdist-preos.iso iso + + - have a look at archiso? + + http://www.syslinux.org/wiki/index.php/Isohybrid + -> uefi + -> mbr + +- PXE diff --git a/docs/src/Makefile b/docs/src/Makefile index 800a80d8..2ecf7a32 100644 --- a/docs/src/Makefile +++ b/docs/src/Makefile @@ -11,7 +11,7 @@ _BUILDDIR = _build # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) - $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don\'t have Sphinx installed, grab it from http://sphinx-doc.org/) + $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don\'t have Sphinx installed, grab it from http://sphinx-doc.org/) endif # Internal variables. diff --git a/docs/src/cdist-best-practice.rst b/docs/src/cdist-best-practice.rst index 57ce5cc1..493f1506 100644 --- a/docs/src/cdist-best-practice.rst +++ b/docs/src/cdist-best-practice.rst @@ -58,7 +58,7 @@ you can clone it multiple times:: machine-b % git clone git://your-git-server/cdist -Seperating work by groups +Separating work by groups ------------------------- If you are working with different groups on one cdist-configuration, you can delegate to other manifests and have the groups edit only diff --git a/docs/src/cdist-features.rst b/docs/src/cdist-features.rst index 8a147741..7018d248 100644 --- a/docs/src/cdist-features.rst +++ b/docs/src/cdist-features.rst @@ -7,7 +7,7 @@ Simplicity There is only one type to extend cdist called **type** Design - + Type and core cleanly seperated + + Type and core cleanly separated + Sticks completly to the KISS (keep it simple and stupid) paradigma + Meaningful error messages - do not lose time debugging error messages + Consistency in behaviour, naming and documentation diff --git a/docs/src/cdist-hacker.rst b/docs/src/cdist-hacker.rst index 326d83ba..d7d6a056 100644 --- a/docs/src/cdist-hacker.rst +++ b/docs/src/cdist-hacker.rst @@ -50,13 +50,13 @@ work nor kill the authors brain: the other needs to be improved. As soon as your work meets these requirements, write a mail -for inclusion to the mailinglist **cdist at cdist -- at -- l.schottelius.org** -or open a pull request at http://github.com/telmich/cdist. +for inclusion to the mailinglist **cdist-configuration-management at googlegroups.com** +or open a pull request at http://github.com/ungleich/cdist. How to submit a new type ------------------------ -For detailled information about types, see `cdist type `_. +For detailed information about types, see `cdist type `_. Submitting a type works as described above, with the additional requirement that a corresponding manpage named man.text in asciidoc format with @@ -77,7 +77,7 @@ The following workflow works fine for most developers .. code-block:: sh # get latest upstream master branch - git clone https://github.com/telmich/cdist.git + git clone https://github.com/ungleich/cdist.git # update if already existing cd cdist; git fetch -v; git merge origin/master diff --git a/docs/src/cdist-manifest.rst b/docs/src/cdist-manifest.rst index 5655c6c2..b29cf0d8 100644 --- a/docs/src/cdist-manifest.rst +++ b/docs/src/cdist-manifest.rst @@ -118,7 +118,7 @@ On line 4 you can see that the instantion of a type "\__link" object needs the object "__file/etc/cdist-configured" to be present, before it can proceed. This also means that the "\__link" command must make sure, that either -"\__file/etc/cdist-configured" allready is present, or, if it's not, it needs +"\__file/etc/cdist-configured" already is present, or, if it's not, it needs to be created. The task of cdist is to make sure, that the dependency will be resolved appropriately and thus "\__file/etc/cdist-configured" be created if necessary before "__link" proceeds (or to abort execution with an error). @@ -216,7 +216,7 @@ How to override objects: .. code-block:: sh - # for example in the inital manifest + # for example in the initial manifest # create user account foobar with some hash for password __user foobar --password 'some_fancy_hash' --home /home/foobarexample diff --git a/docs/src/cdist-quickstart.rst b/docs/src/cdist-quickstart.rst index 7c967691..0020568d 100644 --- a/docs/src/cdist-quickstart.rst +++ b/docs/src/cdist-quickstart.rst @@ -56,7 +56,7 @@ code into your shell to get started and configure localhost:: # Get cdist # Mirrors can be found on # http://www.nico.schottelius.org/software/cdist/install/#index2h4 - git clone git://git.schottelius.org/cdist + git clone git://github.com/ungleich/cdist # Create manifest (maps configuration to host(s) cd cdist diff --git a/docs/src/cdist-reference.rst.sh b/docs/src/cdist-reference.rst.sh index 97b22473..4b94b858 100755 --- a/docs/src/cdist-reference.rst.sh +++ b/docs/src/cdist-reference.rst.sh @@ -273,4 +273,7 @@ CDIST_REMOTE_EXEC CDIST_REMOTE_COPY Use this command for remote copy (should behave like scp). + +CDIST_BETA + Enable beta functionalities. eof diff --git a/docs/src/cdist-remote-exec-copy.rst b/docs/src/cdist-remote-exec-copy.rst index 882f0bc2..bb818310 100644 --- a/docs/src/cdist-remote-exec-copy.rst +++ b/docs/src/cdist-remote-exec-copy.rst @@ -17,6 +17,11 @@ passing them to cdist with the --remote-exec and/or --remote-copy arguments. For __remote_exec, the custom implementation must behave as if it where ssh. For __remote_copy, it must behave like scp. +Please notice, custom implementations should work like ssh/scp so __remote_copy +must support IPv6 addresses enclosed in square brackets. For __remote_exec you +must take into account that for some options (like -L) IPv6 addresses can be +specified by enclosed in square brackets (see :strong:`ssh`\ (1) and +:strong:`scp`\ (1)). With this simple interface the user can take total control of how cdist interacts with the target when required, while the default implementation diff --git a/docs/src/cdist-type.rst b/docs/src/cdist-type.rst index c75d0a52..2c5f9f6a 100644 --- a/docs/src/cdist-type.rst +++ b/docs/src/cdist-type.rst @@ -51,6 +51,19 @@ Example: __myfancysingleton --colour green +Config types +------------ +By default types are used with config command. These are types that are not +flagged by any known command flag. If a type is marked then it will be skipped +with config command. + + +Install types +------------- +If a type is flagged with 'install' flag then it is used only with install command. +With other commands, i.e. config, these types are skipped if used. + + How to write a new type ----------------------- A type consists of @@ -126,7 +139,7 @@ Example: (e.g. in cdist/conf/type/__nginx_vhost/manifest) # parameter with multiple values if [ -f "$__object/parameter/server_alias" ]; then for alias in $(cat "$__object/parameter/server_alias"); do - echo $alias > /some/where/usefull + echo $alias > /some/where/useful done fi @@ -209,6 +222,18 @@ As you can see, the object ID is omitted, because it does not make any sense, if your type can be used only once. +Install - type with install command +----------------------------------- +If you want a type to be used with install command, you must mark it as +install: create the (empty) file "install" in your type directory: + +.. code-block:: sh + + touch cdist/conf/type/__install_NAME/install + +With other commands, i.e. config, it will be skipped if used. + + The type explorers ------------------ If a type needs to explore specific details, it can provide type specific @@ -251,6 +276,12 @@ script, you can write to stderr: # Output to be saved by cdist for execution on the target echo "touch /etc/cdist-configured" +Notice: if you use __remote_copy or __remote_exec directly in your scripts +then for IPv6 address with __remote_copy execution you should enclose IPv6 +address in square brackets. The same applies to __remote_exec if it behaves +the same as ssh for some options where colon is a delimiter, as for -L ssh +option (see :strong:`ssh`\ (1) and :strong:`scp`\ (1)). + Variable access from the generated scripts ------------------------------------------ diff --git a/docs/src/cdist-update.rst b/docs/src/cdist-update.rst index 0b445ba4..e810d6e9 100644 --- a/docs/src/cdist-update.rst +++ b/docs/src/cdist-update.rst @@ -85,7 +85,7 @@ Use `messaging `_ instead. Updating from 2.2 to 2.3 ~~~~~~~~~~~~~~~~~~~~~~~~ -No incompatiblities. +No incompatibilities. Updating from 2.1 to 2.2 ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -164,7 +164,7 @@ Updating from 1.5 to 1.6 Updating from 1.3 to 1.5 ~~~~~~~~~~~~~~~~~~~~~~~~ -No incompatiblities. +No incompatibilities. Updating from 1.2 to 1.3 ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -174,7 +174,7 @@ Rename **gencode** of every type to **gencode-remote**. Updating from 1.1 to 1.2 ~~~~~~~~~~~~~~~~~~~~~~~~ -No incompatiblities. +No incompatibilities. Updating from 1.0 to 1.1 ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/src/man1/cdist.rst b/docs/src/man1/cdist.rst index 47fe195c..adabe052 100644 --- a/docs/src/man1/cdist.rst +++ b/docs/src/man1/cdist.rst @@ -11,7 +11,7 @@ SYNOPSIS :: - cdist [-h] [-d] [-v] [-V] {banner,config,shell} ... + cdist [-h] [-d] [-v] [-V] {banner,config,shell,install} ... cdist banner [-h] [-d] [-v] @@ -20,6 +20,11 @@ SYNOPSIS [--remote-copy REMOTE_COPY] [--remote-exec REMOTE_EXEC] [host [host ...]] + cdist install [-h] [-d] [-v] [-b] [-c CONF_DIR] [-f HOSTFILE] + [-i MANIFEST] [-j [JOBS]] [-n] [-o OUT_PATH] [-p] [-s] + [--remote-copy REMOTE_COPY] [--remote-exec REMOTE_EXEC] + [host [host ...]] + cdist shell [-h] [-d] [-v] [-s SHELL] @@ -41,11 +46,14 @@ All commands accept the following options: .. option:: -d, --debug - Set log level to debug + Set log level to debug (deprecated, use -vvv instead) .. option:: -v, --verbose - Set log level to info, be more verbose + Increase the verbosity level. Every instance of -v increments the verbosity + level by one. Its default value is 0. There are 4 levels of verbosity. The + order of levels from the lowest to the highest are: ERROR (0), WARNING (1), + INFO (2) and DEBUG (3 or higher). .. option:: -V, --version @@ -58,14 +66,15 @@ Displays the cdist banner. Useful for printing cdist posters - a must have for every office. -CONFIG ------- -Configure one or more hosts. +CONFIG/INSTALL +-------------- +Configure/install one or more hosts. -.. option:: -b, --enable-beta +.. option:: -b, --beta - Enable beta functionalities. Beta functionalities include the - following options: -j/--jobs. + Enable beta functionalities. + + Can also be enabled using CDIST_BETA env var. .. option:: -c CONF_DIR, --conf-dir CONF_DIR @@ -82,7 +91,7 @@ Configure one or more hosts. Read additional hosts to operate on from specified file or from stdin if '-' (each host on separate line). If no host or host file is specified then, by default, - read hosts from stdin. + read hosts from stdin. For the file format see below. .. option:: -i MANIFEST, --initial-manifest MANIFEST @@ -117,6 +126,20 @@ Configure one or more hosts. Command to use for remote execution (should behave like ssh) + +HOSTFILE FORMAT +~~~~~~~~~~~~~~~ +HOSTFILE contains hosts per line. +All characters after and including '#' until the end of line is a comment. +In a line, all leading and trailing whitespace characters are ignored. +Empty lines are ignored/skipped. + +Hostfile line is processed like the following. First, all comments are +removed. Then all leading and trailing whitespace characters are stripped. +If such a line results in empty line it is ignored/skipped. Otherwise, +host string is used. + + SHELL ----- This command allows you to spawn a shell that enables access @@ -138,6 +161,12 @@ cdist/conf The distribution configuration directory. It contains official types and explorers. This path is relative to cdist installation directory. +NOTES +----- +cdist detects if host is specified by IPv6 address. If so then remote_copy +command is executed with host address enclosed in square brackets +(see :strong:`scp`\ (1)). + EXAMPLES -------- @@ -177,6 +206,8 @@ EXAMPLES usage: __git --source SOURCE [--state STATE] [--branch BRANCH] [--group GROUP] [--owner OWNER] [--mode MODE] object_id + # Install ikq05.ethz.ch with debug enabled + % cdist install -d ikq05.ethz.ch ENVIRONMENT ----------- @@ -193,7 +224,7 @@ CDIST_LOCAL_SHELL Selects shell for local script execution, defaults to /bin/sh. CDIST_REMOTE_SHELL - Selects shell for remote scirpt execution, defaults to /bin/sh. + Selects shell for remote script execution, defaults to /bin/sh. CDIST_OVERRIDE Allow overwriting type parameters. @@ -207,6 +238,9 @@ CDIST_REMOTE_EXEC CDIST_REMOTE_COPY Use this command for remote copy (should behave like scp). +CDIST_BETA + Enable beta functionalities. + EXIT STATUS ----------- The following exit values shall be returned: @@ -218,7 +252,8 @@ The following exit values shall be returned: AUTHORS ------- -Nico Schottelius +Originally written by Nico Schottelius +and Steven Armstrong . CAVEATS ------- @@ -232,6 +267,35 @@ connection. In this case ssh will disable multiplexing. This limit is controlled with sshd :strong:`MaxSessions` configuration options. For more details refer to :strong:`sshd_config`\ (5). +When requirements for the same object are defined in different manifests (see +example below) in init manifest and in some other type manifest and they differs +then dependency resolver cannot detect dependencies right. This happens because +cdist cannot prepare all objects first and then run objects because some +object can depend on the result of type explorer(s) and explorers are executed +during object run. cdist will detect such case and write warning message. +Example for such a case: + +.. code-block:: sh + + init manifest: + __a a + require="__e/e" __b b + require="__f/f" __c c + __e e + __f f + require="__c/c" __d d + __g g + __h h + + type __g manifest: + require="__c/c __d/d" __a a + + Warning message: + WARNING: cdisttesthost: Object __a/a already exists with requirements: + /usr/home/darko/ungleich/cdist/cdist/test/config/fixtures/manifest/init-deps-resolver /tmp/tmp.cdist.test.ozagkg54/local/759547ff4356de6e3d9e08522b0d0807/data/conf/type/__g/manifest: set() + /tmp/tmp.cdist.test.ozagkg54/local/759547ff4356de6e3d9e08522b0d0807/data/conf/type/__g/manifest: {'__c/c', '__d/d'} + Dependency resolver could not handle dependencies as expected. + COPYING ------- Copyright \(C) 2011-2013 Nico Schottelius. Free use of this software is diff --git a/docs/web/cdist/documentation.mdwn b/docs/web/cdist/documentation.mdwn index 56c2798e..6479a4bb 100644 --- a/docs/web/cdist/documentation.mdwn +++ b/docs/web/cdist/documentation.mdwn @@ -6,4 +6,7 @@ have a look at [all versions](/software/cdist/man). You can also view [speeches about cdist](/software/cdist/speeches). +Checking out beta? Find the docs here: +[beta documentation](/software/cdist/man/beta). + [[!tag cdist unix]] diff --git a/docs/web/cdist/features.mdwn b/docs/web/cdist/features.mdwn index a97f2013..77c61382 100644 --- a/docs/web/cdist/features.mdwn +++ b/docs/web/cdist/features.mdwn @@ -3,7 +3,7 @@ But cdist ticks differently, here is the feature set that makes it unique: [[!table data=""" Keywords | Description Simplicity | There is only one type to extend cdist called ***type*** -Design | Type and core cleanly seperated +Design | Type and core cleanly separated Design | Sticks completly to the KISS (keep it simple and stupid) paradigma Design | Meaningful error messages - do not lose time debugging error messages Design | Consistency in behaviour, naming and documentation diff --git a/docs/web/cdist/install.mdwn b/docs/web/cdist/install.mdwn index cff2d369..0ced26db 100644 --- a/docs/web/cdist/install.mdwn +++ b/docs/web/cdist/install.mdwn @@ -29,7 +29,7 @@ immediately. To install cdist, execute the following commands: - git clone https://github.com/telmich/cdist.git + git clone https://github.com/ungleich/cdist.git cd cdist export PATH=$PATH:$(pwd -P)/bin diff --git a/docs/web/cdist/support.mdwn b/docs/web/cdist/support.mdwn index 39388c5a..4f92853b 100644 --- a/docs/web/cdist/support.mdwn +++ b/docs/web/cdist/support.mdwn @@ -8,7 +8,7 @@ You can join the development ***IRC channel*** ### Mailing list Bug reports, questions, patches, etc. should be send to the -[cdist mailing list](http://l.schottelius.org/mailman/listinfo/cdist). +[cdist mailing list](https://groups.google.com/forum/#!forum/cdist-configuration-management). ### Linkedin @@ -17,6 +17,9 @@ at [Linked in](http://www.linkedin.com/), you can join the [cdist group](http://www.linkedin.com/groups/cdist-configuration-management-3952797). +### Chat +Chat with us: [ungleich chat](https://chat.ungleich.ch/channel/cdist). + ### Commercial support You can request commercial support for cdist from diff --git a/docs/web/cdist/update.mdwn b/docs/web/cdist/update.mdwn index 28f41da7..df4617bb 100644 --- a/docs/web/cdist/update.mdwn +++ b/docs/web/cdist/update.mdwn @@ -67,7 +67,7 @@ Use [messaging](/software/cdist/man/3.0.0/man7/cdist-messaging.html) instead. ### Updating from 2.2 to 2.3 -No incompatiblities. +No incompatibilities. ### Updating from 2.1 to 2.2 @@ -134,7 +134,7 @@ Have a look at the update guide for [[2.0 to 2.1|2.0-to-2.1]]. ### Updating from 1.3 to 1.5 -No incompatiblities. +No incompatibilities. ### Updating from 1.2 to 1.3 @@ -142,7 +142,7 @@ Rename **gencode** of every type to **gencode-remote**. ### Updating from 1.1 to 1.2 -No incompatiblities. +No incompatibilities. ### Updating from 1.0 to 1.1 diff --git a/docs/web/cdist/update/2.0-to-2.1.mdwn b/docs/web/cdist/update/2.0-to-2.1.mdwn index 1d0037ab..3b5f5dc4 100644 --- a/docs/web/cdist/update/2.0-to-2.1.mdwn +++ b/docs/web/cdist/update/2.0-to-2.1.mdwn @@ -10,7 +10,7 @@ explorers and manifest to custom directories. This document will guide you to a successful update. -## Preperation +## Preparation As for every software and system you use in production, you should first of all make a backup of your data. To prevent any breakage, it is @@ -35,7 +35,7 @@ Now try to merge upstream into the new branch. % git merge origin/2.1 Fix any conflicts that may have been occurred due to local changes -and then **git add** and *git commit** those changes. This should seldomly +and then **git add** and *git commit** those changes. This should seldom occur and if, it's mostly for people hacking on the cdist core. ## Move "conf" directory diff --git a/hacking/.gitignore b/hacking/.gitignore new file mode 100644 index 00000000..375edb27 --- /dev/null +++ b/hacking/.gitignore @@ -0,0 +1,3 @@ +iso/ +*.iso +preos/ diff --git a/hacking/README b/hacking/README new file mode 100644 index 00000000..937564d5 --- /dev/null +++ b/hacking/README @@ -0,0 +1,33 @@ +- next step + - rootfs fix + - get working to login + - have sshd enabled + - kernel -> initramfs? + http://jootamam.net/howto-initramfs-image.htm + - busybox!! + +- everything into initramfs? + +- permission problem on various files below /etc + +- Target: + - get working iso + - have it configured and gathered by cdist? + + +- boot process via ...? + - systemd? + +- packaging via ... + - packages? + - binlist + - bootstrap of os + -> root permissions! + +- boot device + +- uefi support + [9:15] wurzel:hacking% pacman -Ql syslinux | grep ldlin + syslinux /usr/lib/syslinux/bios/ldlinux.c32 + syslinux /usr/lib/syslinux/efi32/ldlinux.e32 + syslinux /usr/lib/syslinux/efi64/ldlinux.e64 diff --git a/hacking/v1-debootstrap-pacstrap/arch_bootstrap.sh b/hacking/v1-debootstrap-pacstrap/arch_bootstrap.sh new file mode 100644 index 00000000..0472bf3c --- /dev/null +++ b/hacking/v1-debootstrap-pacstrap/arch_bootstrap.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +fakeroot pacman -r $(pwd -P)/preos -Syu --noconfirm --cachedir $(pwd -P)/preos/var/cache/pacman base + diff --git a/hacking/v1-debootstrap-pacstrap/debian_bootstrap.sh b/hacking/v1-debootstrap-pacstrap/debian_bootstrap.sh new file mode 100644 index 00000000..75628116 --- /dev/null +++ b/hacking/v1-debootstrap-pacstrap/debian_bootstrap.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +fakeroot debootstrap jessie ./preos-debootstrap/ diff --git a/hacking/v2-initramfs-from-os/add_kernel_isolinux.sh b/hacking/v2-initramfs-from-os/add_kernel_isolinux.sh new file mode 100755 index 00000000..ec7b610c --- /dev/null +++ b/hacking/v2-initramfs-from-os/add_kernel_isolinux.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# FIXME: Write cdist type / explorer that finds +# package for a file, distro independent + +if [ "$#" -ne 1 ]; then + echo "$0 dir-out" + exit 1 +fi + +dir=$1; shift +boot=$dir/boot + +mkdir -p "$boot" +cp /boot/vmlinuz-linux \ + /boot/initramfs-linux-fallback.img \ + /usr/lib/syslinux/bios/isolinux.bin \ + "$boot" + +cp /usr/lib/syslinux/bios/ldlinux.c32 \ + "$dir" + +cat > "$dir/isolinux.cfg" << eof +default preos +label preos +title cdist PreOS +linux /boot/vmlinuz-linux +initrd /boot/initramfs-linux-fallback.img +eof diff --git a/hacking/v2-initramfs-from-os/all.sh b/hacking/v2-initramfs-from-os/all.sh new file mode 100755 index 00000000..fe3d6d11 --- /dev/null +++ b/hacking/v2-initramfs-from-os/all.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +dir=./iso +iso=preos.iso + +./filelist_from_package.sh | ./filelist_to_dir.sh "$dir" +echo "MISSING: copy libraries" >&2 +./add_kernel_isolinux.sh "$dir" +./create_iso.sh "$dir" "$iso" diff --git a/hacking/v2-initramfs-from-os/bin_to_pkg.sh b/hacking/v2-initramfs-from-os/bin_to_pkg.sh new file mode 100755 index 00000000..111b1fa9 --- /dev/null +++ b/hacking/v2-initramfs-from-os/bin_to_pkg.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +abspath=$(command -v "$1") +pacman -Qoq "$abspath" diff --git a/hacking/v2-initramfs-from-os/copy_files_for_iso.sh b/hacking/v2-initramfs-from-os/copy_files_for_iso.sh new file mode 100755 index 00000000..0318c072 --- /dev/null +++ b/hacking/v2-initramfs-from-os/copy_files_for_iso.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -ex + +testdir=./iso-root-dir + +# Create base +rm -rf "$testdir" +mkdir "$testdir" + +# Copy binaries + +# Copy kernel +mkdir -p "$testdir/boot" +cp /boot/vmlinuz-linux "$testdir/boot/kernel" +cp /boot/initramfs-linux-fallback.img "$testdir/boot/initramfs" + +# Create iso +genisoimage -v -V "cdist preos v0.1" \ + -cache-inodes -J -l \ + -r -no-emul-boot \ + -boot-load-size 4 -b isolinux.bin -c boot.cat -o cdist-preos.iso iso + diff --git a/hacking/v2-initramfs-from-os/file_list_of_packages.sh b/hacking/v2-initramfs-from-os/file_list_of_packages.sh new file mode 100644 index 00000000..608fdfbc --- /dev/null +++ b/hacking/v2-initramfs-from-os/file_list_of_packages.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +pacman -Qlq "$@" diff --git a/hacking/v2-initramfs-from-os/filelist_from_package.sh b/hacking/v2-initramfs-from-os/filelist_from_package.sh new file mode 100755 index 00000000..5652ba66 --- /dev/null +++ b/hacking/v2-initramfs-from-os/filelist_from_package.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Generate filelist excluding stuff that takes only space +( + for pkg in systemd openssh \ + bash bzip2 coreutils cryptsetup device-mapper dhcpcd \ + diffutils e2fsprogs file filesystem findutils gawk \ + gettext glibc grep gzip inetutils iproute2 \ + iputils jfsutils less licenses linux logrotate lvm2 \ + man-db man-pages mdadm nano pacman pciutils \ + pcmciautils procps-ng psmisc reiserfsprogs \ + s-nail sed shadow sysfsutils systemd-sysvcompat tar \ + usbutils util-linux vi which xfsprogs \ + ; do + pacman -Qlq $pkg | grep -v \ + -e /usr/share/man/ \ + -e /usr/share/doc/ \ + -e /usr/include + + done +) | sort | uniq diff --git a/hacking/v2-initramfs-from-os/filelist_to_dir.sh b/hacking/v2-initramfs-from-os/filelist_to_dir.sh new file mode 100755 index 00000000..3ce19b9f --- /dev/null +++ b/hacking/v2-initramfs-from-os/filelist_to_dir.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ "$#" -ne 1 ]; then + echo "$0 outdir" + exit 1 +fi + +outdir=$1; shift + +mkdir -p "$outdir" + +while read file; do + if [ -d "$file" ]; then + mkdir -p "$outdir$file" + else + cp --preserve=mode,links "$file" "$outdir$file" + fi +done diff --git a/hacking/v2-initramfs-from-os/packages_arch b/hacking/v2-initramfs-from-os/packages_arch new file mode 100644 index 00000000..ed879512 --- /dev/null +++ b/hacking/v2-initramfs-from-os/packages_arch @@ -0,0 +1,29 @@ +base syslinux + +[10:06] wurzel:hacking% sudo !! +sudo pacman -S base +[sudo] password for nico: +:: linux is in IgnorePkg/IgnoreGroup. Install anyway? [Y/n] y +:: There are 50 members in group base: +:: Repository core + 1) bash 2) bzip2 3) coreutils 4) cryptsetup 5) device-mapper 6) dhcpcd 7) diffutils 8) e2fsprogs 9) file + 10) filesystem 11) findutils 12) gawk 13) gcc-libs 14) gettext 15) glibc 16) grep 17) gzip 18) inetutils + 19) iproute2 20) iputils 21) jfsutils 22) less 23) licenses 24) linux 25) logrotate 26) lvm2 27) man-db + 28) man-pages 29) mdadm 30) nano 31) netctl 32) pacman 33) pciutils 34) pcmciautils 35) perl 36) procps-ng + 37) psmisc 38) reiserfsprogs 39) s-nail 40) sed 41) shadow 42) sysfsutils 43) systemd-sysvcompat 44) tar + 45) texinfo 46) usbutils 47) util-linux 48) vi 49) which 50) xfsprogs + +Enter a selection (default=all): + +:18,23s/ [0-9]*)//g + + bash bzip2 coreutils cryptsetup device-mapper dhcpcd diffutils e2fsprogs file + filesystem findutils gawk gcc-libs gettext glibc grep gzip inetutils + iproute2 iputils jfsutils less licenses linux logrotate lvm2 man-db + man-pages mdadm nano netctl pacman pciutils pcmciautils perl procps-ng + psmisc reiserfsprogs s-nail sed shadow sysfsutils systemd-sysvcompat tar + texinfo usbutils util-linux vi which xfsprogs + +6J + +bash bzip2 coreutils cryptsetup device-mapper dhcpcd diffutils e2fsprogs file filesystem findutils gawk gcc-libs gettext glibc grep gzip inetutils iproute2 iputils jfsutils less licenses linux logrotate lvm2 man-db man-pages mdadm nano netctl pacman pciutils pcmciautils perl procps-ng psmisc reiserfsprogs s-nail sed shadow sysfsutils systemd-sysvcompat tar texinfo usbutils util-linux vi which xfsprogs diff --git a/hacking/v3-busybox/add_kernel_isolinux.sh b/hacking/v3-busybox/add_kernel_isolinux.sh new file mode 100755 index 00000000..ac5d495b --- /dev/null +++ b/hacking/v3-busybox/add_kernel_isolinux.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# FIXME: distro specific kernel location + +if [ "$#" -ne 1 ]; then + echo "$0 dir-out" + exit 1 +fi + +dir=$1; shift +boot=$dir/boot + +mkdir -p "$boot" +cp /boot/vmlinuz-linux "$boot/linux" +cp /usr/lib/syslinux/bios/isolinux.bin "$boot" +cp /usr/lib/syslinux/bios/ldlinux.c32 "$dir" + +cat > "$dir/isolinux.cfg" << eof +default preos +label preos +title cdist PreOS +linux /boot/linux +initrd /boot/initramfs +eof diff --git a/hacking/v3-busybox/all.sh b/hacking/v3-busybox/all.sh new file mode 100755 index 00000000..65a3706b --- /dev/null +++ b/hacking/v3-busybox/all.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +rm -rf preos +mkdir -p preos/boot + +./create_initramfs.sh > preos/boot/initramfs +./add_kernel_isolinux.sh preos +./copy_bin_with_libs.sh preos +./create_iso.sh preos preos.iso diff --git a/hacking/v3-busybox/copy_bin_with_libs.sh b/hacking/v3-busybox/copy_bin_with_libs.sh new file mode 100755 index 00000000..ee2b532e --- /dev/null +++ b/hacking/v3-busybox/copy_bin_with_libs.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# Nico Schottelius +# Fri May 1 17:31:50 CEST 2015 + + +PATH=/bin:/sbin:/usr/bin:/usr/sbin + +if [ "$#" -ne 1 ]; then + echo "$0 dir-out" + exit 1 +fi + + +out_dir=$1 + +#bin_list="udevadm bash fdisk mount syslinux umount rm mv" +bin_list="udevadm fdisk" + +libs=$(mktemp /tmp/cdist-preos-libs.XXXXXXXXXXXXX) + +mkdir -p "$out_dir/bin" "$out_dir/lib" + +( + for bin in $bin_list; do + src=$(which "$bin") + cp "$src" "$out_dir/bin" + + ldd "$src" | sed -e 's/=>//' -e 's/(.*//' | awk '{ if(NF == 2) { print $2 } else { print $1 } }' + done +) | sort | uniq > "$libs" + + +while read lib; do + if echo $lib | grep '^/'; then + # echo "Copying fqdn lib $lib ..." + cp "$lib" "$out_dir/lib" + else + echo "How to copy $lib ?" + fi +done < "$libs" + + +rm -f "$libs" + +exit 0 + + +bin=$1 + +# Not used alternatives +# new_list=$(objdump -p /usr/bin/ls | awk '$1 ~ /NEEDED/ { print $2 }') +# ldconfig -p | grep 'libBrokenLocale.so.1$' | sed 's/.* => //' + + +for new_item in $new_list; do + + +done + +ldconfig -p | diff --git a/hacking/v3-busybox/create_initramfs.sh b/hacking/v3-busybox/create_initramfs.sh new file mode 100755 index 00000000..f87a7ef6 --- /dev/null +++ b/hacking/v3-busybox/create_initramfs.sh @@ -0,0 +1,32 @@ +#!/bin/sh +set -ex + + +initramfs_dir=$(mktemp -d /tmp/cdist-preos.XXXXXXX) +# initramfs_dir=$1 + +for dir in bin sbin etc proc sys newroot usr/bin usr/sbin; do + mkdir -p ${initramfs_dir}/$dir +done +touch ${initramfs_dir}/etc/mdev.conf + +cp init "${initramfs_dir}/init" +cp $(which busybox) "${initramfs_dir}/bin" + +for link in sh mount; do + ln -fs busybox "${initramfs_dir}/bin/$link" +done + +cd "${initramfs_dir}" +find . | cpio -H newc -o | gzip + +rm -rf "${initramfs_dir}" + +exit 0 + +# TODO: +# - Kernel modules +# - ssh +# - various mkfs +# - libs + diff --git a/hacking/v3-busybox/create_iso.sh b/hacking/v3-busybox/create_iso.sh new file mode 100755 index 00000000..c6b39be6 --- /dev/null +++ b/hacking/v3-busybox/create_iso.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# FIXME: include os explorer to name preos + +if [ "$#" -ne 2 ]; then + echo "$0 dir-in iso-out" + exit 1 +fi + +indir=$1; shift +iso=$1; shift + +version=0.4 + +out=preos-${version}.iso + + # -cache-inodes \ +genisoimage -r -J -l \ + -V "cdist PreOS $version" \ + -b boot/isolinux.bin -no-emul-boot -c boot.cat -boot-load-size 4 -boot-info-table \ + -o "$iso" "$indir" diff --git a/hacking/v3-busybox/init b/hacking/v3-busybox/init new file mode 100755 index 00000000..a961526f --- /dev/null +++ b/hacking/v3-busybox/init @@ -0,0 +1,61 @@ +#!/bin/sh + +#Create all the symlinks to /bin/busybox +/bin/busybox --install -s + +#Mount things needed by this script +mount -t proc proc /proc +mount -t sysfs sysfs /sys + +#Disable kernel messages from popping onto the screen +echo 0 > /proc/sys/kernel/printk + + +#Create device nodes +mknod /dev/null c 1 3 +mknod /dev/tty c 5 0 +mdev -s + +#Function for parsing command line options with "=" in them +# get_opt("init=/sbin/init") will return "/sbin/init" +get_opt() { + echo "$@" | cut -d "=" -f 2 +} + +#Defaults +init="/sbin/init" +root="/dev/hda1" + +#Process command line options +for i in $(cat /proc/cmdline); do + case $i in + root\=*) + root=$(get_opt $i) + ;; + init\=*) + init=$(get_opt $i) + ;; + esac +done + + +exec sh + +# Skipping the rest + +#Mount the root device +mount "${root}" /newroot + +#Check if $init exists and is executable +if [[ -x "/newroot/${init}" ]] ; then + #Unmount all other mounts so that the ram used by + #the initramfs can be cleared after switch_root + umount /sys /proc + + #Switch to the new root and execute init + exec switch_root /newroot "${init}" +fi + +#This will only be run if the exec above failed +echo "Failed to switch_root, dropping to a shell" +exec sh diff --git a/hacking/v3-busybox/qemu-test.sh b/hacking/v3-busybox/qemu-test.sh new file mode 100755 index 00000000..02afc2e6 --- /dev/null +++ b/hacking/v3-busybox/qemu-test.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ "$#" -ne 1 ]; then + echo "$0 iso" + exit 1 +fi + +iso=$1; shift + +qemu-system-x86_64 -m 512 -boot order=cd \ + -drive file=$iso,media=cdrom + diff --git a/scripts/cdist b/scripts/cdist index 91dec2c9..498091b8 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # -# 2010-2013 Nico Schottelius (nico-cdist at schottelius.org) +# 2010-2016 Nico Schottelius (nico-cdist at schottelius.org) # 2016 Darko Poljak (darko.poljak at gmail.com) # # This file is part of cdist. @@ -21,157 +21,28 @@ # # - -# list of beta arguments for sub-commands -BETA_ARGS = { - 'config': ['jobs', ], -} - - -def check_positive_int(value): - import argparse - - try: - val = int(value) - except ValueError as e: - raise argparse.ArgumentTypeError( - "{} is invalid int value".format(value)) - if val <= 0: - raise argparse.ArgumentTypeError( - "{} is invalid positive int value".format(val)) - return val - - -def check_beta(args_dict): - if 'beta' not in args_dict: - args_dict['beta'] = False - # Check only if beta is not enabled: if beta option is specified then - # raise error. - if not args_dict['beta']: - cmd = args_dict['command'] - if cmd in BETA_ARGS: - for arg in BETA_ARGS[cmd]: - if arg in args_dict and args_dict[arg]: - raise cdist.CdistBetaRequired(cmd, arg) +import collections +import logging def commandline(): """Parse command line""" - import argparse + import cdist.argparse import cdist.banner import cdist.config + import cdist.install import cdist.shell import shutil import os - import multiprocessing - - # Construct parser others can reuse - parser = {} - # Options _all_ parsers have in common - parser['loglevel'] = argparse.ArgumentParser(add_help=False) - parser['loglevel'].add_argument( - '-d', '--debug', help='Set log level to debug', - action='store_true', default=False) - parser['loglevel'].add_argument( - '-v', '--verbose', help='Set log level to info, be more verbose', - action='store_true', default=False) - - # Main subcommand parser - parser['main'] = argparse.ArgumentParser( - description='cdist ' + cdist.VERSION, parents=[parser['loglevel']]) - parser['main'].add_argument( - '-V', '--version', help='Show version', action='version', - version='%(prog)s ' + cdist.VERSION) - parser['sub'] = parser['main'].add_subparsers( - title="Commands", dest="command") - - # Banner - parser['banner'] = parser['sub'].add_parser( - 'banner', parents=[parser['loglevel']]) - parser['banner'].set_defaults(func=cdist.banner.banner) - - # Config - parser['config'] = parser['sub'].add_parser( - 'config', parents=[parser['loglevel']]) - parser['config'].add_argument( - 'host', nargs='*', help='host(s) to operate on') - parser['config'].add_argument( - '-b', '--enable-beta', - help=('Enable beta functionalities. Beta functionalities ' - 'include the following options: -j/--jobs.'), - action='store_true', dest='beta', default=False) - parser['config'].add_argument( - '-c', '--conf-dir', - help=('Add configuration directory (can be repeated, ' - 'last one wins)'), action='append') - parser['config'].add_argument( - '-f', '--file', - help=('Read additional hosts to operate on from specified file ' - 'or from stdin if \'-\' (each host on separate line). ' - 'If no host or host file is specified then, by default, ' - 'read hosts from stdin.'), - dest='hostfile', required=False) - parser['config'].add_argument( - '-i', '--initial-manifest', - help='Path to a cdist manifest or \'-\' to read from stdin.', - dest='manifest', required=False) - parser['config'].add_argument( - '-j', '--jobs', nargs='?', type=check_positive_int, - help=('Specify the maximum number of parallel jobs, currently ' - 'only global explorers are supported (currently in beta'), - action='store', dest='jobs', - const=multiprocessing.cpu_count()) - parser['config'].add_argument( - '-n', '--dry-run', - help='Do not execute code', action='store_true') - parser['config'].add_argument( - '-o', '--out-dir', - help='Directory to save cdist output in', dest="out_path") - parser['config'].add_argument( - '-p', '--parallel', - help='Operate on multiple hosts in parallel', - action='store_true', dest='parallel') - parser['config'].add_argument( - '-s', '--sequential', - help='Operate on multiple hosts sequentially (default)', - action='store_false', dest='parallel') - # remote-copy and remote-exec defaults are environment variables - # if set; if not then None - these will be futher handled after - # parsing to determine implementation default - parser['config'].add_argument( - '--remote-copy', - help='Command to use for remote copy (should behave like scp)', - action='store', dest='remote_copy', - default=os.environ.get('CDIST_REMOTE_COPY')) - parser['config'].add_argument( - '--remote-exec', - help=('Command to use for remote execution ' - '(should behave like ssh)'), - action='store', dest='remote_exec', - default=os.environ.get('CDIST_REMOTE_EXEC')) - parser['config'].set_defaults(func=cdist.config.Config.commandline) - - # Shell - parser['shell'] = parser['sub'].add_parser( - 'shell', parents=[parser['loglevel']]) - parser['shell'].add_argument( - '-s', '--shell', - help=('Select shell to use, defaults to current shell. Used shell' - ' should be POSIX compatible shell.')) - parser['shell'].set_defaults(func=cdist.shell.Shell.commandline) - - for p in parser: - parser[p].epilog = ( - "Get cdist at http://www.nico.schottelius.org/software/cdist/") + parser = cdist.argparse.get_parsers() args = parser['main'].parse_args(sys.argv[1:]) - # Loglevels are handled globally in here and debug wins over verbose - if args.verbose: - logging.root.setLevel(logging.INFO) - if args.debug: - logging.root.setLevel(logging.DEBUG) + # Loglevels are handled globally in here + retval = cdist.argparse.handle_loglevel(args) + if retval: + log.warning(retval) log.debug(args) log.info("version %s" % cdist.VERSION) @@ -191,23 +62,21 @@ def commandline(): parser['main'].print_help() sys.exit(0) - check_beta(vars(args)) + cdist.argparse.check_beta(vars(args)) args.func(args) if __name__ == "__main__": - # Sys is needed for sys.exit() import sys cdistpythonversion = '3.2' if sys.version < cdistpythonversion: - print('Python >= ' + cdistpythonversion + - ' is required on the source host.', file=sys.stderr) + print('Python >= {} is required on the source host.'.format( + cdistpythonversion), file=sys.stderr) sys.exit(1) exit_code = 0 try: - import logging import os import re import cdist