diff --git a/.gitignore b/.gitignore index 69a8ea98..6e2d4437 100644 --- a/.gitignore +++ b/.gitignore @@ -2,17 +2,27 @@ .*.swp # Ignore generated manpages -doc/man/.marker -doc/man/man1/*.1 -doc/man/man7/*.7 -doc/man/man*/*.html -doc/man/man*/*.xml -doc/man/man7/cdist-type__*.text -doc/man/man7/cdist-reference.text -doc/man/man*/docbook-xsl.css +docs/man/.marker +docs/man/man1/*.1 +docs/man/man7/*.7 +docs/man/man*/*.html +docs/man/man*/*.xml +docs/man/man*/docbook-xsl.css +docs/man/man7/cdist-type__*.text +docs/man/man7/cdist-reference.text # Ignore cdist cache for version control /cache/ -# Python / cache +# Python: cache, distutils, distribution in general __pycache__/ +MANIFEST +dist/ +cdist/version.py + +# Packaging: Archlinux +/PKGBUILD +/cdist-*.pkg.tar.xz +/cdist-*.tar.gz +/pkg +/src diff --git a/.version b/.version new file mode 100644 index 00000000..71f08595 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +2.1.0-pre1 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..a675f446 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include docs/changelog +recursive-include docs/gfx *.png *.text +recursive-include docs *.text *.html *.1 *.7 diff --git a/PKGBUILD.in b/PKGBUILD.in new file mode 100755 index 00000000..68bd6add --- /dev/null +++ b/PKGBUILD.in @@ -0,0 +1,23 @@ +#!/bin/sh + +version=$(git describe) +outfile=${0%.in} + +cat << eof > "${outfile}" +pkgname=cdist +pkgver=$version +pkgrel=1 +pkgdesc='A Usable Configuration Management System"' +arch=('any') +url='http://www.nico.schottelius.org/software/cdist/' +license=('GPL3') +depends=('python>=3.2.0') +source=("http://pypi.python.org/packages/source/c/cdist/cdist-\${pkgver}.tar.gz") + +package() { + cd cdist-\${pkgver} + python3 setup.py build install --root="\${pkgdir}" +} +eof + +makepkg -g >> "${outfile}" diff --git a/README b/README index 965138c4..a67e25e3 100644 --- a/README +++ b/README @@ -1,313 +1,6 @@ -[[!meta title="cdist - usable configuration management"]] - - - .. . .x+=:. s - dF @88> z` ^% :8 - '88bu. %8P . = 2.0.4)](man) - -### OS support - -cdist was tested or is know to run on at least - - * [Archlinux](http://www.archlinux.org/) - * [Debian](http://www.debian.org/) - * [CentOS](http://www.centos.org/) - * [Fedora](http://fedoraproject.org/) - * [Gentoo](http://www.gentoo.org/) - * [Mac OS X](http://www.apple.com/macosx/) - * [OpenBSD](http://www.openbsd.org) - * [Redhat](http://www.redhat.com/) - * [Ubuntu](http://www.ubuntu.com/) - * [XenServer](http://www.citrix.com/xenserver/) - - -## Requirements - -### Server - - * A posix like shell - * Python (>= 3.2 required) - * SSH client - * Asciidoc (for building the manpages) - -### Client ("target host") - - * A posix like shell - * SSH server - - -## Installation - -### Preparation - -Ensure you have Python 3.2 installed on the machine you use to **deploy to the targets** -(the ***source host***). - -#### Archlinux - -Archlinux already has python >= 3.2, so you only need to do: - - pacman -S python - -#### Debian - -For Debian >= wheezy: - - aptitude install python3 - -For older Debian versions, installing python 3.2 manually is required. - -#### Fedora - -For Fedora >= 15: - - yum install python3 - -#### FreeBSD - -For the port: - - cd /usr/ports/lang/python32/ && make install clean - -For the package: - - pkg_add -r python32 - -#### Gentoo - -Gentoo only provides python 3.2 in testing packages (http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=3&chap=3). -If you want to ensure nothing breaks you must set back the python version to what was default before. - - emerge -av =python-3.2.2 --autounmask-write - emerge -av =python-3.2.2 - eselect python list - eselect python list set python3.2 - -#### Max OS X - -You can choose between Homebrew and Macports, either way works: - -[Homebrew](http://mxcl.github.com/homebrew/) variant: - - brew install python3 - -[Macports](http://www.macports.org/install.php) variant: - - port install python32 - ln -s /opt/local/bin/python3.2 /opt/local/bin/python3 - -### Get cdist - -You can clone cdist from git, which gives you the advantage of having -a version control in place for development of your own stuff as well. -To install cdist, execute the following commands: - - git clone git://git.schottelius.org/cdist - cd cdist - export PATH=$PATH:$(pwd -P)/bin - - # If you want the manpages - ./build man - export MANPATH=$MANPATH:$(pwd -P)/doc/man - - -### Available versions - -There are at least the following branches available: - - * Development: master - * 2.0: Python rewrite of cdist core [stable branch] - -Old versions: - - * 1.7: Bugfixes, cleanups, new type and explorer rename - * 1.6: New types, cleaned up \_\_package* types, internal cleanup - * 1.5: Focus on object orientation instead of global stage orientation - * 1.4: Support for redefiniton of objects (if equal) - * 1.3: Support for local and remote code execution (current stable) - * 1.2: Dependencies supported - * 1.1: \_\_file to \_\_file, \_\_directory, \_\_link migration - * 1.0: First official release - -Other branches may be available for features or bugfixes, but they -may vanish at any point. To select a specific branch use - - # Generic code - git checkout -b origin/ - - # Stay on a specific version - version=2.0 - git checkout -b $version origin/$version - -### Mirrors - - * git://github.com/telmich/cdist.git ([github](https://github.com/telmich/cdist)) - * git://git.code.sf.net/p/cdist/code ([sourceforge](https://sourceforge.net/p/cdist/code)) - -## Update - -To upgrade cdist in the current branch use - - git pull - - # Also update the manpages - ./build man - export MANPATH=$MANPATH:$(pwd -P)/doc/man - -If you stay on a version branche (i.e. 1.0, 1.1., ...), nothing should break. -The master branch on the other hand is the development branch and may not be -working, break your setup or eat the tree in your garden. - -### Upgrading from 1.7 to 2.0 - -* Ensure python (>= 3.2) is installed on the server -* Use "cdist config host" instead of "cdist-deploy-to host" -* Use "cdist config -p host1 host2" instead of "cdist-mass-deploy" -* Use "cdist banner" for fun -* Use **\_\_object_fq** instead of **\_\_self** in manifests - -### Upgrading from 1.6 to 1.7 - -* If you used the global explorer **hardware_type**, you need to change - your code to use **machine** instead. - -### Upgrading from 1.5 to 1.6 - -* If you used **\_\_package_apt --preseed**, you need to use the new - type **\_\_debconf_set_selections** instead. -* The **\_\_package** types accepted either --state deinstalled or - --state uninstaaled. Starting with 1.6, it was made consistently - to --state removed. - -### Upgrading from 1.3 to 1.5 - -No incompatiblities. - -### Upgrading from 1.2 to 1.3 - -Rename **gencode** of every type to **gencode-remote**. - -### Upgrading from 1.1 to 1.2 - -No incompatiblities. - -### Upgrading from 1.0 to 1.1 - -In 1.1 the type **\_\_file** was split into **\_\_directory**, **\_\_file** and -**\_\_link**. The parameter **--type** was removed from **\_\_file**. Thus you -need to replace **\_\_file** calls in your manifests: - - * Remove --type from all \_\_file calls - * If type was symlink, use \_\_link and --type symbolic - * If type was directory, use \_\_directory - - -## Support - -### IRC - -You can join the development ***IRC channel*** -[#cstar on irc.freenode.org](irc://irc.freenode.org/#cstar). - -### Mailing list - -Bug reports, questions, patches, etc. should be send to the -[cdist mailing list](http://l.schottelius.org/mailman/listinfo/cdist). - -### Linkedin - -If you have an account -at [Linked in](http://www.linkedin.com/), -you can join the -[cdist group](http://www.linkedin.com/groups/cdist-configuration-management-3952797). - -### Commercial support - -You can request commercial support for cdist from -[my company](http://firma.schottelius.org/english/). - -## Used by - -If you're using cdist, feel free to send a report to the mailing list. -Interesting information are for instance - - * Which services do you manage? - * How many machines do you manage? - * What are the pros/cons you see in cdist? - * General comments/critics - -### Nico Schottelius, Systems Group ETH Zurich and privately - -Yes, I'm actually eating my own dogfood and currently managing - - * [plone](http://plone.org/) (cms) - * [moinmoin](http://moinmo.in/) (wiki) - * [apache](http://httpd.apache.org/) (webserver) - * [kerberos (mit)](http://web.mit.edu/kerberos/) (authentication) - * [nss-pam-ldapd](http://arthurdejong.org/nss-pam-ldapd/) (authentication) - * [ircd-hybrid](http://www.ircd-hybrid.org/) (chat) - * [stunnel](http://stunnel.mirt.net/) (SSL tunnel) - * [mercurial-server](http://www.lshift.net/mercurial-server.html) (version control) - * [xfce](http://www.xfce.org/) (lightweight desktop environment) - * [slim](http://slim.berlios.de/) (graphical login manager for X11) - -with cdist on more than **60** production machines of the -[Systems Group](http://www.systems.ethz.ch) at the -[ETH Zurich](http://www.ethz.ch) as well at home. - -### Steven Armstrong, CBRG ETH Zurich - -The CBRG is managing most of their compute clusters with cdist. +cdist +----- +cdist is a usable configuration management system. +For the web documentation have a look at docs/web/. diff --git a/bin/cdist b/bin/cdist index c6467477..dfe4fa00 100755 --- a/bin/cdist +++ b/bin/cdist @@ -1,7 +1,7 @@ -#!/usr/bin/env python3 +#!/bin/sh # -*- coding: utf-8 -*- # -# 2010-2012 Nico Schottelius (nico-cdist at schottelius.org) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -20,215 +20,14 @@ # # -def commandline(): - """Parse command line""" - import argparse +# Wrapper for real script to allow execution from checkout +dir=${0%/*} - import cdist.banner - import cdist.config - import cdist.install +# Ensure version is present - the bundled/shipped version contains a static version, +# the git version contains a dynamic version +"$dir/../build" version - # 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) +libdir=$(cd "${dir}/../" && pwd -P) +export PYTHONPATH="${libdir}" - # 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") - - # Banner - parser['banner'] = parser['sub'].add_parser('banner', - parents=[parser['loglevel']]) - parser['banner'].set_defaults(func=cdist.banner.banner) - - # Config and install (common stuff) - parser['configinstall'] = argparse.ArgumentParser(add_help=False) - parser['configinstall'].add_argument('host', nargs='+', - help='one or more hosts to operate on') - parser['configinstall'].add_argument('-c', '--cdist-home', - help='Change cdist home (default: .. from bin directory)', - action='store') - parser['configinstall'].add_argument('-i', '--initial-manifest', - help='Path to a cdist manifest or \'-\' to read from stdin.', - dest='manifest', required=False) - parser['configinstall'].add_argument('-p', '--parallel', - help='Operate on multiple hosts in parallel', - action='store_true', dest='parallel') - parser['configinstall'].add_argument('-s', '--sequential', - help='Operate on multiple hosts sequentially (default)', - action='store_false', dest='parallel') - - # Config - parser['config'] = parser['sub'].add_parser('config', - parents=[parser['loglevel'], parser['configinstall']]) - parser['config'].set_defaults(func=config) - - # Install - parser['install'] = parser['sub'].add_parser('install', - parents=[parser['loglevel'], parser['configinstall']]) - parser['install'].set_defaults(func=install) - - for p in parser: - parser[p].epilog = "Get cdist at http://www.nico.schottelius.org/software/cdist/" - - 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) - - log.debug(args) - args.func(args) - -def config(args): - configinstall(args, mode=cdist.config.Config) - -def install(args): - configinstall(args, mode=cdist.install.Install) - -def configinstall(args, mode): - """Configure or install remote system""" - import multiprocessing - import time - - initial_manifest_tempfile = None - if args.manifest == '-': - # read initial manifest from stdin - import tempfile - try: - handle, initial_manifest_temp_path = tempfile.mkstemp(prefix='cdist.stdin.') - with os.fdopen(handle, 'w') as fd: - fd.write(sys.stdin.read()) - except (IOError, OSError) as e: - raise cdist.Error("Creating tempfile for stdin data failed: %s" % e) - - args.manifest = initial_manifest_temp_path - import atexit - atexit.register(lambda: os.remove(initial_manifest_temp_path)) - - process = {} - failed_hosts = [] - time_start = time.time() - - for host in args.host: - if args.parallel: - log.debug("Creating child process for %s", host) - process[host] = multiprocessing.Process(target=configinstall_onehost, args=(host, args, mode, True)) - process[host].start() - else: - try: - configinstall_onehost(host, args, mode, parallel=False) - except cdist.Error as e: - failed_hosts.append(host) - - # Catch errors in parallel mode when joining - if args.parallel: - for host in process.keys(): - log.debug("Joining process %s", host) - process[host].join() - - if not process[host].exitcode == 0: - failed_hosts.append(host) - - time_end = time.time() - log.info("Total processing time for %s host(s): %s", len(args.host), - (time_end - time_start)) - - if len(failed_hosts) > 0: - raise cdist.Error("Failed to deploy to the following hosts: " + - " ".join(failed_hosts)) - -def configinstall_onehost(host, args, mode, parallel): - """Configure or install ONE remote system""" - - try: - import cdist.context - - context = cdist.context.Context( - target_host=host, - initial_manifest=args.manifest, - base_path=args.cdist_home, - exec_path=sys.argv[0], - debug=args.debug) - - c = mode(context) - c.deploy_and_cleanup() - context.cleanup() - - except cdist.Error as e: - # We are running in our own process here, need to sys.exit! - if parallel: - log.error(e) - sys.exit(1) - else: - raise - - except KeyboardInterrupt: - # Ignore in parallel mode, we are existing anyway - if parallel: - sys.exit(0) - # Pass back to controlling code in sequential mode - else: - raise - -def emulator(): - """Prepare and run emulator""" - import cdist.emulator - emulator = cdist.emulator.Emulator(sys.argv) - return emulator.run() - -if __name__ == "__main__": - # Sys is needed for sys.exit() - import sys - - exit_code = 0 - - try: - import logging - import os - import re - - cdistpythonversion = '3.2' - if sys.version < cdistpythonversion: - raise cdist.Error('Cdist requires Python >= ' + cdistpythonversion + - ' on the source host.') - - # Ensure our /lib/ is included into PYTHON_PATH - sys.path.insert(0, os.path.abspath( - os.path.join(os.path.dirname(os.path.realpath(__file__)), '../lib'))) - - # And now import our stuff - import cdist - - log = logging.getLogger("cdist") - - logging.basicConfig(format='%(levelname)s: %(message)s') - - if re.match("__", os.path.basename(sys.argv[0])): - emulator() - else: - commandline() - - except KeyboardInterrupt: - pass - - except cdist.Error as e: - log.error(e) - exit_code = 1 - - # Determine exit code by return value of function - - sys.exit(exit_code) +"$dir/../scripts/cdist" "$@" diff --git a/build b/build index b209e1c2..fb01c565 100755 --- a/build +++ b/build @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -26,6 +26,7 @@ # exit on any error #set -e +basedir=${0%/*} version=$(git describe) # Manpage and HTML @@ -33,139 +34,378 @@ A2XM="a2x -f manpage --no-xmllint -a encoding=UTF-8" A2XH="a2x -f xhtml --no-xmllint -a encoding=UTF-8" # Developer webbase -WEBDIR=$HOME/niconetz -WEBBASE=$WEBDIR/software/cdist +WEBDIR=$HOME/www.nico.schottelius.org +WEBBLOG=$WEBDIR/blog +WEBTOPDIR=$WEBDIR/software +WEBBASE=$WEBTOPDIR/cdist WEBMAN=$WEBBASE/man/$version WEBPAGE=${WEBBASE}.mdwn # Documentation -MANDIR=doc/man +MANDIR=docs/man MAN1DSTDIR=${MANDIR}/man1 MAN7DSTDIR=${MANDIR}/man7 -SPEECHESDIR=doc/speeches +SPEECHESDIR=docs/speeches + +# Change to checkout directory +cd "$basedir" case "$1" in - man) - set -e - "$0" mangen - "$0" mantype - "$0" manbuild + man) + set -e + "$0" mangen + "$0" mantype + "$0" manbuild + ;; + + manbuild) + trap abort INT + abort() { + kill 0 + } + for section in 1 7; do + for src in ${MANDIR}/man${section}/*.text; do + manpage="${src%.text}.$section" + if [ ! -f "$manpage" -o "$manpage" -ot "$src" ]; then + echo "Compiling man page for $src" + $A2XM "$src" + fi + htmlpage="${src%.text}.html" + if [ ! -f "$htmlpage" -o "$htmlpage" -ot "$src" ]; then + echo "Compiling html page for $src" + $A2XH "$src" + fi + done + done + ;; + + mantype) + for mansrc in cdist/conf/type/*/man.text; do + dst="$(echo $mansrc | sed -e 's;cdist/conf/;cdist-;' -e 's;/;;' -e 's;/man;;' -e 's;^;docs/man/man7/;')" + ln -sf "../../../$mansrc" "$dst" + done + ;; + + mangen) + ${MANDIR}/cdist-reference.text.sh + ;; + + man-pub) + $0 man + + version=$($0 changelog-version) + + rm -rf "${WEBMAN}" + mkdir -p "${WEBMAN}/man1" "${WEBMAN}/man7" + cp ${MAN1DSTDIR}/*.html ${MAN1DSTDIR}/*.css ${WEBMAN}/man1 + cp ${MAN7DSTDIR}/*.html ${MAN7DSTDIR}/*.css ${WEBMAN}/man7 + cd ${WEBMAN} && git add . && git commit -m "Cdist Manpage update: $version" + ;; + + dist) + set -e + # Do the checks + $0 dist-check + + # Git changes - everything depends on this + $0 dist-tag + $0 dist-branch-merge + + # Pypi first - is the base for others + $0 dist-pypi + + # Archlinux depends on successful pypi ;-) + $0 dist-archlinux + + # Update website (includes documentation) + $0 web + + # Update manpages on website + $0 man-pub + + # update git repos + $0 pub + + $0 dist-blog + $0 dist-freecode + $0 dist-ml + $0 dist-manual + ;; + + changelog-changes) + awk -F: 'BEGIN { start=0 } { if ($0 ~ /^[[:digit:]]/) { if(start == 0) {start = 1 } else { exit } } else { if(start==1) {print $0 }} }' "$basedir/docs/changelog" + ;; + + changelog-version) + # get version from changelog and ensure it's not already present + grep '^[[:digit:]]' "$basedir/docs/changelog" | head -n1 | sed 's/:.*//' + ;; + + dist-check) + set -e + echo "Verifying documentation building works ..." + $0 clean + $0 man + + changelog_version=$($0 changelog-version) + echo "Target version from changelog: $changelog_version" + + if git show --quiet $changelog_version >/dev/null 2>&1; then + echo "Version $changelog_version already exists, aborting." + exit 1 + fi + + # verify date in changelog + date_today="$(date +%Y-%m-%d)" + date_changelog=$(grep '^[[:digit:]]' "$basedir/docs/changelog" | head -n1 | sed 's/.*: //') + + if [ "$date_today" != "$date_changelog" ]; then + echo "Date in changelog is not today" + echo "Changelog: $date_changelog" + exit 1 + fi + + ;; + + blog) + version=$($0 changelog-version) + blogfile=$WEBBLOG/cdist-${version}-released.mdwn + cat << eof > "$blogfile" +[[!meta title="Cdist $version released"]] + +Here's a short overview about the changes found in this release: + +eof + + $0 changelog-changes >> "$blogfile" + + cat << eof >> "$blogfile" +For more information visit the [[cdist homepage|software/cdist]]. + +[[!tag cdist config unix]] +eof + ;; + + dist-blog) + $0 blog + version=$($0 changelog-version) + file=cdist-${version}-released.mdwn + cd "$WEBBLOG" + git add "$file" + git commit -m "New cdist version (blogentry): $version" "$file" + git push + ;; + + dist-ml) + $0 blog + version=$($0 changelog-version) + to_a=cdist + to_d=l.schottelius.org + to=${to_a}@${to_d} + + from_a=nico-cdist + from_d=schottelius.org + from=${from_a}@${from_d} + + ( + cat << eof +From: Nico -telmich- Schottelius <$from> +To: cdist mailing list <$to> +Subject: cdist $version released + +Hello .*, + +cdist $version has been released with the following changes: + +eof + + "$0" changelog-changes + cat << eof + +Cheers, + +Nico + +-- +Automatisation at its best level. With cdist. +eof + ) | /usr/sbin/sendmail -f "$from" "$to" + ;; + + + dist-manual) + cat << notes + + To be done manually... + + - linkedin entry +notes + + ;; + + dist-tag) + version=$($0 changelog-version) + # add tag + printf "Enter tag description for %s> " "$version" + read tagmessage + git tag "$version" -m "$tagmessage" + ;; + + dist-branch-merge) + version=$($0 changelog-version) + target_branch=${version%\.*} + current_branch=$(git rev-parse --abbrev-ref HEAD) + + if [ "$target_branch" = "$current_branch" ]; then + echo "Skipping merge, already on destination branch" + else + printf "Press enter to git merge $current_branch into \"$target_branch\" > " + read prompt + git checkout "$target_branch" + git merge "$current_branch" + git checkout "$current_branch" + fi ;; - manbuild) - trap abort INT - abort() { - kill 0 - } - for section in 1 7; do - for src in ${MANDIR}/man${section}/*.text; do - manpage="${src%.text}.$section" - if [ ! -f "$manpage" -o "$manpage" -ot "$src" ]; then - echo "Compiling man page for $src" - $A2XM "$src" - fi - htmlpage="${src%.text}.html" - if [ ! -f "$htmlpage" -o "$htmlpage" -ot "$src" ]; then - echo "Compiling html page for $src" - $A2XH "$src" - fi - done - done - ;; + dist-archlinux) + $0 dist-archlinux-makepkg + $0 dist-archlinux-aur-upload + ;; - mantype) - for mansrc in conf/type/*/man.text; do - dst="$(echo $mansrc | sed -e 's;conf/;cdist-;' -e 's;/;;' -e 's;/man;;' -e 's;^;doc/man/man7/;')" - ln -sf "../../../$mansrc" "$dst" - done - ;; + dist-archlinux-makepkg) + ./PKGBUILD.in + makepkg -c --source + ;; - mangen) - ${MANDIR}/cdist-reference.text.sh - ;; + dist-archlinux-aur-upload) + version=$($0 changelog-version) + tar=cdist-${version}-1.src.tar.gz + burp -c system "$tar" + ;; - release) - ./doc/dev/releasechecklist - ;; + dist-freecode) + version=$($0 changelog-version) + api_token=$(awk '/machine freecode login/ { print $8 }' ~/.netrc) - speeches) - cd "$SPEECHESDIR" - for speech in *tex; do - pdflatex "$speech" - pdflatex "$speech" - pdflatex "$speech" - done - ;; - - webmain) - cp README ${WEBPAGE} - cd ${WEBDIR} && git commit -m "cdist main update" ${WEBPAGE} - cd ${WEBDIR} && make pub - ;; + printf "Enter tag list for freecode release %s> " "$version" + read taglist - web) - cp README ${WEBPAGE} - rm -rf ${WEBMAN} - mkdir -p ${WEBMAN}/man1 ${WEBMAN}/man7 + printf "Enter changelog for freecode release %s> " "$version" + read changelog - # old stuff - # rm -rf ${WEBDIR}/${WEBBASE}/speeches && mkdir ${WEBDIR}/${WEBBASE}/speeches - # cp ${SPEECHESDIR}/*.pdf ${WEBDIR}/${WEBBASE}/speeches - # git describe > ${WEBDIR}/${WEBBASE}/man/VERSION + echo "Submit preview" + cat << eof +tag_list = $taglist +changelog = $changelog +version = $version +eof + printf "Press enter to submit to freecode> " + read dummy - cp ${MAN1DSTDIR}/*.html ${MAN1DSTDIR}/*.css ${WEBMAN}/man1 - cp ${MAN7DSTDIR}/*.html ${MAN7DSTDIR}/*.css ${WEBMAN}/man7 - - cd ${WEBDIR} && git add ${WEBBASE} - cd ${WEBDIR} && git commit -m "cdist update" ${WEBBASE} ${WEBPAGE} - cd ${WEBDIR} && make pub + cat << eof | cfreecode-api release-add cdist + { + "auth_code": "$api_token", + "release": { + "tag_list": "$taglist", + "version": "$version", + "changelog": "$changelog", + "hidden_from_frontpage": false + } + } +eof - # Fix ikiwiki, which does not like symlinks for pseudo security - ssh tee.schottelius.org \ - "cd /home/services/www/nico/www.nico.schottelius.org/www/software/cdist/man && - rm -f latest && ln -sf "$version" latest" - ;; + ;; - p|pu|pub) - git push --mirror - git push --mirror github - git push --mirror sf - git push --mirror ethz - ;; + dist-pypi) + $0 man + $0 version + python3 setup.py sdist upload + ;; - clean) - rm -f ${MAN7DSTDIR}/cdist-reference.text - find "${MANDIR}" -mindepth 2 -type l \ - -o -name "*.1" \ - -o -name "*.7" \ - -o -name "*.html" \ - -o -name "*.xml" \ - | xargs rm -f - ;; + speeches) + cd "$SPEECHESDIR" + for speech in *tex; do + pdflatex "$speech" + pdflatex "$speech" + pdflatex "$speech" + done + ;; + + web) + set -e + rsync -av "${basedir}/docs/web/" "${WEBTOPDIR}" - test) - shift # skip t - export PYTHONPATH=$PYTHONPATH:$(pwd -P)/lib + cd "${WEBDIR}" && git add "${WEBBASE}" + cd "${WEBDIR}" && git commit -m "cdist update" "${WEBBASE}" "${WEBPAGE}" + cd "${WEBDIR}" && make pub - if [ $# -lt 1 ]; then - python3 -m cdist.test - else - python3 -m unittest "$@" - fi - ;; + # Fix ikiwiki, which does not like symlinks for pseudo security + ssh tee.schottelius.org \ + "cd /home/services/www/nico/www.nico.schottelius.org/www/software/cdist/man && + rm -f latest && ln -sf "$version" latest" + ;; + + p|pu|pub) + for remote in "" github sf ethz; do + echo "Pushing to $remote" + git push --mirror $remote + done + ;; + + clean) + rm -f ${MAN7DSTDIR}/cdist-reference.text + + find "${MANDIR}" -mindepth 2 -type l \ + -o -name "*.1" \ + -o -name "*.7" \ + -o -name "*.html" \ + -o -name "*.xml" \ + | xargs rm -f + + find * -name __pycache__ | xargs rm -rf + ;; + clean-dist) + rm -f cdist/version.py MANIFEST PKGBUILD + rm -rf cache/ dist/ + + # Archlinux + rm -f cdist-*.pkg.tar.xz cdist-*.tar.gz + rm -rf pkg/ src/ + ;; + + very-clean) + $0 clean + $0 clean-dist + ;; + + test) + shift # skip t + export PYTHONPATH="$(pwd -P)" + + if [ $# -lt 1 ]; then + python3 -m cdist.test + else + python3 -m unittest "$@" + fi + ;; + + version) + echo "VERSION=\"$version\"" > cdist/version.py + ;; + + *) + echo '' + echo 'Welcome to cdist!' + echo '' + echo 'Here are the possible targets:' + echo '' + echo ' clean: Remove build stuff' + echo ' man: Build manpages (requires Asciidoc)' + echo ' test: Run tests' + echo '' + echo '' + echo "Unknown target, \"$1\"" >&2 + exit 1 + ;; - *) - echo '' - echo 'Welcome to cdist!' - echo '' - echo 'Here are the possible targets:' - echo '' - echo ' clean: Remove build stuff' - echo ' man: Build manpages (requires Asciidoc)' - echo ' test: Run tests' - echo '' - echo '' - echo "Unknown target, \"$1\"" >&2 - exit 1 - ;; esac diff --git a/lib/cdist/__init__.py b/cdist/__init__.py similarity index 96% rename from lib/cdist/__init__.py rename to cdist/__init__.py index bd8e6483..02d708b1 100644 --- a/lib/cdist/__init__.py +++ b/cdist/__init__.py @@ -19,7 +19,12 @@ # # -VERSION = "2.0.9" +import os +import subprocess + +import cdist.version + +VERSION = cdist.version.VERSION BANNER = """ .. . .x+=:. s @@ -38,8 +43,6 @@ BANNER = """ DOT_CDIST = ".cdist" -import os - class Error(Exception): """Base exception class for this project""" pass diff --git a/lib/cdist/banner.py b/cdist/banner.py similarity index 100% rename from lib/cdist/banner.py rename to cdist/banner.py diff --git a/conf/.gitignore b/cdist/conf/.gitignore similarity index 100% rename from conf/.gitignore rename to cdist/conf/.gitignore diff --git a/conf/README b/cdist/conf/README similarity index 100% rename from conf/README rename to cdist/conf/README diff --git a/conf/explorer/hostname b/cdist/conf/explorer/hostname similarity index 87% rename from conf/explorer/hostname rename to cdist/conf/explorer/hostname index a3ae4e15..2ae23759 100755 --- a/conf/explorer/hostname +++ b/cdist/conf/explorer/hostname @@ -1,6 +1,7 @@ #!/bin/sh # # 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -19,4 +20,6 @@ # # -hostname +if command -v hostname; then + hostname +fi diff --git a/cdist/conf/explorer/interfaces b/cdist/conf/explorer/interfaces new file mode 100755 index 00000000..6804f2db --- /dev/null +++ b/cdist/conf/explorer/interfaces @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2012 Sébastien Gross +# +# 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 . +# +# +# List all network interfaces in explorer/ifaces. One interface per line. +# +# If your OS is not supported please provide a ifconfig output +# + +# Use ip, if available +if command -v ip; then + ip -o link show | sed -n 's/^[0-9]\+: \(.\+\): <.*/\1/p' + exit 0 +fi + +if ! command -v ifconfig; then + # no ifconfig, nothing we could do + exit 0 +fi + +uname_s="$(uname -s)" +REGEXP='s/^(.*)(:[[:space:]]*flags=|Link encap).*/\1/p' + +case "$uname_s" in + Darwin) + ifconfig -a | sed -n -E "$REGEXP" + ;; + Linux|*BSD) + ifconfig -a | sed -n -r "$REGEXP" + ;; + *) + echo "Unsupported ifconfig output for $uname_s" >&2 + exit 1 + ;; +esac diff --git a/conf/explorer/lsb_codename b/cdist/conf/explorer/lsb_codename similarity index 94% rename from conf/explorer/lsb_codename rename to cdist/conf/explorer/lsb_codename index 22b6d51e..eebd3e0f 100755 --- a/conf/explorer/lsb_codename +++ b/cdist/conf/explorer/lsb_codename @@ -25,7 +25,7 @@ case "$($__explorer/os)" in (. /etc/openwrt_release && echo "$DISTRIB_CODENAME") ;; *) - lsb_release=$(which lsb_release 2>/dev/null) + lsb_release=$(command -v lsb_release) if [ -x "$lsb_release" ]; then $lsb_release --short --codename fi diff --git a/conf/explorer/lsb_description b/cdist/conf/explorer/lsb_description similarity index 94% rename from conf/explorer/lsb_description rename to cdist/conf/explorer/lsb_description index 48aff30d..23f45421 100755 --- a/conf/explorer/lsb_description +++ b/cdist/conf/explorer/lsb_description @@ -25,7 +25,7 @@ case "$($__explorer/os)" in (. /etc/openwrt_release && echo "$DISTRIB_DESCRIPTION") ;; *) - lsb_release=$(which lsb_release 2>/dev/null) + lsb_release=$(command -v lsb_release) if [ -x "$lsb_release" ]; then $lsb_release --short --description fi diff --git a/conf/explorer/lsb_id b/cdist/conf/explorer/lsb_id similarity index 94% rename from conf/explorer/lsb_id rename to cdist/conf/explorer/lsb_id index 0dd0f9f4..9754eb63 100755 --- a/conf/explorer/lsb_id +++ b/cdist/conf/explorer/lsb_id @@ -25,7 +25,7 @@ case "$($__explorer/os)" in (. /etc/openwrt_release && echo "$DISTRIB_ID") ;; *) - lsb_release=$(which lsb_release 2>/dev/null) + lsb_release=$(command -v lsb_release) if [ -x "$lsb_release" ]; then $lsb_release --short --id fi diff --git a/conf/explorer/lsb_release b/cdist/conf/explorer/lsb_release similarity index 94% rename from conf/explorer/lsb_release rename to cdist/conf/explorer/lsb_release index 8266171a..35b5547c 100755 --- a/conf/explorer/lsb_release +++ b/cdist/conf/explorer/lsb_release @@ -25,7 +25,7 @@ case "$($__explorer/os)" in (. /etc/openwrt_release && echo "$DISTRIB_RELEASE") ;; *) - lsb_release=$(which lsb_release 2>/dev/null) + lsb_release=$(command -v lsb_release) if [ -x "$lsb_release" ]; then $lsb_release --short --release fi diff --git a/conf/explorer/machine b/cdist/conf/explorer/machine similarity index 94% rename from conf/explorer/machine rename to cdist/conf/explorer/machine index 25fc76a9..bb6e0beb 100755 --- a/conf/explorer/machine +++ b/cdist/conf/explorer/machine @@ -22,4 +22,6 @@ # # -uname -m +if command -v uname; then + uname -m +fi diff --git a/conf/explorer/os b/cdist/conf/explorer/os similarity index 100% rename from conf/explorer/os rename to cdist/conf/explorer/os diff --git a/conf/explorer/os_version b/cdist/conf/explorer/os_version similarity index 100% rename from conf/explorer/os_version rename to cdist/conf/explorer/os_version diff --git a/conf/explorer/runlevel b/cdist/conf/explorer/runlevel similarity index 95% rename from conf/explorer/runlevel rename to cdist/conf/explorer/runlevel index 7cdd81ef..02d3a245 100755 --- a/conf/explorer/runlevel +++ b/cdist/conf/explorer/runlevel @@ -20,7 +20,7 @@ # set +e -executable=$(which runlevel 2>/dev/null) +executable=$(command -v runlevel) if [ -x "$executable" ]; then "$executable" | awk '{ print $2 }' fi diff --git a/cdist/conf/manifest/sample-from-distribution b/cdist/conf/manifest/sample-from-distribution new file mode 100755 index 00000000..56d52cf5 --- /dev/null +++ b/cdist/conf/manifest/sample-from-distribution @@ -0,0 +1,62 @@ +## # +## # Sample manifest from cdist distribution +## # +## +## # Every machine becomes a marker, so sysadmins know that automatic +## # configurations are happening +## __file /etc/cdist-configured +## __cdistmarker +## +## case "$__target_host" in +## # Everybody has this +## localhost) +## require="__file/etc/cdist-configured" __link /tmp/cdist-testfile \ +## --source /etc/cdist-configured --type symbolic +## require="__directory/tmp/cdist-test-dir" __file /tmp/cdist-test-dir/test-file \ +## --mode 0750 --owner nobody --group root +## __directory /tmp/cdist-test-dir --mode 4777 +## +## require="__file/etc/cdist-configured __link/tmp/cdist-testfile" \ +## __file /tmp/cdist-another-testfile +## +## ;; +## +## # +## # Use an alias in /etc/hosts for localhost to use these hosts: +## # +## # 127.0.0.1 localhost.localdomain localhost cdist-archlinux +## # +## cdist-archlinux) +## # This is the specific package type for pacman +## __package_pacman zsh --state installed +## +## # The __package type autoselect the right type based on the os +## __package vim --state installed +## +## # If the type is a singleton, it does not take an object id +## __issue +## ;; +## # This is how it would look like on gentoo +## cdist-gentoo) +## # Same stuff for gentoo +## __package tree --state installed +## ;; +## +## cdist-debian) +## __package_apt atop --state installed +## __package apache2 --state removed +## ;; +## +## cdist-redhat) +## __issue +## __motd +## ;; +## +## # Real machines may be used with their hostname or fqdn, +## # depending on how you call cdist +## # ... +## # ;; +## # machine.example.org) +## # ... +## # ;; +## esac diff --git a/conf/type/__apt_ppa/explorer/state b/cdist/conf/type/__apt_ppa/explorer/state similarity index 87% rename from conf/type/__apt_ppa/explorer/state rename to cdist/conf/type/__apt_ppa/explorer/state index 8a5638b2..2bb4f65a 100755 --- a/conf/type/__apt_ppa/explorer/state +++ b/cdist/conf/type/__apt_ppa/explorer/state @@ -26,8 +26,8 @@ name="$__object_id" . /etc/lsb-release repo_name="${name#ppa:}" -repo_file_name="$(echo "$repo_name" | sed "s:\/:\-:")-${DISTRIB_CODENAME}.list" +repo_file_name="$(echo "$repo_name" | sed -e "s|[/:]|-|" -e "s|\.|_|")-${DISTRIB_CODENAME}.list" [ -s "/etc/apt/sources.list.d/${repo_file_name}" ] \ - && echo enabled || echo disabled + && echo present || echo absent diff --git a/conf/type/__apt_ppa/files/remove-apt-repository b/cdist/conf/type/__apt_ppa/files/remove-apt-repository similarity index 100% rename from conf/type/__apt_ppa/files/remove-apt-repository rename to cdist/conf/type/__apt_ppa/files/remove-apt-repository diff --git a/conf/type/__apt_ppa/gencode-remote b/cdist/conf/type/__apt_ppa/gencode-remote similarity index 78% rename from conf/type/__apt_ppa/gencode-remote rename to cdist/conf/type/__apt_ppa/gencode-remote index 0e7fe163..0ea8011c 100755 --- a/conf/type/__apt_ppa/gencode-remote +++ b/cdist/conf/type/__apt_ppa/gencode-remote @@ -22,14 +22,16 @@ name="$__object_id" state_should="$(cat "$__object/parameter/state")" state_is="$(cat "$__object/explorer/state")" -if [ "$state_should" != "$state_is" ]; then - case "$state_should" in - enabled) - echo add-apt-repository \"$name\" - ;; - disabled) - echo remove-apt-repository \"$name\" - ;; - esac +if [ "$state_should" == "$state_is" ]; then + # Nothing to do, move along + exit 0 fi +case "$state_should" in + present) + echo add-apt-repository \"$name\" + ;; + absent) + echo remove-apt-repository \"$name\" + ;; +esac diff --git a/conf/type/__apt_ppa/man.text b/cdist/conf/type/__apt_ppa/man.text similarity index 81% rename from conf/type/__apt_ppa/man.text rename to cdist/conf/type/__apt_ppa/man.text index f986eb2d..6a5990d5 100644 --- a/conf/type/__apt_ppa/man.text +++ b/cdist/conf/type/__apt_ppa/man.text @@ -16,7 +16,7 @@ This cdist type allows manage ubuntu ppa repositories. REQUIRED PARAMETERS ------------------- state:: - The state the ppa should be in, either "enabled" or "disabled". + The state the ppa should be in, either "present" or "absent". OPTIONAL PARAMETERS @@ -29,10 +29,10 @@ EXAMPLES -------------------------------------------------------------------------------- # Enable a ppa repository -__apt_ppa ppa:sans-intern/missing-bits --state enabled +__apt_ppa ppa:sans-intern/missing-bits --state present # Disable a ppa repository -__apt_ppa ppa:sans-intern/missing-bits --state disabled +__apt_ppa ppa:sans-intern/missing-bits --state absent -------------------------------------------------------------------------------- diff --git a/conf/type/__apt_ppa/manifest b/cdist/conf/type/__apt_ppa/manifest similarity index 94% rename from conf/type/__apt_ppa/manifest rename to cdist/conf/type/__apt_ppa/manifest index 04c66ce0..e7ad0c26 100755 --- a/conf/type/__apt_ppa/manifest +++ b/cdist/conf/type/__apt_ppa/manifest @@ -20,7 +20,7 @@ name="$__object_id" -__package python-software-properties --state installed +__package python-software-properties --state present require="__package/python-software-properties" \ __file /usr/local/bin/remove-apt-repository \ diff --git a/conf/type/__apt_ppa/parameter/required b/cdist/conf/type/__apt_ppa/parameter/required similarity index 100% rename from conf/type/__apt_ppa/parameter/required rename to cdist/conf/type/__apt_ppa/parameter/required diff --git a/conf/type/__apt_update_index/gencode-remote b/cdist/conf/type/__apt_update_index/gencode-remote similarity index 91% rename from conf/type/__apt_update_index/gencode-remote rename to cdist/conf/type/__apt_update_index/gencode-remote index e66ff7a3..61ce11a9 100755 --- a/conf/type/__apt_update_index/gencode-remote +++ b/cdist/conf/type/__apt_update_index/gencode-remote @@ -20,7 +20,7 @@ # run 'apt-get update' if anything in /etc/apt is newer then /var/lib/apt/lists cat << DONE -if find /etc/apt -cnewer /var/lib/apt/lists | grep . > /dev/null; then +if find /etc/apt -mindepth 1 -cnewer /var/lib/apt/lists | grep . > /dev/null; then apt-get update || apt-get update fi DONE diff --git a/conf/type/__apt_update_index/man.text b/cdist/conf/type/__apt_update_index/man.text similarity index 100% rename from conf/type/__apt_update_index/man.text rename to cdist/conf/type/__apt_update_index/man.text diff --git a/conf/type/__apt_update_index/singleton b/cdist/conf/type/__apt_update_index/singleton similarity index 100% rename from conf/type/__apt_update_index/singleton rename to cdist/conf/type/__apt_update_index/singleton diff --git a/conf/type/__cdistmarker/gencode-remote b/cdist/conf/type/__cdistmarker/gencode-remote similarity index 100% rename from conf/type/__cdistmarker/gencode-remote rename to cdist/conf/type/__cdistmarker/gencode-remote diff --git a/conf/type/__cdistmarker/man.text b/cdist/conf/type/__cdistmarker/man.text similarity index 96% rename from conf/type/__cdistmarker/man.text rename to cdist/conf/type/__cdistmarker/man.text index 360598d8..ca5611a7 100644 --- a/conf/type/__cdistmarker/man.text +++ b/cdist/conf/type/__cdistmarker/man.text @@ -1,6 +1,6 @@ cdist-type__cdistmarker(7) ========================== -Daniel Maher +Daniel Maher NAME diff --git a/conf/type/__cdistmarker/parameter/optional b/cdist/conf/type/__cdistmarker/parameter/optional similarity index 100% rename from conf/type/__cdistmarker/parameter/optional rename to cdist/conf/type/__cdistmarker/parameter/optional diff --git a/conf/type/__autofs_master/singleton b/cdist/conf/type/__cdistmarker/singleton similarity index 100% rename from conf/type/__autofs_master/singleton rename to cdist/conf/type/__cdistmarker/singleton diff --git a/conf/type/__cron/explorer/entry b/cdist/conf/type/__cron/explorer/entry similarity index 92% rename from conf/type/__cron/explorer/entry rename to cdist/conf/type/__cron/explorer/entry index 362c96fe..1b4bec42 100755 --- a/conf/type/__cron/explorer/entry +++ b/cdist/conf/type/__cron/explorer/entry @@ -24,7 +24,7 @@ user="$(cat "$__object/parameter/user")" prefix="#cdist:__cron/$name" suffix="#/cdist:__cron/$name" -crontab -u $user -l | awk -v prefix="$prefix" -v suffix="$suffix" ' +crontab -u $user -l 2>/dev/null | awk -v prefix="$prefix" -v suffix="$suffix" ' { if (index($0,prefix)) { triggered=1 diff --git a/conf/type/__cron/gencode-remote b/cdist/conf/type/__cron/gencode-remote similarity index 86% rename from conf/type/__cron/gencode-remote rename to cdist/conf/type/__cron/gencode-remote index 947c75ae..37e0dc15 100755 --- a/conf/type/__cron/gencode-remote +++ b/cdist/conf/type/__cron/gencode-remote @@ -18,6 +18,7 @@ # along with cdist. If not, see . # +os="$(cat "$__global/explorer/os")" user="$(cat "$__object/parameter/user")" state_should="$(cat "$__object/parameter/state")" state_is=$(diff -q "$__object/parameter/entry" "$__object/explorer/entry" \ @@ -25,14 +26,21 @@ state_is=$(diff -q "$__object/parameter/entry" "$__object/explorer/entry" \ || echo absent ) +# FreeBSD mktemp doesn't allow execution without at least one param +if [ "$os" = "freebsd" ]; then + mktemp="mktemp -t tmp" +else + mktemp="mktemp" +fi + if [ "$state_is" != "$state_should" ]; then case "$state_should" in present) cat << DONE -tmp=\$(mktemp) +tmp=\$($mktemp) crontab -u $user -l > \$tmp cat >> \$tmp << EOC -$(cat "$__object/parameter/entry")" +$(cat "$__object/parameter/entry") EOC crontab -u $user \$tmp rm \$tmp diff --git a/conf/type/__cron/man.text b/cdist/conf/type/__cron/man.text similarity index 100% rename from conf/type/__cron/man.text rename to cdist/conf/type/__cron/man.text diff --git a/conf/type/__cron/manifest b/cdist/conf/type/__cron/manifest similarity index 100% rename from conf/type/__cron/manifest rename to cdist/conf/type/__cron/manifest diff --git a/conf/type/__cron/parameter/optional b/cdist/conf/type/__cron/parameter/optional similarity index 100% rename from conf/type/__cron/parameter/optional rename to cdist/conf/type/__cron/parameter/optional diff --git a/conf/type/__cron/parameter/required b/cdist/conf/type/__cron/parameter/required similarity index 100% rename from conf/type/__cron/parameter/required rename to cdist/conf/type/__cron/parameter/required diff --git a/conf/type/__debconf_set_selections/gencode-remote b/cdist/conf/type/__debconf_set_selections/gencode-remote similarity index 100% rename from conf/type/__debconf_set_selections/gencode-remote rename to cdist/conf/type/__debconf_set_selections/gencode-remote diff --git a/conf/type/__debconf_set_selections/man.text b/cdist/conf/type/__debconf_set_selections/man.text similarity index 100% rename from conf/type/__debconf_set_selections/man.text rename to cdist/conf/type/__debconf_set_selections/man.text diff --git a/conf/type/__debconf_set_selections/parameter/required b/cdist/conf/type/__debconf_set_selections/parameter/required similarity index 100% rename from conf/type/__debconf_set_selections/parameter/required rename to cdist/conf/type/__debconf_set_selections/parameter/required diff --git a/conf/type/__file/explorer/exists b/cdist/conf/type/__directory/explorer/state similarity index 96% rename from conf/type/__file/explorer/exists rename to cdist/conf/type/__directory/explorer/state index f8b85671..9bdd9024 100755 --- a/conf/type/__file/explorer/exists +++ b/cdist/conf/type/__directory/explorer/state @@ -24,7 +24,7 @@ destination="/$__object_id" if [ -e "$destination" ]; then - echo yes + echo present else - echo no + echo absent fi diff --git a/cdist/conf/type/__directory/gencode-remote b/cdist/conf/type/__directory/gencode-remote new file mode 100755 index 00000000..21f4c5b6 --- /dev/null +++ b/cdist/conf/type/__directory/gencode-remote @@ -0,0 +1,59 @@ +#!/bin/sh +# +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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_should="present" +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" +state_is="$(cat "$__object/explorer/state")" +[ "$state_should" = "$state_is" ] && exit 0 + +destination="/$__object_id" + +mkdiropt="" +[ -f "$__object/parameter/parents" ] && mkdiropt="-p" +recursive="" +[ -f "$__object/parameter/recursive" ] && recursive="-R" + +case "$state_should" in + present) + echo mkdir $mkdiropt \"$destination\" + + # Mode settings + if [ -f "$__object/parameter/mode" ]; then + echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\" + fi + + # Group + if [ -f "$__object/parameter/group" ]; then + echo chgrp $recursive \"$(cat "$__object/parameter/group")\" \"$destination\" + fi + + # Owner + if [ -f "$__object/parameter/owner" ]; then + echo chown $recursive \"$(cat "$__object/parameter/owner")\" \"$destination\" + fi + ;; + absent) + echo rm -rf \"$destination\" + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/conf/type/__directory/man.text b/cdist/conf/type/__directory/man.text similarity index 80% rename from conf/type/__directory/man.text rename to cdist/conf/type/__directory/man.text index afba0875..1f4def7d 100644 --- a/conf/type/__directory/man.text +++ b/cdist/conf/type/__directory/man.text @@ -32,13 +32,15 @@ mode:: owner:: User to chown to. + +BOOLEAN PARAMETERS +------------------ parents:: - Whether to create parents as well (mkdir -p behaviour). Must be yes or no. + Whether to create parents as well (mkdir -p behaviour) recursive:: If supplied the chgrp and chown call will run recursively. This does *not* influence the behaviour of chmod. - Must be yes or no. EXAMPLES @@ -55,13 +57,18 @@ __directory /tmp/foobar --state absent __directory /etc --owner root --group root --mode 0755 # Create nfs service directory, including parents -__directory /home/services/nfs --parents yes +__directory /home/services/nfs --parents # Change permissions recursively -__directory /home/services --recursive yes --owner root --group root +__directory /home/services --recursive --owner root --group root # Setup a temp directory __directory /local --mode 1777 + +# Take it all +__directory /home/services/kvm --recursive --parents \ + --owner root --group root --mode 0755 --state present + -------------------------------------------------------------------------------- diff --git a/cdist/conf/type/__directory/parameter/boolean b/cdist/conf/type/__directory/parameter/boolean new file mode 100644 index 00000000..357c5e81 --- /dev/null +++ b/cdist/conf/type/__directory/parameter/boolean @@ -0,0 +1,2 @@ +parents +recursive diff --git a/conf/type/__directory/parameter/optional b/cdist/conf/type/__directory/parameter/optional similarity index 56% rename from conf/type/__directory/parameter/optional rename to cdist/conf/type/__directory/parameter/optional index 27f9d76a..08798bc5 100644 --- a/conf/type/__directory/parameter/optional +++ b/cdist/conf/type/__directory/parameter/optional @@ -2,5 +2,3 @@ state group mode owner -parents -recursive diff --git a/conf/type/__file/explorer/cksum b/cdist/conf/type/__file/explorer/cksum similarity index 78% rename from conf/type/__file/explorer/cksum rename to cdist/conf/type/__file/explorer/cksum index dcad99ba..335e4e7a 100755 --- a/conf/type/__file/explorer/cksum +++ b/cdist/conf/type/__file/explorer/cksum @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -24,11 +24,11 @@ destination="/$__object_id" if [ -e "$destination" ]; then - if [ -f "$destination" ]; then - cksum < "$destination" - else - echo "NO REGULAR FILE" - fi + if [ -f "$destination" ]; then + cksum < "$destination" + else + echo "NO REGULAR FILE" + fi else - echo "NO FILE FOUND, NO CHECKSUM CALCULATED." + echo "NO FILE FOUND, NO CHECKSUM CALCULATED." fi diff --git a/cdist/conf/type/__file/explorer/exists b/cdist/conf/type/__file/explorer/exists new file mode 100755 index 00000000..c319cb5d --- /dev/null +++ b/cdist/conf/type/__file/explorer/exists @@ -0,0 +1,30 @@ +#!/bin/sh +# +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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 . +# +# +# Check whether file exists or not +# + +destination="/$__object_id" + +if [ -e "$destination" ]; then + echo yes +else + echo no +fi diff --git a/conf/type/__file/gencode-local b/cdist/conf/type/__file/gencode-local similarity index 73% rename from conf/type/__file/gencode-local rename to cdist/conf/type/__file/gencode-local index d9839a19..087011c4 100755 --- a/conf/type/__file/gencode-local +++ b/cdist/conf/type/__file/gencode-local @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -22,11 +22,18 @@ # destination="/$__object_id" -state_should="$(cat "$__object/parameter/state")" +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" +exists="$(cat "$__object/explorer/exists")" -if [ "$state_should" = "present" ]; then +[ "$state_should" = "exists" -a "$exists" = "yes" ] && exit 0 # nothing to do + +if [ "$state_should" = "present" -o "$state_should" = "exists" ]; then if [ -f "$__object/parameter/source" ]; then source="$(cat "$__object/parameter/source")" + if [ "$source" = "-" ]; then + source="$__object/stdin" + fi if [ -f "$source" ]; then local_cksum="$(cksum < "$source")" diff --git a/conf/type/__file/gencode-remote b/cdist/conf/type/__file/gencode-remote similarity index 90% rename from conf/type/__file/gencode-remote rename to cdist/conf/type/__file/gencode-remote index 2b4c7e45..8b03e919 100755 --- a/conf/type/__file/gencode-remote +++ b/cdist/conf/type/__file/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -22,11 +22,12 @@ # destination="/$__object_id" -state_should="$(cat "$__object/parameter/state")" +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" exists="$(cat "$__object/explorer/exists")" case "$state_should" in - present) + present|exists) # No source? Create empty file if [ ! -f "$__object/parameter/source" ]; then if [ "$exists" = "no" ]; then diff --git a/conf/type/__file/man.text b/cdist/conf/type/__file/man.text similarity index 69% rename from conf/type/__file/man.text rename to cdist/conf/type/__file/man.text index 5e91599f..1c61fd51 100644 --- a/conf/type/__file/man.text +++ b/cdist/conf/type/__file/man.text @@ -21,7 +21,11 @@ None. OPTIONAL PARAMETERS ------------------- state:: - 'present' or 'absent', defaults to 'present' + '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. @@ -35,6 +39,7 @@ owner:: 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. EXAMPLES @@ -55,6 +60,17 @@ __file /etc/issue --source "$__type/files/archlinux" --state present __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 +__file /home/frodo/.bashrc --source "/etc/skel/.bashrc" \ + --state exists \ + --owner frodo --mode 0600 + +# Take file content from stdin +__file /tmp/whatever --owner root --group root --mode 644 --source - << DONE +Here goes the content for /tmp/whatever +DONE + -------------------------------------------------------------------------------- diff --git a/conf/type/__file/parameter/optional b/cdist/conf/type/__file/parameter/optional similarity index 100% rename from conf/type/__file/parameter/optional rename to cdist/conf/type/__file/parameter/optional diff --git a/conf/type/__group/TODO b/cdist/conf/type/__group/TODO similarity index 100% rename from conf/type/__group/TODO rename to cdist/conf/type/__group/TODO diff --git a/conf/type/__group/explorer/group b/cdist/conf/type/__group/explorer/group similarity index 100% rename from conf/type/__group/explorer/group rename to cdist/conf/type/__group/explorer/group diff --git a/conf/type/__group/explorer/gshadow b/cdist/conf/type/__group/explorer/gshadow similarity index 90% rename from conf/type/__group/explorer/gshadow rename to cdist/conf/type/__group/explorer/gshadow index e3c2dd6c..5ab4ed80 100755 --- a/conf/type/__group/explorer/gshadow +++ b/cdist/conf/type/__group/explorer/gshadow @@ -23,6 +23,12 @@ name=$__object_id os_version="$($__explorer/os_version)" +os="$($__explorer/os)" + +if [ "$os" = "freebsd" ]; then + echo "FreeBSD does not have getent gshadow" + exit 0 +fi case "$os_version" in "Red Hat Enterprise Linux Server release "[45]*|"CentOS release "[45]*) diff --git a/conf/type/__group/gencode-remote b/cdist/conf/type/__group/gencode-remote similarity index 64% rename from conf/type/__group/gencode-remote rename to cdist/conf/type/__group/gencode-remote index 2b4774ab..bb6797c2 100755 --- a/conf/type/__group/gencode-remote +++ b/cdist/conf/type/__group/gencode-remote @@ -24,6 +24,7 @@ name="$__object_id" os_version="$(cat "$__global/explorer/os_version")" +os="$(cat "$__global/explorer/os")" cd "$__object/parameter" if grep -q "^${name}:" "$__object/explorer/group"; then @@ -35,7 +36,10 @@ if grep -q "^${name}:" "$__object/explorer/group"; then case "$property" in password) - current_value="$(awk -F: '{ print $2 }' < "$__object/explorer/gshadow")" + if [ "$os" = "freebsd" ]; then + echo "group/$name: FreeBSD doesn't support password modification" >&2 + exit 1 + fi case "$os_version" in "Red Hat Enterprise Linux Server release "[45]*|"CentOS release "[45]*) # TODO: Use gpasswd? Need to fix gshadow explorer first. @@ -43,6 +47,7 @@ if grep -q "^${name}:" "$__object/explorer/group"; then exit 1 ;; esac + current_value="$(awk -F: '{ print $2 }' < "$__object/explorer/gshadow")" ;; gid) # set to -g to support older redhat/centos @@ -57,15 +62,48 @@ if grep -q "^${name}:" "$__object/explorer/group"; then done if [ $# -gt 0 ]; then - echo groupmod "$@" "$name" - else - true + case $os in + freebsd) + echo pw group mod "$@" "$name" + ;; + *) + echo groupmod "$@" "$name" + ;; + esac fi else for property in $(ls .); do new_value="$(cat "$property")" - set -- "$@" "--$property" \"$new_value\" + if [ "$os" = "freebsd" ]; then + case $property in + gid) + proparg="-g" + ;; + password) + echo "group/$name: FreeBSD doesn't support password setting" >&2 + exit 1 + ;; + *) + # The type has been updated to support more properties than it knows how to handle for FreeBSD + # tell the user about this. + echo "Currently unknown property: $property" >&2 + exit 1 + ;; + esac + else + proparg="--$property" + fi + + set -- "$@" "$proparg" \"$new_value\" done - echo groupadd "$@" "$name" + case $os in + freebsd) + echo pw group add "$@" "$name" + ;; + *) + echo groupadd "$@" "$name" + ;; + esac fi + diff --git a/conf/type/__group/man.text b/cdist/conf/type/__group/man.text similarity index 100% rename from conf/type/__group/man.text rename to cdist/conf/type/__group/man.text diff --git a/conf/type/__group/parameter/optional b/cdist/conf/type/__group/parameter/optional similarity index 100% rename from conf/type/__group/parameter/optional rename to cdist/conf/type/__group/parameter/optional diff --git a/conf/type/__issue/files/archlinux b/cdist/conf/type/__issue/files/archlinux similarity index 100% rename from conf/type/__issue/files/archlinux rename to cdist/conf/type/__issue/files/archlinux diff --git a/conf/type/__issue/files/default b/cdist/conf/type/__issue/files/default similarity index 100% rename from conf/type/__issue/files/default rename to cdist/conf/type/__issue/files/default diff --git a/conf/type/__issue/files/redhat b/cdist/conf/type/__issue/files/redhat similarity index 100% rename from conf/type/__issue/files/redhat rename to cdist/conf/type/__issue/files/redhat diff --git a/conf/type/__issue/man.text b/cdist/conf/type/__issue/man.text similarity index 100% rename from conf/type/__issue/man.text rename to cdist/conf/type/__issue/man.text diff --git a/conf/type/__issue/manifest b/cdist/conf/type/__issue/manifest similarity index 74% rename from conf/type/__issue/manifest rename to cdist/conf/type/__issue/manifest index eff6b808..d2720f2d 100755 --- a/conf/type/__issue/manifest +++ b/cdist/conf/type/__issue/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -24,17 +24,16 @@ destination=/etc/issue os="$(cat "$__global/explorer/os")" if [ -f "$__object/parameter/source" ]; then - source="$(cat "$__object/parameter/source")" - echo using $source + source="$(cat "$__object/parameter/source")" else - case "$os" in - archlinux|redhat) - source="$__type/files/$os" - ;; - *) - source="$__type/files/default" - ;; - esac + case "$os" in + archlinux|redhat) + source="$__type/files/$os" + ;; + *) + source="$__type/files/default" + ;; + esac fi __file "$destination" --source "$source" diff --git a/conf/type/__issue/parameter/optional b/cdist/conf/type/__issue/parameter/optional similarity index 100% rename from conf/type/__issue/parameter/optional rename to cdist/conf/type/__issue/parameter/optional diff --git a/conf/type/__cdistmarker/singleton b/cdist/conf/type/__issue/singleton similarity index 100% rename from conf/type/__cdistmarker/singleton rename to cdist/conf/type/__issue/singleton diff --git a/cdist/conf/type/__jail/.gitignore b/cdist/conf/type/__jail/.gitignore new file mode 100644 index 00000000..e0471be4 --- /dev/null +++ b/cdist/conf/type/__jail/.gitignore @@ -0,0 +1 @@ +files/jailbase.tgz diff --git a/cdist/conf/type/__jail/explorer/basepresent b/cdist/conf/type/__jail/explorer/basepresent new file mode 100755 index 00000000..f167a19c --- /dev/null +++ b/cdist/conf/type/__jail/explorer/basepresent @@ -0,0 +1,54 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# See if the jailbase.tgz or $jaildir/base dir exists +# + +# Debug +#exec >&2 +#set -x + +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/name")" +else + jaildir="/usr/jail" +fi + +name="base:jailbase.tgz" +out="" + +save_IFS="$IFS" +IFS=":" +for cur in $name; do + if [ -e "${jaildir}/$cur" ]; then + out="${out}:${cur}" + fi +done +IFS="$save_IFS" + +if [ -z "$out" ]; then + echo "NONE" +else + echo "${out}" +fi + +# Debug +#set +x + diff --git a/conf/type/__addifnosuchline/gencode-remote b/cdist/conf/type/__jail/explorer/present similarity index 62% rename from conf/type/__addifnosuchline/gencode-remote rename to cdist/conf/type/__jail/explorer/present index f97789ae..2ba3b2af 100755 --- a/conf/type/__addifnosuchline/gencode-remote +++ b/cdist/conf/type/__jail/explorer/present @@ -1,6 +1,6 @@ #!/bin/sh # -# 2010-2011 Daniel Roth (dani-cdist@d-roth.li) +# 2012 Jake Guffey (jake.guffey at eprotex.com) # # This file is part of cdist. # @@ -18,16 +18,26 @@ # along with cdist. If not, see . # # +# See if the requested jail exists +# -if [ -f "$__object/parameter/file" ]; then - file=$(cat "$__object/parameter/file") +# Debug +#exec >&2 +#set -x + +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" else - file="/$__object_id" + name=$__object_id fi -result=$(cat "$__object/explorer/findline") - -if [ "$result" = "NOTFOUND" ]; then - line=$(cat "$__object/parameter/line") - echo "echo $line >> $file" +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/name")" +else + jaildir="/usr/jail" fi + +[ -d "${jaildir}/$name" ] && echo "EXISTS" || echo "NOTEXIST" + +#set +x + diff --git a/cdist/conf/type/__jail/explorer/status b/cdist/conf/type/__jail/explorer/status new file mode 100755 index 00000000..fe81eaf7 --- /dev/null +++ b/cdist/conf/type/__jail/explorer/status @@ -0,0 +1,52 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# See if the requested jail is started +# + +# Debug +#exec >&2 +#set -x + +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name="$__object_id" +fi + +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/name")" +else + jaildir="/usr/jail" +fi +# backslash-escaped $jaildir +sjaildir="$(echo ${jaildir} | sed 's#/#\\/#g')" + +jls_output="$(jls | grep "[ ^I]${sjaildir}\/${name}\$")" || true + +if [ -n "${jls_output}" ]; then + echo "STARTED" +else + echo "NOTSTART" +fi + +# Debug +#set +x + diff --git a/cdist/conf/type/__jail/gencode-local b/cdist/conf/type/__jail/gencode-local new file mode 100755 index 00000000..075a6ef1 --- /dev/null +++ b/cdist/conf/type/__jail/gencode-local @@ -0,0 +1,53 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# The __jail type creates, configures, and deletes FreeBSD jails for use as +# virtual machines. +# + +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/name")" +else + jaildir="/usr/jail" +fi + +if [ -f "$__object/parameter/jailbase" ]; then + jailbase="$(cat "$__object/parameter/jailbase")" +else + jailbase="" +fi + +state="$(cat "$__object/parameter/state")" + +if [ "$state" = "present" ] && [ -z "$jailbase" ]; then + exec >&2 + echo "jailbase is a REQUIRED parameter when state=present!" + exit 1 +fi + +remotebase="${jaildir}/jailbase.tgz" +basepresent="$(cat "$__object/explorer/basepresent")" + +if [ "$state" = "present" ]; then + if [ "$basepresent" = "NONE" ]; then + echo "$__remote_copy" "${jailbase}" "$__target_host:${remotebase}" + fi # basepresent=NONE +fi # state=present + diff --git a/cdist/conf/type/__jail/gencode-remote b/cdist/conf/type/__jail/gencode-remote new file mode 100755 index 00000000..4aff6509 --- /dev/null +++ b/cdist/conf/type/__jail/gencode-remote @@ -0,0 +1,363 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# The __jail type creates, configures, and deletes FreeBSD jails for use as +# virtual machines. +# + +# Debug +#exec >&2 +#set -x + +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name="$__object_id" +fi + +state="$(cat "$__object/parameter/state")" + +if [ -f "$__object/parameter/started" ]; then + started="$(cat "$__object/parameter/started")" +else + if [ ! "$state" = "present" ]; then + started="false" + else + started="true" + fi +fi + +if [ -f "$__object/parameter/ip" ]; then + ip="$(cat "$__object/parameter/ip")" +else +# IP is an optional param when $state=absent, but +# when $state=present, it's required. Enforce this. + if [ "$state" = "present" ]; then + exec >&2 + echo "If --state is 'present,' --ip must be given\!" + exit 1 + fi +fi + +if [ -f "$__object/parameter/hostname" ]; then + hostname="$(cat "$__object/parameter/hostname")" +else + hostname="$name" +fi + +if [ -f "$__object/parameter/interface" ]; then + interface="$(cat "$__object/parameter/interface")" +fi + +if [ -f "$__object/parameter/devfs-enable" ]; then + devfsenable="$(cat "$__object/parameter/devfs-enable")" +else + devfsenable="true" +fi + +if [ -f "$__object/parameter/devfs-ruleset" ]; then + devfsruleset="$(cat "$__object/parameter/devfs-ruleset")" +else + devfsruleset="jailrules" +fi + +# devfs_ruleset being defined without devfs_enable being true +# is pointless. Treat this as an error. +if [ -n "$devfsruleset" -a "$devfsenable" = "false" ]; then + exec >&2 + echo "Can't have --devfs-ruleset defined without --devfs-enable true." + exit 1 +fi + +if [ -f "$__object/parameter/onboot" ]; then + onboot="$(cat "$__object/parameter/onboot")" +fi + +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/name")" +else + jaildir="/usr/jail" +fi + +present="$(cat "$__object/explorer/present")" +status="$(cat "$__object/explorer/status")" + +# Defining a jail as absent and started at the same time +# makes no sense. Treat this as an error. +if [ "$started" = "true" -a "$state" = "absent" ]; then + exec >&2 + echo "Can't have --state absent and --started true together\!" + exit 1 +fi + +stopJail() { +# Check $status before issuing command + if [ "$status" = "STARTED" ]; then + echo "/etc/rc.d/jail stop ${name}" + fi +} + +startJail() { +# Check $status before issuing command + if [ "$status" = "NOTSTART" ]; then + echo "/etc/rc.d/jail start ${name}" + fi +} + +deleteJail() { +# Unmount the jail's mountpoints if necessary + cat <=1 rw mount is mounted still + for DIR in "${output}"; do + umount -F "/etc/fstab.${name}" "\$(echo "${DIR}" | awk '{print $3}')" + done + fi + output="\$(mount | grep "\/${name} (")" || true + if [ -n "\${output}" ]; then # ro mount is mounted still + umount -F "/etc/fstab.${name}" "\$(echo "${output}" | awk '{print $3}')" + fi +EOF +# Remove the jail's rw mountpoints + echo "rm -rf \"${jaildir}/rw/${name}\"" +# Remove the jail directory + echo "rm -rf \"${jaildir}/${name}\"" +# Remove the jail's fstab + echo "rm -f \"/etc/fstab.${name}\"" +# Remove jail_$name_* lines from rc.conf + cat </etc/fstab.${name} <>/etc/rc.conf + elif [ ! "\$(echo \$jail_enable | tr '[a-z]' '[A-Z]')" = "YES" ]; then # jail_enable="NO" + sed -i '.bak' 's/^jail_enable=.*$/jail_enable="YES"/g' /etc/rc.conf # fix this -^ + rm -f /etc/rc.conf.bak + fi + cat >>/etc/rc.conf <>/etc/rc.conf <>/etc/rc.conf <>/etc/rc.conf <&- >&- + # add default ruleset + cat >>/etc/devfs.rules <"${jaildir}/rw/${name}/etc/rc.conf" +echo sshd_enable=\"YES\" >>"${jaildir}/rw/${name}/etc/rc.conf" +echo sendmail_enable=\"NONE\" >>"${jaildir}/rw/${name}/etc/rc.conf" +echo syslogd_enable=\"YES\" >>"${jaildir}/rw/${name}/etc/rc.conf" +echo syslogd_flags=\"-ss\" >>"${jaildir}/rw/${name}/etc/rc.conf" + +EOF +# Configure SSHd's listening address +cat < + + +NAME +---- +cdist-type__jail - Manage FreeBSD jails + + +DESCRIPTION +----------- +This type is used on FreeBSD to manage jails. + + +REQUIRED PARAMETERS +------------------- +state:: + Either "present" or "absent." + +jailbase:: + The location of the .tgz archive containing the base fs for your jails. + + +OPTIONAL PARAMETERS +------------------- +name:: + The name of the jail. Default is to use the object_id as the jail name. + +started:: + Either "true" or "false." Defaults to true. + +ip:: + The ifconfig style IP/netmask combination to use for the jail guest. If + the state parameter is "present," this parameter is required. + +hostname:: + The FQDN to use for the jail guest. Defaults to the name parameter. + +interface:: + The name of the physical interface on the jail server to bind the jail to. + Defaults to the first interface found in the output of ifconfig -l. + +devfs-enable:: + Whether to allow devfs mounting within the jail. Must be "true" or "false." + Defaults to true. + +devfs-ruleset:: + The name of the devfs ruleset to associate with the jail. Defaults to + "jailrules." This ruleset must be copied to the server via another type. + To use this option, devfs-enable must be "true." + +onboot:: + Whether to add the jail to rc.conf's jail_list variable. Must be either + "true" or "false." Defaults to false. + +jaildir:: + The location on the remote server to use for hosting jail filesystems. + Defaults to /usr/jail. + + +CAVEATS +------- +This type does not currently support modification of jail options. If, for +example a jail needs to have its IP address or netmask changed, the jail must +be removed then re-added with the correct IP address/netmask or the appropriate +line (jail__ip="...") modified within rc.conf through some alternate +means. + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Create a jail called www +__jail www --state present --ip "192.168.1.2" --jailbase /my/jail/base.tgz + +# Remove the jail called www +__jail www --state absent --jailbase /my/jail/base.tgz + +# Ensure that the jail called www is started +__jail www --state present --started true \ + --ip "192.168.1.2 netmask 255.255.255.0" \ + --jailbase /my/jail/base.tgz + +# Use the name variable explicitly +__jail thisjail --state present --name www \ + --ip "192.168.1.2" \ + --jailbase /my/jail/base.tgz + +# Go nuts +__jail lotsofoptions --state present --name testjail --started true \ + --ip "192.168.1.100 netmask 255.255.255.0" \ + --hostname "testjail.example.com" --interface "em0" \ + --onboot yes --jailbase /my/jail/base.tgz --jaildir /jails +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2012 Jake Guffey. 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/__jail/manifest b/cdist/conf/type/__jail/manifest new file mode 100755 index 00000000..0570d62d --- /dev/null +++ b/cdist/conf/type/__jail/manifest @@ -0,0 +1,46 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# The __jail type creates, configures, and deletes FreeBSD jails for use as +# virtual machines. +# + +# Debug +#exec >&2 +#set -x + +# Can only be used on FreeBSD +os="$(cat "$__global/explorer/os")" +if [ ! "$os" = "freebsd" ]; then + echo "__jail can only be used on FreeBSD targets!" >&2 + exit 1 +fi + +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/name")" +else + jaildir="/usr/jail" +fi + +__directory ${jaildir} --parents + +# Debug +#set +x + diff --git a/cdist/conf/type/__jail/parameter/optional b/cdist/conf/type/__jail/parameter/optional new file mode 100644 index 00000000..1b5f0810 --- /dev/null +++ b/cdist/conf/type/__jail/parameter/optional @@ -0,0 +1,10 @@ +name +started +ip +hostname +interface +devfs-enable +devfs-ruleset +onboot +jaildir +jailbase diff --git a/conf/type/__package/parameter/required b/cdist/conf/type/__jail/parameter/required similarity index 100% rename from conf/type/__package/parameter/required rename to cdist/conf/type/__jail/parameter/required diff --git a/conf/type/__key_value/explorer/state b/cdist/conf/type/__key_value/explorer/state similarity index 100% rename from conf/type/__key_value/explorer/state rename to cdist/conf/type/__key_value/explorer/state diff --git a/cdist/conf/type/__key_value/gencode-remote b/cdist/conf/type/__key_value/gencode-remote new file mode 100755 index 00000000..5fa24d5b --- /dev/null +++ b/cdist/conf/type/__key_value/gencode-remote @@ -0,0 +1,60 @@ +#!/bin/sh +# +# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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 . +# + +key="$__object_id" +[ -f "$__object/parameter/key" ] && key="$(cat "$__object/parameter/key")" +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" + +file="$(cat "$__object/parameter/file")" +delimiter="$(cat "$__object/parameter/delimiter")" +value="$(cat "$__object/parameter/value")" + +state_is="$(cat "$__object/explorer/state")" + +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + absent) + # remove lines starting with key + echo "sed '/^$key\($delimiter\+\)/d' \"$file\" > \"$file.cdist-tmp\"" + echo "mv \"$file.cdist-tmp\" \"$file\"" + ;; + present) + case "$state_is" in + absent) + # add new key and value + echo "echo \"${key}${delimiter}${value}\" >> \"$file\"" + ;; + wrongvalue) + # change exisiting value + echo "sed \"s|^$key\($delimiter\+\).*|$key\1$value|\" \"$file\" > \"$file.cdist-tmp\"" + echo "mv \"$file.cdist-tmp\" \"$file\"" + ;; + *) + echo "Unknown explorer state: $state_is" >&2 + exit 1 + esac + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 +esac diff --git a/conf/type/__key_value/man.text b/cdist/conf/type/__key_value/man.text similarity index 100% rename from conf/type/__key_value/man.text rename to cdist/conf/type/__key_value/man.text diff --git a/conf/type/__start_on_boot/manifest b/cdist/conf/type/__key_value/manifest similarity index 75% rename from conf/type/__start_on_boot/manifest rename to cdist/conf/type/__key_value/manifest index 6b5e1ca7..8ed9cc9c 100755 --- a/conf/type/__start_on_boot/manifest +++ b/cdist/conf/type/__key_value/manifest @@ -19,6 +19,10 @@ # along with cdist. If not, see . # -# set default: present, if not setup -statefile="$__object/parameter/state" -[ -f "$statefile" ] || echo present > "$statefile" +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" + +if [ "$state_should" = "present" -a ! -f "$__object/parameter/value" ]; then + echo "Missing required parameter 'value'" >&2 + exit 1 +fi diff --git a/conf/type/__key_value/parameter/optional b/cdist/conf/type/__key_value/parameter/optional similarity index 100% rename from conf/type/__key_value/parameter/optional rename to cdist/conf/type/__key_value/parameter/optional diff --git a/conf/type/__key_value/parameter/required b/cdist/conf/type/__key_value/parameter/required similarity index 100% rename from conf/type/__key_value/parameter/required rename to cdist/conf/type/__key_value/parameter/required diff --git a/conf/type/__addifnosuchline/explorer/findline b/cdist/conf/type/__line/explorer/state similarity index 59% rename from conf/type/__addifnosuchline/explorer/findline rename to cdist/conf/type/__line/explorer/state index b45bd6ea..d240bf4d 100755 --- a/conf/type/__addifnosuchline/explorer/findline +++ b/cdist/conf/type/__line/explorer/state @@ -1,7 +1,6 @@ #!/bin/sh # -# 2010-2011 Daniel Roth (dani-cdist@d-roth.li) -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -20,29 +19,22 @@ # # -if [ -f "$__object/parameter/file" ]; then - file=$(cat "$__object/parameter/file") -else - file="/$__object_id" -fi +file="/$__object_id" +[ -f "$__object/parameter/file" ] && file=$(cat "$__object/parameter/file") if [ -f "$__object/parameter/regex" ]; then regex=$(cat "$__object/parameter/regex") else - wrap=$(cat "$__object/parameter/line") - regex="^$wrap\$" + if [ ! -f "$__object/parameter/line" ]; then + echo "Parameter line and regex missing - cannot explore" >&2 + exit 1 + fi + regex="^$(cat "$__object/parameter/line")\$" fi -if [ -f "$file" ]; then - # sh -e is our environment, we know what we do, - # skip error detection for now - set +e - grep -q "$regex" "$file" - if [ $? -eq 1 ]; then - echo "NOTFOUND" - else - echo "FOUND" - fi +# Allow missing file - thus 2>/dev/null +if grep -q "$regex" "$file" 2>/dev/null; then + echo present else - echo "NOTFOUND" + echo absent fi diff --git a/cdist/conf/type/__line/gencode-remote b/cdist/conf/type/__line/gencode-remote new file mode 100755 index 00000000..8ac273e2 --- /dev/null +++ b/cdist/conf/type/__line/gencode-remote @@ -0,0 +1,62 @@ +#!/bin/sh +# +# 2012 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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 . +# +# + +file="/$__object_id" +regex="" +state_should="present" +[ -f "$__object/parameter/file" ] && file=$(cat "$__object/parameter/file") +[ -f "$__object/parameter/regex" ] && regex=$(cat "$__object/parameter/regex") +[ -f "$__object/parameter/state" ] && state_should=$(cat "$__object/parameter/state") +[ -f "$__object/parameter/line" ] && line=$(cat "$__object/parameter/line") + +state_is="$(cat "$__object/explorer/state")" + +[ "$state_should" = "$state_is" ] && exit 0 + +case "$state_should" in + present) + if [ ! "$line" ]; then + echo "Required parameter \"line\" is missing" >&2 + exit 1 + fi + + echo "echo \"$line\" >> $file" + + ;; + absent) + if [ "$regex" -a "$line" ]; then + echo "Mutally exclusive parameters regex and line given for state absent" >&2 + exit 1 + fi + + [ "$line" ] && regex="^$line\$" + + cat << eof +tmp=\$(mktemp) +sed '/$regex/d' "$file" > \$tmp && cat "\$tmp" > "$file" && rm -f "\$tmp" +eof + #echo "echo q | ex -c \"/${line}/d|w|q\" \"${file}\"" + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__line/man.text b/cdist/conf/type/__line/man.text new file mode 100644 index 00000000..e1a5941c --- /dev/null +++ b/cdist/conf/type/__line/man.text @@ -0,0 +1,72 @@ +cdist-type__line(7) +=================== +Nico Schottelius + + +NAME +---- +cdist-type__line - Manage lines in files + + +DESCRIPTION +----------- +This cdist type allows you to add lines and remove lines from files. + + +REQUIRED PARAMETERS +------------------- + +OPTIONAL PARAMETERS +------------------- +state:: + 'present' or 'absent', defaults to 'present' + +line:: + Specifies the line which should be absent or present + + Must be present, if state is present. + Must not be combined with regex, if state is absent. + +regex:: + If state is present, search for this pattern and add + given line, if the given regular expression does not match. + + In case of absent, ensure all lines matching the + regular expression are absent (cannot be combined with + the line parameter, if state is absent). + + If the regular expression contains / (slashes), they need + to be escaped with \ (backslash): / becomes \/. + +file:: + If supplied, use this as the destination file. + Otherwise the object_id is used. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Manage the DAEMONS line in rc.conf +__line daemons --file /etc/rc.conf --line 'DAEMONS=(hwclock !network sshd crond postfix)' + +# Ensure the home mount is present in /etc/fstab - explicitly make it present +__line home-fstab \ + --file /etc/fstab \ + --line 'filer.fs:/vol/home /home nfs defaults 0 0' \ + --state present + +# Removes the line specifiend in "include_www" from the file "lighttpd.conf" +__line legacy_timezone --file /etc/rc.conf --regex 'TIMEZONE=.*' --state absent +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2012 Nico Schottelius. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__addifnosuchline/parameter/optional b/cdist/conf/type/__line/parameter/optional similarity index 50% rename from conf/type/__addifnosuchline/parameter/optional rename to cdist/conf/type/__line/parameter/optional index 7ecfcde9..604a203e 100644 --- a/conf/type/__addifnosuchline/parameter/optional +++ b/cdist/conf/type/__line/parameter/optional @@ -1,2 +1,4 @@ -file +state regex +file +line diff --git a/conf/type/__link/explorer/state b/cdist/conf/type/__link/explorer/state similarity index 100% rename from conf/type/__link/explorer/state rename to cdist/conf/type/__link/explorer/state diff --git a/conf/type/__link/gencode-remote b/cdist/conf/type/__link/gencode-remote similarity index 61% rename from conf/type/__link/gencode-remote rename to cdist/conf/type/__link/gencode-remote index 8d4cc3d5..2975ef69 100755 --- a/conf/type/__link/gencode-remote +++ b/cdist/conf/type/__link/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -27,35 +27,33 @@ type="$(cat "$__object/parameter/type")" source="$(cat "$__object/parameter/source")" case "$type" in - symbolic) - lnopt="-s" - ;; - hard) - lnopt="" - ;; - *) - echo "Unknown type: $type" >&2 - exit 1 - ;; + symbolic) + lnopt="-s" + ;; + hard) + lnopt="" + ;; + *) + echo "Unknown link type: $type" >&2 + exit 1 + ;; esac state_is="$(cat "$__object/explorer/state")" -state_should="$(cat "$__object/parameter/state")" +state_should=present +[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")" -if [ "$state_should" = "$state_is" ]; then - # nothing to do - exit 0 -fi +[ "$state_should" = "$state_is" ] && exit 0 case "$state_should" in - present) - echo ln ${lnopt} -f \"$source\" \"$destination\" - ;; - absent) - echo rm -f \"$destination\" - ;; - *) - echo "Unknown state: $state_should" >&2 - exit 1 - ;; + present) + echo ln ${lnopt} -f \"$source\" \"$destination\" + ;; + absent) + echo rm -f \"$destination\" + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; esac diff --git a/conf/type/__link/man.text b/cdist/conf/type/__link/man.text similarity index 100% rename from conf/type/__link/man.text rename to cdist/conf/type/__link/man.text diff --git a/conf/type/__link/parameter/optional b/cdist/conf/type/__link/parameter/optional similarity index 100% rename from conf/type/__link/parameter/optional rename to cdist/conf/type/__link/parameter/optional diff --git a/conf/type/__link/parameter/required b/cdist/conf/type/__link/parameter/required similarity index 100% rename from conf/type/__link/parameter/required rename to cdist/conf/type/__link/parameter/required diff --git a/conf/type/__motd/files/motd b/cdist/conf/type/__motd/files/motd similarity index 100% rename from conf/type/__motd/files/motd rename to cdist/conf/type/__motd/files/motd diff --git a/conf/type/__motd/man.text b/cdist/conf/type/__motd/man.text similarity index 100% rename from conf/type/__motd/man.text rename to cdist/conf/type/__motd/man.text diff --git a/conf/type/__motd/manifest b/cdist/conf/type/__motd/manifest similarity index 100% rename from conf/type/__motd/manifest rename to cdist/conf/type/__motd/manifest diff --git a/conf/type/__motd/parameter/optional b/cdist/conf/type/__motd/parameter/optional similarity index 100% rename from conf/type/__motd/parameter/optional rename to cdist/conf/type/__motd/parameter/optional diff --git a/conf/type/__issue/singleton b/cdist/conf/type/__motd/singleton similarity index 100% rename from conf/type/__issue/singleton rename to cdist/conf/type/__motd/singleton diff --git a/conf/type/__mysql_database/gencode-remote b/cdist/conf/type/__mysql_database/gencode-remote similarity index 100% rename from conf/type/__mysql_database/gencode-remote rename to cdist/conf/type/__mysql_database/gencode-remote diff --git a/conf/type/__mysql_database/man.text b/cdist/conf/type/__mysql_database/man.text similarity index 100% rename from conf/type/__mysql_database/man.text rename to cdist/conf/type/__mysql_database/man.text diff --git a/conf/type/__mysql_database/parameter/optional b/cdist/conf/type/__mysql_database/parameter/optional similarity index 100% rename from conf/type/__mysql_database/parameter/optional rename to cdist/conf/type/__mysql_database/parameter/optional diff --git a/conf/type/__package/man.text b/cdist/conf/type/__package/man.text similarity index 90% rename from conf/type/__package/man.text rename to cdist/conf/type/__package/man.text index 071a8bfb..b656c890 100644 --- a/conf/type/__package/man.text +++ b/cdist/conf/type/__package/man.text @@ -16,9 +16,7 @@ It dispatches the actual work to the package system dependant types. REQUIRED PARAMETERS ------------------- -state:: - The state the package should be in, either "present" or "absent" - (the old values "installed" or "removed" will be removed in cdist 2.1). +None OPTIONAL PARAMETERS @@ -35,6 +33,9 @@ type:: e.g. __package_apt for Debian __package_emerge for Gentoo +state:: + Either "present" or "absent", defaults to "present" + EXAMPLES -------- diff --git a/conf/type/__package/manifest b/cdist/conf/type/__package/manifest similarity index 98% rename from conf/type/__package/manifest rename to cdist/conf/type/__package/manifest index 118525b1..6a84cb7f 100755 --- a/conf/type/__package/manifest +++ b/cdist/conf/type/__package/manifest @@ -35,6 +35,7 @@ else debian|ubuntu) type="apt" ;; freebsd) type="pkg_freebsd" ;; gentoo) type="emerge" ;; + suse) type="zypper" ;; openwrt) type="opkg" ;; *) echo "Don't know how to manage packages on: $os" >&2 diff --git a/conf/type/__package/parameter/optional b/cdist/conf/type/__package/parameter/optional similarity index 81% rename from conf/type/__package/parameter/optional rename to cdist/conf/type/__package/parameter/optional index 6f793411..9982507e 100644 --- a/conf/type/__package/parameter/optional +++ b/cdist/conf/type/__package/parameter/optional @@ -2,3 +2,4 @@ name version type pkgsite +state diff --git a/conf/type/__package_apt/explorer/state b/cdist/conf/type/__package_apt/explorer/state similarity index 100% rename from conf/type/__package_apt/explorer/state rename to cdist/conf/type/__package_apt/explorer/state diff --git a/conf/type/__package_apt/gencode-remote b/cdist/conf/type/__package_apt/gencode-remote similarity index 73% rename from conf/type/__package_apt/gencode-remote rename to cdist/conf/type/__package_apt/gencode-remote index 0bcdb946..a80d707e 100755 --- a/conf/type/__package_apt/gencode-remote +++ b/cdist/conf/type/__package_apt/gencode-remote @@ -27,19 +27,11 @@ else name="$__object_id" fi -state_should="$(cat "$__object/parameter/state")" - -# Correct pre 2.1 naming - FIXME in 2.1 -case "$state_should" in - installed) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="present" - ;; - removed) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="absent" - ;; -esac +if [ -f "$__object/parameter/state" ]; then + state_should="$(cat "$__object/parameter/state")" +else + state_should="present" +fi # FIXME: use grep directly, state is a list, not a line! state_is="$(cat "$__object/explorer/state")" diff --git a/conf/type/__package_apt/man.text b/cdist/conf/type/__package_apt/man.text similarity index 82% rename from conf/type/__package_apt/man.text rename to cdist/conf/type/__package_apt/man.text index fd9c1a9c..5d4656c1 100644 --- a/conf/type/__package_apt/man.text +++ b/cdist/conf/type/__package_apt/man.text @@ -16,9 +16,7 @@ manage packages. REQUIRED PARAMETERS ------------------- -state:: - The state the package should be in, either "present" or "absent" - (the old values "installed" or "removed" will be removed in cdist 2.1). +None OPTIONAL PARAMETERS @@ -26,6 +24,9 @@ OPTIONAL PARAMETERS name:: If supplied, use the name and not the object id as the package name. +state:: + Either "present" or "absent", defaults to "present" + EXAMPLES -------- @@ -50,5 +51,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011 Nico Schottelius. Free use of this software is +Copyright \(C) 2011-2012 Nico Schottelius. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__package_apt/notes.txt b/cdist/conf/type/__package_apt/notes.txt similarity index 100% rename from conf/type/__package_apt/notes.txt rename to cdist/conf/type/__package_apt/notes.txt diff --git a/conf/type/__package_apt/parameter/optional b/cdist/conf/type/__package_apt/parameter/optional similarity index 68% rename from conf/type/__package_apt/parameter/optional rename to cdist/conf/type/__package_apt/parameter/optional index a52167d3..41b8e6cf 100644 --- a/conf/type/__package_apt/parameter/optional +++ b/cdist/conf/type/__package_apt/parameter/optional @@ -1,2 +1,3 @@ name version +state diff --git a/conf/type/__package_luarocks/explorer/pkg_status b/cdist/conf/type/__package_luarocks/explorer/pkg_status similarity index 100% rename from conf/type/__package_luarocks/explorer/pkg_status rename to cdist/conf/type/__package_luarocks/explorer/pkg_status diff --git a/conf/type/__package_luarocks/gencode-remote b/cdist/conf/type/__package_luarocks/gencode-remote similarity index 71% rename from conf/type/__package_luarocks/gencode-remote rename to cdist/conf/type/__package_luarocks/gencode-remote index 327f812c..7a5a5b04 100755 --- a/conf/type/__package_luarocks/gencode-remote +++ b/cdist/conf/type/__package_luarocks/gencode-remote @@ -29,19 +29,11 @@ else name="$__object_id" fi -state_should="$(cat "$__object/parameter/state")" -# Correct pre 2.1 naming - FIXME in 2.1 -case "$state_should" in - installed) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="present" - ;; - removed) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="absent" - ;; -esac - +if [ -f "$__object/parameter/state" ]; then + state_should="$(cat "$__object/parameter/state")" +else + state_should="present" +fi if grep -q "(installed)" "$__object/explorer/pkg_status"; then state_is="present" diff --git a/conf/type/__package_luarocks/man.text b/cdist/conf/type/__package_luarocks/man.text similarity index 87% rename from conf/type/__package_luarocks/man.text rename to cdist/conf/type/__package_luarocks/man.text index 8b041b7c..657f68e5 100644 --- a/conf/type/__package_luarocks/man.text +++ b/cdist/conf/type/__package_luarocks/man.text @@ -15,9 +15,7 @@ LuaRocks is a deployment and management system for Lua modules. REQUIRED PARAMETERS ------------------- -state:: - The state the package should be in, either "present" or "absent" - (the old values "installed" or "removed" will be removed in cdist 2.1). +None OPTIONAL PARAMETERS @@ -25,6 +23,9 @@ OPTIONAL PARAMETERS name:: If supplied, use the name and not the object id as the package name. +state:: + Either "present" or "absent", defaults to "present" + EXAMPLES -------- diff --git a/conf/type/__package_luarocks/manifest b/cdist/conf/type/__package_luarocks/manifest similarity index 100% rename from conf/type/__package_luarocks/manifest rename to cdist/conf/type/__package_luarocks/manifest diff --git a/conf/type/__package_rubygem/parameter/required b/cdist/conf/type/__package_luarocks/parameter/optional similarity index 54% rename from conf/type/__package_rubygem/parameter/required rename to cdist/conf/type/__package_luarocks/parameter/optional index ff72b5c7..1b423dc4 100644 --- a/conf/type/__package_rubygem/parameter/required +++ b/cdist/conf/type/__package_luarocks/parameter/optional @@ -1 +1,2 @@ +name state diff --git a/conf/type/__package_opkg/explorer/pkg_status b/cdist/conf/type/__package_opkg/explorer/pkg_status similarity index 100% rename from conf/type/__package_opkg/explorer/pkg_status rename to cdist/conf/type/__package_opkg/explorer/pkg_status diff --git a/conf/type/__package_opkg/gencode-remote b/cdist/conf/type/__package_opkg/gencode-remote similarity index 92% rename from conf/type/__package_opkg/gencode-remote rename to cdist/conf/type/__package_opkg/gencode-remote index bd9a599b..43f1ad8a 100755 --- a/conf/type/__package_opkg/gencode-remote +++ b/cdist/conf/type/__package_opkg/gencode-remote @@ -28,7 +28,12 @@ else name="$__object_id" fi -state_should="$(cat "$__object/parameter/state")" +if [ -f "$__object/parameter/state" ]; then + state_should="$(cat "$__object/parameter/state")" +else + state_should="present" +fi + state_is="$(cat "$__object/explorer/pkg_status")" case "$state_is" in absent*) @@ -54,4 +59,3 @@ if [ "$state_is" != "$state_should" ]; then ;; esac fi - diff --git a/conf/type/__package_opkg/man.text b/cdist/conf/type/__package_opkg/man.text similarity index 93% rename from conf/type/__package_opkg/man.text rename to cdist/conf/type/__package_opkg/man.text index 19d26af6..aeb0a1c5 100644 --- a/conf/type/__package_opkg/man.text +++ b/cdist/conf/type/__package_opkg/man.text @@ -15,8 +15,7 @@ opkg is usually used on OpenWRT to manage packages. REQUIRED PARAMETERS ------------------- -state:: - The state the package should be in, either "present" or "absent" +None OPTIONAL PARAMETERS @@ -24,6 +23,9 @@ OPTIONAL PARAMETERS name:: If supplied, use the name and not the object id as the package name. +state:: + Either "present" or "absent", defaults to "present" + EXAMPLES -------- diff --git a/conf/type/__package_yum/parameter/required b/cdist/conf/type/__package_opkg/parameter/optional similarity index 54% rename from conf/type/__package_yum/parameter/required rename to cdist/conf/type/__package_opkg/parameter/optional index ff72b5c7..1b423dc4 100644 --- a/conf/type/__package_yum/parameter/required +++ b/cdist/conf/type/__package_opkg/parameter/optional @@ -1 +1,2 @@ +name state diff --git a/conf/type/__package_pacman/explorer/pkg_version b/cdist/conf/type/__package_pacman/explorer/pkg_version similarity index 100% rename from conf/type/__package_pacman/explorer/pkg_version rename to cdist/conf/type/__package_pacman/explorer/pkg_version diff --git a/conf/type/__package_pacman/gencode-remote b/cdist/conf/type/__package_pacman/gencode-remote similarity index 67% rename from conf/type/__package_pacman/gencode-remote rename to cdist/conf/type/__package_pacman/gencode-remote index 9defabe8..02744fa8 100755 --- a/conf/type/__package_pacman/gencode-remote +++ b/cdist/conf/type/__package_pacman/gencode-remote @@ -25,25 +25,17 @@ # exec >&2 # set -x -pacopts="--needed --noconfirm --noprogressbar" - if [ -f "$__object/parameter/name" ]; then name="$__object/parameter/name" else name="$__object_id" fi -state_should="$(cat "$__object/parameter/state")" -case "$state_should" in - installed) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="present" - ;; - removed) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="absent" - ;; -esac +if [ -f "$__object/parameter/state" ]; then + state_should="$(cat "$__object/parameter/state")" +else + state_should="present" +fi pkg_version="$(cat "$__object/explorer/pkg_version")" if [ -z "$pkg_version" ]; then @@ -57,10 +49,10 @@ fi case "$state_should" in present) - echo pacman "$pacopts" -S \"$name\" + echo pacman --needed --noconfirm --noprogressbar -S \"$name\" ;; absent) - echo pacman "$pacopts" -R \"$name\" + echo pacman --noconfirm --noprogressbar -R \"$name\" ;; *) echo "Unknown state: $state_should" >&2 diff --git a/conf/type/__package_pacman/man.text b/cdist/conf/type/__package_pacman/man.text similarity index 82% rename from conf/type/__package_pacman/man.text rename to cdist/conf/type/__package_pacman/man.text index fe2abac8..2e24ecd9 100644 --- a/conf/type/__package_pacman/man.text +++ b/cdist/conf/type/__package_pacman/man.text @@ -10,15 +10,12 @@ cdist-type__package_pacman - Manage packages with pacman DESCRIPTION ----------- -Pacman is usually used on the Archlinux distribution to manage -packages. +Pacman is usually used on the Archlinux distribution to manage packages. REQUIRED PARAMETERS ------------------- -state:: - The state the package should be in, either "present" or "absent" - (the old values "installed" or "removed" will be removed in cdist 2.1). +None OPTIONAL PARAMETERS @@ -26,6 +23,9 @@ OPTIONAL PARAMETERS name:: If supplied, use the name and not the object id as the package name. +state:: + Either "present" or "absent", defaults to "present" + EXAMPLES -------- diff --git a/conf/type/__package_pkg_openbsd/parameter/required b/cdist/conf/type/__package_pacman/parameter/optional similarity index 54% rename from conf/type/__package_pkg_openbsd/parameter/required rename to cdist/conf/type/__package_pacman/parameter/optional index ff72b5c7..1b423dc4 100644 --- a/conf/type/__package_pkg_openbsd/parameter/required +++ b/cdist/conf/type/__package_pacman/parameter/optional @@ -1 +1,2 @@ +name state diff --git a/conf/type/__package_pip/explorer/state b/cdist/conf/type/__package_pip/explorer/state similarity index 100% rename from conf/type/__package_pip/explorer/state rename to cdist/conf/type/__package_pip/explorer/state diff --git a/conf/type/__package_pip/gencode-remote b/cdist/conf/type/__package_pip/gencode-remote similarity index 90% rename from conf/type/__package_pip/gencode-remote rename to cdist/conf/type/__package_pip/gencode-remote index 0f15abdc..3456ced2 100644 --- a/conf/type/__package_pip/gencode-remote +++ b/cdist/conf/type/__package_pip/gencode-remote @@ -22,7 +22,11 @@ # state_is=$(cat "$__object/explorer/state") -state_should=$(cat "$__object/parameter/state") +if [ -f "$__object/parameter/state" ]; then + state_should="$(cat "$__object/parameter/state")" +else + state_should="present" +fi [ "$state_is" = "$state_should" ] && exit 0 diff --git a/conf/type/__package_pip/man.text b/cdist/conf/type/__package_pip/man.text similarity index 94% rename from conf/type/__package_pip/man.text rename to cdist/conf/type/__package_pip/man.text index 2a620658..5f619871 100644 --- a/conf/type/__package_pip/man.text +++ b/cdist/conf/type/__package_pip/man.text @@ -16,8 +16,7 @@ It is also included in the python virtualenv environment. REQUIRED PARAMETERS ------------------- -state:: - Either "present" or "absent". +None OPTIONAL PARAMETERS @@ -28,6 +27,9 @@ name:: pip:: Instead of using pip from PATH, use the specific pip path. +state:: + Either "present" or "absent", defaults to "present" + EXAMPLES -------- diff --git a/conf/type/__package_pkg_freebsd/parameter/required b/cdist/conf/type/__package_pip/parameter/optional similarity index 60% rename from conf/type/__package_pkg_freebsd/parameter/required rename to cdist/conf/type/__package_pip/parameter/optional index ff72b5c7..f32876f7 100644 --- a/conf/type/__package_pkg_freebsd/parameter/required +++ b/cdist/conf/type/__package_pip/parameter/optional @@ -1 +1,2 @@ +pip state diff --git a/conf/type/__package_pkg_freebsd/explorer/pkg_version b/cdist/conf/type/__package_pkg_freebsd/explorer/pkg_version similarity index 86% rename from conf/type/__package_pkg_freebsd/explorer/pkg_version rename to cdist/conf/type/__package_pkg_freebsd/explorer/pkg_version index 4bca24b6..1335ba79 100755 --- a/conf/type/__package_pkg_freebsd/explorer/pkg_version +++ b/cdist/conf/type/__package_pkg_freebsd/explorer/pkg_version @@ -30,6 +30,10 @@ fi # Don't produce "no pkgs installed" output -- breaks things PKG_OUTPUT=$(pkg_info 2>&1) if [ ! "$PKG_OUTPUT" = "pkg_info: no packages installed" ]; then - echo "$(echo "$PKG_OUTPUT" | grep "^$name-" | cut '-d ' -f1 | sed "s/$name-//g")" + echo -n "$(echo "$PKG_OUTPUT" \ + | awk '{print $1}' \ + | sed 's/^\(.*\)-\([^-]*\)$/name:\1 ver:\2/g' \ + | grep "name:$name ver:" \ + | sed 's/^.*ver:\(.*\)/\1/g')" fi diff --git a/conf/type/__package_pkg_freebsd/gencode-remote b/cdist/conf/type/__package_pkg_freebsd/gencode-remote similarity index 95% rename from conf/type/__package_pkg_freebsd/gencode-remote rename to cdist/conf/type/__package_pkg_freebsd/gencode-remote index fa962970..3f5ebde7 100755 --- a/conf/type/__package_pkg_freebsd/gencode-remote +++ b/cdist/conf/type/__package_pkg_freebsd/gencode-remote @@ -63,7 +63,11 @@ if [ -f "$__object/parameter/pkgsite" ]; then pkgsite="$(cat "$__object/parameter/pkgsite")" fi -state="$(cat "$__object/parameter/state")" +if [ -f "$__object/parameter/state" ]; then + state="$(cat "$__object/parameter/state")" +else + state="present" +fi curr_version="$(cat "$__object/explorer/pkg_version")" add_cmd="pkg_add" rm_cmd="pkg_delete" @@ -107,7 +111,7 @@ if [ -n "$curr_version" ]; then # PKG *is* installed assert "! ${version} = ${curr_version}" $LINENO cmd="${rm_cmd} ${name}-${curr_version}" execcmd "remove" "${cmd}" - cmd="${add_cmd} ${name}-${version}" + cmd="${add_cmd} -r ${name}-${version}" execcmd "add" "${cmd}" fi else # Don't care what version to use @@ -133,4 +137,3 @@ fi # Debug #set +x - diff --git a/conf/type/__package_pkg_freebsd/man.text b/cdist/conf/type/__package_pkg_freebsd/man.text similarity index 65% rename from conf/type/__package_pkg_freebsd/man.text rename to cdist/conf/type/__package_pkg_freebsd/man.text index f41ac47a..71387148 100644 --- a/conf/type/__package_pkg_freebsd/man.text +++ b/cdist/conf/type/__package_pkg_freebsd/man.text @@ -15,23 +15,25 @@ This type is usually used on FreeBSD to manage packages. REQUIRED PARAMETERS ------------------- -state:: - Either "present" or "absent". +None OPTIONAL PARAMETERS ------------------- name:: - If supplied, use the name and not the object id as the package name. + If supplied, use the name and not the object id as the package name. flavor:: - If supplied, use to avoid ambiguity. + If supplied, use to avoid ambiguity. version:: - If supplied, use to install a specific version of the package named. + If supplied, use to install a specific version of the package named. pkgsite:: - If supplied, use to install from a specific package repository. + If supplied, use to install from a specific package repository. + +state:: + Either "present" or "absent", defaults to "present" EXAMPLES @@ -39,16 +41,16 @@ EXAMPLES -------------------------------------------------------------------------------- # Ensure zsh is installed -__package_pkg_freebsd zsh --state installed +__package_pkg_freebsd zsh --state present # Ensure vim is installed, use flavor no_x11 -__package_pkg_freebsd vim --state installed --flavor no_x11 +__package_pkg_freebsd vim --state present --flavor no_x11 # If you don't want to follow pythonX packages, but always use python -__package_pkg_freebsd python --state installed --name python2 +__package_pkg_freebsd python --state present --name python2 # Remove obsolete package -__package_pkg_freebsd puppet --state removed +__package_pkg_freebsd puppet --state absent -------------------------------------------------------------------------------- diff --git a/conf/type/__package_pkg_freebsd/parameter/optional b/cdist/conf/type/__package_pkg_freebsd/parameter/optional similarity index 82% rename from conf/type/__package_pkg_freebsd/parameter/optional rename to cdist/conf/type/__package_pkg_freebsd/parameter/optional index 3fb2f29e..8cb68f98 100644 --- a/conf/type/__package_pkg_freebsd/parameter/optional +++ b/cdist/conf/type/__package_pkg_freebsd/parameter/optional @@ -2,3 +2,4 @@ name flavor version pkgsite +state diff --git a/conf/type/__package_pkg_openbsd/explorer/pkg_version b/cdist/conf/type/__package_pkg_openbsd/explorer/pkg_version similarity index 100% rename from conf/type/__package_pkg_openbsd/explorer/pkg_version rename to cdist/conf/type/__package_pkg_openbsd/explorer/pkg_version diff --git a/conf/type/__package_pkg_openbsd/gencode-remote b/cdist/conf/type/__package_pkg_openbsd/gencode-remote similarity index 80% rename from conf/type/__package_pkg_openbsd/gencode-remote rename to cdist/conf/type/__package_pkg_openbsd/gencode-remote index 26dd4689..1df87997 100755 --- a/conf/type/__package_pkg_openbsd/gencode-remote +++ b/cdist/conf/type/__package_pkg_openbsd/gencode-remote @@ -42,18 +42,11 @@ else name="$__object_id" fi -state_should="$(cat "$__object/parameter/state")" -# Correct pre 2.1 naming - FIXME in 2.1 -case "$state_should" in - installed) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="present" - ;; - removed) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="absent" - ;; -esac +if [ -f "$__object/parameter/state" ]; then + state_should="$(cat "$__object/parameter/state")" +else + state_should="present" +fi pkg_version="$(cat "$__object/explorer/pkg_version")" diff --git a/conf/type/__package_pkg_openbsd/man.text b/cdist/conf/type/__package_pkg_openbsd/man.text similarity index 89% rename from conf/type/__package_pkg_openbsd/man.text rename to cdist/conf/type/__package_pkg_openbsd/man.text index 71cf9d4e..f523a892 100644 --- a/conf/type/__package_pkg_openbsd/man.text +++ b/cdist/conf/type/__package_pkg_openbsd/man.text @@ -15,9 +15,7 @@ This type is usually used on OpenBSD to manage packages. REQUIRED PARAMETERS ------------------- -state:: - The state the package should be in, either "present" or "absent" - (the old values "installed" or "removed" will be removed in cdist 2.1). +None OPTIONAL PARAMETERS @@ -28,6 +26,9 @@ name:: flavor:: If supplied, use to avoid ambiguity. +state:: + Either "present" or "absent", defaults to "present" + EXAMPLES -------- diff --git a/conf/type/__package_pkg_openbsd/parameter/optional b/cdist/conf/type/__package_pkg_openbsd/parameter/optional similarity index 66% rename from conf/type/__package_pkg_openbsd/parameter/optional rename to cdist/conf/type/__package_pkg_openbsd/parameter/optional index 29b123ef..77fd22b3 100644 --- a/conf/type/__package_pkg_openbsd/parameter/optional +++ b/cdist/conf/type/__package_pkg_openbsd/parameter/optional @@ -1,2 +1,3 @@ name flavor +state diff --git a/conf/type/__package_rubygem/explorer/pkg_status b/cdist/conf/type/__package_rubygem/explorer/pkg_status similarity index 100% rename from conf/type/__package_rubygem/explorer/pkg_status rename to cdist/conf/type/__package_rubygem/explorer/pkg_status diff --git a/conf/type/__package_rubygem/gencode-remote b/cdist/conf/type/__package_rubygem/gencode-remote similarity index 71% rename from conf/type/__package_rubygem/gencode-remote rename to cdist/conf/type/__package_rubygem/gencode-remote index 638c4252..6256e308 100755 --- a/conf/type/__package_rubygem/gencode-remote +++ b/cdist/conf/type/__package_rubygem/gencode-remote @@ -27,18 +27,11 @@ else name="$__object_id" fi -state_should="$(cat "$__object/parameter/state")" -# Correct pre 2.1 naming - FIXME in 2.1 -case "$state_should" in - installed) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="present" - ;; - removed) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="absent" - ;; -esac +if [ -f "$__object/parameter/state" ]; then + state_should="$(cat "$__object/parameter/state")" +else + state_should="present" +fi if grep -q true "$__object/explorer/pkg_status"; then state_is="present" diff --git a/conf/type/__package_rubygem/man.text b/cdist/conf/type/__package_rubygem/man.text similarity index 87% rename from conf/type/__package_rubygem/man.text rename to cdist/conf/type/__package_rubygem/man.text index 79bb8b52..a808c2aa 100644 --- a/conf/type/__package_rubygem/man.text +++ b/cdist/conf/type/__package_rubygem/man.text @@ -15,9 +15,7 @@ Rubygems is the default package management system for the Ruby programming langu REQUIRED PARAMETERS ------------------- -state:: - The state the package should be in, either "present" or "absent" - (the old values "installed" or "removed" will be removed in cdist 2.1). +None OPTIONAL PARAMETERS @@ -25,6 +23,9 @@ OPTIONAL PARAMETERS name:: If supplied, use the name and not the object id as the package name. +state:: + Either "present" or "absent", defaults to "present" + EXAMPLES -------- diff --git a/cdist/conf/type/__package_rubygem/parameter/optional b/cdist/conf/type/__package_rubygem/parameter/optional new file mode 100644 index 00000000..1b423dc4 --- /dev/null +++ b/cdist/conf/type/__package_rubygem/parameter/optional @@ -0,0 +1,2 @@ +name +state diff --git a/other/types_submitted_for_inclusion/__package_zypper/explorer/pkg_version b/cdist/conf/type/__package_yum/explorer/pkg_version similarity index 88% rename from other/types_submitted_for_inclusion/__package_zypper/explorer/pkg_version rename to cdist/conf/type/__package_yum/explorer/pkg_version index 0e078f68..fb3b7753 100755 --- a/other/types_submitted_for_inclusion/__package_zypper/explorer/pkg_version +++ b/cdist/conf/type/__package_yum/explorer/pkg_version @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -18,7 +18,7 @@ # along with cdist. If not, see . # # -# Retrieve the status of a package - parsed dpkg output +# Retrieve the status of a package # if [ -f "$__object/parameter/name" ]; then diff --git a/conf/type/__package_yum/gencode-remote b/cdist/conf/type/__package_yum/gencode-remote similarity index 73% rename from conf/type/__package_yum/gencode-remote rename to cdist/conf/type/__package_yum/gencode-remote index a10e60dd..9c98c257 100755 --- a/conf/type/__package_yum/gencode-remote +++ b/cdist/conf/type/__package_yum/gencode-remote @@ -22,22 +22,16 @@ # if [ -f "$__object/parameter/name" ]; then - name="$__object/parameter/name" + name="$(cat "$__object/parameter/name")" else name="$__object_id" fi -state_should="$(cat "$__object/parameter/state")" -case "$state_should" in - installed) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="present" - ;; - removed) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="absent" - ;; -esac +if [ -f "$__object/parameter/state" ]; then + state_should="$(cat "$__object/parameter/state")" +else + state_should="present" +fi if grep -q -E "(centos|redhat|amazon)" "$__global/explorer/os"; then opts="-y --quiet" diff --git a/conf/type/__package_yum/man.text b/cdist/conf/type/__package_yum/man.text similarity index 84% rename from conf/type/__package_yum/man.text rename to cdist/conf/type/__package_yum/man.text index 9dfb394e..d958dd1e 100644 --- a/conf/type/__package_yum/man.text +++ b/cdist/conf/type/__package_yum/man.text @@ -17,9 +17,7 @@ slightly confusing error message "Error: Nothing to do". REQUIRED PARAMETERS ------------------- -state:: - The state the package should be in, either "present" or "absent" - (the old values "installed" or "removed" will be removed in cdist 2.1). +None OPTIONAL PARAMETERS @@ -27,6 +25,9 @@ OPTIONAL PARAMETERS name:: If supplied, use the name and not the object id as the package name. +state:: + Either "present" or "absent", defaults to "present" + EXAMPLES -------- @@ -51,5 +52,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011 Nico Schottelius. Free use of this software is +Copyright \(C) 2011-2012 Nico Schottelius. 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/__package_yum/parameter/optional b/cdist/conf/type/__package_yum/parameter/optional new file mode 100644 index 00000000..1b423dc4 --- /dev/null +++ b/cdist/conf/type/__package_yum/parameter/optional @@ -0,0 +1,2 @@ +name +state diff --git a/conf/type/__package_yum/explorer/pkg_version b/cdist/conf/type/__package_zypper/explorer/pkg_version similarity index 88% rename from conf/type/__package_yum/explorer/pkg_version rename to cdist/conf/type/__package_zypper/explorer/pkg_version index 0e078f68..fb3b7753 100755 --- a/conf/type/__package_yum/explorer/pkg_version +++ b/cdist/conf/type/__package_zypper/explorer/pkg_version @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -18,7 +18,7 @@ # along with cdist. If not, see . # # -# Retrieve the status of a package - parsed dpkg output +# Retrieve the status of a package # if [ -f "$__object/parameter/name" ]; then diff --git a/other/types_submitted_for_inclusion/__package_zypper/gencode-remote b/cdist/conf/type/__package_zypper/gencode-remote similarity index 57% rename from other/types_submitted_for_inclusion/__package_zypper/gencode-remote rename to cdist/conf/type/__package_zypper/gencode-remote index 2d1112d3..ca9aec33 100755 --- a/other/types_submitted_for_inclusion/__package_zypper/gencode-remote +++ b/cdist/conf/type/__package_zypper/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -18,34 +18,39 @@ # along with cdist. If not, see . # # -# Manage packages with yum (mostly Fedora) +# Manage packages with Zypper (mostly suse) # +# Debug +# exec >&2 +# set -x + +globalopts="--quiet --non-interactive" + if [ -f "$__object/parameter/name" ]; then name="$__object/parameter/name" else name="$__object_id" fi -state="$(cat "$__object/parameter/state")" +if [ -f "$__object/parameter/state" ]; then + state_should="$(cat "$__object/parameter/state")" +else + state_should="present" +fi -opts="-n -q" +# Exit if nothing is needed to be done +[ "$state_is" = "$state_should" ] && exit 0 -not_installed="^no package provides" - -case "$state" in - installed) - if grep -q "$not_installed" "$__object/explorer/pkg_version"; then - echo zypper $opts install \"$name\" - fi +case "$state_should" in + present) + echo zypper "$globalopts" install --auto-agree-with-licenses \"$name\" ;; - removed) - if ! grep -q "$not_installed" "$__object/explorer/pkg_version"; then - echo zypper $opts remove \"$name\" - fi + absent) + echo pacman "$globalopts" remove \"$name\" ;; *) - echo "Unknown state: $state" >&2 + echo "Unknown state: $state_should" >&2 exit 1 ;; esac diff --git a/other/types_submitted_for_inclusion/__package_zypper/man.text b/cdist/conf/type/__package_zypper/man.text similarity index 57% rename from other/types_submitted_for_inclusion/__package_zypper/man.text rename to cdist/conf/type/__package_zypper/man.text index 3a4f1026..e2261d33 100644 --- a/other/types_submitted_for_inclusion/__package_zypper/man.text +++ b/cdist/conf/type/__package_zypper/man.text @@ -1,6 +1,6 @@ cdist-type__package_zypper(7) -========================== -Franky Van Liedekerke +============================= +Nico Schottelius NAME @@ -10,19 +10,21 @@ cdist-type__package_zypper - Manage packages with zypper DESCRIPTION ----------- -zypper is usually used on the Suse distribution to manage packages. +Zypper is usually used on the SuSE distribution to manage packages. REQUIRED PARAMETERS ------------------- -state:: - Either "installed" or "removed". +None OPTIONAL PARAMETERS ------------------- name:: - If supplied, use the name and not the object id as the package name. + If supplied, use the name and not the object id as the package name. + +state:: + Either "present" or "absent", defaults to "present" EXAMPLES @@ -30,13 +32,13 @@ EXAMPLES -------------------------------------------------------------------------------- # Ensure zsh in installed -__package_zypper zsh --state installed +__package_zypper zsh --state present # If you don't want to follow pythonX packages, but always use python -__package_zypper python --state installed --name python2 +__package_zypper python --state present --name python2 -# Remove obsolete package -__package_zypper puppet --state removed +# Remove package +__package_zypper cfengine --state absent -------------------------------------------------------------------------------- @@ -48,5 +50,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011 Nico Schottelius. Free use of this software is +Copyright \(C) 2012 Nico Schottelius. 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/__package_zypper/parameter/optional b/cdist/conf/type/__package_zypper/parameter/optional new file mode 100644 index 00000000..1b423dc4 --- /dev/null +++ b/cdist/conf/type/__package_zypper/parameter/optional @@ -0,0 +1,2 @@ +name +state diff --git a/cdist/conf/type/__pf_apply/explorer/rcvar b/cdist/conf/type/__pf_apply/explorer/rcvar new file mode 100755 index 00000000..20e9dfcc --- /dev/null +++ b/cdist/conf/type/__pf_apply/explorer/rcvar @@ -0,0 +1,36 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Get the location of the pf ruleset on the target host. +# + +# Debug +#exec >&2 +#set -x + +# Check /etc/rc.conf for pf's configuration file name. Default to /etc/pf.conf + +RC="/etc/rc.conf" +PFCONF="$(grep '^pf_rules=' ${RC} | cut -d= -f2 | sed 's/"//g')" +echo ${PFCONF:-"/etc/pf.conf"} + +# Debug +#set +x + diff --git a/cdist/conf/type/__pf_apply/gencode-remote b/cdist/conf/type/__pf_apply/gencode-remote new file mode 100755 index 00000000..f7c889b4 --- /dev/null +++ b/cdist/conf/type/__pf_apply/gencode-remote @@ -0,0 +1,51 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Apply pf(4) ruleset on *BSD +# + +# Debug +#exec >&2 +#set -x + +rcvar=$(cat "$__object/explorer/rcvar") + +cat <&2 + fi +fi +EOF + +# Debug +#set +x + diff --git a/cdist/conf/type/__pf_apply/man.text b/cdist/conf/type/__pf_apply/man.text new file mode 100644 index 00000000..2e0d7802 --- /dev/null +++ b/cdist/conf/type/__pf_apply/man.text @@ -0,0 +1,52 @@ +cdist-type__pf_apply(7) +======================= +Jake Guffey + + +NAME +---- +cdist-type__pf_apply - Apply pf(4) ruleset on *BSD + + +DESCRIPTION +----------- +This type is used on *BSD systems to manage the pf firewall's active ruleset. + + +REQUIRED PARAMETERS +------------------- +NONE + + +OPTIONAL PARAMETERS +------------------- +NONE + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Modify the ruleset on $__target_host: +__pf_ruleset --state present --source /my/pf/ruleset.conf +require="__pf_ruleset" \ + __pf_apply + +# Remove the ruleset on $__target_host (implies disabling pf(4): +__pf_ruleset --state absent +require="__pf_ruleset" \ + __pf_apply +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__pf_ruleset(7) +- pf(4) + + +COPYING +------- +Copyright \(C) 2012 Jake Guffey. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__motd/singleton b/cdist/conf/type/__pf_apply/singleton similarity index 100% rename from conf/type/__motd/singleton rename to cdist/conf/type/__pf_apply/singleton diff --git a/cdist/conf/type/__pf_ruleset/explorer/cksum b/cdist/conf/type/__pf_ruleset/explorer/cksum new file mode 100755 index 00000000..f8679836 --- /dev/null +++ b/cdist/conf/type/__pf_ruleset/explorer/cksum @@ -0,0 +1,41 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Get the 256 bit SHA2 checksum of the pf ruleset on the target host. +# + +# Debug +#exec >&2 +#set -x + +# Check /etc/rc.conf for pf's configuration file name. Default to /etc/pf.conf +# See if file exists and if so, get checksum + +RC="/etc/rc.conf" +TMP="$(grep '^pf_rules=' ${RC} | cut -d= -f2 | sed 's/"//g')" +PFCONF="${TMP:-"/etc/pf.conf"}" + +if [ -f "${PFCONF}" ]; then # The pf config file exists, find its cksum. + cksum -o 1 ${PFCONF} | cut -d= -f2 | awk '{print $1}' +fi + +# Debug +#set +x + diff --git a/cdist/conf/type/__pf_ruleset/explorer/rcvar b/cdist/conf/type/__pf_ruleset/explorer/rcvar new file mode 100755 index 00000000..20e9dfcc --- /dev/null +++ b/cdist/conf/type/__pf_ruleset/explorer/rcvar @@ -0,0 +1,36 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Get the location of the pf ruleset on the target host. +# + +# Debug +#exec >&2 +#set -x + +# Check /etc/rc.conf for pf's configuration file name. Default to /etc/pf.conf + +RC="/etc/rc.conf" +PFCONF="$(grep '^pf_rules=' ${RC} | cut -d= -f2 | sed 's/"//g')" +echo ${PFCONF:-"/etc/pf.conf"} + +# Debug +#set +x + diff --git a/cdist/conf/type/__pf_ruleset/gencode-local b/cdist/conf/type/__pf_ruleset/gencode-local new file mode 100644 index 00000000..c2495509 --- /dev/null +++ b/cdist/conf/type/__pf_ruleset/gencode-local @@ -0,0 +1,73 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Manage pf(4) on *BSD +# + +# Debug +#exec >&2 +#set -x + +# Send files to $__target_host via $__remote_copy + +uname=$(uname) # Need to know what the cdist host is running so we know how to compute the ruleset's checksum +state=$(cat "$__object/parameter/state") + +if [ "$state" = "absent" ]; then # There is nothing more for a *local* script to do + exit 0 +fi + +if [ -f "$__object/parameter/source" ]; then + source=$(cat "$__object/parameter/source") +fi + +rcvar=$(cat "$__object/explorer/rcvar") +cksum=$(cat "$__object/explorer/cksum") + + +cat <&2 + exit 1 + ;; +esac + +if [ -n "${cksum}" ]; then + if [ ! "\${currentSum}" = "${cksum}" ]; then + $__remote_copy "${source}" "$__target_host:${rcvar}.new" + fi +else # File just doesn't exist yet + $__remote_copy "${source}" "$__target_host:${rcvar}.new" +fi +EOF + +# Debug +#exec +x + diff --git a/conf/type/__mkfs/gencode-remote b/cdist/conf/type/__pf_ruleset/gencode-remote old mode 100755 new mode 100644 similarity index 51% rename from conf/type/__mkfs/gencode-remote rename to cdist/conf/type/__pf_ruleset/gencode-remote index b3561bad..6e9030ea --- a/conf/type/__mkfs/gencode-remote +++ b/cdist/conf/type/__pf_ruleset/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Jake Guffey (jake.guffey at eprotex.com) # # This file is part of cdist. # @@ -17,22 +17,33 @@ # You should have received a copy of the GNU General Public License # along with cdist. If not, see . # +# +# Manage pf(4) on *BSD +# -device="$(cat "$__object/parameter/device")" -type="$(cat "$__object/parameter/type")" +# Debug +#exec >&2 +#set -x -if [ "$type" = "swap" ]; then - echo "mkswap $device" +# Remove ${rcvar} in the case of --state absent + +state=$(cat "$__object/parameter/state") +rcvar=$(cat "$__object/explorer/rcvar") + +if [ "$state" = "present" ]; then # There is nothing more for a *remote* script to do + exit 0 +elif [ "$state" = "absent" ]; then + # --state absent, so ensure that .new doesn't exist and that conf is renamed to .old + cat <&2 + exit 1 fi + diff --git a/cdist/conf/type/__pf_ruleset/man.text b/cdist/conf/type/__pf_ruleset/man.text new file mode 100644 index 00000000..0dc07f71 --- /dev/null +++ b/cdist/conf/type/__pf_ruleset/man.text @@ -0,0 +1,52 @@ +cdist-type__pf_ruleset(7) +========================= +Jake Guffey + + +NAME +---- +cdist-type__pf_ruleset - Copy a pf(4) ruleset to $__target_host + + +DESCRIPTION +----------- +This type is used on *BSD systems to manage the pf firewall's ruleset. + + +REQUIRED PARAMETERS +------------------- +state:: + Either "absent" (no ruleset at all) or "present" + + +OPTIONAL PARAMETERS +------------------- +source:: + If supplied, use to define the ruleset to load onto the $__target_host for pf(4). + Note that this type is almost useless without a ruleset defined, but it's technically not + needed, e.g. for the case of disabling the firewall temporarily. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Remove the current ruleset in place +__pf_ruleset --state absent + +# Enable the firewall with the ruleset defined in $__manifest/files/pf.conf +__pf_ruleset --state present --source $__manifest/files/pf.conf + +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- pf(4) + + +COPYING +------- +Copyright \(C) 2012 Jake Guffey. 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/__pf_ruleset/parameter/optional b/cdist/conf/type/__pf_ruleset/parameter/optional new file mode 100644 index 00000000..5a18cd2f --- /dev/null +++ b/cdist/conf/type/__pf_ruleset/parameter/optional @@ -0,0 +1 @@ +source diff --git a/conf/type/__package_apt/parameter/required b/cdist/conf/type/__pf_ruleset/parameter/required similarity index 100% rename from conf/type/__package_apt/parameter/required rename to cdist/conf/type/__pf_ruleset/parameter/required diff --git a/conf/type/__partition_msdos_apply/singleton b/cdist/conf/type/__pf_ruleset/singleton similarity index 100% rename from conf/type/__partition_msdos_apply/singleton rename to cdist/conf/type/__pf_ruleset/singleton diff --git a/conf/type/__postgres_database/explorer/state b/cdist/conf/type/__postgres_database/explorer/state similarity index 100% rename from conf/type/__postgres_database/explorer/state rename to cdist/conf/type/__postgres_database/explorer/state diff --git a/conf/type/__postgres_database/gencode-remote b/cdist/conf/type/__postgres_database/gencode-remote similarity index 100% rename from conf/type/__postgres_database/gencode-remote rename to cdist/conf/type/__postgres_database/gencode-remote diff --git a/conf/type/__postgres_database/man.text b/cdist/conf/type/__postgres_database/man.text similarity index 96% rename from conf/type/__postgres_database/man.text rename to cdist/conf/type/__postgres_database/man.text index 06cb736f..d01ca8f6 100644 --- a/conf/type/__postgres_database/man.text +++ b/cdist/conf/type/__postgres_database/man.text @@ -36,6 +36,7 @@ __postgres_database mydbname --state present --owner mydbusername SEE ALSO -------- - cdist-type(7) +- cdist-type__postgres_role(7) COPYING diff --git a/conf/type/__postgres_database/parameter/optional b/cdist/conf/type/__postgres_database/parameter/optional similarity index 100% rename from conf/type/__postgres_database/parameter/optional rename to cdist/conf/type/__postgres_database/parameter/optional diff --git a/conf/type/__package_luarocks/parameter/required b/cdist/conf/type/__postgres_database/parameter/required similarity index 100% rename from conf/type/__package_luarocks/parameter/required rename to cdist/conf/type/__postgres_database/parameter/required diff --git a/conf/type/__postgres_role/explorer/state b/cdist/conf/type/__postgres_role/explorer/state similarity index 100% rename from conf/type/__postgres_role/explorer/state rename to cdist/conf/type/__postgres_role/explorer/state diff --git a/cdist/conf/type/__postgres_role/gencode-remote b/cdist/conf/type/__postgres_role/gencode-remote new file mode 100755 index 00000000..c9de4707 --- /dev/null +++ b/cdist/conf/type/__postgres_role/gencode-remote @@ -0,0 +1,49 @@ +#!/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 . +# + +name="$__object_id" +state_is="$(cat "$__object/explorer/state")" +state_should="$(cat "$__object/parameter/state")" + +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + if [ -f "$__object/parameter/password" ]; then + password="$(cat "$__object/parameter/$parameter")" + fi + booleans="" + for boolean in login createdb createrole superuser; do + if [ ! -f "$__object/parameter/$boolean" ]; then + boolean="no${boolean}" + fi + upper=$(echo $boolean | tr '[a-z]' '[A-Z]') + booleans="$booleans $upper" + done + + [ -n "$password" ] && password="PASSWORD '$password'" + + cmd="CREATE ROLE $name WITH $password $booleans" + echo "su - postgres -c \"psql -c \\\"$cmd\\\"\"" + ;; + absent) + echo "su - postgres -c \"dropuser \\\"$name\\\"\"" + ;; +esac diff --git a/conf/type/__postgres_role/man.text b/cdist/conf/type/__postgres_role/man.text similarity index 78% rename from conf/type/__postgres_role/man.text rename to cdist/conf/type/__postgres_role/man.text index bcc7b5d7..904f0831 100644 --- a/conf/type/__postgres_role/man.text +++ b/cdist/conf/type/__postgres_role/man.text @@ -16,22 +16,27 @@ This cdist type allows you to create or drop postgres roles. REQUIRED PARAMETERS ------------------- state:: - either 'present' or 'absent' + Either "present" or "absent", defaults to "present" OPTIONAL PARAMETERS ------------------- -All optional parameter map directly to the corresponding postgres createrole +All parameter map directly to the corresponding postgres createrole parameters. password:: + +BOOLEAN PARAMETERS +------------------ +All parameter map directly to the corresponding postgres createrole +parameters. + login:: createdb:: createrole:: superuser:: inherit:: - EXAMPLES -------- @@ -40,15 +45,16 @@ __postgres_role myrole --state present __postgres_role myrole --state present --password 'secret' -__postgres_role admin --state present --password 'very-secret' --superuser true +__postgres_role admin --state present --password 'very-secret' --superuser -__postgres_role dbcustomer --state present --password 'bla' --createdb true +__postgres_role dbcustomer --state present --password 'bla' --createdb -------------------------------------------------------------------------------- SEE ALSO -------- - cdist-type(7) +- cdist-type__postgres_database(7) - http://www.postgresql.org/docs/current/static/sql-createrole.html diff --git a/conf/type/__postgres_role/parameter/optional b/cdist/conf/type/__postgres_role/parameter/boolean similarity index 83% rename from conf/type/__postgres_role/parameter/optional rename to cdist/conf/type/__postgres_role/parameter/boolean index c5abb57f..a581b3fd 100644 --- a/conf/type/__postgres_role/parameter/optional +++ b/cdist/conf/type/__postgres_role/parameter/boolean @@ -1,4 +1,3 @@ -password login createdb createrole diff --git a/cdist/conf/type/__postgres_role/parameter/optional b/cdist/conf/type/__postgres_role/parameter/optional new file mode 100644 index 00000000..f3097ab1 --- /dev/null +++ b/cdist/conf/type/__postgres_role/parameter/optional @@ -0,0 +1 @@ +password diff --git a/conf/type/__package_opkg/parameter/required b/cdist/conf/type/__postgres_role/parameter/required similarity index 100% rename from conf/type/__package_opkg/parameter/required rename to cdist/conf/type/__postgres_role/parameter/required diff --git a/conf/type/__process/explorer/runs b/cdist/conf/type/__process/explorer/runs similarity index 85% rename from conf/type/__process/explorer/runs rename to cdist/conf/type/__process/explorer/runs index 240ebef9..561e2fe9 100755 --- a/conf/type/__process/explorer/runs +++ b/cdist/conf/type/__process/explorer/runs @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -22,9 +22,9 @@ # if [ -f "$__object/parameter/name" ]; then - name="$(cat "$__object/parameter/name")" + name="$(cat "$__object/parameter/name")" else - name="$__object_id" + name="$__object_id" fi pgrep -x -f "$name" || true diff --git a/conf/type/__process/gencode-remote b/cdist/conf/type/__process/gencode-remote similarity index 74% rename from conf/type/__process/gencode-remote rename to cdist/conf/type/__process/gencode-remote index 3411734e..fdb6033a 100755 --- a/conf/type/__process/gencode-remote +++ b/cdist/conf/type/__process/gencode-remote @@ -20,22 +20,12 @@ # if [ -f "$__object/parameter/name" ]; then - name="$(cat "$__object/parameter/name")" + name="$(cat "$__object/parameter/name")" else - name="$__object_id" + name="$__object_id" fi state_should="$(cat "$__object/parameter/state")" -case "$state_should" in - running) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="present" - ;; - stopped) - echo "WARNING: ${__object_name}: $state_should is deprecated and will be removed in cdist 2.1. Please change to present/absent." >&2 - state_should="absent" - ;; -esac runs="$(cat "$__object/explorer/runs")" if [ "$runs" ]; then diff --git a/conf/type/__process/man.text b/cdist/conf/type/__process/man.text similarity index 78% rename from conf/type/__process/man.text rename to cdist/conf/type/__process/man.text index 961a7f9a..0d457ead 100644 --- a/conf/type/__process/man.text +++ b/cdist/conf/type/__process/man.text @@ -16,25 +16,23 @@ This cdist type allows you to define the state of a process. REQUIRED PARAMETERS ------------------- state:: - State of the process: Either present or absent - (old values "stopped" and "running" are deprecated and will be removed in - cdist 2.1). + Either "present" or "absent", defaults to "present" OPTIONAL PARAMETERS ------------------- name:: - Process name to match on when using pgrep -f -x. + Process name to match on when using pgrep -f -x. - This is useful, if the name starts with a "/", - because the leading slash is stripped away from - the object id by cdist. + This is useful, if the name starts with a "/", + because the leading slash is stripped away from + the object id by cdist. stop:: - Executable to use for stopping the process. + Executable to use for stopping the process. start:: - Executable to use for starting the process. + Executable to use for starting the process. EXAMPLES @@ -66,6 +64,7 @@ __process rpcstatd --state present --start "/etc/init.d/statd start" \ SEE ALSO -------- - cdist-type(7) +- cdist-type__start_on_boot(7) COPYING diff --git a/conf/type/__process/parameter/optional b/cdist/conf/type/__process/parameter/optional similarity index 100% rename from conf/type/__process/parameter/optional rename to cdist/conf/type/__process/parameter/optional diff --git a/conf/type/__package_pacman/parameter/required b/cdist/conf/type/__process/parameter/required similarity index 100% rename from conf/type/__package_pacman/parameter/required rename to cdist/conf/type/__process/parameter/required diff --git a/conf/type/__directory/explorer/exists b/cdist/conf/type/__qemu_img/explorer/exists similarity index 98% rename from conf/type/__directory/explorer/exists rename to cdist/conf/type/__qemu_img/explorer/exists index f8b85671..c80b1181 100755 --- a/conf/type/__directory/explorer/exists +++ b/cdist/conf/type/__qemu_img/explorer/exists @@ -25,6 +25,4 @@ destination="/$__object_id" if [ -e "$destination" ]; then echo yes -else - echo no fi diff --git a/cdist/conf/type/__qemu_img/gencode-remote b/cdist/conf/type/__qemu_img/gencode-remote new file mode 100644 index 00000000..e5ff1b4f --- /dev/null +++ b/cdist/conf/type/__qemu_img/gencode-remote @@ -0,0 +1,21 @@ +################################################################################ +# State: absent is handled by manifest - we need only to do stuff if image is +# not existing and state != absent +# +state="present" +[ -f "$__object/parameter/state" ] state="$(cat "$__object/parameter/state")" +[ "$state" = "absent" ] && exit 0 + +exists="$(cat "$__object/explorer/exists")" +[ "$exists" ] && exit 0 + +################################################################################ +# Still there? Create image +# + +format=qcow2 +[ -f "$__object/parameter/format" ] && format="$(cat "$__object/parameter/format")" +size="$(cat "$__object/parameter/size")" +diskimage="/$__object_id" + +echo qemu-img create -f \"$format\" \"$diskimage\" \"$size\" diff --git a/cdist/conf/type/__qemu_img/man.text b/cdist/conf/type/__qemu_img/man.text new file mode 100644 index 00000000..39188ab0 --- /dev/null +++ b/cdist/conf/type/__qemu_img/man.text @@ -0,0 +1,50 @@ +cdist-type__qemu_img(7) +======================== +Nico Schottelius + + +NAME +---- +cdist-type__qemu_img - Manage VM disk images + + +DESCRIPTION +----------- +The qemu-img program is used to create qemu images for +qemu and (qemu-)kvm. + + +REQUIRED PARAMETERS +------------------- +size:: + Size of the image in qemu-img compatible units. + See qemu-img(1). + + +OPTIONAL PARAMETERS +------------------- +state:: + Either "present" or "absent", defaults to "present" + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Create a 50G size image +__qemu_img /home/services/kvm/vm/myvmname/system-disk --size 50G + +# Remove image +__qemu_img /home/services/kvm/vm/myoldvm/system-disk --state absent +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2012 Nico Schottelius. 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/__qemu_img/manifest b/cdist/conf/type/__qemu_img/manifest new file mode 100644 index 00000000..b835301d --- /dev/null +++ b/cdist/conf/type/__qemu_img/manifest @@ -0,0 +1,15 @@ +################################################################################ +# Default settings +# + +format=qcow2 +state=present +[ -f "$__object/parameter/format" ] && format="$(cat "$__object/parameter/format")" +[ -f "$__object/parameter/state" ] && state="$(cat "$__object/parameter/state")" + +diskimage="/$__object_id" + +# Absent is ensured by __file, present by gencode-remote +if [ "$state" = "absent" ]; then + __file "$diskimage" --state absent +fi diff --git a/cdist/conf/type/__qemu_img/parameter/optional b/cdist/conf/type/__qemu_img/parameter/optional new file mode 100644 index 00000000..0e8469e7 --- /dev/null +++ b/cdist/conf/type/__qemu_img/parameter/optional @@ -0,0 +1 @@ +format diff --git a/cdist/conf/type/__qemu_img/parameter/required b/cdist/conf/type/__qemu_img/parameter/required new file mode 100644 index 00000000..2a613ba5 --- /dev/null +++ b/cdist/conf/type/__qemu_img/parameter/required @@ -0,0 +1 @@ +size diff --git a/cdist/conf/type/__rvm/explorer/state b/cdist/conf/type/__rvm/explorer/state new file mode 100755 index 00000000..f43f5509 --- /dev/null +++ b/cdist/conf/type/__rvm/explorer/state @@ -0,0 +1,36 @@ +#!/bin/sh +# +# 2012 Evax Software +# +# 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 . +# + +user="$__object_id" + +# RVM behaves differently if root is the username / uid == 0 +if [ "$user" = "root" ]; then + if [ -d /usr/local/rvm ]; then + echo present + else + echo absent + fi +else + if su - $user -c "[ -d \"\$HOME/.rvm\" ]" ; then + echo "present" + else + echo "absent" + fi +fi diff --git a/conf/type/__rvm/gencode-remote b/cdist/conf/type/__rvm/gencode-remote similarity index 64% rename from conf/type/__rvm/gencode-remote rename to cdist/conf/type/__rvm/gencode-remote index f306979a..dbc6ba60 100755 --- a/conf/type/__rvm/gencode-remote +++ b/cdist/conf/type/__rvm/gencode-remote @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Evax Software +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -21,19 +22,20 @@ user="$__object_id" state_is="$(cat "$__object/explorer/state")" state_should="$(cat "$__object/parameter/state")" -if [ "$state_is" != "$state_should" ]; then - case "$state_should" in - installed) - cat << DONE -su - $user -c "bash -s stable < <(curl -s \ -https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)" + +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + cat << DONE +su - $user -c "unset rvm_path; unset rvm_bin_path; unset rvm_prefix; unset rvm_version; curl -L get.rvm.io | bash -s stable" DONE - ;; - removed) - cat << DONE + ;; + absent) + cat << DONE su - $user -c "rm -Rf \"\\\$HOME/.rvm\"; -sed -i '/rvm\/scripts\/rvm/d' \"\\\$HOME/.bashrc\"" +sed '/rvm\/scripts\/rvm/d' \"\\\$HOME/.bashrc\" > \"\\\$HOME/.bashrc.cdist-tmp\" +mv \"\\\$HOME/.bashrc.cdist-tmp\" \"\\\$HOME/.bashrc\"" DONE - ;; - esac -fi + ;; +esac diff --git a/conf/type/__rvm/man.text b/cdist/conf/type/__rvm/man.text similarity index 89% rename from conf/type/__rvm/man.text rename to cdist/conf/type/__rvm/man.text index d54e2d1b..c1f83e60 100644 --- a/conf/type/__rvm/man.text +++ b/cdist/conf/type/__rvm/man.text @@ -16,7 +16,7 @@ RVM is the Ruby enVironment Manager for the Ruby programming language. REQUIRED PARAMETERS ------------------- state:: - Either "installed" or "removed". + Either "present" or "absent". EXAMPLES @@ -24,10 +24,10 @@ EXAMPLES -------------------------------------------------------------------------------- # Install rvm for user billie -__rvm billie --state installed +__rvm billie --state present # Remove rvm -__rvm billie --state removed +__rvm billie --state absent -------------------------------------------------------------------------------- diff --git a/conf/type/__rvm/manifest b/cdist/conf/type/__rvm/manifest similarity index 84% rename from conf/type/__rvm/manifest rename to cdist/conf/type/__rvm/manifest index 8e63a2c5..482c0d17 100755 --- a/conf/type/__rvm/manifest +++ b/cdist/conf/type/__rvm/manifest @@ -19,7 +19,7 @@ # # rvm core dependencies -__package bash --state installed -__package curl --state installed -__package git-core --state installed -__package patch --state installed +__package bash --state present +__package curl --state present +__package git-core --state present +__package patch --state present diff --git a/conf/type/__package_pip/parameter/required b/cdist/conf/type/__rvm/parameter/required similarity index 100% rename from conf/type/__package_pip/parameter/required rename to cdist/conf/type/__rvm/parameter/required diff --git a/conf/type/__rvm_gem/explorer/state b/cdist/conf/type/__rvm_gem/explorer/state similarity index 81% rename from conf/type/__rvm_gem/explorer/state rename to cdist/conf/type/__rvm_gem/explorer/state index b0232985..4146d666 100755 --- a/conf/type/__rvm_gem/explorer/state +++ b/cdist/conf/type/__rvm_gem/explorer/state @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Evax Software +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -24,16 +25,16 @@ ruby="$(echo "$gemset" | cut -d '@' -f 1)" gemsetname="$(echo "$gemset" | cut -d '@' -f2)" user="$(cat "$__object/parameter/user")" if su - "$user" -c "[ ! -d \"\$HOME/.rvm\" ]" ; then - echo "removed" + echo "absent" exit 0 fi if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\" rvm list | grep -q $ruby"; then if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\" -rvm use $ruby > /dev/null; rvm gemset list | grep -q $gemsetname && -rvm use $gemset > /dev/null && gem list | grep -q $gem"; then - echo "installed" +rvm use $ruby > /dev/null 2>&1; rvm gemset list | grep -q $gemsetname && +rvm use $gemset > /dev/null 2>&1 && gem list | grep -q $gem"; then + echo "present" exit 0 fi fi -echo "removed" +echo "absent" diff --git a/conf/type/__rvm_gem/gencode-remote b/cdist/conf/type/__rvm_gem/gencode-remote similarity index 71% rename from conf/type/__rvm_gem/gencode-remote rename to cdist/conf/type/__rvm_gem/gencode-remote index 80e1becf..1fe6e78e 100755 --- a/conf/type/__rvm_gem/gencode-remote +++ b/cdist/conf/type/__rvm_gem/gencode-remote @@ -1,6 +1,6 @@ -#!/bin/sh -# +#!/bin/sh # # 2012 Evax Software +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -25,19 +25,18 @@ gemsetname="$(echo "$gemset" | cut -d '@' -f 2)" state_is="$(cat "$__object/explorer/state")" user="$(cat "$__object/parameter/user")" state_should="$(cat "$__object/parameter/state")" -if [ "$state_is" != "$state_should" ]; then - case "$state_should" in - installed) - cat << DONE -su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\" -rvm use $gemset; gem install $gem" + +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + cat << DONE +su - "$user" -c 'source ~/.rvm/scripts/rvm; rvm use "$gemset"; gem install "$gem"' DONE - ;; - removed) - cat << DONE -su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\" -rvm use $gemset; gem uninstall $gem" + ;; + absent) + cat << DONE +su - "$user" -c 'source ~/.rvm/scripts/rvm; rvm use "$gemset"; gem uninstall "$gem"' DONE - ;; - esac -fi + ;; +esac diff --git a/conf/type/__rvm_gem/man.text b/cdist/conf/type/__rvm_gem/man.text similarity index 84% rename from conf/type/__rvm_gem/man.text rename to cdist/conf/type/__rvm_gem/man.text index 27b16053..2b72e7ae 100644 --- a/conf/type/__rvm_gem/man.text +++ b/cdist/conf/type/__rvm_gem/man.text @@ -16,30 +16,30 @@ RVM is the Ruby enVironment Manager for the Ruby programming language. REQUIRED PARAMETERS ------------------- user:: - The remote user account to use + The remote user account to use gemset:: - The gemset to use + The gemset to use state:: - Either "installed" or "removed". + Either "present" or "absent" OPTIONAL PARAMETERS ------------------- default:: - Make the selected gemset the default + Make the selected gemset the default EXAMPLES -------- -------------------------------------------------------------------------------- # Install the rails gem in gemset ruby-1.9.3-p0@myset for user bill -__rvm_gemset rails --gemset ruby-1.9.3-p0@myset --user bill --state installed +__rvm_gemset rails --gemset ruby-1.9.3-p0@myset --user bill --state present # Do the same and also make ruby-1.9.3-p0@myset the default gemset __rvm_gemset rails --gemset ruby-1.9.3-p0@myset --user bill \ - --state installed --default yes + --state present --default # Remove it -__rvm_ruby rails --gemset ruby-1.9.3-p0@myset --user bill --state removed +__rvm_ruby rails --gemset ruby-1.9.3-p0@myset --user bill --state absent -------------------------------------------------------------------------------- diff --git a/conf/type/__rvm_gem/parameter/optional b/cdist/conf/type/__rvm_gem/parameter/optional similarity index 100% rename from conf/type/__rvm_gem/parameter/optional rename to cdist/conf/type/__rvm_gem/parameter/optional diff --git a/conf/type/__rvm_gem/parameter/required b/cdist/conf/type/__rvm_gem/parameter/required similarity index 100% rename from conf/type/__rvm_gem/parameter/required rename to cdist/conf/type/__rvm_gem/parameter/required diff --git a/conf/type/__rvm_gemset/explorer/state b/cdist/conf/type/__rvm_gemset/explorer/state similarity index 71% rename from conf/type/__rvm_gemset/explorer/state rename to cdist/conf/type/__rvm_gemset/explorer/state index b33f570e..fa643a6e 100755 --- a/conf/type/__rvm_gemset/explorer/state +++ b/cdist/conf/type/__rvm_gemset/explorer/state @@ -22,16 +22,16 @@ gemset="$__object_id" ruby="$(echo "$gemset" | cut -d '@' -f 1)" gemsetname="$(echo "$gemset" | cut -d '@' -f2)" user="$(cat "$__object/parameter/user")" -if su - "$user" -c "[ ! -d \"\$HOME/.rvm\" ]" ; then - echo "removed" + +if [ ! -e "~$user/.rvm/scripts/rvm" ] ; then + echo "absent" exit 0 fi -if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\" -rvm list | grep -q $ruby"; then - if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\" -rvm use $ruby > /dev/null; rvm gemset list | grep -q $gemsetname"; then - echo "installed" + +if su - "$user" -c 'source ~/.rvm/scripts/rvm; rvm list strings | grep -q "^$ruby\$"'; then + if su - "$user" -c 'source ~/.rvm/scripts/rvm; rvm use "$ruby" > /dev/null; rvm gemset list strings | cut -f 1 -d " " | grep -q "^$gemsetname\$"'; then + echo "present" exit 0 fi fi -echo "removed" +echo "absent" diff --git a/conf/type/__rvm_gemset/gencode-remote b/cdist/conf/type/__rvm_gemset/gencode-remote similarity index 60% rename from conf/type/__rvm_gemset/gencode-remote rename to cdist/conf/type/__rvm_gemset/gencode-remote index 0e240462..f0c0052b 100755 --- a/conf/type/__rvm_gemset/gencode-remote +++ b/cdist/conf/type/__rvm_gemset/gencode-remote @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Evax Software +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -23,31 +24,25 @@ ruby="$(echo "$gemset" | cut -d '@' -f 1)" gemsetname="$(echo "$gemset" | cut -d '@' -f 2)" state_is="$(cat "$__object/explorer/state")" user="$(cat "$__object/parameter/user")" -default="$(cat "$__object/parameter/default")" state_should="$(cat "$__object/parameter/state")" -if [ "$state_is" != "$state_should" ]; then - case "$state_should" in - installed) - cat << DONE -su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\" -rvm $gemset --create" + +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + cat << DONE +su - "$user" -c "source ~/.rvm/scripts/rvm; rvm $gemset --create" DONE - case "$default" in - no) - ;; - *) - cat << DONE -su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\" -rvm use --default $gemset" + if -f "$__object/parameter/default"; then + cat << DONE +su - "$user" -c "source ~/.rvm/scripts/rvm; rvm use --default $gemset" DONE - ;; - esac - ;; - removed) - cat << DONE -su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\" -rvm use $ruby; rvm --force gemset delete $gemsetname" + fi + + ;; + absent) + cat << DONE +su - "$user" -c "source ~/.rvm/scripts/rvm; rvm use $ruby; rvm --force gemset delete $gemsetname" DONE - ;; - esac -fi + ;; +esac diff --git a/conf/type/__rvm_gemset/man.text b/cdist/conf/type/__rvm_gemset/man.text similarity index 71% rename from conf/type/__rvm_gemset/man.text rename to cdist/conf/type/__rvm_gemset/man.text index f1e3f2bf..44c0c555 100644 --- a/conf/type/__rvm_gemset/man.text +++ b/cdist/conf/type/__rvm_gemset/man.text @@ -16,27 +16,28 @@ RVM is the Ruby enVironment Manager for the Ruby programming language. REQUIRED PARAMETERS ------------------- user:: - The remote user account to use + The remote user account to use state:: - Either "installed" or "removed". + Either "present" or "absent". -OPTIONAL PARAMETERS +BOOLEAN PARAMETERS ------------------- default:: - If set to anything but "no" (the default), set the given gemset as default. + If present, set the given gemset as default. + EXAMPLES -------- -------------------------------------------------------------------------------- # Install the gemset @myset for user charles on based on ruby-1.9.3-0 -__rvm_gemset ruby-1.9.3-p0@myset --user charles --state installed +__rvm_gemset ruby-1.9.3-p0@myset --user charles --state present # Do the same and make ruby-1.9.3-p0@myset the default gemset -__rvm_gemset ruby-1.9.3-p0@myset --user charles --state installed --default yes +__rvm_gemset ruby-1.9.3-p0@myset --user charles --state present --default # Remove the gemset @myset for user john -__rvm_ruby ruby-1.9.3-p0@myset --user john --state removed +__rvm_ruby ruby-1.9.3-p0@myset --user john --state absent -------------------------------------------------------------------------------- diff --git a/conf/type/__rvm_gemset/parameter/optional b/cdist/conf/type/__rvm_gemset/parameter/boolean similarity index 100% rename from conf/type/__rvm_gemset/parameter/optional rename to cdist/conf/type/__rvm_gemset/parameter/boolean diff --git a/conf/type/__rvm_gemset/parameter/required b/cdist/conf/type/__rvm_gemset/parameter/required similarity index 100% rename from conf/type/__rvm_gemset/parameter/required rename to cdist/conf/type/__rvm_gemset/parameter/required diff --git a/conf/type/__rvm_ruby/explorer/state b/cdist/conf/type/__rvm_ruby/explorer/state similarity index 94% rename from conf/type/__rvm_ruby/explorer/state rename to cdist/conf/type/__rvm_ruby/explorer/state index 71d682be..43dafd4f 100755 --- a/conf/type/__rvm_ruby/explorer/state +++ b/cdist/conf/type/__rvm_ruby/explorer/state @@ -21,12 +21,12 @@ ruby="$__object_id" user="$(cat "$__object/parameter/user")" if su - "$user" -c "[ ! -d \"\$HOME/.rvm\" ]" ; then - echo "removed" + echo "absent" exit 0 fi if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\" rvm list | grep -q $ruby"; then - echo "installed" + echo "present" else - echo "removed" + echo "absent" fi diff --git a/conf/type/__rvm_ruby/gencode-remote b/cdist/conf/type/__rvm_ruby/gencode-remote similarity index 56% rename from conf/type/__rvm_ruby/gencode-remote rename to cdist/conf/type/__rvm_ruby/gencode-remote index a3bcf318..f1de3906 100755 --- a/conf/type/__rvm_ruby/gencode-remote +++ b/cdist/conf/type/__rvm_ruby/gencode-remote @@ -21,25 +21,27 @@ ruby="$__object_id" state_is="$(cat "$__object/explorer/state")" user="$(cat "$__object/parameter/user")" -default="$(cat "$__object/parameter/default")" +default="$(cat "$__object/parameter/default" 2>/dev/null || true)" state_should="$(cat "$__object/parameter/state")" -if [ "$state_is" != "$state_should" ]; then - case "$state_should" in - installed) - echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\ - "rvm install $ruby\"" - case "$default" in - no) - ;; - *) - echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\ - "rvm use --default $ruby\"" - ;; - esac - ;; - removed) - echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\ - "rvm remove $ruby\"" - ;; - esac -fi + +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\ + "rvm install $ruby\"" + if [ -f "$__object/parameter/default" ]; then + echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\ + "rvm use --default $ruby\"" + fi + ;; + absent) + echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\ + "rvm remove $ruby\"" + ;; + + *) + echo "Unknown state $state_should" >&2 + exit 1 + ;; +esac diff --git a/conf/type/__rvm_ruby/man.text b/cdist/conf/type/__rvm_ruby/man.text similarity index 71% rename from conf/type/__rvm_ruby/man.text rename to cdist/conf/type/__rvm_ruby/man.text index c3183a7b..dbbab85e 100644 --- a/conf/type/__rvm_ruby/man.text +++ b/cdist/conf/type/__rvm_ruby/man.text @@ -16,27 +16,27 @@ RVM is the Ruby enVironment Manager for the Ruby programming language. REQUIRED PARAMETERS ------------------- user:: - The remote user account to use + The remote user account to use state:: - Either "installed" or "removed". + Either "present" or "absent". -OPTIONAL PARAMETERS -------------------- +BOOLEAN PARAMETERS +------------------ default: - If set to anything but "no" (the default), set the given version as default + Set the given version as default EXAMPLES -------- -------------------------------------------------------------------------------- # Install ruby 1.9.3 through rvm for user thelonious -__rvm_ruby ruby-1.9.3-p0 --user thelonious --state installed +__rvm_ruby ruby-1.9.3-p0 --user thelonious --state present # Install ruby 1.9.3 through rvm for user ornette and make it the default -__rvm_ruby ruby-1.9.3-p0 --user ornette --state installed --default yes +__rvm_ruby ruby-1.9.3-p0 --user ornette --state present --default # Remove ruby 1.9.3 for user john -__rvm_ruby ruby-1.9.3-p0 --user john --state removed +__rvm_ruby ruby-1.9.3-p0 --user john --state absent -------------------------------------------------------------------------------- diff --git a/conf/type/__link/manifest b/cdist/conf/type/__rvm_ruby/manifest similarity index 79% rename from conf/type/__link/manifest rename to cdist/conf/type/__rvm_ruby/manifest index 6b5e1ca7..db8fd830 100755 --- a/conf/type/__link/manifest +++ b/cdist/conf/type/__rvm_ruby/manifest @@ -1,6 +1,5 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. @@ -18,7 +17,9 @@ # You should have received a copy of the GNU General Public License # along with cdist. If not, see . # +# -# set default: present, if not setup -statefile="$__object/parameter/state" -[ -f "$statefile" ] || echo present > "$statefile" +# Required packages for building ruby +for package in bzip2 gcc make; do + __package "$package" --state present +done diff --git a/conf/type/__rvm_ruby/parameter/optional b/cdist/conf/type/__rvm_ruby/parameter/boolean similarity index 100% rename from conf/type/__rvm_ruby/parameter/optional rename to cdist/conf/type/__rvm_ruby/parameter/boolean diff --git a/conf/type/__rvm_ruby/parameter/required b/cdist/conf/type/__rvm_ruby/parameter/required similarity index 100% rename from conf/type/__rvm_ruby/parameter/required rename to cdist/conf/type/__rvm_ruby/parameter/required diff --git a/cdist/conf/type/__ssh_authorized_key/explorer/dstuser_group b/cdist/conf/type/__ssh_authorized_key/explorer/dstuser_group new file mode 100644 index 00000000..c79f8d9f --- /dev/null +++ b/cdist/conf/type/__ssh_authorized_key/explorer/dstuser_group @@ -0,0 +1,15 @@ +#!/bin/sh + +# Get option dstuser if defined +if [ -f "$__object/parameter/dstuser" ]; then + dstuser=`cat "$__object/parameter/dstuser"` +else + dstuser="root" +fi + +if id $dstuser >/dev/null 2>&1 ; then + id -ng $dstuser +else + echo "$__object_id: Destination user $dstuser does not exist" >&2 + exit 1 +fi diff --git a/conf/type/__ssh_authorized_key/man.text b/cdist/conf/type/__ssh_authorized_key/man.text similarity index 94% rename from conf/type/__ssh_authorized_key/man.text rename to cdist/conf/type/__ssh_authorized_key/man.text index af0c2017..b372b354 100644 --- a/conf/type/__ssh_authorized_key/man.text +++ b/cdist/conf/type/__ssh_authorized_key/man.text @@ -1,6 +1,6 @@ cdist-type__ssh_authorized_key(7) ================================= -Aurélien Bondis - aurelien.bondis AT gmail DOT com +Aurélien Bondis NAME diff --git a/conf/type/__ssh_authorized_key/manifest b/cdist/conf/type/__ssh_authorized_key/manifest similarity index 82% rename from conf/type/__ssh_authorized_key/manifest rename to cdist/conf/type/__ssh_authorized_key/manifest index efadc3f6..86c58740 100755 --- a/conf/type/__ssh_authorized_key/manifest +++ b/cdist/conf/type/__ssh_authorized_key/manifest @@ -21,7 +21,7 @@ # This type allows to send a public ssh key from a user to the # authorized_keys of another # -#require="__package openssh-server --state installed" +#require="__package openssh-server --state present" # Get option srcuser if defined if [ -f "$__object/parameter/srcuser" ]; then srcuser=`cat "$__object/parameter/srcuser"` @@ -29,8 +29,13 @@ fi # Get option dstuser if defined if [ -f "$__object/parameter/dstuser" ]; then dstuser=`cat "$__object/parameter/dstuser"` +else + dstuser="root" fi +# retrieve destination group +dstgroup=$(cat "$__object/explorer/dstuser_group") + # if a source user is defined, use it's public key if [ "$srcuser" ]; then srcrsa="/home/${srcuser}/.ssh/id_rsa.pub" @@ -46,10 +51,16 @@ else sshpath="/root/.ssh" fi rsa=`cat $srcrsa` -__directory $sshpath +__directory $sshpath \ + --owner $dstuser \ + --group $dstgroup \ + --mode 700 # the file authorized_keys depends on the .ssh folder -require="__directory${sshpath}" __file "$sshpath/authorized_keys" --mode 640 +require="__directory${sshpath}" \ + __file "$sshpath/authorized_keys" \ + --mode 640 \ + --owner $dstuser \ + --group $dstgroup # the line added depends on authorized_keys existence require="__file${sshpath}/authorized_keys" __addifnosuchline sshkey --file \ "$sshpath/authorized_keys" --line "$rsa" - diff --git a/conf/type/__ssh_authorized_key/parameter/optional b/cdist/conf/type/__ssh_authorized_key/parameter/optional similarity index 100% rename from conf/type/__ssh_authorized_key/parameter/optional rename to cdist/conf/type/__ssh_authorized_key/parameter/optional diff --git a/conf/type/__start_on_boot/explorer/state b/cdist/conf/type/__start_on_boot/explorer/state similarity index 97% rename from conf/type/__start_on_boot/explorer/state rename to cdist/conf/type/__start_on_boot/explorer/state index bf24738a..6fd0ea92 100755 --- a/conf/type/__start_on_boot/explorer/state +++ b/cdist/conf/type/__start_on_boot/explorer/state @@ -49,7 +49,7 @@ case "$os" in [ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent" ;; - amazon|centos|fedora|owl|redhat) + amazon|centos|fedora|owl|redhat|suse) state=$(chkconfig --level "$runlevel" "$name" || echo absent) [ "$state" ] || state="present" ;; diff --git a/conf/type/__start_on_boot/gencode-remote b/cdist/conf/type/__start_on_boot/gencode-remote similarity index 78% rename from conf/type/__start_on_boot/gencode-remote rename to cdist/conf/type/__start_on_boot/gencode-remote index cefdc385..7724e8c7 100755 --- a/conf/type/__start_on_boot/gencode-remote +++ b/cdist/conf/type/__start_on_boot/gencode-remote @@ -19,10 +19,10 @@ # # -state_should="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo present)" state_is=$(cat "$__object/explorer/state") -# Nothing todo, go away +# Short circuit if nothing is to be done [ "$state_should" = "$state_is" ] && exit 0 os=$(cat "$__global/explorer/os") @@ -32,7 +32,8 @@ case "$state_should" in present) case "$os" in archlinux) - echo "sed -i /etc/rc.conf \'s/^\\(DAEMONS=.*\\))/\\1 $name)/\'" + echo "sed 's/^\\(DAEMONS=.*\\))/\\1 $name)/' /etc/rc.conf > /etc/rc.conf.cdist-tmp" + echo "mv /etc/rc.conf.cdist-tmp /etc/rc.conf" ;; debian|ubuntu) echo "update-rc.d \"$name\" defaults >/dev/null" @@ -43,7 +44,7 @@ case "$state_should" in # echo rc-update add \"$name\" default # ;; - centos|fedora|owl|redhat) + amazon|centos|fedora|owl|redhat|suse) echo chkconfig \"$name\" on ;; @@ -66,7 +67,8 @@ case "$state_should" in archlinux) # Replace a) at the beginning b) in the middle c) end d) only # Support @name as well...makes it more ugly, but well... - echo "sed -i /etc/rc.conf -e 's/^\\(DAEMONS=(\\)@\\{0,1\\}$name /\\1/' -e 's/^\\(DAEMONS=(.* \\)@\\{0,1\\}$name \\(.*\\)/\\1\\2/' -e 's/^\\(DAEMONS=(.*\\) @\\{0,1\\}$name)/\\1)/' -e 's/^\\(DAEMONS=(\\)@\\{0,1\\}$name)/\\1)/'" + echo "sed /etc/rc.conf -e 's/^\\(DAEMONS=(\\)@\\{0,1\\}$name /\\1/' -e 's/^\\(DAEMONS=(.* \\)@\\{0,1\\}$name \\(.*\\)/\\1\\2/' -e 's/^\\(DAEMONS=(.*\\) @\\{0,1\\}$name)/\\1)/' -e 's/^\\(DAEMONS=(\\)@\\{0,1\\}$name)/\\1)/' > /etc/rc.conf.cdist-tmp" + echo "mv /etc/rc.conf.cdist-tmp /etc/rc.conf" ;; debian|ubuntu) echo update-rc.d -f \"$name\" remove @@ -77,7 +79,7 @@ case "$state_should" in # echo rc-update del \"$name\" # ;; - centos|fedora|owl|redhat) + centos|fedora|owl|redhat|suse) echo chkconfig \"$name\" off ;; diff --git a/conf/type/__start_on_boot/man.text b/cdist/conf/type/__start_on_boot/man.text similarity index 93% rename from conf/type/__start_on_boot/man.text rename to cdist/conf/type/__start_on_boot/man.text index 0e75c9ab..6d804884 100644 --- a/conf/type/__start_on_boot/man.text +++ b/cdist/conf/type/__start_on_boot/man.text @@ -24,7 +24,7 @@ None. OPTIONAL PARAMETERS ------------------- state:: - 'present' or 'absent', defaults to 'present' + Either "present" or "absent", defaults to "present" EXAMPLES @@ -45,6 +45,7 @@ __start_on_boot puppet --state absent SEE ALSO -------- - cdist-type(7) +- cdist-type__process(7) COPYING diff --git a/conf/type/__start_on_boot/parameter/optional b/cdist/conf/type/__start_on_boot/parameter/optional similarity index 100% rename from conf/type/__start_on_boot/parameter/optional rename to cdist/conf/type/__start_on_boot/parameter/optional diff --git a/conf/type/__timezone/manifest b/cdist/conf/type/__timezone/gencode-remote similarity index 78% rename from conf/type/__timezone/manifest rename to cdist/conf/type/__timezone/gencode-remote index b0bae209..b4782d4b 100755 --- a/conf/type/__timezone/manifest +++ b/cdist/conf/type/__timezone/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Ramon Salvadó (rsalvado at gnuine dot com) +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -21,8 +21,10 @@ # This type allows to configure the desired localtime timezone. timezone="$__object_id" +os=$(cat "$__global/explorer/os") -__package tzdata --state installed -require="__package/tzdata" __link /etc/localtime \ - --source "/usr/share/zoneinfo/${timezone}" \ - --type symbolic +case "$os" in + ubuntu|debian) + echo "echo \"$timezone\" > /etc/timezone" + ;; +esac diff --git a/conf/type/__timezone/man.text b/cdist/conf/type/__timezone/man.text similarity index 94% rename from conf/type/__timezone/man.text rename to cdist/conf/type/__timezone/man.text index 89136855..6f0c5101 100644 --- a/conf/type/__timezone/man.text +++ b/cdist/conf/type/__timezone/man.text @@ -1,6 +1,6 @@ cdist-type__timezone(7) ======================= -Ramon Salvadó - rsalvado at gnuine dot com +Ramon Salvadó NAME diff --git a/cdist/conf/type/__timezone/manifest b/cdist/conf/type/__timezone/manifest new file mode 100755 index 00000000..81de0217 --- /dev/null +++ b/cdist/conf/type/__timezone/manifest @@ -0,0 +1,39 @@ +#!/bin/sh +# +# 2011 Ramon Salvadó (rsalvado at gnuine dot com) +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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 . +# +# +# This type allows to configure the desired localtime timezone. + +timezone="$__object_id" +os=$(cat "$__global/explorer/os") + +case "$os" in + archlinux|debian|ubuntu) + __package tzdata --state present + require="__package/tzdata" __link /etc/localtime \ + --source "/usr/share/zoneinfo/${timezone}" \ + --type symbolic + ;; + *) + echo "Unsupported OS $os" >&2 + exit 1 + ;; +esac diff --git a/conf/type/__user/TODO b/cdist/conf/type/__user/TODO similarity index 100% rename from conf/type/__user/TODO rename to cdist/conf/type/__user/TODO diff --git a/conf/type/__user/explorer/group b/cdist/conf/type/__user/explorer/group similarity index 100% rename from conf/type/__user/explorer/group rename to cdist/conf/type/__user/explorer/group diff --git a/conf/type/__user/explorer/passwd b/cdist/conf/type/__user/explorer/passwd similarity index 100% rename from conf/type/__user/explorer/passwd rename to cdist/conf/type/__user/explorer/passwd diff --git a/conf/type/__user/explorer/shadow b/cdist/conf/type/__user/explorer/shadow similarity index 82% rename from conf/type/__user/explorer/shadow rename to cdist/conf/type/__user/explorer/shadow index c75e36f4..a949ec51 100755 --- a/conf/type/__user/explorer/shadow +++ b/cdist/conf/type/__user/explorer/shadow @@ -22,6 +22,13 @@ # name=$__object_id +os="$($__explorer/os)" +# Default to using shadow passwords +database="shadow" -getent shadow "$name" || true +if [ "$os" = "freebsd" ]; then + database="passwd" +fi + +getent "$database" "$name" || true diff --git a/conf/type/__user/gencode-remote b/cdist/conf/type/__user/gencode-remote similarity index 75% rename from conf/type/__user/gencode-remote rename to cdist/conf/type/__user/gencode-remote index 8979c56e..baa6f354 100755 --- a/conf/type/__user/gencode-remote +++ b/cdist/conf/type/__user/gencode-remote @@ -24,6 +24,25 @@ name="$__object_id" +os="$(cat "$__global/explorer/os")" + +# We need to shorten options for both usermod and useradd since on some +# systems (such as *BSD, Darwin) those commands do not handle GNU style long +# options. +shorten_property() { + unset ret + case "$1" in + comment) ret="-c";; + home) ret="-d";; + gid) ret="-g";; + groups) ret="-G";; + password) ret="-p";; + shell) ret="-s";; + uid) ret="-u";; + esac + echo "$ret" +} + cd "$__object/parameter" if grep -q "^${name}:" "$__object/explorer/passwd"; then for property in $(ls .); do @@ -67,20 +86,28 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then fi if [ "$new_value" != "$current_value" ]; then - set -- "$@" "--$property" \'$new_value\' + set -- "$@" "$(shorten_property $property)" \'$new_value\' fi done if [ $# -gt 0 ]; then - echo usermod "$@" "$name" + if [ "$os" = "freebsd" ]; then + echo pw usermod "$@" "$name" + else + echo usermod "$@" "$name" + fi else true fi else for property in $(ls .); do new_value="$(cat "$property")" - set -- "$@" "--$property" \'$new_value\' + set -- "$@" "$(shorten_property $property)" \'$new_value\' done - echo useradd "$@" "$name" + if [ "$os" = "freebsd" ]; then + echo pw useradd "$@" "$name" + else + echo useradd "$@" "$name" + fi fi diff --git a/conf/type/__user/man.text b/cdist/conf/type/__user/man.text similarity index 97% rename from conf/type/__user/man.text rename to cdist/conf/type/__user/man.text index e571c7c5..9db4a9f0 100644 --- a/conf/type/__user/man.text +++ b/cdist/conf/type/__user/man.text @@ -26,8 +26,6 @@ home:: see above gid:: see above -groups:: - see above password:: see above shell:: @@ -54,6 +52,7 @@ __user foobar --uid 1001 --shell /bin/zsh --home /home/foobar SEE ALSO -------- - cdist-type(7) +- usermod(8) or pw(8) COPYING diff --git a/conf/type/__user/parameter/optional b/cdist/conf/type/__user/parameter/optional similarity index 83% rename from conf/type/__user/parameter/optional rename to cdist/conf/type/__user/parameter/optional index fe02e227..e3cf52d5 100644 --- a/conf/type/__user/parameter/optional +++ b/cdist/conf/type/__user/parameter/optional @@ -1,7 +1,6 @@ comment home gid -groups password shell uid diff --git a/cdist/conf/type/__user_groups/explorer/group b/cdist/conf/type/__user_groups/explorer/group new file mode 100755 index 00000000..a8cb63af --- /dev/null +++ b/cdist/conf/type/__user_groups/explorer/group @@ -0,0 +1,23 @@ +#!/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 . +# + +user="$(cat "$__object/parameter/user" 2>/dev/null || echo "$__object_id")" + +(id --groups --name "$user" | tr ' ' '\n' | sort) 2>/dev/null || true diff --git a/cdist/conf/type/__user_groups/gencode-remote b/cdist/conf/type/__user_groups/gencode-remote new file mode 100755 index 00000000..c5e4a35e --- /dev/null +++ b/cdist/conf/type/__user_groups/gencode-remote @@ -0,0 +1,46 @@ +#!/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 . +# + +user="$(cat "$__object/parameter/user" 2>/dev/null || echo "$__object_id")" +state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")" + +mkdir "$__object/files" +# file has to be sorted for comparison with `comm` +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="-a" + ;; + absent) + changed_groups="$(comm -12 "$__object/explorer/group" "$__object/files/group.sorted")" + action="-d" + ;; +esac + +if [ -z "$changed_groups" ]; then + # Nothing to do, move along + exit 0 +fi + +for group in $changed_groups; do + echo "gpasswd $action \"$user\" \"$group\"" +done diff --git a/cdist/conf/type/__user_groups/man.text b/cdist/conf/type/__user_groups/man.text new file mode 100644 index 00000000..d45784fe --- /dev/null +++ b/cdist/conf/type/__user_groups/man.text @@ -0,0 +1,52 @@ +cdist-type__user_groups(7) +========================== +Steven Armstrong + + +NAME +---- +cdist-type__user_groups - manage user groups + + +DESCRIPTION +----------- +Adds or removes a user from one or more groups. + + +REQUIRED PARAMETERS +------------------- +group:: + the group to which this user should be added or removed. + Can be specified multiple times. + + +OPTIONAL PARAMETERS +------------------- +user:: + the name of the user. Defaults to object_id + +state:: + absent or present. Defaults to present. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__user_groups nginx --group webuser1 --group webuser2 + +# remove user nginx from groups webuser2 +__user_groups nginx-webuser2 --user nginx \ + --group webuser2 --state absent +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2012 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/__user_groups/parameter/optional b/cdist/conf/type/__user_groups/parameter/optional new file mode 100644 index 00000000..7d9ecf60 --- /dev/null +++ b/cdist/conf/type/__user_groups/parameter/optional @@ -0,0 +1,2 @@ +user +state diff --git a/cdist/conf/type/__user_groups/parameter/required_multiple b/cdist/conf/type/__user_groups/parameter/required_multiple new file mode 100644 index 00000000..3a60ccec --- /dev/null +++ b/cdist/conf/type/__user_groups/parameter/required_multiple @@ -0,0 +1 @@ +group diff --git a/lib/cdist/config.py b/cdist/config.py similarity index 100% rename from lib/cdist/config.py rename to cdist/config.py diff --git a/lib/cdist/config_install.py b/cdist/config_install.py similarity index 95% rename from lib/cdist/config_install.py rename to cdist/config_install.py index 7cce240e..2c1edc44 100644 --- a/lib/cdist/config_install.py +++ b/cdist/config_install.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # -# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2010-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -48,9 +48,9 @@ class ConfigInstall(object): self.remote = context.remote # Initialise local directory structure - self.local.create_directories() + self.local.create_files_dirs() # Initialise remote directory structure - self.remote.create_directories() + self.remote.create_files_dirs() self.explorer = core.Explorer(self.context.target_host, self.local, self.remote) self.manifest = core.Manifest(self.context.target_host, self.local) @@ -79,7 +79,6 @@ class ConfigInstall(object): def stage_prepare(self): """Do everything for a deploy, minus the actual code stage""" - self.local.link_emulator(self.context.exec_path) self.explorer.run_global_explorers(self.local.global_explorer_out_path) self.manifest.run_initial_manifest(self.context.initial_manifest) @@ -141,7 +140,7 @@ class ConfigInstall(object): self.local.type_path) dependency_resolver = resolver.DependencyResolver(objects) - self.log.debug(pprint.pformat(dependency_resolver.graph)) + self.log.debug(pprint.pformat(dependency_resolver.dependencies)) for cdist_object in dependency_resolver: self.log.debug("Run object: %s", cdist_object) diff --git a/lib/cdist/context.py b/cdist/context.py similarity index 76% rename from lib/cdist/context.py rename to cdist/context.py index ab8677a7..767b17a8 100644 --- a/lib/cdist/context.py +++ b/cdist/context.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # -# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2010-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -35,27 +35,21 @@ class Context(object): def __init__(self, target_host, + remote_copy, + remote_exec, initial_manifest=False, - base_path=False, + add_conf_dirs=[], exec_path=sys.argv[0], debug=False): - self.debug = debug - + self.debug = debug self.target_host = target_host - - # Only required for testing self.exec_path = exec_path # Context logging self.log = logging.getLogger(self.target_host) self.log.addFilter(self) - # Local base directory - self.base_path = (base_path or - os.path.abspath(os.path.join(os.path.dirname(__file__), - os.pardir, os.pardir))) - # Local temp directory # FIXME: if __cdist_out_dir can be given from the outside, the same directory will be used for all hosts if '__cdist_out_dir' in os.environ: @@ -65,15 +59,23 @@ class Context(object): self.temp_dir = tempfile.mkdtemp() self.out_path = os.path.join(self.temp_dir, "out") - self.local = local.Local(self.target_host, self.base_path, self.out_path) + self.local = local.Local(self.target_host, self.out_path, self.exec_path, add_conf_dirs=add_conf_dirs) self.initial_manifest = (initial_manifest or os.path.join(self.local.manifest_path, "init")) - # Remote + self._init_remote(remote_copy, remote_exec) + + # Remote stuff + def _init_remote(self, remote_copy, remote_exec): + self.remote_base_path = os.environ.get('__cdist_remote_out_dir', "/var/lib/cdist") - self.remote_exec = os.environ.setdefault('__remote_exec', "ssh -o User=root -q") - self.remote_copy = os.environ.setdefault('__remote_copy', "scp -o User=root -q") + self.remote_copy = remote_copy + self.remote_exec = remote_exec + + os.environ['__remote_copy'] = self.remote_copy + os.environ['__remote_exec'] = self.remote_exec + self.remote = remote.Remote(self.target_host, self.remote_base_path, self.remote_exec, self.remote_copy) @@ -85,6 +87,6 @@ class Context(object): def filter(self, record): """Add hostname to logs via logging Filter""" - record.msg = self.target_host + ": " + record.msg + record.msg = self.target_host + ": " + str(record.msg) return True diff --git a/lib/cdist/core/__init__.py b/cdist/core/__init__.py similarity index 100% rename from lib/cdist/core/__init__.py rename to cdist/core/__init__.py diff --git a/lib/cdist/core/cdist_object.py b/cdist/core/cdist_object.py similarity index 96% rename from lib/cdist/core/cdist_object.py rename to cdist/core/cdist_object.py index e12bcfbd..7e587bf3 100644 --- a/lib/cdist/core/cdist_object.py +++ b/cdist/core/cdist_object.py @@ -186,6 +186,9 @@ class CdistObject(object): return os.path.join(self.path, "explorer") requirements = fsproperty.FileListProperty(lambda obj: os.path.join(obj.absolute_path, 'require')) + before = fsproperty.FileListProperty(lambda obj: os.path.join(obj.absolute_path, 'before')) + after = fsproperty.FileListProperty(lambda obj: os.path.join(obj.absolute_path, 'after')) + autorequire = fsproperty.FileListProperty(lambda obj: os.path.join(obj.absolute_path, 'autorequire')) parameters = fsproperty.DirectoryDictProperty(lambda obj: os.path.join(obj.base_path, obj.parameter_path)) explorers = fsproperty.DirectoryDictProperty(lambda obj: os.path.join(obj.base_path, obj.explorer_path)) changed = fsproperty.FileBooleanProperty(lambda obj: os.path.join(obj.absolute_path, "changed")) diff --git a/lib/cdist/core/cdist_type.py b/cdist/core/cdist_type.py similarity index 80% rename from lib/cdist/core/cdist_type.py rename to cdist/core/cdist_type.py index 1d2472c4..44e192fc 100644 --- a/lib/cdist/core/cdist_type.py +++ b/cdist/core/cdist_type.py @@ -24,7 +24,6 @@ import os import cdist - class NoSuchTypeError(cdist.Error): def __init__(self, type_path, type_absolute_path): self.type_path = type_path @@ -81,7 +80,9 @@ class CdistType(object): self.__explorers = None self.__required_parameters = None + self.__required_multiple_parameters = None self.__optional_parameters = None + self.__optional_multiple_parameters = None self.__boolean_parameters = None def __repr__(self): @@ -130,6 +131,22 @@ class CdistType(object): self.__required_parameters = parameters return self.__required_parameters + @property + def required_multiple_parameters(self): + """Return a list of required multiple parameters""" + if not self.__required_multiple_parameters: + parameters = [] + try: + with open(os.path.join(self.absolute_path, "parameter", "required_multiple")) as fd: + for line in fd: + parameters.append(line.strip()) + except EnvironmentError: + # error ignored + pass + finally: + self.__required_multiple_parameters = parameters + return self.__required_multiple_parameters + @property def optional_parameters(self): """Return a list of optional parameters""" @@ -146,6 +163,22 @@ class CdistType(object): self.__optional_parameters = parameters return self.__optional_parameters + @property + def optional_multiple_parameters(self): + """Return a list of optional multiple parameters""" + if not self.__optional_multiple_parameters: + parameters = [] + try: + with open(os.path.join(self.absolute_path, "parameter", "optional_multiple")) as fd: + for line in fd: + parameters.append(line.strip()) + except EnvironmentError: + # error ignored + pass + finally: + self.__optional_multiple_parameters = parameters + return self.__optional_multiple_parameters + @property def boolean_parameters(self): """Return a list of boolean parameters""" diff --git a/lib/cdist/core/code.py b/cdist/core/code.py similarity index 99% rename from lib/cdist/core/code.py rename to cdist/core/code.py index 2ffef9cf..fa1ed3c1 100644 --- a/lib/cdist/core/code.py +++ b/cdist/core/code.py @@ -103,7 +103,6 @@ class Code(object): '__object': cdist_object.absolute_path, '__object_id': cdist_object.object_id, '__object_name': cdist_object.name, - '__self': cdist_object.name, }) return self.local.run_script(script, env=env, return_output=True) diff --git a/lib/cdist/core/explorer.py b/cdist/core/explorer.py similarity index 96% rename from lib/cdist/core/explorer.py rename to cdist/core/explorer.py index d49b7ac4..86ce52ac 100644 --- a/lib/cdist/core/explorer.py +++ b/cdist/core/explorer.py @@ -98,6 +98,7 @@ class Explorer(object): """Transfer the global explorers to the remote side.""" self.remote.mkdir(self.remote.global_explorer_path) self.remote.transfer(self.local.global_explorer_path, self.remote.global_explorer_path) + self.remote.run(["chmod", "0700", "%s/*" % (self.remote.global_explorer_path)]) def run_global_explorer(self, explorer): """Run the given global explorer and return it's output.""" @@ -135,6 +136,7 @@ class Explorer(object): env.update({ '__object': os.path.join(self.remote.object_path, cdist_object.path), '__object_id': cdist_object.object_id, + '__object_name': cdist_object.name, '__object_fq': cdist_object.path, '__type_explorer': os.path.join(self.remote.type_path, cdist_type.explorer_path) }) @@ -151,6 +153,7 @@ class Explorer(object): destination = os.path.join(self.remote.type_path, cdist_type.explorer_path) self.remote.mkdir(destination) self.remote.transfer(source, destination) + self.remote.run(["chmod", "0700", "%s" % (destination)]) self._type_explorers_transferred.append(cdist_type.name) def transfer_object_parameters(self, cdist_object): diff --git a/lib/cdist/core/manifest.py b/cdist/core/manifest.py similarity index 53% rename from lib/cdist/core/manifest.py rename to cdist/core/manifest.py index 8b784229..19639618 100644 --- a/lib/cdist/core/manifest.py +++ b/cdist/core/manifest.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -57,6 +57,29 @@ type manifeste is: creates: new objects through type emulator ''' +class NoInitialManifestError(cdist.Error): + """ + Display missing initial manifest: + - Display path if user given + - try to resolve link if it is a link + - Omit path if default (is a linked path in temp directory without + much help) + """ + + def __init__(self, manifest_path, user_supplied): + msg_header = "Initial manifest missing" + + if user_supplied: + if os.path.islink(manifest_path): + self.message = "%s: %s -> %s" % (msg_header, manifest_path, os.path.realpath(manifest_path)) + else: + self.message = "%s: %s" % (msg_header, manifest_path) + else: + self.message = "%s" % (msg_header) + + def __str__(self): + return repr(self.message) + class Manifest(object): """Executes cdist manifests. @@ -70,33 +93,52 @@ class Manifest(object): self.env = { 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), - '__target_host': self.target_host, - '__global': self.local.out_path, '__cdist_type_base_path': self.local.type_path, # for use in type emulator + '__global': self.local.out_path, + '__target_host': self.target_host, } if self.log.getEffectiveLevel() == logging.DEBUG: self.env.update({'__cdist_debug': "yes" }) - def run_initial_manifest(self, script): + def env_initial_manifest(self, initial_manifest): env = os.environ.copy() env.update(self.env) + env['__cdist_manifest'] = initial_manifest env['__manifest'] = self.local.manifest_path - env['__cdist_manifest'] = script - self.log.info("Running initial manifest " + self.local.manifest_path) - self.local.run_script(script, env=env) + + return env + + def run_initial_manifest(self, initial_manifest=None): + if not initial_manifest: + initial_manifest = self.local.initial_manifest + user_supplied = False + else: + user_supplied = True + + self.log.info("Running initial manifest " + initial_manifest) + + if not os.path.isfile(initial_manifest): + raise NoInitialManifestError(initial_manifest, user_supplied) + + self.local.run_script(initial_manifest, env=self.env_initial_manifest(initial_manifest)) + + def env_type_manifest(self, cdist_object): + type_manifest = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path) + env = os.environ.copy() + env.update(self.env) + env.update({ + '__cdist_manifest': type_manifest, + '__manifest': self.local.manifest_path, + '__object': cdist_object.absolute_path, + '__object_id': cdist_object.object_id, + '__object_name': cdist_object.name, + '__type': cdist_object.cdist_type.absolute_path, + }) + + return env def run_type_manifest(self, cdist_object): - script = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path) - if os.path.isfile(script): - env = os.environ.copy() - env.update(self.env) - env.update({ - '__object': cdist_object.absolute_path, - '__object_id': cdist_object.object_id, - '__object_name': cdist_object.name, - '__self': cdist_object.name, - '__type': cdist_object.cdist_type.absolute_path, - '__cdist_manifest': script, - }) - self.local.run_script(script, env=env) + type_manifest = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path) + if os.path.isfile(type_manifest): + self.local.run_script(type_manifest, env=self.env_type_manifest(cdist_object)) diff --git a/lib/cdist/emulator.py b/cdist/emulator.py similarity index 57% rename from lib/cdist/emulator.py rename to cdist/emulator.py index c4b84feb..bd3661d3 100644 --- a/lib/cdist/emulator.py +++ b/cdist/emulator.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -22,21 +23,26 @@ import argparse import logging import os +import warnings +import sys import cdist from cdist import core class Emulator(object): - def __init__(self, argv): + def __init__(self, argv, stdin=sys.stdin.buffer, env=os.environ): self.argv = argv + self.stdin = stdin + self.env = env + self.object_id = False - self.global_path = os.environ['__global'] - self.target_host = os.environ['__target_host'] + self.global_path = self.env['__global'] + self.target_host = self.env['__target_host'] # Internally only - self.object_source = os.environ['__cdist_manifest'] - self.type_base_path = os.environ['__cdist_type_base_path'] + self.object_source = self.env['__cdist_manifest'] + self.type_base_path = self.env['__cdist_type_base_path'] self.object_base_path = os.path.join(self.global_path, "object") @@ -60,13 +66,14 @@ class Emulator(object): def run(self): """Emulate type commands (i.e. __file and co)""" - if '__install' in os.environ: + if '__install' in self.env: if not self.cdist_type.is_install: self.log.debug("Running in install mode, ignoring non install type") return True self.commandline() self.setup_object() + self.save_stdin() self.record_requirements() self.record_auto_requirements() self.log.debug("Finished %s %s" % (self.cdist_object.path, self.parameters)) @@ -76,7 +83,7 @@ class Emulator(object): logformat = '%(levelname)s: %(message)s' logging.basicConfig(format=logformat) - if '__cdist_debug' in os.environ: + if '__cdist_debug' in self.env: logging.root.setLevel(logging.DEBUG) else: logging.root.setLevel(logging.INFO) @@ -86,15 +93,25 @@ class Emulator(object): def commandline(self): """Parse command line""" + self.meta_parameters = dict.fromkeys(('after', 'before')) + meta_parser = argparse.ArgumentParser(add_help=False) + for meta_parameter in self.meta_parameters.keys(): + meta_parser.add_argument('--%s' % meta_parameter, action='append', required=False) - parser = argparse.ArgumentParser(add_help=False, argument_default=argparse.SUPPRESS) + parser = argparse.ArgumentParser(add_help=False, parents=[meta_parser], argument_default=argparse.SUPPRESS) - for parameter in self.cdist_type.optional_parameters: - argument = "--" + parameter - parser.add_argument(argument, dest=parameter, action='store', required=False) for parameter in self.cdist_type.required_parameters: argument = "--" + parameter parser.add_argument(argument, dest=parameter, action='store', required=True) + for parameter in self.cdist_type.required_multiple_parameters: + argument = "--" + parameter + parser.add_argument(argument, dest=parameter, action='append', required=True) + for parameter in self.cdist_type.optional_parameters: + argument = "--" + parameter + parser.add_argument(argument, dest=parameter, action='store', required=False) + for parameter in self.cdist_type.optional_multiple_parameters: + argument = "--" + parameter + parser.add_argument(argument, dest=parameter, action='append', required=False) for parameter in self.cdist_type.boolean_parameters: argument = "--" + parameter parser.add_argument(argument, dest=parameter, action='store_const', const='') @@ -107,6 +124,11 @@ class Emulator(object): self.args = parser.parse_args(self.argv[1:]) self.log.debug('Args: %s' % self.args) + # Handle meta parameters + for meta_parameter in self.meta_parameters.keys(): + if meta_parameter in self.args: + self.meta_parameters[meta_parameter] = getattr(self.args, meta_parameter) + delattr(self.args, meta_parameter) def setup_object(self): # Setup object_id - FIXME: unset / do not setup anymore! @@ -123,6 +145,8 @@ class Emulator(object): self.parameters = {} for key,value in vars(self.args).items(): if value is not None: + if isinstance(value, list): + value = '\n'.join(value) self.parameters[key] = value if self.cdist_object.exists: @@ -137,12 +161,42 @@ class Emulator(object): # Record / Append source self.cdist_object.source.append(self.object_source) + chunk_size = 65536 + def _read_stdin(self): + return self.stdin.read(self.chunk_size) + + def save_stdin(self): + """If something is written to stdin, save it in the object as + $__object/stdin so it can be accessed in manifest and gencode-* + scripts. + """ + if not self.stdin.isatty(): + try: + # go directly to file instead of using CdistObject's api + # as that does not support streaming + path = os.path.join(self.cdist_object.absolute_path, 'stdin') + with open(path, 'wb') as fd: + chunk = self._read_stdin() + while chunk: + fd.write(chunk) + chunk = self._read_stdin() + except EnvironmentError as e: + raise cdist.Error('Failed to read from stdin: %s' % e) + def record_requirements(self): """record requirements""" + for key in ('before', 'after'): + if key in self.meta_parameters and self.meta_parameters[key]: + for value in self.meta_parameters[key]: + self.log.debug("Recording requirement: %s %s %s", self.cdist_object.name, key, value) + dependency_list = getattr(self.cdist_object, key) + # append to the object.after or object.before lists + dependency_list.append(value) - if "require" in os.environ: - requirements = os.environ['require'] - self.log.debug("reqs = " + requirements) + if "require" in self.env: + warnings.warn("The 'require' envrionment variable is deprecated. Use the --before and --after meta parameters to define dependencies.", category=PendingDeprecationWarning, stacklevel=2) + + requirements = self.env['require'] for requirement in requirements.split(" "): # Ignore empty fields - probably the only field anyway if len(requirement) == 0: continue @@ -151,19 +205,23 @@ class Emulator(object): cdist_object = self.cdist_object.object_from_name(requirement) self.log.debug("Recording requirement: " + requirement) - # Save the sanitised version, not the user supplied one # (__file//bar => __file/bar) # This ensures pattern matching is done against sanitised list - self.cdist_object.requirements.append(cdist_object.name) + self.cdist_object.after.append(cdist_object.name) def record_auto_requirements(self): """An object shall automatically depend on all objects that it defined in it's type manifest. """ - # __object_name is the name of the object whose type manifest is currenlty executed - __object_name = os.environ.get('__object_name', None) + # __object_name is the name of the object whose type manifest is currently executed + __object_name = self.env.get('__object_name', None) if __object_name: - _object = self.cdist_object.object_from_name(__object_name) - # prevent circular dependencies - if not _object.name in self.cdist_object.requirements: - _object.requirements.append(self.cdist_object.name) + # The object whose type manifest is currently run + parent = self.cdist_object.object_from_name(__object_name) + # The object currently being defined + current_object = self.cdist_object + # As parent defined current_object it shall automatically depend on it. + # But only if the user hasn't said otherwise. + # Must prevent circular dependencies. + if not parent.name in current_object.requirements: + parent.autorequire.append(current_object.name) diff --git a/lib/cdist/exec/__init__.py b/cdist/exec/__init__.py similarity index 100% rename from lib/cdist/exec/__init__.py rename to cdist/exec/__init__.py diff --git a/lib/cdist/exec/local.py b/cdist/exec/local.py similarity index 50% rename from lib/cdist/exec/local.py rename to cdist/exec/local.py index d3c6a0ce..7ef11458 100644 --- a/lib/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -20,8 +20,6 @@ # # -# FIXME: common base class with Remote? - import io import os import sys @@ -39,31 +37,73 @@ class Local(object): Directly accessing the local side from python code is a bug. """ - def __init__(self, target_host, local_base_path, out_path): + def __init__(self, target_host, out_path, exec_path, add_conf_dirs=[], cache_dir=None): + self.target_host = target_host - self.base_path = local_base_path - - # Local input - self.cache_path = os.path.join(self.base_path, "cache") - self.conf_path = os.path.join(self.base_path, "conf") - self.global_explorer_path = os.path.join(self.conf_path, "explorer") - self.manifest_path = os.path.join(self.conf_path, "manifest") - self.type_path = os.path.join(self.conf_path, "type") - # FIXME: should not be needed anywhere - self.lib_path = os.path.join(self.base_path, "lib") - - # Local output self.out_path = out_path + self.exec_path = exec_path + + self._add_conf_dirs = add_conf_dirs + + self._init_log() + self._init_permissions() + self._init_paths() + self._init_cache_dir(cache_dir) + self._init_conf_dirs() + + @property + def dist_conf_dir(self): + return os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf")) + + @property + def home_dir(self): + if 'HOME' in os.environ: + return os.path.join(os.environ['HOME'], ".cdist") + else: + return None + + def _init_log(self): + self.log = logging.getLogger(self.target_host) + + def _init_permissions(self): + # Setup file permissions using umask + os.umask(0o077) + + def _init_paths(self): + # Depending on out_path self.bin_path = os.path.join(self.out_path, "bin") + self.conf_path = os.path.join(self.out_path, "conf") self.global_explorer_out_path = os.path.join(self.out_path, "explorer") self.object_path = os.path.join(self.out_path, "object") - self.log = logging.getLogger(self.target_host) + # Depending on conf_path + self.global_explorer_path = os.path.join(self.conf_path, "explorer") + self.manifest_path = os.path.join(self.conf_path, "manifest") + self.type_path = os.path.join(self.conf_path, "type") - def create_directories(self): - self.mkdir(self.out_path) - self.mkdir(self.global_explorer_out_path) - self.mkdir(self.bin_path) + def _init_conf_dirs(self): + self.conf_dirs = [] + + # Comes with the distribution + system_conf_dir = os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf")) + self.conf_dirs.append(system_conf_dir) + + # Is the default place for user created explorer, type and manifest + if self.home_dir: + self.conf_dirs.append(self.home_dir) + + # Add user supplied directories + if self._add_conf_dirs: + self.conf_dirs.extend(self._add_conf_dirs) + + def _init_cache_dir(self, cache_dir): + if cache_dir: + self.cache_path = cache_dir + else: + if self.home_dir: + self.cache_path = os.path.join(self.home_dir, "cache") + else: + raise cdist.Error("No homedir setup and no cache dir location given") def rmdir(self, path): """Remove directory on the local side.""" @@ -73,8 +113,7 @@ class Local(object): def mkdir(self, path): """Create directory on the local side.""" self.log.debug("Local mkdir: %s", path) - # FIXME: dont set mode here, fix unittest mkdtemp instead - os.makedirs(path, mode=0o700, exist_ok=True) + os.makedirs(path, exist_ok=True) def run(self, command, env=None, return_output=False): """Run the given command with the given environment. @@ -109,9 +148,51 @@ class Local(object): return self.run(command, env, return_output) - def link_emulator(self, exec_path): + def create_files_dirs(self): + self._create_context_dirs() + self._create_conf_path_and_link_conf_dirs() + self._link_types_for_emulator() + + def _create_context_dirs(self): + self.mkdir(self.out_path) + + self.mkdir(self.conf_path) + self.mkdir(self.global_explorer_out_path) + self.mkdir(self.bin_path) + + def _create_conf_path_and_link_conf_dirs(self): + # Link destination directories + for sub_dir in [ "explorer", "manifest", "type" ]: + self.mkdir(os.path.join(self.conf_path, sub_dir)) + + # Iterate over all directories and link the to the output dir + for conf_dir in self.conf_dirs: + self.log.debug("Checking conf_dir %s ..." % (conf_dir)) + for sub_dir in [ "explorer", "manifest", "type" ]: + current_dir = os.path.join(conf_dir, sub_dir) + + # Allow conf dirs to contain only partial content + if not os.path.exists(current_dir): + continue + + for entry in os.listdir(current_dir): + rel_entry_path = os.path.join(sub_dir, entry) + src = os.path.join(conf_dir, sub_dir, entry) + dst = os.path.join(self.conf_path, sub_dir, entry) + + # Already exists? remove and link + if os.path.exists(dst): + os.unlink(dst) + + self.log.debug("Linking %s to %s ..." % (src, dst)) + try: + os.symlink(src, dst) + except OSError as e: + raise cdist.Error("Linking %s %s to %s failed: %s" % (sub_dir, src, dst, e.__str__())) + + def _link_types_for_emulator(self): """Link emulator to types""" - src = os.path.abspath(exec_path) + src = os.path.abspath(self.exec_path) for cdist_type in core.CdistType.list_types(self.type_path): dst = os.path.join(self.bin_path, cdist_type.name) self.log.debug("Linking emulator: %s to %s", src, dst) diff --git a/lib/cdist/exec/remote.py b/cdist/exec/remote.py similarity index 92% rename from lib/cdist/exec/remote.py rename to cdist/exec/remote.py index 11b8c78e..d4d2cb2b 100644 --- a/lib/cdist/exec/remote.py +++ b/cdist/exec/remote.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -57,7 +57,7 @@ class Remote(object): self.log = logging.getLogger(self.target_host) - def create_directories(self): + def create_files_dirs(self): self.rmdir(self.base_path) self.mkdir(self.base_path) self.mkdir(self.conf_path) @@ -77,12 +77,7 @@ class Remote(object): self.log.debug("Remote transfer: %s -> %s", source, destination) self.rmdir(destination) command = self._copy.split() - # support rsync by appending a "/" to the source if it's a directory - if os.path.isdir(source): - command.extend(["-r", source + "/", self.target_host + ":" + destination]) - else: - command.extend(["-r", source, self.target_host + ":" + destination]) - + command.extend(["-r", source, self.target_host + ":" + destination]) self._run_command(command) def run_script(self, script, env=None, return_output=False): @@ -105,6 +100,10 @@ class Remote(object): cmd = self._exec.split() cmd.append(self.target_host) + # Always call umask before actual call to ensure proper file permissions + cmd.append("umask 077;") + + # FIXME: replace this by -o SendEnv name -o SendEnv name ... to ssh? # can't pass environment to remote side, so prepend command with # variable declarations if env: diff --git a/lib/cdist/install.py b/cdist/install.py similarity index 100% rename from lib/cdist/install.py rename to cdist/install.py diff --git a/lib/cdist/resolver.py b/cdist/resolver.py similarity index 51% rename from lib/cdist/resolver.py rename to cdist/resolver.py index 368c9eb8..d181d066 100644 --- a/lib/cdist/resolver.py +++ b/cdist/resolver.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2012 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -50,36 +50,41 @@ class DependencyResolver(object): """Cdist's dependency resolver. Usage: - resolver = DependencyResolver(list_of_objects) - from pprint import pprint - pprint(resolver.graph) - - for cdist_object in resolver: - do_something_with(cdist_object) - + >> resolver = DependencyResolver(list_of_objects) + # Easy access to the objects we are working with + >> resolver.objects['__some_type/object_id'] + + # Easy access to a specific objects dependencies + >> resolver.dependencies['__some_type/object_id'] + [, ] + # Pretty print the dependency graph + >> from pprint import pprint + >> pprint(resolver.dependencies) + # Iterate over all existing objects in the correct order + >> for cdist_object in resolver: + >> do_something_with(cdist_object) """ def __init__(self, objects, logger=None): - self.objects = list(objects) # make sure we store as list, not generator - self._object_index = dict((o.name, o) for o in self.objects) - self._graph = None + self.objects = dict((o.name, o) for o in objects) + self._dependencies = None self.log = logger or log @property - def graph(self): + def dependencies(self): """Build the dependency graph. Returns a dict where the keys are the object names and the values are lists of all dependencies including the key object itself. """ - if self._graph is None: - graph = {} - for o in self.objects: + if self._dependencies is None: + self._dependencies = d = {} + self._preprocess_requirements() + for name,cdist_object in self.objects.items(): resolved = [] unresolved = [] - self.resolve_object_dependencies(o, resolved, unresolved) - graph[o.name] = resolved - self._graph = graph - return self._graph + self._resolve_object_dependencies(cdist_object, resolved, unresolved) + d[name] = resolved + return self._dependencies def find_requirements_by_name(self, requirements): """Takes a list of requirement patterns and returns a list of matching object instances. @@ -89,21 +94,55 @@ class DependencyResolver(object): find_requirements_by_name(['__type/object_id', '__other_type/*']) -> [, , ] """ - object_names = self._object_index.keys() + object_names = self.objects.keys() for pattern in requirements: found = False for requirement in fnmatch.filter(object_names, pattern): found = True - yield self._object_index[requirement] + yield self.objects[requirement] if not found: # FIXME: get rid of the singleton object_id, it should be invisible to the code -> hide it in Object singleton = os.path.join(pattern, 'singleton') - if singleton in self._object_index: - yield self._object_index[singleton] + if singleton in self.objects: + yield self.objects[singleton] else: raise RequirementNotFoundError(pattern) - def resolve_object_dependencies(self, cdist_object, resolved, unresolved): + def _preprocess_requirements(self): + """Find all before, after and autorequire dependencies and merge them + to be just requirements for further processing. + """ + for cdist_object in self.objects.values(): + if cdist_object.after: + cdist_object.requirements.extend(cdist_object.after) + # As we changed the object on disc, we have to ensure it is not + # preprocessed again if someone would call us multiple times. + cdist_object.after = [] + if cdist_object.before: + for other_object in self.find_requirements_by_name(cdist_object.before): + other_object.requirements.append(cdist_object.name) + # As we changed the object on disc, we have to ensure it is not + # preprocessed again if someone would call us multiple times. + cdist_object.before = [] + if cdist_object.autorequire: + # The objects (children) that this cdist_object (parent) defined + # in it's type manifest shall inherit all explicit requirements + # that the parent has so that user defined requirements are + # fullfilled and processed in the expected order. + for auto_requirement in self.find_requirements_by_name(cdist_object.autorequire): + for requirement in cdist_object.requirements: + if requirement not in auto_requirement.requirements: + auto_requirement.requirements.append(requirement) + # On the other hand the parent shall depend on all the children + # it created so that the user can setup dependencies on it as a + # whole without having to know anything about the parents + # internals. + cdist_object.requirements.extend(cdist_object.autorequire) + # As we changed the object on disc, we have to ensure it is not + # preprocessed again if someone would call us multiple times. + cdist_object.autorequire = [] + + def _resolve_object_dependencies(self, cdist_object, resolved, unresolved): """Resolve all dependencies for the given cdist_object and store them in the list which is passed as the 'resolved' arguments. @@ -121,16 +160,16 @@ class DependencyResolver(object): if required_object not in resolved: if required_object in unresolved: raise CircularReferenceError(cdist_object, required_object) - self.resolve_object_dependencies(required_object, resolved, unresolved) + self._resolve_object_dependencies(required_object, resolved, unresolved) resolved.append(cdist_object) unresolved.remove(cdist_object) except RequirementNotFoundError as e: raise cdist.CdistObjectError(cdist_object, "requires non-existing " + e.requirement) def __iter__(self): - """Iterate over all unique objects while resolving dependencies. + """Iterate over all unique objects and yield them in the correct order. """ - iterable = itertools.chain(*self.graph.values()) + iterable = itertools.chain(*self.dependencies.values()) # Keep record of objects that have already been seen seen = set() seen_add = seen.add diff --git a/lib/cdist/test/__init__.py b/cdist/test/__init__.py similarity index 72% rename from lib/cdist/test/__init__.py rename to cdist/test/__init__.py index faa9dc2d..ab767699 100644 --- a/lib/cdist/test/__init__.py +++ b/cdist/test/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -24,13 +24,19 @@ import unittest import tempfile cdist_base_path = os.path.abspath( - os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../")) + os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../")) -cdist_exec_path = os.path.join(cdist_base_path, "bin/cdist") +cdist_exec_path = os.path.join(cdist_base_path, "scripts/cdist") +global_fixtures_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "fixtures")) class CdistTestCase(unittest.TestCase): + remote_exec = os.path.join(global_fixtures_dir, "remote", "exec") + remote_copy = os.path.join(global_fixtures_dir, "remote", "copy") + + target_host = 'cdisttesthost' + def mkdtemp(self, **kwargs): return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs) diff --git a/lib/cdist/test/__main__.py b/cdist/test/__main__.py similarity index 100% rename from lib/cdist/test/__main__.py rename to cdist/test/__main__.py diff --git a/cdist/test/autorequire/__init__.py b/cdist/test/autorequire/__init__.py new file mode 100644 index 00000000..2a647954 --- /dev/null +++ b/cdist/test/autorequire/__init__.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +# +# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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 os +import shutil + +import cdist +from cdist import test +from cdist.exec import local +from cdist import core +from cdist.core import manifest +from cdist import resolver +from cdist import config +import cdist.context + +import os.path as op +my_dir = op.abspath(op.dirname(__file__)) +fixtures = op.join(my_dir, 'fixtures') +add_conf_dir = op.join(fixtures, 'conf') + +class AutorequireTestCase(test.CdistTestCase): + + def setUp(self): + self.orig_environ = os.environ + os.environ = os.environ.copy() + self.temp_dir = self.mkdtemp() + + self.out_dir = os.path.join(self.temp_dir, "out") + self.remote_out_dir = os.path.join(self.temp_dir, "remote") + + os.environ['__cdist_out_dir'] = self.out_dir + os.environ['__cdist_remote_out_dir'] = self.remote_out_dir + + self.context = cdist.context.Context( + target_host=self.target_host, + remote_copy=self.remote_copy, + remote_exec=self.remote_exec, + add_conf_dirs=[add_conf_dir], + exec_path=test.cdist_exec_path, + debug=False) + + self.config = config.Config(self.context) + + def tearDown(self): + os.environ = self.orig_environ + shutil.rmtree(self.temp_dir) + + def test_implicit_dependencies(self): + self.context.initial_manifest = os.path.join(self.config.local.manifest_path, 'implicit_dependencies') + self.config.stage_prepare() + + objects = core.CdistObject.list_objects(self.config.local.object_path, self.config.local.type_path) + dependency_resolver = resolver.DependencyResolver(objects) + expected_dependencies = [ + dependency_resolver.objects['__package_special/b'], + dependency_resolver.objects['__package/b'], + dependency_resolver.objects['__package_special/a'] + ] + resolved_dependencies = dependency_resolver.dependencies['__package_special/a'] + self.assertEqual(resolved_dependencies, expected_dependencies) + + def test_circular_dependency(self): + self.context.initial_manifest = os.path.join(self.config.local.manifest_path, 'circular_dependency') + self.config.stage_prepare() + # raises CircularDependecyError + self.config.stage_run() diff --git a/lib/cdist/test/manifest/fixtures/conf/type/__moon/.keep b/cdist/test/autorequire/fixtures/conf/explorer/.keep similarity index 100% rename from lib/cdist/test/manifest/fixtures/conf/type/__moon/.keep rename to cdist/test/autorequire/fixtures/conf/explorer/.keep diff --git a/cdist/test/autorequire/fixtures/conf/manifest/circular_dependency b/cdist/test/autorequire/fixtures/conf/manifest/circular_dependency new file mode 100755 index 00000000..6ea308d1 --- /dev/null +++ b/cdist/test/autorequire/fixtures/conf/manifest/circular_dependency @@ -0,0 +1,2 @@ +# this has triggered CircularReferenceError +__nfsroot_client test diff --git a/cdist/test/autorequire/fixtures/conf/manifest/implicit_dependencies b/cdist/test/autorequire/fixtures/conf/manifest/implicit_dependencies new file mode 100755 index 00000000..7d68aed2 --- /dev/null +++ b/cdist/test/autorequire/fixtures/conf/manifest/implicit_dependencies @@ -0,0 +1,3 @@ +# this creates implicit dependencies through autorequire. +# this failed because autorequired dependencies where not aware of their anchestors dependencies +__top test diff --git a/lib/cdist/test/manifest/fixtures/conf/type/__planet/.keep b/cdist/test/autorequire/fixtures/conf/type/__addifnosuchline/.keep similarity index 100% rename from lib/cdist/test/manifest/fixtures/conf/type/__planet/.keep rename to cdist/test/autorequire/fixtures/conf/type/__addifnosuchline/.keep diff --git a/lib/cdist/test/object/fixtures/object/__first/.keep b/cdist/test/autorequire/fixtures/conf/type/__directory/.keep similarity index 100% rename from lib/cdist/test/object/fixtures/object/__first/.keep rename to cdist/test/autorequire/fixtures/conf/type/__directory/.keep diff --git a/cdist/test/autorequire/fixtures/conf/type/__nfsroot_client/manifest b/cdist/test/autorequire/fixtures/conf/type/__nfsroot_client/manifest new file mode 100755 index 00000000..f6cb7833 --- /dev/null +++ b/cdist/test/autorequire/fixtures/conf/type/__nfsroot_client/manifest @@ -0,0 +1,3 @@ +__user root +__root_ssh_authorized_key john +__root_ssh_authorized_key frank diff --git a/cdist/test/autorequire/fixtures/conf/type/__package/manifest b/cdist/test/autorequire/fixtures/conf/type/__package/manifest new file mode 100755 index 00000000..6f70e627 --- /dev/null +++ b/cdist/test/autorequire/fixtures/conf/type/__package/manifest @@ -0,0 +1 @@ +__package_special "$__object_id" diff --git a/lib/cdist/test/object/fixtures/object/__first/man/.cdist/.keep b/cdist/test/autorequire/fixtures/conf/type/__package_special/.keep similarity index 100% rename from lib/cdist/test/object/fixtures/object/__first/man/.cdist/.keep rename to cdist/test/autorequire/fixtures/conf/type/__package_special/.keep diff --git a/cdist/test/autorequire/fixtures/conf/type/__root_ssh_authorized_key/manifest b/cdist/test/autorequire/fixtures/conf/type/__root_ssh_authorized_key/manifest new file mode 100755 index 00000000..6224629f --- /dev/null +++ b/cdist/test/autorequire/fixtures/conf/type/__root_ssh_authorized_key/manifest @@ -0,0 +1,4 @@ +user="$__object_id" +__directory /root/.ssh +require="__directory/root/.ssh" \ + __addifnosuchline "ssh-root-$user" diff --git a/cdist/test/autorequire/fixtures/conf/type/__top/manifest b/cdist/test/autorequire/fixtures/conf/type/__top/manifest new file mode 100755 index 00000000..d6968c25 --- /dev/null +++ b/cdist/test/autorequire/fixtures/conf/type/__top/manifest @@ -0,0 +1,2 @@ +__package b +require="__package/b" __package a diff --git a/lib/cdist/test/object/fixtures/object/__second/.keep b/cdist/test/autorequire/fixtures/conf/type/__user/.keep similarity index 100% rename from lib/cdist/test/object/fixtures/object/__second/.keep rename to cdist/test/autorequire/fixtures/conf/type/__user/.keep diff --git a/lib/cdist/test/banner/__init__.py b/cdist/test/banner/__init__.py similarity index 100% rename from lib/cdist/test/banner/__init__.py rename to cdist/test/banner/__init__.py diff --git a/lib/cdist/test/code/__init__.py b/cdist/test/code/__init__.py similarity index 88% rename from lib/cdist/test/code/__init__.py rename to cdist/test/code/__init__.py index dc701cce..284ef9c0 100644 --- a/lib/cdist/test/code/__init__.py +++ b/cdist/test/code/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -19,10 +20,9 @@ # # +import getpass import os import shutil -import getpass -import logging import cdist from cdist import core @@ -34,23 +34,27 @@ from cdist.core import code import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -local_base_path = fixtures +conf_dir = op.join(fixtures, 'conf') class CodeTestCase(test.CdistTestCase): def setUp(self): self.target_host = 'localhost' - self.local_base_path = local_base_path self.out_path = self.mkdtemp() - self.local = local.Local(self.target_host, self.local_base_path, self.out_path) - self.local.create_directories() + + self.local = local.Local( + target_host=self.target_host, + out_path = self.out_path, + exec_path = cdist.test.cdist_exec_path, + add_conf_dirs=[conf_dir]) + self.local.create_files_dirs() self.remote_base_path = self.mkdtemp() - self.user = getpass.getuser() - remote_exec = "ssh -o User=%s -q" % self.user - remote_copy = "scp -o User=%s -q" % self.user + remote_exec = self.remote_exec + remote_copy = self.remote_copy self.remote = remote.Remote(self.target_host, self.remote_base_path, remote_exec, remote_copy) + self.remote.create_files_dirs() self.code = code.Code(self.target_host, self.local, self.remote) @@ -58,8 +62,6 @@ class CodeTestCase(test.CdistTestCase): self.cdist_object = core.CdistObject(self.cdist_type, self.local.object_path, 'whatever') self.cdist_object.create() - self.log = logging.getLogger("cdist") - def tearDown(self): shutil.rmtree(self.out_path) shutil.rmtree(self.remote_base_path) @@ -78,7 +80,6 @@ class CodeTestCase(test.CdistTestCase): self.assertEqual(output_dict['__object'], self.cdist_object.absolute_path) self.assertEqual(output_dict['__object_id'], self.cdist_object.object_id) self.assertEqual(output_dict['__object_name'], self.cdist_object.name) - self.assertEqual(output_dict['__self'], self.cdist_object.name) def test_run_gencode_remote_environment(self): output_string = self.code.run_gencode_remote(self.cdist_object) @@ -94,7 +95,6 @@ class CodeTestCase(test.CdistTestCase): self.assertEqual(output_dict['__object'], self.cdist_object.absolute_path) self.assertEqual(output_dict['__object_id'], self.cdist_object.object_id) self.assertEqual(output_dict['__object_name'], self.cdist_object.name) - self.assertEqual(output_dict['__self'], self.cdist_object.name) def test_transfer_code_remote(self): self.cdist_object.code_remote = self.code.run_gencode_remote(self.cdist_object) diff --git a/lib/cdist/test/code/fixtures/conf/type/__dump_environment/gencode-local b/cdist/test/code/fixtures/conf/type/__dump_environment/gencode-local similarity index 88% rename from lib/cdist/test/code/fixtures/conf/type/__dump_environment/gencode-local rename to cdist/test/code/fixtures/conf/type/__dump_environment/gencode-local index ed1265c9..771894fb 100755 --- a/lib/cdist/test/code/fixtures/conf/type/__dump_environment/gencode-local +++ b/cdist/test/code/fixtures/conf/type/__dump_environment/gencode-local @@ -6,4 +6,3 @@ echo "echo __type: $__type" echo "echo __object: $__object" echo "echo __object_id: $__object_id" echo "echo __object_name: $__object_name" -echo "echo __self: $__self" diff --git a/lib/cdist/test/code/fixtures/conf/type/__dump_environment/gencode-remote b/cdist/test/code/fixtures/conf/type/__dump_environment/gencode-remote similarity index 100% rename from lib/cdist/test/code/fixtures/conf/type/__dump_environment/gencode-remote rename to cdist/test/code/fixtures/conf/type/__dump_environment/gencode-remote diff --git a/lib/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py similarity index 60% rename from lib/cdist/test/emulator/__init__.py rename to cdist/test/emulator/__init__.py index 370d3d82..fc0b6695 100644 --- a/lib/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -19,98 +20,95 @@ # # +import io import os import shutil +import string +import filecmp +import random import cdist from cdist import test from cdist.exec import local from cdist import emulator from cdist import core +from cdist import config +import cdist.context -local_base_path = test.cdist_base_path +import os.path as op +my_dir = op.abspath(op.dirname(__file__)) +fixtures = op.join(my_dir, 'fixtures') +conf_dir = op.join(fixtures, 'conf') class EmulatorTestCase(test.CdistTestCase): def setUp(self): - self.orig_environ = os.environ - os.environ = os.environ.copy() self.temp_dir = self.mkdtemp() handle, self.script = self.mkstemp(dir=self.temp_dir) os.close(handle) - self.target_host = 'localhost' out_path = self.temp_dir - self.local = local.Local(self.target_host, local_base_path, out_path) - self.local.create_directories() - self.env = { - 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), - '__target_host': self.target_host, - '__global': self.local.out_path, - '__cdist_type_base_path': self.local.type_path, # for use in type emulator - '__manifest': self.local.manifest_path, - '__cdist_manifest': self.script, - } + + self.local = local.Local( + target_host=self.target_host, + out_path=out_path, + 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) def tearDown(self): - os.environ = self.orig_environ shutil.rmtree(self.temp_dir) def test_nonexistent_type_exec(self): argv = ['__does-not-exist'] - os.environ.update(self.env) - self.assertRaises(core.NoSuchTypeError, emulator.Emulator, argv) + self.assertRaises(core.NoSuchTypeError, emulator.Emulator, argv, env=self.env) def test_nonexistent_type_requirement(self): argv = ['__file', '/tmp/foobar'] - os.environ.update(self.env) - os.environ['require'] = '__does-not-exist/some-id' - emu = emulator.Emulator(argv) + self.env['require'] = '__does-not-exist/some-id' + emu = emulator.Emulator(argv, env=self.env) self.assertRaises(core.NoSuchTypeError, emu.run) def test_illegal_object_id_requirement(self): argv = ['__file', '/tmp/foobar'] - os.environ.update(self.env) - os.environ['require'] = '__file/bad/id/with/.cdist/inside' - emu = emulator.Emulator(argv) + self.env['require'] = '__file/bad/id/with/.cdist/inside' + emu = emulator.Emulator(argv, env=self.env) self.assertRaises(core.IllegalObjectIdError, emu.run) def test_missing_object_id_requirement(self): argv = ['__file', '/tmp/foobar'] - os.environ.update(self.env) - os.environ['require'] = '__file' - emu = emulator.Emulator(argv) + self.env['require'] = '__file' + emu = emulator.Emulator(argv, env=self.env) self.assertRaises(core.IllegalObjectIdError, emu.run) def test_singleton_object_requirement(self): argv = ['__file', '/tmp/foobar'] - os.environ.update(self.env) - os.environ['require'] = '__issue' - emu = emulator.Emulator(argv) + self.env['require'] = '__issue' + emu = emulator.Emulator(argv, env=self.env) emu.run() # if we get here all is fine def test_requirement_pattern(self): argv = ['__file', '/tmp/foobar'] - os.environ.update(self.env) - os.environ['require'] = '__file/etc/*' - emu = emulator.Emulator(argv) + self.env['require'] = '__file/etc/*' + emu = emulator.Emulator(argv, env=self.env) # if we get here all is fine -import os.path as op -my_dir = op.abspath(op.dirname(__file__)) -fixtures = op.join(my_dir, 'fixtures') - class AutoRequireEmulatorTestCase(test.CdistTestCase): def setUp(self): self.temp_dir = self.mkdtemp() - self.target_host = 'localhost' - out_path = self.temp_dir - _local_base_path = fixtures - self.local = local.Local(self.target_host, _local_base_path, out_path) - self.local.create_directories() - self.local.link_emulator(cdist.test.cdist_exec_path) + out_path = os.path.join(self.temp_dir, "out") + + self.local = local.Local( + target_host=self.target_host, + out_path=out_path, + 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) def tearDown(self): @@ -123,29 +121,26 @@ class AutoRequireEmulatorTestCase(test.CdistTestCase): cdist_object = core.CdistObject(cdist_type, self.local.object_path, 'singleton') self.manifest.run_type_manifest(cdist_object) expected = ['__planet/Saturn', '__moon/Prometheus'] - self.assertEqual(sorted(cdist_object.requirements), sorted(expected)) + self.assertEqual(sorted(cdist_object.autorequire), sorted(expected)) class ArgumentsTestCase(test.CdistTestCase): def setUp(self): self.temp_dir = self.mkdtemp() - self.target_host = 'localhost' out_path = self.temp_dir handle, self.script = self.mkstemp(dir=self.temp_dir) os.close(handle) - _local_base_path = fixtures - self.local = local.Local(self.target_host, _local_base_path, out_path) - self.local.create_directories() - self.local.link_emulator(test.cdist_exec_path) - self.env = { - 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), - '__target_host': self.target_host, - '__global': self.local.out_path, - '__cdist_type_base_path': self.local.type_path, # for use in type emulator - '__manifest': self.local.manifest_path, - '__cdist_manifest': self.script, - } + + self.local = local.Local( + target_host=self.target_host, + out_path=out_path, + 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) def tearDown(self): shutil.rmtree(self.temp_dir) @@ -198,7 +193,7 @@ class ArgumentsTestCase(test.CdistTestCase): # argv = [type_name, object_id, '--required1', value] # os.environ.update(self.env) # emu = emulator.Emulator(argv) -# +# # self.assertRaises(SystemExit, emu.run) def test_optional(self): @@ -215,3 +210,66 @@ class ArgumentsTestCase(test.CdistTestCase): self.assertTrue('optional1' in cdist_object.parameters) self.assertFalse('optional2' in cdist_object.parameters) self.assertEqual(cdist_object.parameters['optional1'], value) + + +class StdinTestCase(test.CdistTestCase): + + def setUp(self): + self.orig_environ = os.environ + os.environ = os.environ.copy() + + self.temp_dir = self.mkdtemp() + out_path = os.path.join(self.temp_dir, "out") + + self.local = local.Local( + target_host=self.target_host, + out_path=out_path, + exec_path=test.cdist_exec_path, + add_conf_dirs=[conf_dir]) + + self.local.create_files_dirs() + + self.manifest = core.Manifest( + target_host=self.target_host, + local = self.local) + + def tearDown(self): + os.environ = self.orig_environ + shutil.rmtree(self.temp_dir) + + def test_file_from_stdin(self): + """ + Test whether reading from stdin works + """ + + ###################################################################### + # Create string with random content + random_string = str(random.sample(range(1000), 800)) + random_buffer = io.BytesIO(bytes(random_string, 'utf-8')) + + ###################################################################### + # Prepare required args and environment for emulator + type_name = '__file' + object_id = "cdist-test-id" + argv = [type_name, object_id] + + initial_manifest_path = "/cdist-test/path/that/does/not/exist" + env = self.manifest.env_initial_manifest(initial_manifest_path) + + ###################################################################### + # Create path where stdin should reside at + cdist_type = core.CdistType(self.local.type_path, type_name) + cdist_object = core.CdistObject(cdist_type, self.local.object_path, object_id) + stdin_out_path = os.path.join(cdist_object.absolute_path, 'stdin') + + ###################################################################### + # Run emulator + emu = emulator.Emulator(argv, stdin=random_buffer, env=env) + emu.run() + + ###################################################################### + # Read where emulator should have placed stdin + with open(stdin_out_path, 'r') as fd: + stdin_saved_by_emulator = fd.read() + + self.assertEqual(random_string, stdin_saved_by_emulator) diff --git a/lib/cdist/test/object/fixtures/object/__second/on-the/.cdist/.keep b/cdist/test/emulator/fixtures/conf/explorer/.keep similarity index 100% rename from lib/cdist/test/object/fixtures/object/__second/on-the/.cdist/.keep rename to cdist/test/emulator/fixtures/conf/explorer/.keep diff --git a/lib/cdist/test/emulator/fixtures/conf/manifest/init b/cdist/test/emulator/fixtures/conf/manifest/init similarity index 100% rename from lib/cdist/test/emulator/fixtures/conf/manifest/init rename to cdist/test/emulator/fixtures/conf/manifest/init diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__arguments_boolean/parameter/boolean b/cdist/test/emulator/fixtures/conf/type/__arguments_boolean/parameter/boolean similarity index 100% rename from lib/cdist/test/emulator/fixtures/conf/type/__arguments_boolean/parameter/boolean rename to cdist/test/emulator/fixtures/conf/type/__arguments_boolean/parameter/boolean diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__arguments_optional/parameter/optional b/cdist/test/emulator/fixtures/conf/type/__arguments_optional/parameter/optional similarity index 100% rename from lib/cdist/test/emulator/fixtures/conf/type/__arguments_optional/parameter/optional rename to cdist/test/emulator/fixtures/conf/type/__arguments_optional/parameter/optional diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__arguments_required/parameter/required b/cdist/test/emulator/fixtures/conf/type/__arguments_required/parameter/required similarity index 100% rename from lib/cdist/test/emulator/fixtures/conf/type/__arguments_required/parameter/required rename to cdist/test/emulator/fixtures/conf/type/__arguments_required/parameter/required diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__arguments_with_dashes/parameter/required b/cdist/test/emulator/fixtures/conf/type/__arguments_with_dashes/parameter/required similarity index 100% rename from lib/cdist/test/emulator/fixtures/conf/type/__arguments_with_dashes/parameter/required rename to cdist/test/emulator/fixtures/conf/type/__arguments_with_dashes/parameter/required diff --git a/cdist/test/emulator/fixtures/conf/type/__file_from_stdin/manifest b/cdist/test/emulator/fixtures/conf/type/__file_from_stdin/manifest new file mode 100755 index 00000000..b4908cbf --- /dev/null +++ b/cdist/test/emulator/fixtures/conf/type/__file_from_stdin/manifest @@ -0,0 +1,4 @@ +#!/bin/sh + +source="$(cat "$__object/parameter/source")" +cat "$source" | __file "/$__object_id" --source /dev/null diff --git a/cdist/test/emulator/fixtures/conf/type/__file_from_stdin/parameter/required b/cdist/test/emulator/fixtures/conf/type/__file_from_stdin/parameter/required new file mode 100644 index 00000000..5a18cd2f --- /dev/null +++ b/cdist/test/emulator/fixtures/conf/type/__file_from_stdin/parameter/required @@ -0,0 +1 @@ +source diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__moon/manifest b/cdist/test/emulator/fixtures/conf/type/__moon/manifest similarity index 100% rename from lib/cdist/test/emulator/fixtures/conf/type/__moon/manifest rename to cdist/test/emulator/fixtures/conf/type/__moon/manifest diff --git a/conf/type/__package_luarocks/parameter/optional b/cdist/test/emulator/fixtures/conf/type/__moon/parameter/optional similarity index 100% rename from conf/type/__package_luarocks/parameter/optional rename to cdist/test/emulator/fixtures/conf/type/__moon/parameter/optional diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/required b/cdist/test/emulator/fixtures/conf/type/__moon/parameter/required similarity index 100% rename from lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/required rename to cdist/test/emulator/fixtures/conf/type/__moon/parameter/required diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__planet/manifest b/cdist/test/emulator/fixtures/conf/type/__planet/manifest similarity index 100% rename from lib/cdist/test/emulator/fixtures/conf/type/__planet/manifest rename to cdist/test/emulator/fixtures/conf/type/__planet/manifest diff --git a/conf/type/__package_opkg/parameter/optional b/cdist/test/emulator/fixtures/conf/type/__planet/parameter/optional similarity index 100% rename from conf/type/__package_opkg/parameter/optional rename to cdist/test/emulator/fixtures/conf/type/__planet/parameter/optional diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__saturn/manifest b/cdist/test/emulator/fixtures/conf/type/__saturn/manifest similarity index 100% rename from lib/cdist/test/emulator/fixtures/conf/type/__saturn/manifest rename to cdist/test/emulator/fixtures/conf/type/__saturn/manifest diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__saturn/singleton b/cdist/test/emulator/fixtures/conf/type/__saturn/singleton similarity index 100% rename from lib/cdist/test/emulator/fixtures/conf/type/__saturn/singleton rename to cdist/test/emulator/fixtures/conf/type/__saturn/singleton diff --git a/lib/cdist/test/exec/__init__.py b/cdist/test/exec/__init__.py similarity index 100% rename from lib/cdist/test/exec/__init__.py rename to cdist/test/exec/__init__.py diff --git a/lib/cdist/test/exec/local.py b/cdist/test/exec/local.py similarity index 66% rename from lib/cdist/test/exec/local.py rename to cdist/test/exec/local.py index e6f2c2b0..687c13a5 100644 --- a/lib/cdist/test/exec/local.py +++ b/cdist/test/exec/local.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -25,9 +26,6 @@ import shutil import string import random -#import logging -#logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s') - import cdist from cdist import test from cdist.exec import local @@ -35,17 +33,23 @@ from cdist.exec import local import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -local_base_path = fixtures - +conf_dir = op.join(fixtures, "conf") class LocalTestCase(test.CdistTestCase): def setUp(self): - self.temp_dir = self.mkdtemp() + target_host = 'localhost' + self.temp_dir = self.mkdtemp() self.out_path = self.temp_dir - self.base_path = local_base_path - self.local = local.Local(target_host, self.base_path, self.out_path) + + self.local = local.Local( + target_host=target_host, + out_path=self.out_path, + exec_path=test.cdist_exec_path + ) + + self.home_dir = os.path.join(os.environ['HOME'], ".cdist") def tearDown(self): shutil.rmtree(self.temp_dir) @@ -53,19 +57,10 @@ class LocalTestCase(test.CdistTestCase): ### test api def test_cache_path(self): - self.assertEqual(self.local.cache_path, os.path.join(self.base_path, "cache")) + self.assertEqual(self.local.cache_path, os.path.join(self.home_dir, "cache")) def test_conf_path(self): - self.assertEqual(self.local.conf_path, os.path.join(self.base_path, "conf")) - - def test_global_explorer_path(self): - self.assertEqual(self.local.global_explorer_path, os.path.join(self.base_path, "conf", "explorer")) - - def test_manifest_path(self): - self.assertEqual(self.local.manifest_path, os.path.join(self.base_path, "conf", "manifest")) - - def test_type_path(self): - self.assertEqual(self.local.type_path, os.path.join(self.base_path, "conf", "type")) + self.assertEqual(self.local.conf_path, os.path.join(self.out_path, "conf")) def test_out_path(self): self.assertEqual(self.local.out_path, self.out_path) @@ -81,6 +76,53 @@ class LocalTestCase(test.CdistTestCase): ### /test api + ### test internal implementation + + def test_global_explorer_path(self): + self.assertEqual(self.local.global_explorer_path, os.path.join(self.out_path, "conf", "explorer")) + + def test_manifest_path(self): + self.assertEqual(self.local.manifest_path, os.path.join(self.out_path, "conf", "manifest")) + + def test_type_path(self): + self.assertEqual(self.local.type_path, os.path.join(self.out_path, "conf", "type")) + + def test_dist_conf_dir_linking(self): + """Ensure that links are correctly created for types included in distribution""" + + test_type="__file" + + link_test_local = local.Local( + target_host='localhost', + out_path=self.out_path, + exec_path=test.cdist_exec_path, + ) + + link_test_local._create_conf_path_and_link_conf_dirs() + + our_type_dir = os.path.join(link_test_local.type_path, test_type) + + self.assertTrue(os.path.isdir(our_type_dir)) + + def test_added_conf_dir_linking(self): + """Ensure that links are correctly created for types in added conf directories""" + + test_type="__cdist_test_type" + + link_test_local = local.Local( + target_host='localhost', + out_path=self.out_path, + exec_path=test.cdist_exec_path, + add_conf_dirs=[conf_dir] + ) + + link_test_local._create_conf_path_and_link_conf_dirs() + + our_type_dir = os.path.join(link_test_local.type_path, test_type) + + self.assertTrue(os.path.isdir(our_type_dir)) + + ### other tests def test_run_success(self): self.local.run(['/bin/true']) @@ -98,7 +140,7 @@ class LocalTestCase(test.CdistTestCase): handle, script = self.mkstemp(dir=self.temp_dir) with os.fdopen(handle, "w") as fd: fd.writelines(["#!/bin/sh\n", "/bin/false"]) - self.assertRaises(local.LocalScriptError, self.local.run_script, script) + self.assertRaises(cdist.Error, self.local.run_script, script) def test_run_script_get_output(self): handle, script = self.mkstemp(dir=self.temp_dir) @@ -117,7 +159,8 @@ class LocalTestCase(test.CdistTestCase): self.local.rmdir(temp_dir) self.assertFalse(os.path.isdir(temp_dir)) - def test_create_directories(self): - self.local.create_directories() + def test_create_files_dirs(self): + self.local.create_files_dirs() self.assertTrue(os.path.isdir(self.local.out_path)) self.assertTrue(os.path.isdir(self.local.bin_path)) + self.assertTrue(os.path.isdir(self.local.conf_path)) diff --git a/lib/cdist/test/exec/remote.py b/cdist/test/exec/remote.py similarity index 100% rename from lib/cdist/test/exec/remote.py rename to cdist/test/exec/remote.py diff --git a/lib/cdist/test/explorer/__init__.py b/cdist/test/explorer/__init__.py similarity index 77% rename from lib/cdist/test/explorer/__init__.py rename to cdist/test/explorer/__init__.py index 257ad8a9..a97b538a 100644 --- a/lib/cdist/test/explorer/__init__.py +++ b/cdist/test/explorer/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -23,7 +23,6 @@ import os import shutil import getpass -import logging import cdist from cdist import core @@ -35,35 +34,45 @@ from cdist.core import explorer import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -local_base_path = fixtures +conf_dir = op.join(fixtures, "conf") class ExplorerClassTestCase(test.CdistTestCase): def setUp(self): self.target_host = 'localhost' - self.local_base_path = local_base_path - self.out_path = self.mkdtemp() - self.local = local.Local(self.target_host, self.local_base_path, self.out_path) - self.local.create_directories() + self.temp_dir = self.mkdtemp() + self.out_path = os.path.join(self.temp_dir, "out") + self.remote_base_path = os.path.join(self.temp_dir, "remote") + os.makedirs(self.remote_base_path) - self.remote_base_path = self.mkdtemp() - self.user = getpass.getuser() - remote_exec = "ssh -o User=%s -q" % self.user - remote_copy = "scp -o User=%s -q" % self.user - self.remote = remote.Remote(self.target_host, self.remote_base_path, remote_exec, remote_copy) + self.local = local.Local( + target_host=self.target_host, + out_path=self.out_path, + exec_path=test.cdist_exec_path, + add_conf_dirs=[conf_dir]) - self.explorer = explorer.Explorer(self.target_host, self.local, self.remote) + self.local.create_files_dirs() - self.log = logging.getLogger(self.target_host) + self.remote = remote.Remote( + self.target_host, + self.remote_base_path, + self.remote_exec, + self.remote_copy) + self.remote.create_files_dirs() + + self.explorer = explorer.Explorer( + self.target_host, + self.local, + self.remote) def tearDown(self): - shutil.rmtree(self.out_path) - shutil.rmtree(self.remote_base_path) + shutil.rmtree(self.temp_dir) def test_list_global_explorer_names(self): - expected = ['foobar', 'global'] - self.assertEqual(self.explorer.list_global_explorer_names(), expected) + names = self.explorer.list_global_explorer_names() + self.assertIn("foobar", names) + self.assertIn("global", names) def test_transfer_global_explorers(self): self.explorer.transfer_global_explorers() @@ -72,14 +81,20 @@ class ExplorerClassTestCase(test.CdistTestCase): self.assertEqual(sorted(os.listdir(source)), sorted(os.listdir(destination))) def test_run_global_explorer(self): + """Checkt that running ONE global explorer works""" self.explorer.transfer_global_explorers() output = self.explorer.run_global_explorer('global') self.assertEqual(output, 'global\n') def test_run_global_explorers(self): + """Ensure output is created for every global explorer""" out_path = self.mkdtemp() + self.explorer.run_global_explorers(out_path) - self.assertEqual(sorted(os.listdir(out_path)), sorted(['foobar', 'global'])) + names = sorted(self.explorer.list_global_explorer_names()) + output = sorted(os.listdir(out_path)) + + self.assertEqual(names, output) shutil.rmtree(out_path) def test_list_type_explorer_names(self): diff --git a/lib/cdist/test/explorer/fixtures/conf/explorer/foobar b/cdist/test/explorer/fixtures/conf/explorer/foobar similarity index 100% rename from lib/cdist/test/explorer/fixtures/conf/explorer/foobar rename to cdist/test/explorer/fixtures/conf/explorer/foobar diff --git a/lib/cdist/test/explorer/fixtures/conf/explorer/global b/cdist/test/explorer/fixtures/conf/explorer/global similarity index 100% rename from lib/cdist/test/explorer/fixtures/conf/explorer/global rename to cdist/test/explorer/fixtures/conf/explorer/global diff --git a/lib/cdist/test/explorer/fixtures/conf/type/__test_type/explorer/world b/cdist/test/explorer/fixtures/conf/type/__test_type/explorer/world similarity index 100% rename from lib/cdist/test/explorer/fixtures/conf/type/__test_type/explorer/world rename to cdist/test/explorer/fixtures/conf/type/__test_type/explorer/world diff --git a/lib/cdist/test/explorer/fixtures/conf/type/__test_type_object_parameter/explorer/test_parameter b/cdist/test/explorer/fixtures/conf/type/__test_type_object_parameter/explorer/test_parameter similarity index 100% rename from lib/cdist/test/explorer/fixtures/conf/type/__test_type_object_parameter/explorer/test_parameter rename to cdist/test/explorer/fixtures/conf/type/__test_type_object_parameter/explorer/test_parameter diff --git a/cdist/test/fixtures/remote b/cdist/test/fixtures/remote new file mode 120000 index 00000000..c5db6358 --- /dev/null +++ b/cdist/test/fixtures/remote @@ -0,0 +1 @@ +../../../other/examples/remote/local \ No newline at end of file diff --git a/lib/cdist/test/manifest/__init__.py b/cdist/test/manifest/__init__.py similarity index 90% rename from lib/cdist/test/manifest/__init__.py rename to cdist/test/manifest/__init__.py index a188c788..727017e7 100644 --- a/lib/cdist/test/manifest/__init__.py +++ b/cdist/test/manifest/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -37,8 +38,7 @@ from cdist.core import manifest import os.path as op my_dir = op.abspath(op.dirname(__file__)) fixtures = op.join(my_dir, 'fixtures') -local_base_path = fixtures - +conf_dir = op.join(fixtures, 'conf') class ManifestTestCase(test.CdistTestCase): @@ -48,9 +48,13 @@ class ManifestTestCase(test.CdistTestCase): self.temp_dir = self.mkdtemp() self.target_host = 'localhost' out_path = self.temp_dir - self.local = local.Local(self.target_host, local_base_path, out_path) - self.local.create_directories() - self.local.link_emulator(cdist.test.cdist_exec_path) + self.local = local.Local( + target_host=self.target_host, + out_path=out_path, + exec_path = cdist.test.cdist_exec_path, + add_conf_dirs=[conf_dir]) + self.local.create_files_dirs() + self.manifest = manifest.Manifest(self.target_host, self.local) self.log = logging.getLogger(self.target_host) @@ -101,9 +105,10 @@ class ManifestTestCase(test.CdistTestCase): self.assertEqual(output_dict['__object'], cdist_object.absolute_path) self.assertEqual(output_dict['__object_id'], cdist_object.object_id) self.assertEqual(output_dict['__object_name'], cdist_object.name) - self.assertEqual(output_dict['__self'], cdist_object.name) def test_debug_env_setup(self): + current_level = self.log.getEffectiveLevel() self.log.setLevel(logging.DEBUG) manifest = cdist.core.manifest.Manifest(self.target_host, self.local) self.assertTrue("__cdist_debug" in manifest.env) + self.log.setLevel(current_level) diff --git a/lib/cdist/test/manifest/fixtures/conf/manifest/dump_environment b/cdist/test/manifest/fixtures/conf/manifest/dump_environment similarity index 100% rename from lib/cdist/test/manifest/fixtures/conf/manifest/dump_environment rename to cdist/test/manifest/fixtures/conf/manifest/dump_environment diff --git a/lib/cdist/test/manifest/fixtures/conf/manifest/init b/cdist/test/manifest/fixtures/conf/manifest/init similarity index 100% rename from lib/cdist/test/manifest/fixtures/conf/manifest/init rename to cdist/test/manifest/fixtures/conf/manifest/init diff --git a/lib/cdist/test/manifest/fixtures/conf/type/__dump_environment/manifest b/cdist/test/manifest/fixtures/conf/type/__dump_environment/manifest similarity index 100% rename from lib/cdist/test/manifest/fixtures/conf/type/__dump_environment/manifest rename to cdist/test/manifest/fixtures/conf/type/__dump_environment/manifest diff --git a/lib/cdist/test/object/fixtures/object/__third/.keep b/cdist/test/manifest/fixtures/conf/type/__moon/.keep similarity index 100% rename from lib/cdist/test/object/fixtures/object/__third/.keep rename to cdist/test/manifest/fixtures/conf/type/__moon/.keep diff --git a/lib/cdist/test/manifest/fixtures/conf/type/__moon/manifest b/cdist/test/manifest/fixtures/conf/type/__moon/manifest similarity index 100% rename from lib/cdist/test/manifest/fixtures/conf/type/__moon/manifest rename to cdist/test/manifest/fixtures/conf/type/__moon/manifest diff --git a/conf/type/__package_pacman/parameter/optional b/cdist/test/manifest/fixtures/conf/type/__moon/parameter/optional similarity index 100% rename from conf/type/__package_pacman/parameter/optional rename to cdist/test/manifest/fixtures/conf/type/__moon/parameter/optional diff --git a/lib/cdist/test/manifest/fixtures/conf/type/__moon/parameter/required b/cdist/test/manifest/fixtures/conf/type/__moon/parameter/required similarity index 100% rename from lib/cdist/test/manifest/fixtures/conf/type/__moon/parameter/required rename to cdist/test/manifest/fixtures/conf/type/__moon/parameter/required diff --git a/lib/cdist/test/object/fixtures/object/__third/moon/.cdist/.keep b/cdist/test/manifest/fixtures/conf/type/__planet/.keep similarity index 100% rename from lib/cdist/test/object/fixtures/object/__third/moon/.cdist/.keep rename to cdist/test/manifest/fixtures/conf/type/__planet/.keep diff --git a/lib/cdist/test/manifest/fixtures/conf/type/__planet/manifest b/cdist/test/manifest/fixtures/conf/type/__planet/manifest similarity index 100% rename from lib/cdist/test/manifest/fixtures/conf/type/__planet/manifest rename to cdist/test/manifest/fixtures/conf/type/__planet/manifest diff --git a/conf/type/__package_rubygem/parameter/optional b/cdist/test/manifest/fixtures/conf/type/__planet/parameter/optional similarity index 100% rename from conf/type/__package_rubygem/parameter/optional rename to cdist/test/manifest/fixtures/conf/type/__planet/parameter/optional diff --git a/lib/cdist/test/object/__init__.py b/cdist/test/object/__init__.py similarity index 99% rename from lib/cdist/test/object/__init__.py rename to cdist/test/object/__init__.py index 3a91f709..7bdc037e 100644 --- a/lib/cdist/test/object/__init__.py +++ b/cdist/test/object/__init__.py @@ -87,6 +87,7 @@ class ObjectTestCase(test.CdistTestCase): self.cdist_object.code_local = '' self.cdist_object.code_remote = '' self.cdist_object.state = '' + self.cdist_object.requirements = [] def test_name(self): self.assertEqual(self.cdist_object.name, '__third/moon') diff --git a/lib/cdist/test/object/fixtures/type/__first/.keep b/cdist/test/object/fixtures/object/__first/.keep similarity index 100% rename from lib/cdist/test/object/fixtures/type/__first/.keep rename to cdist/test/object/fixtures/object/__first/.keep diff --git a/lib/cdist/test/object/fixtures/type/__second/.keep b/cdist/test/object/fixtures/object/__first/man/.cdist/.keep similarity index 100% rename from lib/cdist/test/object/fixtures/type/__second/.keep rename to cdist/test/object/fixtures/object/__first/man/.cdist/.keep diff --git a/lib/cdist/test/object/fixtures/type/__third/.keep b/cdist/test/object/fixtures/object/__second/.keep similarity index 100% rename from lib/cdist/test/object/fixtures/type/__third/.keep rename to cdist/test/object/fixtures/object/__second/.keep diff --git a/lib/cdist/test/resolver/fixtures/object/__first/.keep b/cdist/test/object/fixtures/object/__second/on-the/.cdist/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/object/__first/.keep rename to cdist/test/object/fixtures/object/__second/on-the/.cdist/.keep diff --git a/lib/cdist/test/resolver/fixtures/object/__first/child/.cdist/.keep b/cdist/test/object/fixtures/object/__third/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/object/__first/child/.cdist/.keep rename to cdist/test/object/fixtures/object/__third/.keep diff --git a/lib/cdist/test/resolver/fixtures/object/__first/dog/.cdist/.keep b/cdist/test/object/fixtures/object/__third/moon/.cdist/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/object/__first/dog/.cdist/.keep rename to cdist/test/object/fixtures/object/__third/moon/.cdist/.keep diff --git a/lib/cdist/test/object/fixtures/object/__third/moon/.cdist/parameter/name b/cdist/test/object/fixtures/object/__third/moon/.cdist/parameter/name similarity index 100% rename from lib/cdist/test/object/fixtures/object/__third/moon/.cdist/parameter/name rename to cdist/test/object/fixtures/object/__third/moon/.cdist/parameter/name diff --git a/lib/cdist/test/object/fixtures/object/__third/moon/.cdist/parameter/planet b/cdist/test/object/fixtures/object/__third/moon/.cdist/parameter/planet similarity index 100% rename from lib/cdist/test/object/fixtures/object/__third/moon/.cdist/parameter/planet rename to cdist/test/object/fixtures/object/__third/moon/.cdist/parameter/planet diff --git a/lib/cdist/test/resolver/fixtures/object/__first/man/.cdist/.keep b/cdist/test/object/fixtures/type/__first/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/object/__first/man/.cdist/.keep rename to cdist/test/object/fixtures/type/__first/.keep diff --git a/lib/cdist/test/resolver/fixtures/object/__first/woman/.cdist/.keep b/cdist/test/object/fixtures/type/__second/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/object/__first/woman/.cdist/.keep rename to cdist/test/object/fixtures/type/__second/.keep diff --git a/lib/cdist/test/resolver/fixtures/object/__second/.keep b/cdist/test/object/fixtures/type/__third/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/object/__second/.keep rename to cdist/test/object/fixtures/type/__third/.keep diff --git a/lib/cdist/test/resolver/__init__.py b/cdist/test/resolver/__init__.py similarity index 95% rename from lib/cdist/test/resolver/__init__.py rename to cdist/test/resolver/__init__.py index ae8f6915..baae26de 100644 --- a/lib/cdist/test/resolver/__init__.py +++ b/cdist/test/resolver/__init__.py @@ -69,7 +69,7 @@ class ResolverTestCase(test.CdistTestCase): first_man.requirements = [second_on_the.name] second_on_the.requirements = [third_moon.name] self.assertEqual( - self.dependency_resolver.graph['__first/man'], + self.dependency_resolver.dependencies['__first/man'], [third_moon, second_on_the, first_man] ) @@ -79,10 +79,10 @@ class ResolverTestCase(test.CdistTestCase): first_man.requirements = [first_woman.name] first_woman.requirements = [first_man.name] with self.assertRaises(resolver.CircularReferenceError): - self.dependency_resolver.graph + self.dependency_resolver.dependencies def test_requirement_not_found(self): first_man = self.object_index['__first/man'] first_man.requirements = ['__does/not/exist'] with self.assertRaises(cdist.Error): - self.dependency_resolver.graph + self.dependency_resolver.dependencies diff --git a/lib/cdist/test/resolver/fixtures/object/__second/on-the/.cdist/.keep b/cdist/test/resolver/fixtures/object/__first/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/object/__second/on-the/.cdist/.keep rename to cdist/test/resolver/fixtures/object/__first/.keep diff --git a/lib/cdist/test/resolver/fixtures/object/__second/under-the/.cdist/.keep b/cdist/test/resolver/fixtures/object/__first/child/.cdist/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/object/__second/under-the/.cdist/.keep rename to cdist/test/resolver/fixtures/object/__first/child/.cdist/.keep diff --git a/lib/cdist/test/resolver/fixtures/object/__third/.keep b/cdist/test/resolver/fixtures/object/__first/dog/.cdist/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/object/__third/.keep rename to cdist/test/resolver/fixtures/object/__first/dog/.cdist/.keep diff --git a/lib/cdist/test/resolver/fixtures/object/__third/moon/.cdist/.keep b/cdist/test/resolver/fixtures/object/__first/man/.cdist/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/object/__third/moon/.cdist/.keep rename to cdist/test/resolver/fixtures/object/__first/man/.cdist/.keep diff --git a/lib/cdist/test/resolver/fixtures/type/__first/.keep b/cdist/test/resolver/fixtures/object/__first/woman/.cdist/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/type/__first/.keep rename to cdist/test/resolver/fixtures/object/__first/woman/.cdist/.keep diff --git a/lib/cdist/test/resolver/fixtures/type/__second/.keep b/cdist/test/resolver/fixtures/object/__second/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/type/__second/.keep rename to cdist/test/resolver/fixtures/object/__second/.keep diff --git a/lib/cdist/test/resolver/fixtures/type/__third/.keep b/cdist/test/resolver/fixtures/object/__second/on-the/.cdist/.keep similarity index 100% rename from lib/cdist/test/resolver/fixtures/type/__third/.keep rename to cdist/test/resolver/fixtures/object/__second/on-the/.cdist/.keep diff --git a/lib/cdist/test/type/fixtures/__name_path/.keep b/cdist/test/resolver/fixtures/object/__second/under-the/.cdist/.keep similarity index 100% rename from lib/cdist/test/type/fixtures/__name_path/.keep rename to cdist/test/resolver/fixtures/object/__second/under-the/.cdist/.keep diff --git a/lib/cdist/test/type/fixtures/__not_install/.keep b/cdist/test/resolver/fixtures/object/__third/.keep similarity index 100% rename from lib/cdist/test/type/fixtures/__not_install/.keep rename to cdist/test/resolver/fixtures/object/__third/.keep diff --git a/lib/cdist/test/type/fixtures/__not_singleton/.keep b/cdist/test/resolver/fixtures/object/__third/moon/.cdist/.keep similarity index 100% rename from lib/cdist/test/type/fixtures/__not_singleton/.keep rename to cdist/test/resolver/fixtures/object/__third/moon/.cdist/.keep diff --git a/lib/cdist/test/resolver/fixtures/object/__third/moon/.cdist/parameter/name b/cdist/test/resolver/fixtures/object/__third/moon/.cdist/parameter/name similarity index 100% rename from lib/cdist/test/resolver/fixtures/object/__third/moon/.cdist/parameter/name rename to cdist/test/resolver/fixtures/object/__third/moon/.cdist/parameter/name diff --git a/lib/cdist/test/resolver/fixtures/object/__third/moon/.cdist/parameter/planet b/cdist/test/resolver/fixtures/object/__third/moon/.cdist/parameter/planet similarity index 100% rename from lib/cdist/test/resolver/fixtures/object/__third/moon/.cdist/parameter/planet rename to cdist/test/resolver/fixtures/object/__third/moon/.cdist/parameter/planet diff --git a/lib/cdist/test/type/fixtures/__without_boolean_parameters/.keep b/cdist/test/resolver/fixtures/type/__first/.keep similarity index 100% rename from lib/cdist/test/type/fixtures/__without_boolean_parameters/.keep rename to cdist/test/resolver/fixtures/type/__first/.keep diff --git a/lib/cdist/test/type/fixtures/__without_explorers/.keep b/cdist/test/resolver/fixtures/type/__second/.keep similarity index 100% rename from lib/cdist/test/type/fixtures/__without_explorers/.keep rename to cdist/test/resolver/fixtures/type/__second/.keep diff --git a/lib/cdist/test/type/fixtures/__without_optional_parameters/.keep b/cdist/test/resolver/fixtures/type/__third/.keep similarity index 100% rename from lib/cdist/test/type/fixtures/__without_optional_parameters/.keep rename to cdist/test/resolver/fixtures/type/__third/.keep diff --git a/lib/cdist/test/type/__init__.py b/cdist/test/type/__init__.py similarity index 100% rename from lib/cdist/test/type/__init__.py rename to cdist/test/type/__init__.py diff --git a/conf/type/__mkfs/install b/cdist/test/type/fixtures/__install/install similarity index 100% rename from conf/type/__mkfs/install rename to cdist/test/type/fixtures/__install/install diff --git a/lib/cdist/test/type/fixtures/__without_required_parameters/.keep b/cdist/test/type/fixtures/__name_path/.keep similarity index 100% rename from lib/cdist/test/type/fixtures/__without_required_parameters/.keep rename to cdist/test/type/fixtures/__name_path/.keep diff --git a/lib/cdist/test/type/fixtures/list_types/__first/.keep b/cdist/test/type/fixtures/__not_install/.keep similarity index 100% rename from lib/cdist/test/type/fixtures/list_types/__first/.keep rename to cdist/test/type/fixtures/__not_install/.keep diff --git a/lib/cdist/test/type/fixtures/list_types/__second/.keep b/cdist/test/type/fixtures/__not_singleton/.keep similarity index 100% rename from lib/cdist/test/type/fixtures/list_types/__second/.keep rename to cdist/test/type/fixtures/__not_singleton/.keep diff --git a/lib/cdist/test/type/fixtures/__singleton/singleton b/cdist/test/type/fixtures/__singleton/singleton similarity index 100% rename from lib/cdist/test/type/fixtures/__singleton/singleton rename to cdist/test/type/fixtures/__singleton/singleton diff --git a/lib/cdist/test/type/fixtures/__with_boolean_parameters/parameter/boolean b/cdist/test/type/fixtures/__with_boolean_parameters/parameter/boolean similarity index 100% rename from lib/cdist/test/type/fixtures/__with_boolean_parameters/parameter/boolean rename to cdist/test/type/fixtures/__with_boolean_parameters/parameter/boolean diff --git a/lib/cdist/test/type/fixtures/__with_explorers/explorer/whatever b/cdist/test/type/fixtures/__with_explorers/explorer/whatever similarity index 100% rename from lib/cdist/test/type/fixtures/__with_explorers/explorer/whatever rename to cdist/test/type/fixtures/__with_explorers/explorer/whatever diff --git a/lib/cdist/test/type/fixtures/__with_optional_parameters/parameter/optional b/cdist/test/type/fixtures/__with_optional_parameters/parameter/optional similarity index 100% rename from lib/cdist/test/type/fixtures/__with_optional_parameters/parameter/optional rename to cdist/test/type/fixtures/__with_optional_parameters/parameter/optional diff --git a/lib/cdist/test/type/fixtures/__with_required_parameters/parameter/required b/cdist/test/type/fixtures/__with_required_parameters/parameter/required similarity index 100% rename from lib/cdist/test/type/fixtures/__with_required_parameters/parameter/required rename to cdist/test/type/fixtures/__with_required_parameters/parameter/required diff --git a/lib/cdist/test/type/fixtures/list_types/__third/.keep b/cdist/test/type/fixtures/__without_boolean_parameters/.keep similarity index 100% rename from lib/cdist/test/type/fixtures/list_types/__third/.keep rename to cdist/test/type/fixtures/__without_boolean_parameters/.keep diff --git a/conf/type/__partition_msdos/install b/cdist/test/type/fixtures/__without_explorers/.keep similarity index 100% rename from conf/type/__partition_msdos/install rename to cdist/test/type/fixtures/__without_explorers/.keep diff --git a/conf/type/__partition_msdos_apply/install b/cdist/test/type/fixtures/__without_optional_parameters/.keep similarity index 100% rename from conf/type/__partition_msdos_apply/install rename to cdist/test/type/fixtures/__without_optional_parameters/.keep diff --git a/lib/cdist/test/type/fixtures/__install/install b/cdist/test/type/fixtures/__without_required_parameters/.keep similarity index 100% rename from lib/cdist/test/type/fixtures/__install/install rename to cdist/test/type/fixtures/__without_required_parameters/.keep diff --git a/lib/cdist/test/util/__init__.py b/cdist/test/type/fixtures/list_types/__first/.keep similarity index 100% rename from lib/cdist/test/util/__init__.py rename to cdist/test/type/fixtures/list_types/__first/.keep diff --git a/lib/cdist/test/util/fsproperty.py b/cdist/test/type/fixtures/list_types/__second/.keep similarity index 100% rename from lib/cdist/test/util/fsproperty.py rename to cdist/test/type/fixtures/list_types/__second/.keep diff --git a/lib/cdist/util/__init__.py b/cdist/test/type/fixtures/list_types/__third/.keep similarity index 100% rename from lib/cdist/util/__init__.py rename to cdist/test/type/fixtures/list_types/__third/.keep diff --git a/cdist/test/util/__init__.py b/cdist/test/util/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/util/fsproperty.py b/cdist/test/util/fsproperty.py new file mode 100644 index 00000000..e69de29b diff --git a/cdist/util/__init__.py b/cdist/util/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/lib/cdist/util/fsproperty.py b/cdist/util/fsproperty.py similarity index 97% rename from lib/cdist/util/fsproperty.py rename to cdist/util/fsproperty.py index 55428c4d..5814b2b4 100644 --- a/lib/cdist/util/fsproperty.py +++ b/cdist/util/fsproperty.py @@ -134,7 +134,11 @@ class DirectoryDict(collections.MutableMapping): def __setitem__(self, key, value): try: with open(os.path.join(self.path, key), "w") as fd: - fd.write(str(value)) + if type(value) == type([]): + for v in value: + fd.write(str(v) + '\n') + else: + fd.write(str(value)) except EnvironmentError as e: raise cdist.Error(str(e)) diff --git a/conf/manifest/init.sample b/conf/manifest/init.sample deleted file mode 100755 index fca959e2..00000000 --- a/conf/manifest/init.sample +++ /dev/null @@ -1,69 +0,0 @@ -# -# This is a sample manifest, but used in real world -# - -# This is debug and should not be in a production environment -# echo "We could access other manifests in $__manifest" - -# Every machine becomes a marker, so sysadmins know that automatic -# configurations are happening -__file /etc/cdist-configured - -case "$__target_host" in - # Everybody has this - localhost) - require="__file/etc/cdist-configured" __link /tmp/cdist-testfile \ - --source /etc/cdist-configured --type symbolic - require="__directory/tmp/cdist-test-dir" __file /tmp/cdist-test-dir/test-file \ - --mode 0750 --owner nobody --group root - __directory /tmp/cdist-test-dir --mode 4777 - - require="__file/etc/cdist-configured __link/tmp/cdist-testfile" \ - __file /tmp/cdist-another-testfile - - ;; - - # - # Examples using different types - # - - # - # Use an alias in /etc/hosts for localhost to use these hosts: - # - # 127.0.0.1 localhost.localdomain localhost cdist-archlinux - # - cdist-archlinux) - # This is the specific package type for pacman - __package_pacman zsh --state installed - - # The __package type autoselect the right type based on the os - __package vim --state installed - - # If the type is a singleton, it does not take an object id - __issue - ;; - # This is how it would look like on gentoo - cdist-gentoo) - # Same stuff for gentoo - __package tree --state installed - ;; - - cdist-debian) - __package_apt atop --state installed - __package apache2 --state removed - ;; - - cdist-redhat) - __issue - __motd - ;; - - # Real machines may be used with their hostname or fqdn, - # depending on how you call cdist-deploy-to - # machine) - # ... - # ;; - # machine.example.org) - # ... - # ;; -esac diff --git a/conf/type/__addifnosuchline/man.text b/conf/type/__addifnosuchline/man.text deleted file mode 100644 index 3051ff36..00000000 --- a/conf/type/__addifnosuchline/man.text +++ /dev/null @@ -1,52 +0,0 @@ -cdist-type__addifnosuchline(7) -============================== -Daniel Roth - - -NAME ----- -cdist-type__addifnosuchline - Add a line (if not existing already) - - -DESCRIPTION ------------ -This type can be used to check a file for existence of a -specific line and adding it, if it was not found. - - -REQUIRED PARAMETERS -------------------- -line:: - Specifies the content which shall be added if not existing. - - -OPTIONAL PARAMETERS -------------------- -file:: - If supplied, use this as the destination file. - Otherwise the object_id is used. -regex:: - If supplied, search for this regex. - Otherwise entire line must be matched. - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Creates or appends the line specifiend in "include_www" to the file "lighttpd.conf" -__addifnosuchline www --file /etc/lighttpd.conf --line include_www - -# Adds the line "include_git" to the file "lighttpd.conf" -__addifnosuchline /etc/lighttpd.conf --line include_git --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) - - -COPYING -------- -Copyright \(C) 2011 Daniel Roth. Free use of this software is -granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__addifnosuchline/parameter/required b/conf/type/__addifnosuchline/parameter/required deleted file mode 100644 index a999a0c2..00000000 --- a/conf/type/__addifnosuchline/parameter/required +++ /dev/null @@ -1 +0,0 @@ -line diff --git a/conf/type/__autofs_map/manifest b/conf/type/__autofs_map/manifest deleted file mode 100755 index d86ea799..00000000 --- a/conf/type/__autofs_map/manifest +++ /dev/null @@ -1,42 +0,0 @@ -#!/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 . -# - -name="/$__object_id" -map="$(cat "$__object/parameter/map")" - -if [ -f "$__object/parameter/type" ]; then - type="$(cat "$__object/parameter/type")" -else - type="file" - echo "$type" > "$__object/parameter/type" -fi - -# Generate entry for use in auto.master -entry="${name} ${type}:${map}" -if [ -f "$__object/parameter/options" ]; then - entry="$entry $(cat "$__object/parameter/options")" -fi -if [ -f "$__object/parameter/comment" ]; then - echo "# $(cat "$__object/parameter/comment")" > "$__object/parameter/entry" -fi -echo "$entry" >> "$__object/parameter/entry" - -require="$__object_name" __autofs_master - diff --git a/conf/type/__autofs_master/files/auto.master.header b/conf/type/__autofs_master/files/auto.master.header deleted file mode 100644 index 53590257..00000000 --- a/conf/type/__autofs_master/files/auto.master.header +++ /dev/null @@ -1,3 +0,0 @@ -# Generated from cdist __autofs_master -# Do not change this file. Changes will be overwritten. - diff --git a/conf/type/__autofs_master/gencode-local b/conf/type/__autofs_master/gencode-local deleted file mode 100755 index 701f97a8..00000000 --- a/conf/type/__autofs_master/gencode-local +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 . -# -# -# Generate auto.master config based on all defined __autofs_map ojbects. -# - -auto_master="$__object/files/auto.master" -cat "$(cat "$__object/parameter/header")" > "$auto_master" -find "$__global/object/__autofs_map" -path "*.cdist/parameter/entry" | xargs cat >> "$auto_master" diff --git a/conf/type/__autofs_master/parameter/optional b/conf/type/__autofs_master/parameter/optional deleted file mode 100644 index 8e83f898..00000000 --- a/conf/type/__autofs_master/parameter/optional +++ /dev/null @@ -1 +0,0 @@ -header diff --git a/conf/type/__directory/gencode-remote b/conf/type/__directory/gencode-remote deleted file mode 100755 index e871547a..00000000 --- a/conf/type/__directory/gencode-remote +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/sh -# -# 2011 Nico Schottelius (nico-cdist at schottelius.org) -# -# 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="/$__object_id" -state_should="$(cat "$__object/parameter/state")" - -case "$state_should" in - present) - # Include parent directories? - if [ -f "$__object/parameter/parents" ]; then - parents="$(cat "$__object/parameter/parents")" - if [ yes = "$parents" ]; then - mkdiropt="-p" - else - mkdiropt="" - fi - fi - - if [ -f "$__object/parameter/recursive" ]; then - if [ yes = "$(cat "$__object/parameter/recursive")" ]; then - recursive="-R" - fi - fi - - # Only create if not already existent - if [ no = "$(cat "$__object/explorer/exists")" ]; then - echo mkdir $mkdiropt \"$destination\" - fi - - # Mode settings - if [ -f "$__object/parameter/mode" ]; then - echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\" - fi - - # Group - if [ -f "$__object/parameter/group" ]; then - echo chgrp $recursive \"$(cat "$__object/parameter/group")\" \"$destination\" - fi - - # Owner - if [ -f "$__object/parameter/owner" ]; then - echo chown $recursive \"$(cat "$__object/parameter/owner")\" \"$destination\" - fi - ;; - absent) - # Only delete if it exists - if [ yes = "$(cat "$__object/explorer/exists")" ]; then - echo rm -rf \"$destination\" - fi - - ;; - *) - echo "Unknown state: $state_should" >&2 - exit 1 - ;; -esac diff --git a/conf/type/__key_value/gencode-remote b/conf/type/__key_value/gencode-remote deleted file mode 100755 index 0846dca1..00000000 --- a/conf/type/__key_value/gencode-remote +++ /dev/null @@ -1,57 +0,0 @@ -#!/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 . -# - -key="$(cat "$__object/parameter/key")" -file="$(cat "$__object/parameter/file")" -delimiter="$(cat "$__object/parameter/delimiter")" -value="$(cat "$__object/parameter/value")" - -state_is="$(cat "$__object/explorer/state")" -state_should="$(cat "$__object/parameter/state")" - -if [ "$state_is" = "$state_should" ]; then - # nothing to do - exit 0 -fi - -case "$state_should" in - absent) - # remove lines starting with key - echo "sed -i '/^$key\($delimiter\+\)/d' \"$file\"" - ;; - present) - case "$state_is" in - absent) - # add new key and value - echo "echo \"${key}${delimiter}${value}\" >> \"$file\"" - ;; - wrongvalue) - # change exisiting value - echo "sed -i \"s|^$key\($delimiter\+\).*|$key\1$value|\" \"$file\"" - ;; - *) - echo "Unknown explorer state: $state_is" >&2 - exit 1 - esac - ;; - *) - echo "Unknown state: $state_should" >&2 - exit 1 -esac diff --git a/conf/type/__key_value/manifest b/conf/type/__key_value/manifest deleted file mode 100755 index 2e75e175..00000000 --- a/conf/type/__key_value/manifest +++ /dev/null @@ -1,30 +0,0 @@ -#!/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 -key="$(cat "$__object/parameter/key" 2>/dev/null \ - || echo "$__object_id" | tee "$__object/parameter/key")" -state="$(cat "$__object/parameter/state" 2>/dev/null \ - || echo "present" | tee "$__object/parameter/state")" - -if [ "$state" = "present" -a ! -f "$__object/parameter/value" ]; then - echo "Missing required parameter 'value'" >&2 - exit 1 -fi diff --git a/conf/type/__mkfs/man.text b/conf/type/__mkfs/man.text deleted file mode 100644 index 4320c639..00000000 --- a/conf/type/__mkfs/man.text +++ /dev/null @@ -1,57 +0,0 @@ -cdist-type__mkfs(7) -=================== -Steven Armstrong - - -NAME ----- -cdist-type__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 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 --------- - --------------------------------------------------------------------------------- -# reiserfs /dev/sda5 -__mkfs /dev/sda5 --type reiserfs -# same thing with explicit device -__mkfs whatever --device /dev/sda5 --type reiserfs - -# jfs with journal on /dev/sda2 -__mkfs /dev/sda1 --type jfs --options "-j /dev/sda2" --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) -- mkfs(8) - - -COPYING -------- -Copyright \(C) 2011 Steven Armstrong. Free use of this software is -granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__mkfs/manifest b/conf/type/__mkfs/manifest deleted file mode 100755 index e9d275a4..00000000 --- a/conf/type/__mkfs/manifest +++ /dev/null @@ -1,31 +0,0 @@ -#!/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/conf/type/__mkfs/parameter/optional b/conf/type/__mkfs/parameter/optional deleted file mode 100644 index 86aeae30..00000000 --- a/conf/type/__mkfs/parameter/optional +++ /dev/null @@ -1,3 +0,0 @@ -device -options -blocks diff --git a/conf/type/__mkfs/parameter/required b/conf/type/__mkfs/parameter/required deleted file mode 100644 index aa80e646..00000000 --- a/conf/type/__mkfs/parameter/required +++ /dev/null @@ -1 +0,0 @@ -type diff --git a/conf/type/__package_pip/parameter/optional b/conf/type/__package_pip/parameter/optional deleted file mode 100644 index a1b589e3..00000000 --- a/conf/type/__package_pip/parameter/optional +++ /dev/null @@ -1 +0,0 @@ -pip diff --git a/conf/type/__package_yum/parameter/optional b/conf/type/__package_yum/parameter/optional deleted file mode 100644 index f121bdbf..00000000 --- a/conf/type/__package_yum/parameter/optional +++ /dev/null @@ -1 +0,0 @@ -name diff --git a/conf/type/__partition_msdos/man.text b/conf/type/__partition_msdos/man.text deleted file mode 100644 index 78220ee0..00000000 --- a/conf/type/__partition_msdos/man.text +++ /dev/null @@ -1,62 +0,0 @@ -cdist-type__partition_msdos(7) -============================== -Steven Armstrong - - -NAME ----- -cdist-type__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 --------- - --------------------------------------------------------------------------------- -# 128MB, linux, bootable -__partition_msdos /dev/sda1 --type 83 --size 128M --bootable true -# 512MB, swap -__partition_msdos /dev/sda2 --type 82 --size 512M -# 100GB, extended -__partition_msdos /dev/sda3 --type extended --size 100G -# 10GB, linux -__partition_msdos /dev/sda5 --type 83 --size 10G -# 50% of the free space of the extended partition, linux -__partition_msdos /dev/sda6 --type 83 --size 50% -# rest of the extended partition, linux -__partition_msdos /dev/sda7 --type 83 --size + --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) - - -COPYING -------- -Copyright \(C) 2011 Steven Armstrong. Free use of this software is -granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__partition_msdos/manifest b/conf/type/__partition_msdos/manifest deleted file mode 100755 index 21e43856..00000000 --- a/conf/type/__partition_msdos/manifest +++ /dev/null @@ -1,41 +0,0 @@ -#!/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" __partition_msdos_apply diff --git a/conf/type/__partition_msdos/parameter/optional b/conf/type/__partition_msdos/parameter/optional deleted file mode 100644 index b2b0a4c2..00000000 --- a/conf/type/__partition_msdos/parameter/optional +++ /dev/null @@ -1,3 +0,0 @@ -partition -bootable -size diff --git a/conf/type/__partition_msdos/parameter/required b/conf/type/__partition_msdos/parameter/required deleted file mode 100644 index aa80e646..00000000 --- a/conf/type/__partition_msdos/parameter/required +++ /dev/null @@ -1 +0,0 @@ -type diff --git a/conf/type/__partition_msdos_apply/explorer/partitions b/conf/type/__partition_msdos_apply/explorer/partitions deleted file mode 100755 index 6be61af4..00000000 --- a/conf/type/__partition_msdos_apply/explorer/partitions +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -cat /proc/partitions diff --git a/conf/type/__partition_msdos_apply/files/lib.sh b/conf/type/__partition_msdos_apply/files/lib.sh deleted file mode 100644 index 5767ea43..00000000 --- a/conf/type/__partition_msdos_apply/files/lib.sh +++ /dev/null @@ -1,61 +0,0 @@ -die() { - echo "[__partition_msdos_apply] $@" >&2 - exit 1 -} -debug() { - #echo "[__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" - # give disk some time - sleep 1 - return $? -} - -create_disklabel() { - local device=$1 - - debug create_disklabel "creating new msdos disklabel" - fdisk_command ${device} "o" - 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/conf/type/__partition_msdos_apply/gencode-remote b/conf/type/__partition_msdos_apply/gencode-remote deleted file mode 100755 index 5dab7070..00000000 --- a/conf/type/__partition_msdos_apply/gencode-remote +++ /dev/null @@ -1,138 +0,0 @@ -#!/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 . -# - -die() { - echo "[__partition_msdos_apply] $@" >&2 - exit 1 -} -debug() { - #echo "[__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]\+\)\([MmGg%]\)[Bb]\?:\1|\2:')" - local number="$(echo ${number_suffix} | cut -d '|' -f1)" - local suffix="$(echo ${number_suffix} | cut -d '|' -f2)" - - case "$suffix" in - M|m) - size="$number" - ;; - G|g) - size="$(( $number * 1024 ))" - ;; - %) - size="$(( $available_size * $number / 100 ))" - ;; - *) - size="-1" - esac - echo "$size" -} - -# include function library for use on target -cat "$__type/files/lib.sh" - -partitions="$__object/explorer/partitions" -objects=$(find "$__global/object/__partition_msdos" -path "*.cdist") -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'" -done - diff --git a/conf/type/__postgres_database/parameter/required b/conf/type/__postgres_database/parameter/required deleted file mode 100644 index ff72b5c7..00000000 --- a/conf/type/__postgres_database/parameter/required +++ /dev/null @@ -1 +0,0 @@ -state diff --git a/conf/type/__postgres_role/gencode-remote b/conf/type/__postgres_role/gencode-remote deleted file mode 100755 index a3280c09..00000000 --- a/conf/type/__postgres_role/gencode-remote +++ /dev/null @@ -1,54 +0,0 @@ -#!/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 . -# - -name="$__object_id" -state_is="$(cat "$__object/explorer/state")" -state_should="$(cat "$__object/parameter/state")" - -if [ "$state_is" != "$state_should" ]; then - case "$state_should" in - present) - optional="password - login - createdb - createrole - superuser" - for parameter in $optional; do - if [ -f "$__object/parameter/$parameter" ]; then - value="$(cat "$__object/parameter/$parameter")" - eval $parameter=$value - fi - done - - [ -n "$password" ] && password="PASSWORD '$password'" - [ "$login" = "true" ] && login="LOGIN" || login="NOLOGIN" - [ "$createdb" = "true" ] && createdb="CREATEDB" || createdb="NOCREATEDB" - [ "$createrole" = "true" ] && createrole="CREATEROLE" || createrole="NOCREATEROLE" - [ "$superuser" = "true" ] && superuser="SUPERUSER" || superuser="NOSUPERUSER" - [ "$inherit" = "true" ] && inherit="INHERIT" || inherit="NOINHERIT" - - cmd="CREATE ROLE $name WITH $password $login $createdb $createrole $superuser $inherit" - echo "su - postgres -c \"psql -c \\\"$cmd\\\"\"" - ;; - absent) - echo "su - postgres -c \"dropuser \\\"$name\\\"\"" - ;; - esac -fi diff --git a/conf/type/__postgres_role/parameter/required b/conf/type/__postgres_role/parameter/required deleted file mode 100644 index ff72b5c7..00000000 --- a/conf/type/__postgres_role/parameter/required +++ /dev/null @@ -1 +0,0 @@ -state diff --git a/conf/type/__process/parameter/required b/conf/type/__process/parameter/required deleted file mode 100644 index ff72b5c7..00000000 --- a/conf/type/__process/parameter/required +++ /dev/null @@ -1 +0,0 @@ -state diff --git a/conf/type/__removeline/gencode-remote b/conf/type/__removeline/gencode-remote deleted file mode 100755 index 3ec466b9..00000000 --- a/conf/type/__removeline/gencode-remote +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh -# -# 2010-2011 Daniel Roth (dani-cdist@d-roth.li) -# -# 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/file" ]; then - file=$(cat "$__object/parameter/file") -else - file="/$__object_id" -fi - -line=$(cat "$__object/parameter/line") -echo "ex -c \"/${line}/d|w|q\" \"${file}\" < - - -NAME ----- -cdist-type__removeline - Remove a line (if existing) - - -DESCRIPTION ------------ -This type can be used to check a file for existence of a -specific line and removeing it, if it was found. - - -REQUIRED PARAMETERS -------------------- -line:: - Specifies the content which shall be removed if existing. - - -OPTIONAL PARAMETERS -------------------- -file:: - If supplied, use this as the destination file. - Otherwise the object_id is used. - - -EXAMPLES --------- - --------------------------------------------------------------------------------- -# Removes the line specifiend in "include_www" from the file "lighttpd.conf" -__removeline www --file /etc/lighttpd.conf --line include_www - -# Removes the line "include_git" from the file "lighttpd.conf" -__removeline /etc/lighttpd.conf --line include_git --------------------------------------------------------------------------------- - - -SEE ALSO --------- -- cdist-type(7) - - -COPYING -------- -Copyright \(C) 2011 Daniel Roth. Free use of this software is -granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__removeline/parameter/optional b/conf/type/__removeline/parameter/optional deleted file mode 100644 index f73f3093..00000000 --- a/conf/type/__removeline/parameter/optional +++ /dev/null @@ -1 +0,0 @@ -file diff --git a/conf/type/__removeline/parameter/required b/conf/type/__removeline/parameter/required deleted file mode 100644 index a999a0c2..00000000 --- a/conf/type/__removeline/parameter/required +++ /dev/null @@ -1 +0,0 @@ -line diff --git a/conf/type/__rvm/parameter/required b/conf/type/__rvm/parameter/required deleted file mode 100644 index ff72b5c7..00000000 --- a/conf/type/__rvm/parameter/required +++ /dev/null @@ -1 +0,0 @@ -state diff --git a/conf/type/__rvm_gem/manifest b/conf/type/__rvm_gem/manifest deleted file mode 100755 index 245c865d..00000000 --- a/conf/type/__rvm_gem/manifest +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# -# 2012 Evax Software -# -# 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 . -# - -gem="$__object_id" -gemset="$(cat "$__object/parameter/gemset")" -ruby="$(echo "$gemset" | cut -d '@' -f 1)" -gemsetname="$(echo "$gemset" | cut -d '@' -f 2)" -user="$(cat "$__object/parameter/user")" -state="$(cat "$__object/explorer/state")" -if [ -f "$__object/parameter/default" ]; then - default="$(cat "$__object/parameter/default")" -else - default="no" - echo $default > "$__object/parameter/default" -fi - -__rvm "$user" --state installed -require="__rvm/$user" \ - __rvm_ruby $ruby --user "$user" --state installed --default $default -require="__rvm_ruby/$ruby" \ - __rvm_gemset $gemset --user "$user" --state installed --default $default diff --git a/conf/type/__rvm_gemset/manifest b/conf/type/__rvm_gemset/manifest deleted file mode 100755 index 4fdf9cb1..00000000 --- a/conf/type/__rvm_gemset/manifest +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# -# 2012 Evax Software -# -# 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 . -# - -gemset="$__object_id" -ruby="$(echo "$gemset" | cut -d '@' -f 1)" -gemsetname="$(echo "$gemset" | cut -d '@' -f 2)" -user="$(cat "$__object/parameter/user")" -state="$(cat "$__object/explorer/state")" -if [ -f "$__object/parameter/default" ]; then - default="$(cat "$__object/parameter/default")" -else - default="no" - echo $default > "$__object/parameter/default" -fi - -__rvm "$user" --state installed -require="__rvm/$user" \ - __rvm_ruby $ruby --user "$user" --state installed --default $default - diff --git a/conf/type/__rvm_ruby/manifest b/conf/type/__rvm_ruby/manifest deleted file mode 100755 index c6e31244..00000000 --- a/conf/type/__rvm_ruby/manifest +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/sh -# -# 2012 Evax Software -# -# 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/default" ]; then - default="$(cat "$__object/parameter/default")" -else - default="no" - echo "$default" > "$__object/parameter/default" -fi - -ruby="$__object_id" -user="$(cat "$__object/parameter/user")" -state="$(cat "$__object/explorer/state")" - -apt_ruby="build-essential openssl libreadline6 libreadline6-dev curl git-core -zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 -libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison -subversion" -apt_jruby="curl g++ openjdk-6-jre-headless" -apt_jruby_head="ant openjdk-6-jdk" -apt_ironruby="curl mono-2.0-devel" - -emerge_ruby="libiconv readline zlib openssl curl git libyaml sqlite libxslt -libtool gcc autoconf automake bison m4" -emerge_jruby="dev-java/sun-jdk dev-java/sun-jre-bin" -emerge_ironruby="dev-lang/mono" - -pacman_ruby="gcc patch curl zlib readline libxml2 libxslt git autoconf -diffutils make libtool bison subversion" -pacman_jruby="jdk jre curl" -pacman_ironruby="mono" - -yum_ruby="gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel -libffi-devel openssl-devel make bzip2 autoconf automake libtool bison -iconv-devel" -yum_jruby="java" - -os="$(cat "$__global/explorer/os")" -case "$os" in - archlinux) type="pacman" ;; - debian|ubuntu) type="apt" ;; - gentoo) type="emerge" ;; - fedora|redhat|centos) type="yum" ;; - *);; -esac -case "$ruby" in - ruby-head*) - deps_list="${type}_ruby_head" - ;; - ruby*) - deps_list="${type}_ruby" - ;; - jruby-head*) - deps_list="${type}_jruby_head" - ;; - jruby*) - deps_list="${type}_jruby" - ;; - ironruby*) - deps_list="${type}_ironruby" - ;; -esac -deps=$(eval echo \$$deps_list) -for p in $deps; do __package_${type} $p --state installed; done - -__rvm "$user" --state installed diff --git a/doc/dev/releasechecklist b/doc/dev/releasechecklist deleted file mode 100755 index eba81dc0..00000000 --- a/doc/dev/releasechecklist +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/sh -# Nico Schottelius - -files="doc/changelog lib/cdist/__init__.py" - -# Stuff to take care of when doing a release -echo "Preparing next release" - -# Ensure documentation builds cleanly -echo "Testing documentation..." -./build clean && ./build man || exit 1 - -# get version -changelog_version=$(grep '^[[:digit:]]' doc/changelog | head -n1 | sed 's/:.*//') -#git_version=$(git describe) -lib_version=$(grep ^VERSION lib/cdist/__init__.py | sed -e 's/.*= //' -e 's/"//g') - -# get date -date_today="$(date +%Y-%m-%d)" -date_changelog=$(grep '^[[:digit:]]' doc/changelog | head -n1 | sed 's/.*: //') - -echo "Ensure you fixed/prepared version files: $files" -echo "changelog: $changelog_version" -#echo "git: $git_version" -echo "lib: $lib_version" - -if [ "$date_today" != "$date_changelog" ]; then - echo "Messed up date, not releasing:" - echo "Changelog: $date_changelog" - exit 1 -fi - -if [ "$lib_version" != "$changelog_version" ]; then - echo "Messed up versions, not releasing" - exit 1 -else - echo "Versions are sane, continuing" -fi -echo "Press enter to continue" -read wait -version=$lib_version - -# get target branch -branch=${version%.?} - -# add tag -printf "Enter tag description for %s> " "$version" -read tagmessage -git tag "$version" -m "$tagmessage" - -# Import into current version branch -printf "Press enter to git merge into $branch > " -read prompt -git checkout $branch -git merge master -git checkout master - -# Publish manpages and sourcecode -printf "Press enter to publish doc/ and code/ > " -read prompt -./build web -./build pub - -cat << notes -To be done manually... - - - freecode release - - blog entry - - linkedin entry - - mailinglist update - -notes diff --git a/doc/changelog b/docs/changelog similarity index 66% rename from doc/changelog rename to docs/changelog index ce9f798b..943d83e4 100644 --- a/doc/changelog +++ b/docs/changelog @@ -4,9 +4,109 @@ Changelog * Changes are always commented with their author in (braces) * Exception: No braces means author == Nico Schottelius -2.0.10: +next: + * Core: Ensure global and type explorers are executable + * Type __rvm_gemset: Change parameter "default" to be boolean + * New Type: __user_groups (Steven Armstrong) + * Type __user: Remove --groups support (now provided by __user_groups) + * Type __apt_ppa: Bugfix: Installeded ppa detection (Steven Armstrong) + * Core: Support for --after and --before parameters + +2.1.0pre8: 2012-11-15 + * Type cleanup: __apt_ppa, __apt_ppa_update_index, __file, + __ssh_authorized_key, __timezone, all install types (Steven Armstrong) + * Types: Remove all parameter changing code + * Type __rvm_ruby: Change parameter "default" to be boolean + * Documentation: Web documentation clean up + +2.1.0pre7: 2012-11-07 + * Core: All unit tests restored back to working + * Core: Print error message when missing the initial manifest + +2.1.0pre6: 2012-11-05 + * New Example: Turn remote calls into local calls (used for unittesting) + * Core: Export PYTHONPATH, it's also needed by emulator + * Bugfix Type __rvm_ruby: Add clean package dependencies + * Bugfix Type __rvm_gem: Run rvm as user, not as root + * Cleanup Type __rvm, __rvm_gemset: Use shortcut version + * Bugfix __rvm_gemset: Correctly check for gemsets + * Cleanup Type __postgres_database, __postgres_role: Reference each other + in documentation + * Cleanp Type __postgres_role: Use boolean parameters where appropriate + * Cleanp Type __postgres_role: Use shortcut version + +2.1.0pre5: 2012-11-01 + * Core: First round of tests updated to work with multiple configuration directories + +2.1.0pre4: 2012-10-31 + * Dist: PyPi: Moved cdist.py to script/cdist to avoid double import + * Core: Added support for multiple configuration directories (no documentation) + +2.1.0pre3: 2012-10-30 + * Dist: PyPi: Types and explorer included as package data + +2.1.0pre2: 2012-10-26 + * Dist: PyPi: Add conf/ directory to distribution + * Dist: Initial support for archlinux packaging + +2.1.0pre1: 2012-10-26 + * Core: Removed obsolete variable __self + * Removed type __addifnosuchline (replaced by __line) + * Removed type __removeline (replaced by __line) + * Type __directory: Parameter --parents and --recursive are now boolean + * Type __package_apt, __package_luarocks, __package_opkg, + __package_pacman, __package_pkg_freebsd, __package_pkg_openbsd, + __package_rubygem, __package_yum, __process: + Parameter state accepts only "present" and "absent" + * Dist: Initial support for pypi packaging + +2.0.15: 2012-11-02 + * Core: Make variable __object_name available in type explorers (Steven Armtrong) + * New Type: __qemu_img + * New Type: __line + * New Type: __pf_apply (Jake Guffey) + * New Type: __pf_ruleset (Jake Guffey) + * Bugfix Type: __rvm: Make type work if rvm is already installed + +2.0.14: 2012-09-07 + * Bugfix Type: __jail: Use correct variable (Jake Guffey) + * Change Type: __jail: Parameter jailbase now optional (Jake Guffey) + * Bugfix Type: __user: Use passwd database on FreeBSD (Jake Guffey) + * Bugfix Type: __start_on_boot: Do not change parameters + * Feature __user: Added support for BSDs (Sébastien Gross) + * Feature __group: Added support for FreeBSD (Jake Guffey) + * New Type: __package_zypper + * Feature Types: Initial Support for SuSE Linux + +2.0.13: 2012-06-05 + * Bugfix __ssh_authorized_key: Ensure it sets proper group (contradict) + * Bugfix __addifnosuchline: Fixed quotes/interpolation bug ("a b" became "a b") + * New Explorer: interfaces (Sébastien Gross) + * Feature core: Support reading from stdin in types (Steven Armstrong) + * Feature core: Support multiple parameters for types (Steven Armstrong) + * Feature __file: Support reading from stdin with - syntax (Steven Armstrong) + +2.0.12: 2012-05-29 + * Core: Correctly raise error on Python < 3.2 (Steven Armtrong) + * Core: Add support for --remote-exec and --remote-copy parameters + * Documentation: Debian Squeeze hints (Sébastien Gross) + +2.0.11: 2012-05-23 + * Fix insecure file/directory creation: Use umask 077 + +2.0.10: 2012-05-18 * Cleanup __group: No getent gshadow in old Redhat, use groupmod -g (Matt Coddington) + * Bugfix __package_yum: Missing cat + * Bugfix __start_on_boot: Correctly use sed and quotes (Steven Armstrong) + * Feature __file: Support for --state exists (Steven Armstrong) + * Feature core: Make variable __manifest available to type manifests + * Feature core: Correct parent dependency handling (Steven Armstrong) + * Bugfix several types: Fix sed for FreeBSD (Istvan Beregszaszi) + * New Type: __jail (Jake Guffey) + * Change Type: __rvm*: --state present/absent not installed/remvoed (Evax Software) + * Bugfix Type: __cron: Hide error output from crontab + * Various smaller bugfixes (Chris Lamb) 2.0.9: 2012-03-12 * Cleanup documentation: Fix environment variable list to be properly diff --git a/doc/dev/benchmark-oprofile b/docs/dev/benchmark-oprofile similarity index 100% rename from doc/dev/benchmark-oprofile rename to docs/dev/benchmark-oprofile diff --git a/doc/dev/benchmark-parallel-deploy b/docs/dev/benchmark-parallel-deploy similarity index 100% rename from doc/dev/benchmark-parallel-deploy rename to docs/dev/benchmark-parallel-deploy diff --git a/doc/dev/debug/bach25-1.6.2-373-g6fd31f8 b/docs/dev/debug/bach25-1.6.2-373-g6fd31f8 similarity index 100% rename from doc/dev/debug/bach25-1.6.2-373-g6fd31f8 rename to docs/dev/debug/bach25-1.6.2-373-g6fd31f8 diff --git a/doc/dev/debug/ikq04-1.6.2-373-g6fd31f8-dbg b/docs/dev/debug/ikq04-1.6.2-373-g6fd31f8-dbg similarity index 100% rename from doc/dev/debug/ikq04-1.6.2-373-g6fd31f8-dbg rename to docs/dev/debug/ikq04-1.6.2-373-g6fd31f8-dbg diff --git a/doc/dev/fancy-ideas b/docs/dev/fancy-ideas similarity index 100% rename from doc/dev/fancy-ideas rename to docs/dev/fancy-ideas diff --git a/doc/dev/git-post-commit-hook b/docs/dev/git-post-commit-hook similarity index 100% rename from doc/dev/git-post-commit-hook rename to docs/dev/git-post-commit-hook diff --git a/doc/dev/header b/docs/dev/header similarity index 100% rename from doc/dev/header rename to docs/dev/header diff --git a/doc/dev/lastchanges b/docs/dev/lastchanges similarity index 100% rename from doc/dev/lastchanges rename to docs/dev/lastchanges diff --git a/doc/dev/logs/2010-09-25 b/docs/dev/logs/2010-09-25 similarity index 100% rename from doc/dev/logs/2010-09-25 rename to docs/dev/logs/2010-09-25 diff --git a/doc/dev/logs/2010-11-02.steven b/docs/dev/logs/2010-11-02.steven similarity index 100% rename from doc/dev/logs/2010-11-02.steven rename to docs/dev/logs/2010-11-02.steven diff --git a/doc/dev/logs/2010-11-09 b/docs/dev/logs/2010-11-09 similarity index 100% rename from doc/dev/logs/2010-11-09 rename to docs/dev/logs/2010-11-09 diff --git a/doc/dev/logs/2010-11-21 b/docs/dev/logs/2010-11-21 similarity index 100% rename from doc/dev/logs/2010-11-21 rename to docs/dev/logs/2010-11-21 diff --git a/doc/dev/logs/2010-11-29 b/docs/dev/logs/2010-11-29 similarity index 100% rename from doc/dev/logs/2010-11-29 rename to docs/dev/logs/2010-11-29 diff --git a/doc/dev/logs/2010-12-01 b/docs/dev/logs/2010-12-01 similarity index 100% rename from doc/dev/logs/2010-12-01 rename to docs/dev/logs/2010-12-01 diff --git a/doc/dev/logs/2010-12-01.handwritten/SCAN0000.PDF b/docs/dev/logs/2010-12-01.handwritten/SCAN0000.PDF similarity index 100% rename from doc/dev/logs/2010-12-01.handwritten/SCAN0000.PDF rename to docs/dev/logs/2010-12-01.handwritten/SCAN0000.PDF diff --git a/doc/dev/logs/2010-12-01.handwritten/SCAN0001.PDF b/docs/dev/logs/2010-12-01.handwritten/SCAN0001.PDF similarity index 100% rename from doc/dev/logs/2010-12-01.handwritten/SCAN0001.PDF rename to docs/dev/logs/2010-12-01.handwritten/SCAN0001.PDF diff --git a/doc/dev/logs/2010-12-01.handwritten/SCAN0002.PDF b/docs/dev/logs/2010-12-01.handwritten/SCAN0002.PDF similarity index 100% rename from doc/dev/logs/2010-12-01.handwritten/SCAN0002.PDF rename to docs/dev/logs/2010-12-01.handwritten/SCAN0002.PDF diff --git a/doc/dev/logs/2010-12-01.handwritten/SCAN0003.PDF b/docs/dev/logs/2010-12-01.handwritten/SCAN0003.PDF similarity index 100% rename from doc/dev/logs/2010-12-01.handwritten/SCAN0003.PDF rename to docs/dev/logs/2010-12-01.handwritten/SCAN0003.PDF diff --git a/doc/dev/logs/2010-12-01.handwritten/SCAN0004.PDF b/docs/dev/logs/2010-12-01.handwritten/SCAN0004.PDF similarity index 100% rename from doc/dev/logs/2010-12-01.handwritten/SCAN0004.PDF rename to docs/dev/logs/2010-12-01.handwritten/SCAN0004.PDF diff --git a/doc/dev/logs/2011-01-17 b/docs/dev/logs/2011-01-17 similarity index 100% rename from doc/dev/logs/2011-01-17 rename to docs/dev/logs/2011-01-17 diff --git a/doc/dev/logs/2011-01-18.type-creation b/docs/dev/logs/2011-01-18.type-creation similarity index 100% rename from doc/dev/logs/2011-01-18.type-creation rename to docs/dev/logs/2011-01-18.type-creation diff --git a/doc/dev/logs/2011-01-24 b/docs/dev/logs/2011-01-24 similarity index 100% rename from doc/dev/logs/2011-01-24 rename to docs/dev/logs/2011-01-24 diff --git a/doc/dev/logs/2011-02-03 b/docs/dev/logs/2011-02-03 similarity index 100% rename from doc/dev/logs/2011-02-03 rename to docs/dev/logs/2011-02-03 diff --git a/doc/dev/logs/2011-02-04.steven b/docs/dev/logs/2011-02-04.steven similarity index 100% rename from doc/dev/logs/2011-02-04.steven rename to docs/dev/logs/2011-02-04.steven diff --git a/doc/dev/logs/2011-02-22 b/docs/dev/logs/2011-02-22 similarity index 100% rename from doc/dev/logs/2011-02-22 rename to docs/dev/logs/2011-02-22 diff --git a/doc/dev/logs/2011-02-24 b/docs/dev/logs/2011-02-24 similarity index 100% rename from doc/dev/logs/2011-02-24 rename to docs/dev/logs/2011-02-24 diff --git a/doc/dev/logs/2011-02-27 b/docs/dev/logs/2011-02-27 similarity index 100% rename from doc/dev/logs/2011-02-27 rename to docs/dev/logs/2011-02-27 diff --git a/doc/dev/logs/2011-03-03 b/docs/dev/logs/2011-03-03 similarity index 100% rename from doc/dev/logs/2011-03-03 rename to docs/dev/logs/2011-03-03 diff --git a/doc/dev/logs/2011-03-07 b/docs/dev/logs/2011-03-07 similarity index 100% rename from doc/dev/logs/2011-03-07 rename to docs/dev/logs/2011-03-07 diff --git a/doc/dev/logs/2011-03-09 b/docs/dev/logs/2011-03-09 similarity index 100% rename from doc/dev/logs/2011-03-09 rename to docs/dev/logs/2011-03-09 diff --git a/doc/dev/logs/2011-03-15 b/docs/dev/logs/2011-03-15 similarity index 100% rename from doc/dev/logs/2011-03-15 rename to docs/dev/logs/2011-03-15 diff --git a/doc/dev/logs/2011-03-15.file_directory_link b/docs/dev/logs/2011-03-15.file_directory_link similarity index 100% rename from doc/dev/logs/2011-03-15.file_directory_link rename to docs/dev/logs/2011-03-15.file_directory_link diff --git a/doc/dev/logs/2011-03-23.autorequire b/docs/dev/logs/2011-03-23.autorequire similarity index 100% rename from doc/dev/logs/2011-03-23.autorequire rename to docs/dev/logs/2011-03-23.autorequire diff --git a/doc/dev/logs/2011-03-23.manifest_use_explorer b/docs/dev/logs/2011-03-23.manifest_use_explorer similarity index 100% rename from doc/dev/logs/2011-03-23.manifest_use_explorer rename to docs/dev/logs/2011-03-23.manifest_use_explorer diff --git a/doc/dev/logs/2011-03-27.pgrep b/docs/dev/logs/2011-03-27.pgrep similarity index 100% rename from doc/dev/logs/2011-03-27.pgrep rename to docs/dev/logs/2011-03-27.pgrep diff --git a/doc/dev/logs/2011-03-28.execution-order b/docs/dev/logs/2011-03-28.execution-order similarity index 100% rename from doc/dev/logs/2011-03-28.execution-order rename to docs/dev/logs/2011-03-28.execution-order diff --git a/doc/dev/logs/2011-04-02.yum b/docs/dev/logs/2011-04-02.yum similarity index 100% rename from doc/dev/logs/2011-04-02.yum rename to docs/dev/logs/2011-04-02.yum diff --git a/doc/dev/logs/2011-04-04.openbsd b/docs/dev/logs/2011-04-04.openbsd similarity index 100% rename from doc/dev/logs/2011-04-04.openbsd rename to docs/dev/logs/2011-04-04.openbsd diff --git a/doc/dev/logs/2011-04-19 b/docs/dev/logs/2011-04-19 similarity index 100% rename from doc/dev/logs/2011-04-19 rename to docs/dev/logs/2011-04-19 diff --git a/doc/dev/logs/2011-04-20.slashdot-articles b/docs/dev/logs/2011-04-20.slashdot-articles similarity index 100% rename from doc/dev/logs/2011-04-20.slashdot-articles rename to docs/dev/logs/2011-04-20.slashdot-articles diff --git a/doc/dev/logs/2011-04-21.benchmark-eth b/docs/dev/logs/2011-04-21.benchmark-eth similarity index 100% rename from doc/dev/logs/2011-04-21.benchmark-eth rename to docs/dev/logs/2011-04-21.benchmark-eth diff --git a/doc/dev/logs/2011-04-21.benchmark-from-home.with-stdout b/docs/dev/logs/2011-04-21.benchmark-from-home.with-stdout similarity index 100% rename from doc/dev/logs/2011-04-21.benchmark-from-home.with-stdout rename to docs/dev/logs/2011-04-21.benchmark-from-home.with-stdout diff --git a/doc/dev/logs/2011-04-27 b/docs/dev/logs/2011-04-27 similarity index 100% rename from doc/dev/logs/2011-04-27 rename to docs/dev/logs/2011-04-27 diff --git a/doc/dev/logs/2011-04-27.benchmark b/docs/dev/logs/2011-04-27.benchmark similarity index 100% rename from doc/dev/logs/2011-04-27.benchmark rename to docs/dev/logs/2011-04-27.benchmark diff --git a/doc/dev/logs/2011-04-27.benchmark.dash b/docs/dev/logs/2011-04-27.benchmark.dash similarity index 100% rename from doc/dev/logs/2011-04-27.benchmark.dash rename to docs/dev/logs/2011-04-27.benchmark.dash diff --git a/doc/dev/logs/2011-04-27.debug-timing b/docs/dev/logs/2011-04-27.debug-timing similarity index 100% rename from doc/dev/logs/2011-04-27.debug-timing rename to docs/dev/logs/2011-04-27.debug-timing diff --git a/doc/dev/logs/2011-05-09 b/docs/dev/logs/2011-05-09 similarity index 100% rename from doc/dev/logs/2011-05-09 rename to docs/dev/logs/2011-05-09 diff --git a/doc/dev/logs/2011-05-10 b/docs/dev/logs/2011-05-10 similarity index 100% rename from doc/dev/logs/2011-05-10 rename to docs/dev/logs/2011-05-10 diff --git a/doc/dev/logs/2011-05-10.benchmark b/docs/dev/logs/2011-05-10.benchmark similarity index 100% rename from doc/dev/logs/2011-05-10.benchmark rename to docs/dev/logs/2011-05-10.benchmark diff --git a/doc/dev/logs/2011-05-12 b/docs/dev/logs/2011-05-12 similarity index 100% rename from doc/dev/logs/2011-05-12 rename to docs/dev/logs/2011-05-12 diff --git a/doc/dev/logs/2011-06-13.installation-via-cdist b/docs/dev/logs/2011-06-13.installation-via-cdist similarity index 100% rename from doc/dev/logs/2011-06-13.installation-via-cdist rename to docs/dev/logs/2011-06-13.installation-via-cdist diff --git a/doc/dev/logs/2011-06-14.library_for_user b/docs/dev/logs/2011-06-14.library_for_user similarity index 100% rename from doc/dev/logs/2011-06-14.library_for_user rename to docs/dev/logs/2011-06-14.library_for_user diff --git a/doc/dev/logs/2011-06-24.cinst_preos b/docs/dev/logs/2011-06-24.cinst_preos similarity index 100% rename from doc/dev/logs/2011-06-24.cinst_preos rename to docs/dev/logs/2011-06-24.cinst_preos diff --git a/doc/dev/logs/2011-06-25.trigger-graphic b/docs/dev/logs/2011-06-25.trigger-graphic similarity index 100% rename from doc/dev/logs/2011-06-25.trigger-graphic rename to docs/dev/logs/2011-06-25.trigger-graphic diff --git a/doc/dev/logs/2011-07-01.type-gencode b/docs/dev/logs/2011-07-01.type-gencode similarity index 100% rename from doc/dev/logs/2011-07-01.type-gencode rename to docs/dev/logs/2011-07-01.type-gencode diff --git a/doc/dev/logs/2011-07-01.type-global-explorers b/docs/dev/logs/2011-07-01.type-global-explorers similarity index 100% rename from doc/dev/logs/2011-07-01.type-global-explorers rename to docs/dev/logs/2011-07-01.type-global-explorers diff --git a/doc/dev/logs/2011-09-08.obsolete_debugging b/docs/dev/logs/2011-09-08.obsolete_debugging similarity index 100% rename from doc/dev/logs/2011-09-08.obsolete_debugging rename to docs/dev/logs/2011-09-08.obsolete_debugging diff --git a/doc/dev/logs/2011-09-12 b/docs/dev/logs/2011-09-12 similarity index 100% rename from doc/dev/logs/2011-09-12 rename to docs/dev/logs/2011-09-12 diff --git a/doc/dev/logs/2011-09-12.benchmark-home b/docs/dev/logs/2011-09-12.benchmark-home similarity index 100% rename from doc/dev/logs/2011-09-12.benchmark-home rename to docs/dev/logs/2011-09-12.benchmark-home diff --git a/doc/dev/logs/2011-09-13 b/docs/dev/logs/2011-09-13 similarity index 100% rename from doc/dev/logs/2011-09-13 rename to docs/dev/logs/2011-09-13 diff --git a/doc/dev/logs/2011-09-16.benchmark-r815-no-control-socket b/docs/dev/logs/2011-09-16.benchmark-r815-no-control-socket similarity index 100% rename from doc/dev/logs/2011-09-16.benchmark-r815-no-control-socket rename to docs/dev/logs/2011-09-16.benchmark-r815-no-control-socket diff --git a/doc/dev/logs/2011-09-16.benchmark-r815-no-control-socket.dmidecode b/docs/dev/logs/2011-09-16.benchmark-r815-no-control-socket.dmidecode similarity index 100% rename from doc/dev/logs/2011-09-16.benchmark-r815-no-control-socket.dmidecode rename to docs/dev/logs/2011-09-16.benchmark-r815-no-control-socket.dmidecode diff --git a/doc/dev/logs/2011-10-04 b/docs/dev/logs/2011-10-04 similarity index 100% rename from doc/dev/logs/2011-10-04 rename to docs/dev/logs/2011-10-04 diff --git a/doc/dev/logs/2011-10-05 b/docs/dev/logs/2011-10-05 similarity index 100% rename from doc/dev/logs/2011-10-05 rename to docs/dev/logs/2011-10-05 diff --git a/doc/dev/logs/2011-10-06 b/docs/dev/logs/2011-10-06 similarity index 100% rename from doc/dev/logs/2011-10-06 rename to docs/dev/logs/2011-10-06 diff --git a/doc/dev/logs/2011-10-06.ssh_scp_sudo_chroot b/docs/dev/logs/2011-10-06.ssh_scp_sudo_chroot similarity index 100% rename from doc/dev/logs/2011-10-06.ssh_scp_sudo_chroot rename to docs/dev/logs/2011-10-06.ssh_scp_sudo_chroot diff --git a/doc/dev/logs/2011-10-11.emulator-output b/docs/dev/logs/2011-10-11.emulator-output similarity index 100% rename from doc/dev/logs/2011-10-11.emulator-output rename to docs/dev/logs/2011-10-11.emulator-output diff --git a/doc/dev/logs/2011-10-12 b/docs/dev/logs/2011-10-12 similarity index 100% rename from doc/dev/logs/2011-10-12 rename to docs/dev/logs/2011-10-12 diff --git a/doc/dev/logs/2011-10-13.output b/docs/dev/logs/2011-10-13.output similarity index 100% rename from doc/dev/logs/2011-10-13.output rename to docs/dev/logs/2011-10-13.output diff --git a/doc/dev/logs/2011-10-14.error-output b/docs/dev/logs/2011-10-14.error-output similarity index 100% rename from doc/dev/logs/2011-10-14.error-output rename to docs/dev/logs/2011-10-14.error-output diff --git a/doc/dev/logs/2011-10-15.prefix-output-missing b/docs/dev/logs/2011-10-15.prefix-output-missing similarity index 100% rename from doc/dev/logs/2011-10-15.prefix-output-missing rename to docs/dev/logs/2011-10-15.prefix-output-missing diff --git a/doc/dev/logs/2011-10-15.ugly-output-on-breaking-explorer b/docs/dev/logs/2011-10-15.ugly-output-on-breaking-explorer similarity index 100% rename from doc/dev/logs/2011-10-15.ugly-output-on-breaking-explorer rename to docs/dev/logs/2011-10-15.ugly-output-on-breaking-explorer diff --git a/doc/dev/logs/2011-10-16.keyboardirqoutputs b/docs/dev/logs/2011-10-16.keyboardirqoutputs similarity index 100% rename from doc/dev/logs/2011-10-16.keyboardirqoutputs rename to docs/dev/logs/2011-10-16.keyboardirqoutputs diff --git a/doc/dev/logs/2011-10-18.requirement-object b/docs/dev/logs/2011-10-18.requirement-object similarity index 100% rename from doc/dev/logs/2011-10-18.requirement-object rename to docs/dev/logs/2011-10-18.requirement-object diff --git a/doc/dev/logs/2011-10-18.traceback-gencode b/docs/dev/logs/2011-10-18.traceback-gencode similarity index 100% rename from doc/dev/logs/2011-10-18.traceback-gencode rename to docs/dev/logs/2011-10-18.traceback-gencode diff --git a/doc/dev/logs/2011-11-15.startup-yannick b/docs/dev/logs/2011-11-15.startup-yannick similarity index 100% rename from doc/dev/logs/2011-11-15.startup-yannick rename to docs/dev/logs/2011-11-15.startup-yannick diff --git a/doc/dev/logs/2012-01-06.python3-in-distros b/docs/dev/logs/2012-01-06.python3-in-distros similarity index 100% rename from doc/dev/logs/2012-01-06.python3-in-distros rename to docs/dev/logs/2012-01-06.python3-in-distros diff --git a/doc/dev/logs/2012-01-07.urls b/docs/dev/logs/2012-01-07.urls similarity index 100% rename from doc/dev/logs/2012-01-07.urls rename to docs/dev/logs/2012-01-07.urls diff --git a/doc/dev/logs/2012-01-18.urls b/docs/dev/logs/2012-01-18.urls similarity index 100% rename from doc/dev/logs/2012-01-18.urls rename to docs/dev/logs/2012-01-18.urls diff --git a/doc/dev/logs/2012-02-08.explorer-depends-on-another-type b/docs/dev/logs/2012-02-08.explorer-depends-on-another-type similarity index 100% rename from doc/dev/logs/2012-02-08.explorer-depends-on-another-type rename to docs/dev/logs/2012-02-08.explorer-depends-on-another-type diff --git a/doc/dev/logs/2012-02-10.object_id-and-slashes b/docs/dev/logs/2012-02-10.object_id-and-slashes similarity index 100% rename from doc/dev/logs/2012-02-10.object_id-and-slashes rename to docs/dev/logs/2012-02-10.object_id-and-slashes diff --git a/doc/dev/logs/2012-02-13.dependencies b/docs/dev/logs/2012-02-13.dependencies similarity index 100% rename from doc/dev/logs/2012-02-13.dependencies rename to docs/dev/logs/2012-02-13.dependencies diff --git a/doc/dev/logs/2012-02-15.steven b/docs/dev/logs/2012-02-15.steven similarity index 100% rename from doc/dev/logs/2012-02-15.steven rename to docs/dev/logs/2012-02-15.steven diff --git a/doc/dev/logs/2012-02-17.keyboardirq b/docs/dev/logs/2012-02-17.keyboardirq similarity index 100% rename from doc/dev/logs/2012-02-17.keyboardirq rename to docs/dev/logs/2012-02-17.keyboardirq diff --git a/docs/dev/logs/2012-02-20.debug-jake-deps b/docs/dev/logs/2012-02-20.debug-jake-deps new file mode 100644 index 00000000..2ae39f50 --- /dev/null +++ b/docs/dev/logs/2012-02-20.debug-jake-deps @@ -0,0 +1,8 @@ +require="__package/pkg-config" \ + __package libxml2 --version "2.7.8_1" --state installed --pkgsite http://192.168.196.70 + +Kein + INFO: www: Generating and executing code for __package_pkg_freebsd/libxml2 + +für + __package/libxml2 diff --git a/doc/dev/logs/2012-02-20.error-does-not-contain-host b/docs/dev/logs/2012-02-20.error-does-not-contain-host similarity index 100% rename from doc/dev/logs/2012-02-20.error-does-not-contain-host rename to docs/dev/logs/2012-02-20.error-does-not-contain-host diff --git a/docs/dev/logs/2012-05-23.urls b/docs/dev/logs/2012-05-23.urls new file mode 100644 index 00000000..e37407b3 --- /dev/null +++ b/docs/dev/logs/2012-05-23.urls @@ -0,0 +1,5 @@ +http://nu-ex.com/cv.html + +https://lists.metalab.at/pipermail/devops/2012-January/000089.html + +http://www.ir0nik.com/wordpress/?p=121 diff --git a/docs/dev/logs/2012-05-24.makedirs.py-python3.1 b/docs/dev/logs/2012-05-24.makedirs.py-python3.1 new file mode 100644 index 00000000..5ad82b29 --- /dev/null +++ b/docs/dev/logs/2012-05-24.makedirs.py-python3.1 @@ -0,0 +1,27 @@ +# From curl http://armstrong.cc/~steven/tmp/makedirs.py: + +#!/usr/bin/env python2 + +import os + +def makedirs(path, mode=0o777, exist_ok=False): + try: + os.makedirs(path, mode=mode, exist_ok=exist_ok) + except TypeError: + try: + os.makedirs(path, mode=mode) + except OSError as e: + if exist_ok and e.errno == 17: # File exists + pass + else: + raise + + +makedirs('/tmp/python/makedirs') + +try: + makedirs('/tmp/python/makedirs') +except OSError as e: + print(e) + +makedirs('/tmp/python/makedirs', exist_ok=True) diff --git a/docs/dev/logs/2012-05-30.ifconfig-outputs b/docs/dev/logs/2012-05-30.ifconfig-outputs new file mode 100644 index 00000000..c314cce8 --- /dev/null +++ b/docs/dev/logs/2012-05-30.ifconfig-outputs @@ -0,0 +1,177 @@ +Here are some "ifconfig -a" outputs that help for the explorer/ifaces parser. + +The current regexp is 's/^(.*)(:[[:space:]]*flags=|Link encap).*/\1/p' + + +You should get the interface list when you run: + + ifconfig -a | sed -n -r 's/^(.*)(:[[:space:]]*flags=|Link encap).*/\1/p' + +If you don't maybe try to replace the sed -r option by -E (works on Darwin). + + +If you still don't get any output, the regexp might be wrong. + + + +On Archlinux: +--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- +lo: flags=73 mtu 16436 metric 1 + inet 127.0.0.1 netmask 255.0.0.0 + inet6 ::1 prefixlen 128 scopeid 0x10 + loop txqueuelen 0 (Local Loopback) + RX packets 300081 bytes 49637437 (47.3 MiB) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 300081 bytes 49637437 (47.3 MiB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + +wlan0: flags=4163 mtu 1500 metric 1 + inet 192.168.1.38 netmask 255.255.255.0 broadcast 192.168.1.255 + inet6 fe80::ba8d:12ff:fe15:fdfa prefixlen 64 scopeid 0x20 + ether b8:8d:12:15:fd:fa txqueuelen 1000 (Ethernet) + RX packets 421381 bytes 442228597 (421.7 MiB) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 319266 bytes 41111233 (39.2 MiB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 +--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- + +On Debian Linux: +--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- +eth0 Link encap:Ethernet HWaddr 00:16:17:55:2d:00 + inet addr:172.16.5.2 Bcast:172.16.255.255 Mask:255.255.0.0 + inet6 addr: fe80::216:17ff:fe55:2d00/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:2854022168 errors:5 dropped:0 overruns:0 frame:4 + TX packets:2200088072 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:2708386800354 (2.4 TiB) TX bytes:531552070314 (495.0 GiB) + Base address:0x3000 Memory:d0120000-d0140000 + +eth0:1 Link encap:Ethernet HWaddr 00:16:17:55:2d:00 + inet addr:172.16.5.1 Bcast:172.16.255.255 Mask:255.255.0.0 + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + Base address:0x3000 Memory:d0120000-d0140000 + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:36487087 errors:0 dropped:0 overruns:0 frame:0 + TX packets:36487087 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:3388870184 (3.1 GiB) TX bytes:3388870184 (3.1 GiB) + +sit0 Link encap:IPv6-in-IPv4 + NOARP MTU:1480 Metric:1 + RX packets:0 errors:0 dropped:0 overruns:0 frame:0 + TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) + +tap0 Link encap:Ethernet HWaddr 16:db:17:fb:a1:4a + inet addr:10.254.0.1 Bcast:10.254.255.255 Mask:255.255.0.0 + inet6 addr: fe80::14db:17ff:fefb:a14a/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:0 errors:0 dropped:0 overruns:0 frame:0 + TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:100 + RX bytes:0 (0.0 B) TX bytes:468 (468.0 B) + +bond0 Link encap:Ethernet HWaddr 00:13:72:3c:bf:57 + inet6 addr: fe80::213:72ff:fe3c:bf57/64 Scope:Link + UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 + RX packets:6930494799 errors:0 dropped:38584515 overruns:0 frame:17 + TX packets:1678579772 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:10006832472618 (9.1 TiB) TX bytes:168031719693 (156.4 GiB) + +bond0.123 Link encap:Ethernet HWaddr 00:13:72:3c:bf:57 + inet addr:10.73.38.250 Bcast:10.73.38.255 Mask:255.255.255.0 + inet6 addr: fe80::213:72ff:fe3c:bf57/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:12382478 errors:0 dropped:5777 overruns:0 frame:0 + TX packets:564 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:586071334 (558.9 MiB) TX bytes:64180 (62.6 KiB) + +tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 + inet addr:172.31.255.9 P-t-P:172.31.255.10 Mask:255.255.255.255 + UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 + RX packets:9655 errors:0 dropped:0 overruns:0 frame:0 + TX packets:15118 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:100 + RX bytes:1760236 (1.6 MiB) TX bytes:14929984 (14.2 MiB) +--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- + +On OpenBSD: +--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- +lo0: flags=8049 mtu 33160 + priority: 0 + groups: lo + inet6 ::1 prefixlen 128 + inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 + inet 127.0.0.1 netmask 0xff000000 +em0: flags=8843 mtu 1500 + lladdr 00:50:56:b3:00:15 + priority: 0 + groups: egress + media: Ethernet autoselect (1000baseT full-duplex,master) + status: active + inet6 XXXX::XXX:XXXX:XXXX:XX%em0 prefixlen 64 scopeid 0x1 + inet6 XXXX:XXX:XXX:XX::XXX prefixlen 64 + inet XXX.XXX.XXX.XXX netmask 0xffffffc0 broadcast XXX.XXX.XXX.XXX +enc0: flags=0<> + priority: 0 + groups: enc + status: active +pflog0: flags=141 mtu 33160 + priority: 0 + groups: pflog +tun1: flags=8051 mtu 1500 + priority: 0 + groups: tun + status: active + inet 172.31.255.13 --> 172.31.255.14 netmask 0xffffffff +tun2: flags=8011 mtu 1500 + priority: 0 + groups: tun + status: down + inet 172.31.253.1 --> 172.31.253.2 netmask 0xffffffff +tun0: flags=8051 mtu 1500 + priority: 0 + groups: tun + status: active + inet 172.31.254.1 --> 172.31.254.2 netmask 0xffffffff +--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- + +On Darwin: +--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- +lo0: flags=8049 mtu 16384 + inet6 ::1 prefixlen 128 + inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 + inet 127.0.0.1 netmask 0xff000000 +gif0: flags=8010 mtu 1280 +stf0: flags=0<> mtu 1280 +en0: flags=8863 mtu 1500 + ether 34:15:9e:2e:8b:aa + inet6 fe80::3615:9eff:fe2e:8baa%en0 prefixlen 64 scopeid 0x4 + inet 192.168.1.102 netmask 0xffffff00 broadcast 192.168.1.255 + media: autoselect (100baseTX ) + status: active +en1: flags=8863 mtu 1500 + ether 7c:6d:62:a3:6f:57 + inet6 fe80::7e6d:62ff:fea3:6f57%en1 prefixlen 64 scopeid 0x5 + inet 192.168.2.105 netmask 0xffffff00 broadcast 192.168.2.255 + media: autoselect + status: active +fw0: flags=8863 mtu 4078 + lladdr 34:15:9e:ff:fe:2e:8b:aa + media: autoselect + status: inactive +tun0: flags=8851 mtu 1500 + inet 172.31.255.29 --> 172.31.255.30 netmask 0xffffffff + open (pid 24727) +tun1: flags=8851 mtu 1500 + inet 172.31.254.25 --> 172.31.254.26 netmask 0xffffffff + open (pid 24757) +--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<-- diff --git a/docs/dev/logs/2012-05-31.csh-compatibilty b/docs/dev/logs/2012-05-31.csh-compatibilty new file mode 100644 index 00000000..b653a826 --- /dev/null +++ b/docs/dev/logs/2012-05-31.csh-compatibilty @@ -0,0 +1,10 @@ +If root's shell is csh or other non-sh compatible, we have problems. +See https://github.com/telmich/cdist/issues/54. + +Stuff to try out: + + - "-o SendEnv name" [may break remote exec/copy] + - cat * | /bin/sh -s could also work, needs testing though + +Somebody who is affected should give this a try, especially the 2nd +variant. diff --git a/docs/dev/logs/2012-06-06.wikipedia b/docs/dev/logs/2012-06-06.wikipedia new file mode 100644 index 00000000..a9654f1b --- /dev/null +++ b/docs/dev/logs/2012-06-06.wikipedia @@ -0,0 +1,134 @@ +{{db-spam}} +{{Infobox software +|name = cdist +|logo = +|screenshot = +|caption = +|collapsible = +|author = Nico Schottelius, Steven Armstrong +|developer = +|released = 2010 +|latest release version = 2.0.13 +|latest release date = 05-Jun-2012 +|frequently updated = +|programming language = [[Python_(programming_language)|Python]], [[Bourne shell]] +|operating system = [[GNU/Linux]], [[Unix-like]] +|platform = +|size = +|language = +|status = +|genre = [[Configuration management]] +|license = [[GPLv3]]. +|website = http://www.nico.schottelius.org/software/cdist/ +}} + +'''cdist''' is a configuration management system, which adheres to the [[KISS_principle]]. It is being used in small up to enterprise grade environments. +cdist is an alternative to other configuration management systems [[CFEngine]], [[Bcfg2]], [[Chef (software)|Chef]] and [[Puppet (software)|Puppet]]. +cdist development started in 2010 at [[ETH Zurich]] and is actively being developed by a lot of [[FOSS]] contributors +and maintained by the two main developers Nico Schottelius and +Steven Armstrong. cdist is being watched on github by more than 100 people and has more than 30 forks.cdist development at https://github.com/telmich/cdist +The major part of the discussion about cdist happens on the mailinglistcdist mailinglist http://l.schottelius.org/mailman/listinfo/cdist +and on the IRC channel #cstar in the [[Freenode]] network. cdist is being used at various companies in Switzerland (for instance at [[ETH Zurich]]), the USA, Germany and France. + + +Its core is written in [[Python (programming language)|Python]] and the types are +written in [[Bourne Shell]]. Cdist is released under the [[GNU General Public License|GPL]]. +cdist has been a no. 1 topic on [[Hacker News]] for some time.cdist on [[Hacker News]] https://news.ycombinator.com/item?id=3422678 + + +== Architecture == + +cdist is split into two components: + +* The core +* The configuration + +=== Core === + +The core of cdist is implemented in Python 3 and provides the executables to configure target hosts. The core operates in a push model: It connects +from the source host '''to''' the target hosts and configures the machines. For communication and file transfer [[SSH]] is being used. +To allow parallel configuration of hosts, the core supports a parallel mode in which it creates a child process for every connection. +This model allows cdist to scale horizontally with the available computing resources: If at a certain limit is reached and the capacity of the +available CPUs has been used, adding another CPU or distributing cdist to multiple hosts allows to configure more hosts in parallel. + +=== Configuration === + +The configuration is written in [[Bourne Shell]] and consists of + +* The initial manifest (which defines which host is assigned which types) +* Global Explorers (to gain information about the target system) +* Types (which provide all functionality and consist of a manifest, type explorers and gencode scripts) + +Although all of these are written in Shell script, the order of execution in the manifests does not matter: cdist employs a idempotent +configuration. + +=== Comparison === + +In comparison to most other configuration management software, cdist does not have any requirements on the target host besides SSH and a bourne shell. +It requires Python 3.2 on the source host, though.Why cdist requires Python 3.2 on the source host - http://www.nico.schottelius.org/blog/cdist-python-3.2-requirement/ +cdist operates in push based approach, in which a server pushes configurations to the client and the clients do not poll for updates. + +== Configuration DSL == + +All user configurable parts are contained in manifests or gencode-scripts, which are shell scripts. +Shell scripts were chosen, because Unix System Administrators are usually profound in reading +and writing shell scripts. + +cdist reads its configuration from the initial manifest ('''conf/manifest/init'''), in which hosts are mapped to +types: + +
+case "$__target_host" in
+    myhostname)
+        __package zsh --state present
+        __addifnosuchline /tmp/cdist-welcome --line "Welcome to cdist"
+    ;;
+esac
+
+ +When using the types in cdist, they are called like normal programs in manifests and can make use of +advanced parameter parsing as well as reading from stdin: + +
+# Provide a default file, but let the user change it
+__file /home/frodo/.bashrc --source "/etc/skel/.bashrc" \
+   --state exists \
+   --owner frodo --mode 0600
+
+# Take file content from stdin
+__file /tmp/whatever --owner root --group root --mode 644 --source - << DONE
+Here goes the content for /tmp/whatever
+DONE
+
+ +Dependencies are expressed by setting up the '''require''' environment variable: +
+      __directory /tmp/foobar
+      require="__directory//tmp/foobar" __file /tmp/foobar/baz
+
+ +Access to paths and files within types is given by environment variables like $__object. + + +== See also == +{{Portal|Free software}} +* [[Comparison of open source configuration management software]] + +== References == +{{reflist}} + +== External links == +* [http://www.nico.schottelius.org/software/cdist/ cdist Website] +* [https://github.com/telmich/cdist Github home] +* [http://l.schottelius.org/mailman/listinfo/cdist cdist mailinglist] +* [https://freecode.com/projects/cdist cdist on freecode] + + +[[Category:Configuration management]] +[[Category:Free software programmed in Python]] +[[Category:2010 software]] +[[Category:Linux configuration utilities]] +[[Category:Mac OS X]] +[[Category:Linux package management-related software]] +[[Category:Unix package management-related software]] + diff --git a/docs/dev/logs/2012-06-15.explorer-dep-problem b/docs/dev/logs/2012-06-15.explorer-dep-problem new file mode 100644 index 00000000..30803032 --- /dev/null +++ b/docs/dev/logs/2012-06-15.explorer-dep-problem @@ -0,0 +1,4 @@ +Known bug rediscovered: + Explorer for __start_on_boot mysql runs before __package mysql was finished. + +Requires two runs to actually finish the task. diff --git a/docs/dev/logs/2012-10-17.conflicting-types-problem b/docs/dev/logs/2012-10-17.conflicting-types-problem new file mode 100644 index 00000000..5f35ddf7 --- /dev/null +++ b/docs/dev/logs/2012-10-17.conflicting-types-problem @@ -0,0 +1,27 @@ +Seen error: + +INFO: dns-vm-inx01: Generating and executing code for __package/bind-chroot +INFO: dns-vm-inx01: Generating and executing code for __directory/var/named +INFO: dns-vm-snr01: Running manifest and explorers for __directory/opt/local.ch/sys/icinga/conf.d +INFO: dns-vm-inx02: Running manifest and explorers for __directory/opt/local.ch/sys +mkdir: cannot create directory `/var/named': File exists +ERROR: Command failed: ssh -o User=root -q dns-vm-inx01 umask 077; /bin/sh -e /var/lib/cdist/object/__directory/var/named/.cdist/code-remote +INFO: dns-vm-snr01: Running manifest and explorers for __directory/opt/local.ch/web +INFO: dns-vm-inx02: Running manifest and explorers for __directory/opt/local.ch/sys/bin +INFO: dns-vm-snr02: Running manifest and explorers for __directory/opt/local.ch/web + + +Problem source: + +__directory/var/named explorer detects that the directory is missing +__package/named gencode-remote installs package, which creates directory +__directory/var/named gencode-remote outputs mkdir + +Solutions: + + - don't use __directory, because __package does already the job (clean solution) + - re-run explorer before gencode-* stage + - gencode-remote would have caught that + +Not sure yet - although the latter feature has been requested, the first +solution looks better (more clean) to this problem. diff --git a/docs/dev/logs/2012-10-25.version-split b/docs/dev/logs/2012-10-25.version-split new file mode 100644 index 00000000..f381c48f --- /dev/null +++ b/docs/dev/logs/2012-10-25.version-split @@ -0,0 +1,4 @@ +x store version in .version +x when distributed / packaged, include .version into sourcecode + split into two files +x when in git checkout, use dynamic versioning diff --git a/docs/dev/logs/2012-10-29.installed_paths b/docs/dev/logs/2012-10-29.installed_paths new file mode 100644 index 00000000..3587390e --- /dev/null +++ b/docs/dev/logs/2012-10-29.installed_paths @@ -0,0 +1,34 @@ + +Installed paths: (read first) + os.path.dirname(cdist.__file__) + + /conf/explorer + /conf/type + +User paths: (read after, overwrite)? + + $HOME/.cdist + + /explorer + /type + + /manifest + + /cache + +Additional paths: + + CDIST_EXPLORER_EXTRA_PATH=... + CDIST_TYPE_EXTRA_PATH=... + + or + + -c dir -c dir2 -c ... => + add types and explorer from those directories + last one wins? + because they can only be appended to existing "$PATH" + +Open questions: + + - How to tell types to use global explorer? + - How to tell types to find other types? diff --git a/docs/dev/logs/2012-10-30.path-for-types-and-global-explorer-implementation b/docs/dev/logs/2012-10-30.path-for-types-and-global-explorer-implementation new file mode 100644 index 00000000..8a683a40 --- /dev/null +++ b/docs/dev/logs/2012-10-30.path-for-types-and-global-explorer-implementation @@ -0,0 +1,8 @@ +- Allow list of base directories, which may contain explorer/ or type/ subdirectories + - can use the existing -c parameter, only allow it to be specified multiple times +- for each directory, link the given explorer and types to a temporary conf/ directory + similar to bin/ +- last one wins strategy + - what is expected by the user + + diff --git a/docs/dev/logs/2012-11-02.migration_to_2.1 b/docs/dev/logs/2012-11-02.migration_to_2.1 new file mode 100644 index 00000000..6c736a5c --- /dev/null +++ b/docs/dev/logs/2012-11-02.migration_to_2.1 @@ -0,0 +1,47 @@ +create a new branch to ensure nothing breaks + + % git checkout -b 2.1_merge + +fetch latest upstream changes (change origin if you use another +remote name for upstream cdist) + + % git fetch -v origin + +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. + +As the types have a new location, **cdist/conf/** now, you have to move +your own types there as well: + + % git mv conf/type/* cdist/conf/ + +The manifest location also changed, so move this one as well: + + % git mv conf/manifest/* cdist/conf/manifest/ + +Use **git status** to review the changes and ensure they +are in the git database: + + % git commit -m "Move types and manifests for 2.1 migration" + +This should be everything necessary for a 2.1 migration. Test the result +by running cdist on one of your staging hosts: + + % ./bin/cdist config -v staging-host + + +You can now cleanup the empty conf/ directory: + + % rmdir conf/* && rmdir conf + + + +-------------------------------------------------------------------------------- + +Boolean parameter introduced: + __directory /path/to --parents yes => __directory /path/to --parents diff --git a/docs/dev/logs/2012-11-18.problematic-side-effects b/docs/dev/logs/2012-11-18.problematic-side-effects new file mode 100644 index 00000000..032a9f80 --- /dev/null +++ b/docs/dev/logs/2012-11-18.problematic-side-effects @@ -0,0 +1,22 @@ +- Problem: Installing xbmc package creates user xbmc. +As xbmc is the first user, it gets the uid 1000. + +Later on trying to create the user "nutzer" with uid 1000 fails, because +xbmc already has that uid. + + +INFO: matte: Generating and executing code for __package/upower +INFO: matte: Generating and executing code for __nico_managed_desktop/singleton +ln -s '/usr/lib/systemd/system/slim.service' '/etc/systemd/system/display-manager.service' +INFO: matte: Generating and executing code for __directory/etc/sudoers.d +INFO: matte: Generating and executing code for __file/etc/sudoers.d/nico +INFO: matte: Generating and executing code for __cdistmarker/singleton +INFO: matte: Generating and executing code for __package_pacman/sudo +INFO: matte: Generating and executing code for __package/sudo +INFO: matte: Generating and executing code for __package_pacman/xf86-video-intel +INFO: matte: Generating and executing code for __user/nutzer +useradd: UID 1000 is not unique +ERROR: matte: Command failed: ssh -o User=root -q matte umask 077; /bin/sh -e /var/lib/cdist/object/__user/nutzer/.cdist/code-remote +INFO: Total processing time for 1 host(s): 3512.761916399002 +ERROR: Failed to deploy to the following hosts: matte +[17:40] brief:nico% ./bin/cdist config -v matte diff --git a/doc/dev/logs/README b/docs/dev/logs/README similarity index 100% rename from doc/dev/logs/README rename to docs/dev/logs/README diff --git a/doc/dev/logs/linklist b/docs/dev/logs/linklist similarity index 100% rename from doc/dev/logs/linklist rename to docs/dev/logs/linklist diff --git a/doc/dev/logs/times b/docs/dev/logs/times similarity index 100% rename from doc/dev/logs/times rename to docs/dev/logs/times diff --git a/doc/dev/show_all_exported_variables b/docs/dev/show_all_exported_variables similarity index 100% rename from doc/dev/show_all_exported_variables rename to docs/dev/show_all_exported_variables diff --git a/doc/dev/sync-to-testhost b/docs/dev/sync-to-testhost similarity index 100% rename from doc/dev/sync-to-testhost rename to docs/dev/sync-to-testhost diff --git a/doc/dev/todo/3.0 b/docs/dev/todo/3.0 similarity index 100% rename from doc/dev/todo/3.0 rename to docs/dev/todo/3.0 diff --git a/doc/dev/todo/TAKEME b/docs/dev/todo/TAKEME similarity index 80% rename from doc/dev/todo/TAKEME rename to docs/dev/todo/TAKEME index 502810f7..87fc91c5 100644 --- a/doc/dev/todo/TAKEME +++ b/docs/dev/todo/TAKEME @@ -3,6 +3,14 @@ UNASSIGNED TODOS The following list of todos has not been assigned to any developer. Feel free to pick one! +CORE +---- +- support default parameter +- document and add paremeters for remote-copy and remote-exec! + - remove hack, make a feature of it + +- remove var=foo calls on remote side. Use -o SendEnv (yeah, see ssh_config(5)) + TESTS ----- - multiple defines of object: @@ -40,3 +48,6 @@ TYPES - Merge __addifnosuchline and __removeline into __line + --state present|absent - __cron: Support --file to be used instead of user cron (probably direct support of /etc/cron.d) + +- Support uci from openwrt? + - http://wiki.openwrt.org/doc/uci diff --git a/doc/dev/todo/niconext b/docs/dev/todo/niconext similarity index 100% rename from doc/dev/todo/niconext rename to docs/dev/todo/niconext diff --git a/doc/dev/todo/performance-ideas b/docs/dev/todo/performance-ideas similarity index 100% rename from doc/dev/todo/performance-ideas rename to docs/dev/todo/performance-ideas diff --git a/doc/dev/todo/steven b/docs/dev/todo/steven similarity index 100% rename from doc/dev/todo/steven rename to docs/dev/todo/steven diff --git a/doc/dev/todo/tests b/docs/dev/todo/tests similarity index 100% rename from doc/dev/todo/tests rename to docs/dev/todo/tests diff --git a/doc/gfx/cdist-automated-inverted.png b/docs/gfx/cdist-automated-inverted.png similarity index 100% rename from doc/gfx/cdist-automated-inverted.png rename to docs/gfx/cdist-automated-inverted.png diff --git a/doc/gfx/cdist-automated.png b/docs/gfx/cdist-automated.png similarity index 100% rename from doc/gfx/cdist-automated.png rename to docs/gfx/cdist-automated.png diff --git a/doc/gfx/cdist-automated.text b/docs/gfx/cdist-automated.text similarity index 100% rename from doc/gfx/cdist-automated.text rename to docs/gfx/cdist-automated.text diff --git a/docs/gfx/cdist-logo-cm.png b/docs/gfx/cdist-logo-cm.png new file mode 100644 index 00000000..7d988cdc Binary files /dev/null and b/docs/gfx/cdist-logo-cm.png differ diff --git a/doc/gfx/cdist-logo-inverted.png b/docs/gfx/cdist-logo-inverted.png similarity index 100% rename from doc/gfx/cdist-logo-inverted.png rename to docs/gfx/cdist-logo-inverted.png diff --git a/doc/gfx/cdist-logo.png b/docs/gfx/cdist-logo.png similarity index 100% rename from doc/gfx/cdist-logo.png rename to docs/gfx/cdist-logo.png diff --git a/doc/gfx/cdist-logo.text b/docs/gfx/cdist-logo.text similarity index 100% rename from doc/gfx/cdist-logo.text rename to docs/gfx/cdist-logo.text diff --git a/docs/gfx/font-used b/docs/gfx/font-used new file mode 100644 index 00000000..46d3e5d3 --- /dev/null +++ b/docs/gfx/font-used @@ -0,0 +1 @@ +fraktur diff --git a/doc/man/cdist-reference.text.sh b/docs/man/cdist-reference.text.sh similarity index 89% rename from doc/man/cdist-reference.text.sh rename to docs/man/cdist-reference.text.sh index 6bd5f1b8..8e3f49a2 100755 --- a/doc/man/cdist-reference.text.sh +++ b/docs/man/cdist-reference.text.sh @@ -49,7 +49,7 @@ The following global explorers are available: eof ( - cd ../../conf/explorer + cd ../../cdist/conf/explorer for explorer in *; do echo "- $explorer" done @@ -65,16 +65,16 @@ conf/:: Contains the (static) configuration like manifests, types and explorers. conf/manifest/init:: - This is the central entry point used by cdist-manifest-init(1). + This is the central entry point. It is an executable (+x bit set) shell script that can use values from the explorers to decide which configuration to create for the specified target host. - It should be primary used to define mapping from configurations to hosts. + Its intent is to used to define mapping from configurations to hosts. conf/manifest/*:: All other files in this directory are not directly used by cdist, but you can seperate configuration mappings, if you have a lot of code in the - manifest/init file. This may also be helpful to have different admins + conf/manifest/init file. This may also be helpful to have different admins maintain different groups of hosts. conf/explorer/:: @@ -96,10 +96,10 @@ conf/type//manifest:: Used to generate additional objects from a type. conf/type//gencode-local:: - Used to generate code to be executed on the server. + Used to generate code to be executed on the source host conf/type//gencode-remote:: - Used to generate code to be executed on the client. + Used to generate code to be executed on the target host conf/type//parameter/required:: Parameters required by type, \n seperated list. @@ -133,10 +133,6 @@ out/object/:: out/object//explorers:: Output of type specific explorers, per object. -tmp_dir:: - A tempdir and a tempfile is used by cdist internally, - which will be removed when the scripts end automatically. - TYPES ----- The following types are available: @@ -173,7 +169,7 @@ __explorer:: Available for: explorer, type explorer __manifest:: Directory that contains the initial manifest. - Available for: initial manifest + Available for: initial manifest, type manifest __global:: Directory that contains generic output like explorer. Available for: initial manifest, type manifest, type gencode @@ -188,10 +184,6 @@ __object_id:: the filesystem database and ensured by the core). Note: Double slashes ("//") will not be fixed and result in an error. - -__self:: - DEPRECATED: Same as __object_name, do not use anymore, use __object_name instead. - Will be removed in cdist 3.x. __object_name:: The full qualified name of the current object. Available for: type manifest, type explorer, type gencode diff --git a/doc/man/man1/cdist.text b/docs/man/man1/cdist.text similarity index 70% rename from doc/man/man1/cdist.text rename to docs/man/man1/cdist.text index e46e84a3..b92fba18 100644 --- a/doc/man/man1/cdist.text +++ b/docs/man/man1/cdist.text @@ -41,23 +41,29 @@ CONFIG Configure a system -h, --help:: - Show the help screen + Show the help screen -c CDIST_HOME, --cdist-home CDIST_HOME:: - Instead of using the parent of the bin directory as cdist home, - use the specified directory + Instead of using the parent of the bin directory as cdist home, + use the specified directory -d, --debug:: - Enable debug output + Enable debug output -i MANIFEST, --initial-manifest MANIFEST:: - Path to a cdist manifest or - to read from stdin + Path to a cdist manifest or - to read from stdin -p, --parallel:: - Operate on multiple hosts in parallel + Operate on multiple hosts in parallel -s, --sequential:: - Operate on multiple hosts sequentially + Operate on multiple hosts sequentially + +--remote-copy REMOTE_COPY: + Command to use for remote copy (should behave like scp) + +--remote-exec REMOTE_EXEC: + Command to use for remote execution (should behave like ssh) EXAMPLES @@ -69,7 +75,12 @@ cdist config -d ikq05.ethz.ch # Configure hosts in parallel and use a different home directory cdist config -c ~/p/cdist-nutzung \ - -p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch + -p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch + +# Use custom remote exec / copy commands +cdist config --remote-exec /path/to/my/remote/exec \ + --remote-copy /path/to/my/remote/copy \ + -p ikq02.ethz.ch ikq03.ethz.ch ikq04.ethz.ch # Display banner cdist banner @@ -98,7 +109,7 @@ The following exit values shall be returned: 0:: Successful completion 1:: - One or more host configuration failed. + One or more host configurations failed SEE ALSO diff --git a/doc/man/man7/cdist-best-practice.text b/docs/man/man7/cdist-best-practice.text similarity index 100% rename from doc/man/man7/cdist-best-practice.text rename to docs/man/man7/cdist-best-practice.text diff --git a/doc/man/man7/cdist-bootstrap.text b/docs/man/man7/cdist-bootstrap.text similarity index 100% rename from doc/man/man7/cdist-bootstrap.text rename to docs/man/man7/cdist-bootstrap.text diff --git a/doc/man/man7/cdist-explorer.text b/docs/man/man7/cdist-explorer.text similarity index 100% rename from doc/man/man7/cdist-explorer.text rename to docs/man/man7/cdist-explorer.text diff --git a/doc/man/man7/cdist-hacker.text b/docs/man/man7/cdist-hacker.text similarity index 100% rename from doc/man/man7/cdist-hacker.text rename to docs/man/man7/cdist-hacker.text diff --git a/doc/man/man7/cdist-manifest.text b/docs/man/man7/cdist-manifest.text similarity index 98% rename from doc/man/man7/cdist-manifest.text rename to docs/man/man7/cdist-manifest.text index 1f0e253d..b9dfe655 100644 --- a/doc/man/man7/cdist-manifest.text +++ b/docs/man/man7/cdist-manifest.text @@ -47,7 +47,7 @@ on given conditions. INITIAL AND TYPE MANIFESTS -------------------------- -Cdist nows about two types of manifests: The initial manifest and type +Cdist knows about two types of manifests: The initial manifest and type manifests. The initial manifest is used to define, which configurations to apply to which hosts. The type manifests are used to create objects from types. More about manifests in types can be found in cdist-type(7). diff --git a/doc/man/man7/cdist-quickstart.text b/docs/man/man7/cdist-quickstart.text similarity index 98% rename from doc/man/man7/cdist-quickstart.text rename to docs/man/man7/cdist-quickstart.text index 51943d41..b718da64 100644 --- a/doc/man/man7/cdist-quickstart.text +++ b/docs/man/man7/cdist-quickstart.text @@ -77,7 +77,7 @@ git clone git://git.schottelius.org/cdist # Create manifest (maps configuration to host(s) cd cdist -echo '__file /etc/cdist-configured' > conf/manifest/init +echo '__file /etc/cdist-configured' > cdist/conf/manifest/init # Configure localhost in verbose mode ./bin/cdist config -v localhost diff --git a/docs/man/man7/cdist-remote-exec-copy.text b/docs/man/man7/cdist-remote-exec-copy.text new file mode 100644 index 00000000..298891d6 --- /dev/null +++ b/docs/man/man7/cdist-remote-exec-copy.text @@ -0,0 +1,46 @@ +cdist-remote-exec-copy(7) +========================= +Nico Schottelius + + +NAME +---- +cdist-remote-exec-copy - How to use remote exec and copy + + +INTRO +----- +Cdist interacts with the target host in two ways: +- it executes code (__remote_exec) +- and it copies files (__remote_copy) + +By default this is accomplished with ssh and scp respectively. +The default implementations used by cdist are: +__remote_exec: ssh -o User=root -q +__remote_copy: scp -o User=root -q + +The user can override these defaults by providing custom implementations and +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. + +With this simple interface the user can take total control of how cdist +interacts with the target when required, while the default implementation +remains as simple as possible. + + +EXAMPLES +-------- +See cdist/other/examples/remote/ for some example implementations. + + +SEE ALSO +-------- +- cdist(7) + + +COPYING +------- +Copyright \(C) 2011-2012 Nico Schottelius. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/doc/man/man7/cdist-stages.text b/docs/man/man7/cdist-stages.text similarity index 100% rename from doc/man/man7/cdist-stages.text rename to docs/man/man7/cdist-stages.text diff --git a/doc/man/man7/cdist-tutorial.text b/docs/man/man7/cdist-tutorial.text similarity index 100% rename from doc/man/man7/cdist-tutorial.text rename to docs/man/man7/cdist-tutorial.text diff --git a/doc/man/man7/cdist-type.text b/docs/man/man7/cdist-type.text similarity index 81% rename from doc/man/man7/cdist-type.text rename to docs/man/man7/cdist-type.text index 92a2b36d..a5064f91 100644 --- a/doc/man/man7/cdist-type.text +++ b/docs/man/man7/cdist-type.text @@ -74,14 +74,19 @@ DEFINING PARAMETERS ------------------- Every type consists of required, optional and boolean parameters, which must be created in a newline seperated file in ***parameter/required***, -***parameter/optional*** and ***parameter/boolean***. If either is missing, -the type will have no required, no optional, no boolean or no parameters at -all. +***parameter/required_multiple***, ***parameter/optional***, +***parameter/optional_multiple*** and ***parameter/boolean***. +Parameters which are allowed multiple times should be listed in +required_multiple or optional_multiple respectively. For all other parameters +the standard unix behaviour of the last given wins is applied. +If either is missing, the type will have no required, no optional, no boolean +or no parameters at all. Example: -------------------------------------------------------------------------------- echo servername >> conf/type/__nginx_vhost/parameter/required echo logdirectory >> conf/type/__nginx_vhost/parameter/optional +echo server_alias >> conf/type/__nginx_vhost/parameter/optional_multiple echo use_ssl >> conf/type/__nginx_vhost/parameter/boolean -------------------------------------------------------------------------------- @@ -108,6 +113,41 @@ if [ -f "$__object/parameter/use_ssl" ]; then # file exists -> True # do some fancy ssl stuff fi + +# 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 + done +fi + +-------------------------------------------------------------------------------- + + +INPUT FROM STDIN +----------------- +Every type can access what has been written on stdin when it has been called. +The result is saved into the ***stdin*** file in the object directory. + +Example use of a type: (e.g. in conf/type/__archlinux_hostname) +-------------------------------------------------------------------------------- +__file /etc/rc.conf --source - << eof +... +HOSTNAME="$__target_host" +... +eof +-------------------------------------------------------------------------------- +If you have not seen this syntax (<< eof) before, it may help you to read +about "here documents". + +In the __file type, stdin is used as source for the file, if - is used for source: +-------------------------------------------------------------------------------- + if [ -f "$__object/parameter/source" ]; then + source="$(cat "$__object/parameter/source")" + if [ "$source" = "-" ]; then + source="$__object/stdin" + fi + .... -------------------------------------------------------------------------------- diff --git a/doc/speeches/.gitignore b/docs/speeches/.gitignore similarity index 100% rename from doc/speeches/.gitignore rename to docs/speeches/.gitignore diff --git a/doc/speeches/2011-03-18_hacker_erwachen.tex b/docs/speeches/2011-03-18_hacker_erwachen.tex similarity index 100% rename from doc/speeches/2011-03-18_hacker_erwachen.tex rename to docs/speeches/2011-03-18_hacker_erwachen.tex diff --git a/doc/speeches/2011-04-27_sans.tex b/docs/speeches/2011-04-27_sans.tex similarity index 100% rename from doc/speeches/2011-04-27_sans.tex rename to docs/speeches/2011-04-27_sans.tex diff --git a/doc/speeches/2011-05-20_cosin.tex b/docs/speeches/2011-05-20_cosin.tex similarity index 100% rename from doc/speeches/2011-05-20_cosin.tex rename to docs/speeches/2011-05-20_cosin.tex diff --git a/doc/video/cdist-installation-in-less-than-60-seconds.mp4 b/docs/video/cdist-installation-in-less-than-60-seconds.mp4 similarity index 100% rename from doc/video/cdist-installation-in-less-than-60-seconds.mp4 rename to docs/video/cdist-installation-in-less-than-60-seconds.mp4 diff --git a/docs/web/cdist.mdwn b/docs/web/cdist.mdwn new file mode 100644 index 00000000..ee24e910 --- /dev/null +++ b/docs/web/cdist.mdwn @@ -0,0 +1,20 @@ +[[!meta title="cdist - usable configuration management"]] + +![cdist-logo](cdist-logo.png "cdist logo") + +cdist is a usable configuration management system. +It adheres to the KISS principle and +is being used in small up to enterprise grade environments. +cdist is an alternative to other configuration management systems like +[bcfg2](http://trac.mcs.anl.gov/projects/bcfg2), +[chef](http://wiki.opscode.com/display/chef/), +[cfengine](http://www.cfengine.org/) +and [puppet](http://www.puppetlabs.com/). + + * [[Documentation|documentation]] + * [[Supported Operating Systems|os]] + * [[Installation|install]] + * [[Update|update]] + * [[Support|support]] + +[[!tag cdist unix]] diff --git a/docs/web/cdist/cdist-logo.png b/docs/web/cdist/cdist-logo.png new file mode 100644 index 00000000..13c27927 Binary files /dev/null and b/docs/web/cdist/cdist-logo.png differ diff --git a/docs/web/cdist/documentation.mdwn b/docs/web/cdist/documentation.mdwn new file mode 100644 index 00000000..e5fd9bc9 --- /dev/null +++ b/docs/web/cdist/documentation.mdwn @@ -0,0 +1,7 @@ +[[!meta title="Documentation"]] + +You can browse the latest +[latest version of the manpages](/software/cdist/man/latest) or +have a look at [all versions](/software/cdist/man). + +[[!tag cdist unix]] diff --git a/docs/web/cdist/features.mdwn b/docs/web/cdist/features.mdwn new file mode 100644 index 00000000..a97f2013 --- /dev/null +++ b/docs/web/cdist/features.mdwn @@ -0,0 +1,26 @@ +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 | 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 +Design | No surprise factor: Only do what is obviously clear, no magic +Design | Define target state, do not focus on methods or scripts +Design | Push architecture: Instantly apply your changes +Small core | cdist's core is very small - less code, less bugs +Fast development | Focus on straightforwardness of type creation is a main development objective +Fast development | Batteries included: A lot of requirements can be solved using standard types +Modern Programming Language | cdist is written in Python +Requirements, Scalability | No central server needed, cdist operates in push mode and can be run from any computer +Requirements, Scalability, Upgrade | cdist only needs to be updated on the master, not on the target hosts +Requirements, Security | Uses well-know [SSH](http://www.openssh.com/) as transport protocol +Requirements, Simplicity | Requires only shell and SSH server on the target +UNIX | Reuse of existing tools like cat, find, mv, ... +UNIX, familar environment, documentation | Is available as manpages and HTML +UNIX, simplicity, familar environment | cdist is configured in POSIX shell +"""]] + +[[!tag cdist unix]] diff --git a/docs/web/cdist/install.mdwn b/docs/web/cdist/install.mdwn new file mode 100644 index 00000000..ad97cd2b --- /dev/null +++ b/docs/web/cdist/install.mdwn @@ -0,0 +1,179 @@ +[[!meta title="How to install cdist"]] +[[!toc levels=3]] + +## Requirements + +### Source Host + +This is the machine you use to configure the target hosts. + + * /bin/sh: A posix like shell (for instance bash, dash, zsh) + * Python >= 3.2 + * SSH client + * Asciidoc (for building the manpages) + +### Target Hosts + + * /bin/sh: A posix like shell (for instance bash, dash, zsh) + * SSH server + +## Requirement Installation: Python >= 3.2 + +Ensure you have at least Python 3.2 or newer installed on +the **source host**. +You can check this by running **python -V**: + + % python -V + Python 3.3.0 + +### Archlinux + +Archlinux includes a recent python in the extra repository. +You can install it using + + pacman -S python + +### CentOS + +See the "From source" section + +### Debian + +For Debian **wheezy** or newer: + + aptitude install python3 + +On **squeeze** you can add following line in **/etc/apt/sources.list** + + deb http://ftp.debian.org/debian wheezy main + +And add pinning entry in **/etc/apt/preferences.d/wheezy**: + + Package: * + Pin: release n=wheezy + Pin-Priority: 1 + +Please be aware that both **openssh-server** and **openssh-client** might be +removed on **python3.2** installation. You surely want to reinstall them: + + apt-get install -t wheezy openssh-server openssh-client + +For older Debian versions, installing python 3.2 from source is required. + +### Fedora + +Fedora 15 and newer includes a recent python. +You can install it using + + yum install python3 + +### FreeBSD + +For the port: + + cd /usr/ports/lang/python32/ && make install clean + +For the package: + + pkg_add -r python32 + +You can also use any newer version, but at least python 3.2 is required. + +### Gentoo + +Gentoo only provides python 3.2 in testing packages (http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=3&chap=3). +If you want to ensure nothing breaks you must set back the python version to what was default before. + + emerge -av =python-3.2.2 --autounmask-write + emerge -av =python-3.2.2 + eselect python list + eselect python list set python3.2 + +### Max OS X + +You can choose between Homebrew and Macports, either way works: + +[Homebrew](http://mxcl.github.com/homebrew/) variant: + + brew install python3 + +[Macports](http://www.macports.org/install.php) variant: + + port install python32 + ln -s /opt/local/bin/python3.2 /opt/local/bin/python3 + +### Redhat + +See the "From source" section + +### From Source + +For those operating systems not yet supporting Python 3.2: + + pyversion=3.2.3 + wget http://www.python.org/ftp/python/$pyversion/Python-${pyversion}.tar.bz2 + tar xvfj Python-${pyversion}.tar.bz2 + cd Python-${pyversion} + ./configure + make + sudo make install + +This installs python 3.2 to /usr/local/bin. +Ensure this directory is in your PATH environment variable. + +## Install cdist + +You can install cdist either from git or as a python package. + +### From git + +Cloning cdist from git gives you the advantage of having +a version control in place for development of your own stuff +immediately. + +To install cdist, execute the following commands: + + git clone git://git.schottelius.org/cdist + cd cdist + export PATH=$PATH:$(pwd -P)/bin + +If you want to build and use the manpages, run: + + ./build man + export MANPATH=$MANPATH:$(pwd -P)/doc/man + +#### Available versions in git + + * The active development takes place in the **master** branch + * The current stable version can be found in the **2.0** branch + * The upcoming stable version can be found in the **2.1** branch + +Other branches may be available for features or bugfixes, but they +may vanish at any point. To select a specific branch use + + # Generic code + git checkout -b origin/ + +So for instance if you want to use and stay with version 2.0, you can use + + git checkout -b 2.0 origin/2.0 + +#### Git Mirrors + +If the main site is down, you can acquire cdist from one of the following sites: + + * git://github.com/telmich/cdist.git ([github](https://github.com/telmich/cdist)) + * git://git.code.sf.net/p/cdist/code ([sourceforge](https://sourceforge.net/p/cdist/code)) + +### Python Package + +Cdist is available as a python package at +[PyPi](http://pypi.python.org/pypi/cdist/). You can install it using + + pip install cdist + +## Use cdist + +[[Dig into the documentation|documentation]] to get started with cdist! + +[[!tag cdist unix]] diff --git a/docs/web/cdist/os.mdwn b/docs/web/cdist/os.mdwn new file mode 100644 index 00000000..24992439 --- /dev/null +++ b/docs/web/cdist/os.mdwn @@ -0,0 +1,17 @@ +[[!meta title="Supported Operating Systems"]] + +cdist was tested or is know to run on at least + + * [Archlinux](http://www.archlinux.org/) + * [Debian](http://www.debian.org/) + * [CentOS](http://www.centos.org/) + * [Fedora](http://fedoraproject.org/) + * [FreeBSD](http://www.freebsd.org) + * [Gentoo](http://www.gentoo.org/) + * [Mac OS X](http://www.apple.com/macosx/) + * [OpenBSD](http://www.openbsd.org) + * [Redhat](http://www.redhat.com/) + * [Ubuntu](http://www.ubuntu.com/) + * [XenServer](http://www.citrix.com/xenserver/) + +[[!tag cdist unix]] diff --git a/docs/web/cdist/support.mdwn b/docs/web/cdist/support.mdwn new file mode 100644 index 00000000..7515070d --- /dev/null +++ b/docs/web/cdist/support.mdwn @@ -0,0 +1,25 @@ +## Support + +### IRC + +You can join the development ***IRC channel*** +[#cstar on irc.freenode.net](irc://irc.freenode.org/#cstar). + +### Mailing list + +Bug reports, questions, patches, etc. should be send to the +[cdist mailing list](http://l.schottelius.org/mailman/listinfo/cdist). + +### Linkedin + +If you have an account +at [Linked in](http://www.linkedin.com/), +you can join the +[cdist group](http://www.linkedin.com/groups/cdist-configuration-management-3952797). + +### Commercial support + +You can request commercial support for cdist from +[my company](http://firma.schottelius.org/english/). + +[[!tag cdist unix]] diff --git a/docs/web/cdist/update.mdwn b/docs/web/cdist/update.mdwn new file mode 100644 index 00000000..3331ec85 --- /dev/null +++ b/docs/web/cdist/update.mdwn @@ -0,0 +1,91 @@ +[[!meta title="How to update cdist"]] + +## Update The Git Installation + +To upgrade cdist in the current branch use + + git pull + + # Also update the manpages + ./build man + export MANPATH=$MANPATH:$(pwd -P)/doc/man + +If you stay on a version branche (i.e. 1.0, 1.1., ...), nothing should break. +The master branch on the other hand is the development branch and may not be +working, break your setup or eat the tree in your garden. + +## Update The Python Package + +To upgrade to the lastet version do + + pip install --upgrade cdist + +## Update Instructions + +### Updating from 2.0 to 2.1 + + * Type **\_\_package* and \_\_process** use --state **present** or **absent**. + The states **removed/installed** and **stopped/running** have been removed. + Support for the new states is already present in 2.0. + * Type **\_\_directory**: Parameter --parents and --recursive are now boolean + The old "yes/no" values need to be removed. + * Type **\_\_rvm_ruby**: Parameter --default is now boolean + The old "yes/no" values need to be removed. + * Type **\_\_rvm_gemset**: Parameter --default is now boolean + The old "yes/no" values need to be removed. + * Type **\_\_addifnosuchline** and **\_\_removeline** have been replaced by **\_\_line** + * The **conf** directory is now located at **cdist/conf**. + You need to migrate your types, explorers and manifests + manually to the new location. + * Replace the variable **\_\_self** by **\_\_object_name** + Support for the variable **\_\_object_name** is already present in 2.0. + * The types **\_\_autofs**, **\_\_autofs_map** and **\_\_autofs_reload** have been removed + (no maintainer, no users) + * Type **\_\_user**: Parameter --groups removed (use the new \_\_user_groups type) + * require="" is deprecated: Use --after and --before as parameters instead + +### Updating from 1.7 to 2.0 + +* Ensure python (>= 3.2) is installed on the source host +* Use "cdist config host" instead of "cdist-deploy-to host" +* Use "cdist config -p host1 host2" instead of "cdist-mass-deploy" +* Use "cdist banner" for fun +* Use **\_\_object_name** instead of **\_\_self** in manifests + +### Updating from 1.6 to 1.7 + +* If you used the global explorer **hardware_type**, you need to change + your code to use **machine** instead. + +### Updating from 1.5 to 1.6 + +* If you used **\_\_package_apt --preseed**, you need to use the new + type **\_\_debconf_set_selections** instead. +* The **\_\_package** types accepted either --state deinstalled or + --state uninstaaled. Starting with 1.6, it was made consistently + to --state removed. + +### Updating from 1.3 to 1.5 + +No incompatiblities. + +### Updating from 1.2 to 1.3 + +Rename **gencode** of every type to **gencode-remote**. + +### Updating from 1.1 to 1.2 + +No incompatiblities. + +### Updating from 1.0 to 1.1 + +In 1.1 the type **\_\_file** was split into **\_\_directory**, **\_\_file** and +**\_\_link**. The parameter **--type** was removed from **\_\_file**. Thus you +need to replace **\_\_file** calls in your manifests: + + * Remove --type from all \_\_file calls + * If type was symlink, use \_\_link and --type symbolic + * If type was directory, use \_\_directory + + +[[!tag cdist unix]] diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/optional b/lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/optional deleted file mode 100644 index f121bdbf..00000000 --- a/lib/cdist/test/emulator/fixtures/conf/type/__moon/parameter/optional +++ /dev/null @@ -1 +0,0 @@ -name diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__planet/parameter/optional b/lib/cdist/test/emulator/fixtures/conf/type/__planet/parameter/optional deleted file mode 100644 index f121bdbf..00000000 --- a/lib/cdist/test/emulator/fixtures/conf/type/__planet/parameter/optional +++ /dev/null @@ -1 +0,0 @@ -name diff --git a/lib/cdist/test/manifest/fixtures/conf/type/__moon/parameter/optional b/lib/cdist/test/manifest/fixtures/conf/type/__moon/parameter/optional deleted file mode 100644 index f121bdbf..00000000 --- a/lib/cdist/test/manifest/fixtures/conf/type/__moon/parameter/optional +++ /dev/null @@ -1 +0,0 @@ -name diff --git a/lib/cdist/test/manifest/fixtures/conf/type/__planet/parameter/optional b/lib/cdist/test/manifest/fixtures/conf/type/__planet/parameter/optional deleted file mode 100644 index f121bdbf..00000000 --- a/lib/cdist/test/manifest/fixtures/conf/type/__planet/parameter/optional +++ /dev/null @@ -1 +0,0 @@ -name diff --git a/other/archived_types/.README.unmaintained b/other/archived_types/.README.unmaintained new file mode 100644 index 00000000..e9795911 --- /dev/null +++ b/other/archived_types/.README.unmaintained @@ -0,0 +1 @@ +This type is not maintained by anymore and has thus been removed from cdist. diff --git a/other/archived_types/README b/other/archived_types/README new file mode 100644 index 00000000..32cd1f3d --- /dev/null +++ b/other/archived_types/README @@ -0,0 +1,3 @@ +This directory contains types that used to be included with +cdist, but are not in use anymore. Have a look at the README +file in each type, to find out why it was removed. diff --git a/other/archived_types/__autofs/README b/other/archived_types/__autofs/README new file mode 120000 index 00000000..7495e43b --- /dev/null +++ b/other/archived_types/__autofs/README @@ -0,0 +1 @@ +../.README.unmaintained \ No newline at end of file diff --git a/conf/type/__partition_msdos_apply/man.text b/other/archived_types/__autofs/man.text similarity index 60% rename from conf/type/__partition_msdos_apply/man.text rename to other/archived_types/__autofs/man.text index 6cc53b77..9b343309 100644 --- a/conf/type/__partition_msdos_apply/man.text +++ b/other/archived_types/__autofs/man.text @@ -1,21 +1,21 @@ -cdist-type__partition_msdos_apply(7) -==================================== +cdist-type__autofs(7) +===================== Steven Armstrong NAME ---- -cdist-type__partition_msdos_apply - Apply dos partition settings +cdist-type__autofs - install and start autofs DESCRIPTION ----------- -Create the partitions defined with __partition_msdos +This space intentionally left blank. REQUIRED PARAMETERS ------------------- -None +None. OPTIONAL PARAMETERS @@ -27,16 +27,16 @@ EXAMPLES -------- -------------------------------------------------------------------------------- -__partition_msdos_apply +__autofs -------------------------------------------------------------------------------- SEE ALSO -------- - cdist-type(7) -- cdist-type__partition_msdos_apply(7) + COPYING ------- -Copyright \(C) 2011 Steven Armstrong. Free use of this software is +Copyright \(C) 2012 Steven Armstrong. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__file/manifest b/other/archived_types/__autofs/manifest similarity index 70% rename from conf/type/__file/manifest rename to other/archived_types/__autofs/manifest index 6b5e1ca7..4a726c0a 100755 --- a/conf/type/__file/manifest +++ b/other/archived_types/__autofs/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) # 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. @@ -19,6 +19,16 @@ # along with cdist. If not, see . # -# set default: present, if not setup -statefile="$__object/parameter/state" -[ -f "$statefile" ] || echo present > "$statefile" + +os=$(cat "$__global/explorer/os") + +case "$os" in + ubuntu|debian|archlinux) + __package autofs --state present + __start_on_boot autofs --state present + ;; + *) + echo "Unsupported OS: $os" >&2 + exit 1 + ;; +esac diff --git a/other/archived_types/__autofs/singleton b/other/archived_types/__autofs/singleton new file mode 100644 index 00000000..e69de29b diff --git a/other/archived_types/__autofs_map/README b/other/archived_types/__autofs_map/README new file mode 120000 index 00000000..7495e43b --- /dev/null +++ b/other/archived_types/__autofs_map/README @@ -0,0 +1 @@ +../.README.unmaintained \ No newline at end of file diff --git a/other/archived_types/__autofs_map/explorer/entry b/other/archived_types/__autofs_map/explorer/entry new file mode 100755 index 00000000..7aa26518 --- /dev/null +++ b/other/archived_types/__autofs_map/explorer/entry @@ -0,0 +1,50 @@ +#!/bin/sh +# +# 2011 - 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 . +# + +candidates="/etc/auto.master /etc/autofs/auto.master" +find_auto_master() { + # get the path of the auto.master file + for candidate in $candidates; do + if [ -f "$candidate" ]; then + echo "$candidate" + return + fi + done +} + +auto_master="$(find_auto_master)" + +# no auto.master, nothing we could do +[ -f "$auto_master" ] || exit 0 + +# NOTE: keep variables in sync in manifest/explorer/gencode-* +prefix="#cdist:$__object_name" +suffix="#/cdist:$__object_name" +awk -v prefix="$prefix" -v suffix="$suffix" '{ + if (index($0,prefix)) { + triggered=1 + } + if (triggered) { + if (index($0,suffix)) { + triggered=0 + } + print + } +}' "$auto_master" diff --git a/other/archived_types/__autofs_map/gencode-remote b/other/archived_types/__autofs_map/gencode-remote new file mode 100755 index 00000000..fa6acffb --- /dev/null +++ b/other/archived_types/__autofs_map/gencode-remote @@ -0,0 +1,93 @@ +#!/bin/sh +# +# 2011 - 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 . +# + +entry="$__object/files/entry" +state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo present)" +if [ ! -s "$__object/explorer/entry" ]; then + state_is='absent' +else + state_is=$(diff -q "$entry" "$__object/explorer/entry" >/dev/null \ + && echo present \ + || echo changed + ) +fi + +if [ "$state_should" = "$state_is" ]; then + # Nothing to do, move along + exit 0 +fi + +cat << DONE +candidates="/etc/auto.master /etc/autofs/auto.master" +find_auto_master() { + # get the path of the auto.master file + for candidate in \$candidates; do + if [ -f "\$candidate" ]; then + echo "\$candidate" + return + fi + done +} + +auto_master="\$(find_auto_master)" + +if [ ! -f "\$auto_master" ]; then + echo "Could not determine auto.master location, tried: \$candidates" >&2 + exit 1 +fi +DONE + +remove_entry() { + # NOTE: keep variables in sync in manifest/explorer/gencode-* + prefix="#cdist:$__object_name" + suffix="#/cdist:$__object_name" + cat << DONE +awk -v prefix="$prefix" -v suffix="$suffix" ' +{ + if (index(\$0,prefix)) { + triggered=1 + } + if (triggered) { + if (index(\$0,suffix)) { + triggered=0 + } + } else { + print + } +}' "\$auto_master" > "\$auto_master"+ +mv -f "\$auto_master"+ "\$auto_master" +DONE +} + +case "$state_should" in + present) + if [ "$state_is" = "changed" ]; then + remove_entry + fi + cat << DONE +cat >> "\$auto_master" << EOC +$(cat "$entry") +EOC +DONE + ;; + absent) + remove_entry + ;; +esac diff --git a/conf/type/__autofs_map/man.text b/other/archived_types/__autofs_map/man.text similarity index 72% rename from conf/type/__autofs_map/man.text rename to other/archived_types/__autofs_map/man.text index 941e22da..50ce2fa8 100644 --- a/conf/type/__autofs_map/man.text +++ b/other/archived_types/__autofs_map/man.text @@ -36,25 +36,35 @@ comment:: auto.master. +BOOLEAN PARAMETERS +------------------ +noreload:: + don't reload autofs after the entry has been changed + + EXAMPLES -------- -------------------------------------------------------------------------------- -# Add auto mounter at /net +# Add auto mounter at /net and reload __autofs_map /net --map /etc/auto.net --type program -# Add auto mounter at /pub -__autofs_map /pub --map /etc/auto.pub \ - --type file --options nosuid,rw,bg,hard,intr --ghost +# Add auto mounter at /pub and don't reload +__autofs_map /pub \ + --map /etc/auto.pub \ + --type file \ + --options "nosuid,rw,bg,hard,intr --ghost" \ + --noreload -------------------------------------------------------------------------------- SEE ALSO -------- - cdist-type(7) +- cdist-type__autofs_reload(7) COPYING ------- -Copyright \(C) 2011 Steven Armstrong. Free use of this software is +Copyright \(C) 2012 Steven Armstrong. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/other/archived_types/__autofs_map/manifest b/other/archived_types/__autofs_map/manifest new file mode 100755 index 00000000..58dc0f98 --- /dev/null +++ b/other/archived_types/__autofs_map/manifest @@ -0,0 +1,55 @@ +#!/bin/sh +# +# 2011 - 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 . +# + +name="/$__object_id" +map="$(cat "$__object/parameter/map")" +type="$(cat "$__object/parameter/type" 2>/dev/null || echo "file")" +options="$(cat "$__object/parameter/options" 2>/dev/null || true)" + +# NOTE: keep variables in sync in manifest/explorer/gencode-* +prefix="#cdist:$__object_name" +suffix="#/cdist:$__object_name" + +mkdir "$__object/files" + +# Generate entry for inclusion in auto.master +entry="$__object/files/entry" +echo "$prefix" > "$entry" +if [ -f "$__object/parameter/comment" ]; then + echo "# $(cat "$__object/parameter/comment")" >> "$entry" +fi +echo "$name $type:$map $options" >> $entry +echo "$suffix" >> "$entry" + +# Reload autofs after changes if the user wishes this +if [ ! -f "$__object/parameter/noreload" ]; then + state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo present)" + if [ ! -s "$__object/explorer/entry" ]; then + state_is='absent' + else + state_is=$(diff -q "$entry" "$__object/explorer/entry" >/dev/null \ + && echo present \ + || echo changed + ) + fi + if [ "$state_is" != "$state_should" ]; then + require="$__object_name" __autofs_reload + fi +fi diff --git a/other/archived_types/__autofs_map/parameter/boolean b/other/archived_types/__autofs_map/parameter/boolean new file mode 100644 index 00000000..862edc87 --- /dev/null +++ b/other/archived_types/__autofs_map/parameter/boolean @@ -0,0 +1 @@ +noreload diff --git a/conf/type/__autofs_map/parameter/optional b/other/archived_types/__autofs_map/parameter/optional similarity index 100% rename from conf/type/__autofs_map/parameter/optional rename to other/archived_types/__autofs_map/parameter/optional diff --git a/conf/type/__autofs_map/parameter/required b/other/archived_types/__autofs_map/parameter/required similarity index 100% rename from conf/type/__autofs_map/parameter/required rename to other/archived_types/__autofs_map/parameter/required diff --git a/other/archived_types/__autofs_reload/README b/other/archived_types/__autofs_reload/README new file mode 120000 index 00000000..7495e43b --- /dev/null +++ b/other/archived_types/__autofs_reload/README @@ -0,0 +1 @@ +../.README.unmaintained \ No newline at end of file diff --git a/conf/type/__autofs_master/manifest b/other/archived_types/__autofs_reload/gencode-remote similarity index 62% rename from conf/type/__autofs_master/manifest rename to other/archived_types/__autofs_reload/gencode-remote index e429842e..883602e2 100755 --- a/conf/type/__autofs_master/manifest +++ b/other/archived_types/__autofs_reload/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -19,13 +19,19 @@ # -if [ ! -f "$__object/parameter/header" ]; then - echo "$__type/files/auto.master.header" > "$__object/parameter/header" -fi +os=$(cat "$__global/explorer/os") -[ -d "$__object/files" ] || mkdir "$__object/files" -require="$__object_name" __file /etc/auto.master --source "$__object/files/auto.master" \ - --mode 644 \ - --owner root \ - --group root +not_supported() { + 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 +} +case "$os" in + ubuntu|debian|archlinux) + echo "pkill -HUP automount" + ;; + *) + not_supported + ;; +esac diff --git a/conf/type/__autofs_master/man.text b/other/archived_types/__autofs_reload/man.text similarity index 51% rename from conf/type/__autofs_master/man.text rename to other/archived_types/__autofs_reload/man.text index 641c8393..d2085a98 100644 --- a/conf/type/__autofs_master/man.text +++ b/other/archived_types/__autofs_reload/man.text @@ -1,38 +1,33 @@ -cdist-type__autofs_master(7) +cdist-type__autofs_reload(7) ============================ Steven Armstrong NAME ---- -cdist-type__autofs_master - Generate the auto.master file +cdist-type__autofs_reload - tell automounter to reload config file DESCRIPTION ----------- -This cdist type generates a auto.master configuration from given __autofs_map -definitions. See cdist-type__auto_map(7). +This space intentionally left blank. REQUIRED PARAMETERS ------------------- -None +None. + OPTIONAL PARAMETERS ------------------- -header:: - Absolute path to a file used as the header for the generated auto.master - file. +None. + EXAMPLES -------- -------------------------------------------------------------------------------- -# auto.master with default header -__autofs_master - -# auto.master with custom header -__autofs_master --header /path/to/header +__autofs_reload -------------------------------------------------------------------------------- @@ -43,5 +38,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011 Steven Armstrong. Free use of this software is +Copyright \(C) 2012 Steven Armstrong. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/other/archived_types/__autofs_reload/singleton b/other/archived_types/__autofs_reload/singleton new file mode 100644 index 00000000..e69de29b diff --git a/other/examples/remote/chroot/copy b/other/examples/remote/chroot/copy index 528a5faf..8f8cb680 100755 --- a/other/examples/remote/chroot/copy +++ b/other/examples/remote/chroot/copy @@ -22,7 +22,7 @@ # to a remote target host. # # Usage: -# __remote_copy="/path/to/this/script /path/to/your/chroot" cdist config target-id +# cdist config --remote-copy "/path/to/this/script /path/to/your/chroot" target-id # log() { diff --git a/other/examples/remote/chroot/exec b/other/examples/remote/chroot/exec index 19e76b0e..4637f918 100755 --- a/other/examples/remote/chroot/exec +++ b/other/examples/remote/chroot/exec @@ -22,7 +22,7 @@ # on a remote target host. # # Usage: -# __remote_exec="/path/to/this/script /path/to/your/chroot" cdist config target-id +# cdist config --remote-exec "/path/to/this/script /path/to/your/chroot" target-id # log() { diff --git a/other/examples/remote/local/README b/other/examples/remote/local/README new file mode 100644 index 00000000..cfd350f9 --- /dev/null +++ b/other/examples/remote/local/README @@ -0,0 +1,3 @@ +This effectively turns remote calling into local calling. + +Probably most useful for the unittesting. diff --git a/conf/type/__directory/manifest b/other/examples/remote/local/copy similarity index 78% rename from conf/type/__directory/manifest rename to other/examples/remote/local/copy index a8ee5a6f..644fee15 100755 --- a/conf/type/__directory/manifest +++ b/other/examples/remote/local/copy @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Nico Schottelius (nico-cdist schottelius.org) # # This file is part of cdist. # @@ -17,7 +17,11 @@ # You should have received a copy of the GNU General Public License # along with cdist. If not, see . # +# -# set defaults -state="$(cat "$__object/parameter/state" 2>/dev/null \ - || echo "present" | tee "$__object/parameter/state")" +recursive=$1; shift +src=$1; shift +dst=$1; shift + +dst=$(echo $dst | sed "s/^${__target_host}://") +cp "$recursive" "$src" "$dst" diff --git a/conf/type/__rvm/explorer/state b/other/examples/remote/local/exec similarity index 81% rename from conf/type/__rvm/explorer/state rename to other/examples/remote/local/exec index 92fa6e07..838513a9 100755 --- a/conf/type/__rvm/explorer/state +++ b/other/examples/remote/local/exec @@ -1,6 +1,6 @@ #!/bin/sh # -# 2012 Evax Software +# 2012 Nico Schottelius (nico-cdist schottelius.org) # # This file is part of cdist. # @@ -17,10 +17,7 @@ # You should have received a copy of the GNU General Public License # along with cdist. If not, see . # +# -user="$__object_id" -if su - $user -c "[ -d \"\$HOME/.rvm\" ]" ; then - echo "installed" -else - echo "removed" -fi +target_host=$1; shift +echo "$@" | /bin/sh diff --git a/other/examples/remote/rsync/copy b/other/examples/remote/rsync/copy index f6b93c5c..76217caf 100755 --- a/other/examples/remote/rsync/copy +++ b/other/examples/remote/rsync/copy @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Matt Coddington (mcoddington at gmail.com) +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -24,7 +25,25 @@ # at /etc/passwd~cdist. # # Usage: -# __remote_copy="/path/to/this/script" cdist config target_host +# cdist config --remote-copy /path/to/this/script target_host # +# For rsync to do the right thing, the source has to end with "/" if it is +# a directory. The below preprocessor loop takes care of that. + +# second last argument is the source +source_index=$(($#-1)) +index=0 +for arg in $@; do + if [ $index -eq 0 ]; then + # reset $@ + set -- + fi + index=$((index+=1)) + if [ $index -eq $source_index -a -d "$arg" ]; then + arg="${arg%/}/" + fi + set -- "$@" "$arg" +done + rsync --backup --suffix=~cdist -e 'ssh -o User=root' $@ diff --git a/other/examples/remote/schroot-uri b/other/examples/remote/schroot-uri index a23277ec..5b50a195 100755 --- a/other/examples/remote/schroot-uri +++ b/other/examples/remote/schroot-uri @@ -1,6 +1,6 @@ #!/bin/sh -e # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2012 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -21,8 +21,10 @@ # __remote_{exec,copy} script to run cdist against a schroot target uri # # Usage: -# __remote_exec="/path/to/this/script exec" cdist config target_uri -# __remote_copy="/path/to/this/script copy" cdist config target_uri +# cdist config \ +# --remote-exec "/path/to/this/script exec" \ +# --remote-copy "/path/to/this/script copy" \ +# target_uri # # # target_uri examples: # schroot:///chroot-name @@ -49,7 +51,8 @@ my_name="${0##*/}" mode="$1"; shift log() { - echo "$@" | logger -t "cdist-$my_name-$mode" + # uncomment me for debugging + #echo "$@" | logger -t "cdist-$my_name-$mode" : } @@ -109,6 +112,9 @@ else copy_prefix="cp" copy_destination_prefix="" fi +log "exec_prefix: $exec_prefix" +log "copy_prefix: $copy_prefix" +log "copy_destination_prefix: $copy_destination_prefix" case "$mode" in exec) @@ -118,8 +124,9 @@ case "$mode" in ;; copy) # get directory for given chroot_name - schroot_directory="$($exec_prefix schroot $chroot_name --config | awk -F = '/directory=/ {print $2}')" + schroot_directory="$($exec_prefix schroot -c $schroot_name --config | awk -F = '/directory=/ {print $2}')" [ -n "$schroot_directory" ] || die "Failed to retreive schroot directory for schroot: $schroot_name" + log "schroot_directory: $schroot_directory" # prefix destination with chroot code="$copy_prefix $(echo "$@" | sed "s|$uri:|${copy_destination_prefix}${schroot_directory}|g")" ;; diff --git a/other/examples/remote/schroot/copy b/other/examples/remote/schroot/copy index 3587a4f2..d995055e 100755 --- a/other/examples/remote/schroot/copy +++ b/other/examples/remote/schroot/copy @@ -21,7 +21,7 @@ # __remote_copy script to run cdist against a chroot on the target host over ssh. # # Usage: -# __remote_copy="/path/to/this/script schroot-chroot-name" cdist config target_host +# cdist config --remote-copy "/path/to/this/script schroot-chroot-name" target_host # log() { @@ -33,7 +33,7 @@ chroot_name="$1"; shift target_host="$__target_host" # get directory for given chroot_name -chroot="$(ssh -o User=root -q $target_host schroot $chroot_name --config | awk -F = '/directory=/ {print $2}')" +chroot="$(ssh -o User=root -q $target_host schroot -c $chroot_name --config | awk -F = '/directory=/ {print $2}')" # prefix destination with chroot code="$(echo "$@" | sed "s|$target_host:|$target_host:$chroot|g")" diff --git a/other/examples/remote/schroot/exec b/other/examples/remote/schroot/exec index 5b561de0..2510fd22 100755 --- a/other/examples/remote/schroot/exec +++ b/other/examples/remote/schroot/exec @@ -21,7 +21,7 @@ # __remote_exec script to run cdist against a chroot on the target host over ssh. # # Usage: -# __remote_exec="/path/to/this/script schroot-chroot-name" cdist config target_host +# cdist config --remote-exec "/path/to/this/script schroot-chroot-name" target_host # log() { diff --git a/other/examples/remote/ssh/copy b/other/examples/remote/ssh/copy index 0ecd8c52..5b0ed324 100755 --- a/other/examples/remote/ssh/copy +++ b/other/examples/remote/ssh/copy @@ -21,7 +21,7 @@ # same as cdist default # # Usage: -# __remote_copy="/path/to/this/script" cdist config target_host +# cdist config --remote-copy "/path/to/this/script" target_host # #echo "$@" | logger -t "cdist-ssh-copy" diff --git a/other/examples/remote/ssh/exec b/other/examples/remote/ssh/exec index b597a47f..2875c3fc 100755 --- a/other/examples/remote/ssh/exec +++ b/other/examples/remote/ssh/exec @@ -21,7 +21,7 @@ # same as cdist default # # Usage: -# __remote_exec="/path/to/this/script" cdist config target_host +# cdist config --remote-exec "/path/to/this/script" target_host # #echo "$@" | logger -t "cdist-ssh-exec" diff --git a/other/types_submitted_for_inclusion/__package_zypper/README.inclusion b/other/types_submitted_for_inclusion/__package_zypper/README.inclusion deleted file mode 100644 index 1e073e3f..00000000 --- a/other/types_submitted_for_inclusion/__package_zypper/README.inclusion +++ /dev/null @@ -1,5 +0,0 @@ -This type was not accepted, because cleanups are needed and the -manpage does not build. - -If you read this and want this code available in the cdist core, -just fix it and submit a git url :-) diff --git a/other/types_submitted_for_inclusion/__package_zypper/parameter/optional b/other/types_submitted_for_inclusion/__package_zypper/parameter/optional deleted file mode 100644 index f121bdbf..00000000 --- a/other/types_submitted_for_inclusion/__package_zypper/parameter/optional +++ /dev/null @@ -1 +0,0 @@ -name diff --git a/other/types_submitted_for_inclusion/__package_zypper/parameter/required b/other/types_submitted_for_inclusion/__package_zypper/parameter/required deleted file mode 100644 index ff72b5c7..00000000 --- a/other/types_submitted_for_inclusion/__package_zypper/parameter/required +++ /dev/null @@ -1 +0,0 @@ -state diff --git a/scripts/cdist b/scripts/cdist new file mode 100755 index 00000000..fd18933a --- /dev/null +++ b/scripts/cdist @@ -0,0 +1,241 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# 2010-2012 Nico Schottelius (nico-cdist at schottelius.org) +# +# 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 commandline(): + """Parse command line""" + import argparse + + import cdist.banner + import cdist.config + import cdist.install + + # 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") + + # Banner + parser['banner'] = parser['sub'].add_parser('banner', + parents=[parser['loglevel']]) + parser['banner'].set_defaults(func=cdist.banner.banner) + + # Config and install (common stuff) + parser['configinstall'] = argparse.ArgumentParser(add_help=False) + parser['configinstall'].add_argument('host', nargs='+', + help='one or more hosts to operate on') + parser['configinstall'].add_argument('-c', '--conf-dir', + help='Add configuration directory (can be repeated, last one wins)', + action='append') + parser['configinstall'].add_argument('-i', '--initial-manifest', + help='Path to a cdist manifest or \'-\' to read from stdin.', + dest='manifest', required=False) + parser['configinstall'].add_argument('-p', '--parallel', + help='Operate on multiple hosts in parallel', + action='store_true', dest='parallel') + parser['configinstall'].add_argument('-s', '--sequential', + help='Operate on multiple hosts sequentially (default)', + action='store_false', dest='parallel') + + parser['configinstall'].add_argument('--remote-copy', + help='Command to use for remote copy (should behave like scp)', + action='store', dest='remote_copy', + default="scp -o User=root -q") + parser['configinstall'].add_argument('--remote-exec', + help='Command to use for remote execution (should behave like ssh)', + action='store', dest='remote_exec', + default="ssh -o User=root -q") + + # Config + parser['config'] = parser['sub'].add_parser('config', + parents=[parser['loglevel'], parser['configinstall']]) + parser['config'].set_defaults(func=config) + + # Install + # 20120525/sar: commented until it actually does something + #parser['install'] = parser['sub'].add_parser('install', + # parents=[parser['loglevel'], parser['configinstall']]) + #parser['install'].set_defaults(func=install) + + for p in parser: + parser[p].epilog = "Get cdist at http://www.nico.schottelius.org/software/cdist/" + + 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) + + log.debug(args) + args.func(args) + +def config(args): + configinstall(args, mode=cdist.config.Config) + +def install(args): + configinstall(args, mode=cdist.install.Install) + +def configinstall(args, mode): + """Configure or install remote system""" + import multiprocessing + import time + + initial_manifest_tempfile = None + if args.manifest == '-': + # read initial manifest from stdin + import tempfile + try: + handle, initial_manifest_temp_path = tempfile.mkstemp(prefix='cdist.stdin.') + with os.fdopen(handle, 'w') as fd: + fd.write(sys.stdin.read()) + except (IOError, OSError) as e: + raise cdist.Error("Creating tempfile for stdin data failed: %s" % e) + + args.manifest = initial_manifest_temp_path + import atexit + atexit.register(lambda: os.remove(initial_manifest_temp_path)) + + process = {} + failed_hosts = [] + time_start = time.time() + + for host in args.host: + if args.parallel: + log.debug("Creating child process for %s", host) + process[host] = multiprocessing.Process(target=configinstall_onehost, args=(host, args, mode, True)) + process[host].start() + else: + try: + configinstall_onehost(host, args, mode, parallel=False) + except cdist.Error as e: + failed_hosts.append(host) + + # Catch errors in parallel mode when joining + if args.parallel: + for host in process.keys(): + log.debug("Joining process %s", host) + process[host].join() + + if not process[host].exitcode == 0: + failed_hosts.append(host) + + time_end = time.time() + log.info("Total processing time for %s host(s): %s", len(args.host), + (time_end - time_start)) + + if len(failed_hosts) > 0: + raise cdist.Error("Failed to deploy to the following hosts: " + + " ".join(failed_hosts)) + +def configinstall_onehost(host, args, mode, parallel): + """Configure or install ONE remote system""" + + try: + import cdist.context + + context = cdist.context.Context( + target_host=host, + remote_copy=args.remote_copy, + remote_exec=args.remote_exec, + initial_manifest=args.manifest, + add_conf_dirs=args.conf_dir, + exec_path=sys.argv[0], + debug=args.debug) + + c = mode(context) + c.deploy_and_cleanup() + context.cleanup() + + except cdist.Error as e: + context.log.error(e) + # We are running in our own process here, need to sys.exit! + if parallel: + sys.exit(1) + else: + raise + + except KeyboardInterrupt: + # Ignore in parallel mode, we are existing anyway + if parallel: + sys.exit(0) + # Pass back to controlling code in sequential mode + else: + raise + +def emulator(): + """Prepare and run emulator""" + import cdist.emulator + emulator = cdist.emulator.Emulator(sys.argv) + return emulator.run() + +if __name__ == "__main__": + # Sys is needed for sys.exit() + import sys + + cdistpythonversion = '3.2' + if sys.version < cdistpythonversion: + print('Cdist requires Python >= ' + cdistpythonversion + + ' on the source host.', file=sys.stderr) + sys.exit(1) + + + exit_code = 0 + + try: + import logging + import os + import re + import cdist + + log = logging.getLogger("cdist") + logging.basicConfig(format='%(levelname)s: %(message)s') + + if re.match("__", os.path.basename(sys.argv[0])): + emulator() + else: + commandline() + + except KeyboardInterrupt: + pass + + except cdist.Error as e: + log.error(e) + exit_code = 1 + + # Determine exit code by return value of function + + sys.exit(exit_code) diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..25fc4820 --- /dev/null +++ b/setup.py @@ -0,0 +1,55 @@ +from distutils.core import setup +import cdist +import os + +def data_finder(data_dir): + entries = [] + for name in os.listdir(data_dir): + entry = os.path.join(data_dir, name) + if os.path.isdir(entry): + entries.extend(data_finder(entry)) + else: + entries.append(entry) + + return entries + +cur = os.getcwd() +os.chdir("cdist") +package_data = data_finder("conf") +os.chdir(cur) + +setup( + name = "cdist", + packages = ["cdist", "cdist.core", "cdist.exec", "cdist.util" ], + package_data={'cdist': package_data}, + scripts = ["scripts/cdist"], + version = cdist.version.VERSION, + description = "A Usable Configuration Management System", + author = "Nico Schottelius", + author_email = "nico-cdist-pypi@schottelius.org", + url = "http://www.nico.schottelius.org/software/cdist/", + classifiers = [ + "Development Status :: 6 - Mature", + "Environment :: Console", + "Intended Audience :: System Administrators", + "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", + "Operating System :: MacOS :: MacOS X", + "Operating System :: POSIX", + "Operating System :: POSIX :: BSD", + "Operating System :: POSIX :: Linux", + "Operating System :: Unix", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Topic :: System :: Boot", + "Topic :: System :: Installation/Setup", + "Topic :: System :: Operating System", + "Topic :: System :: Software Distribution", + "Topic :: Utilities" + ], + long_description = ''' + cdist is a usable configuration management system. + It adheres to the KISS principle and is being used in small up to enterprise grade environments. + cdist is an alternative to other configuration management systems like + cfengine, bcfg2, chef and puppet. + ''' +)