diff --git a/.gitignore b/.gitignore
index 6e2d4437..baf9b6f2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,3 +26,8 @@ cdist/version.py
/cdist-*.tar.gz
/pkg
/src
+build
+.lock-*
+.git-current-branch
+.lock*
+.pypi-release
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..1962c96e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,254 @@
+#
+# 2013 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 .
+#
+#
+
+A2XM=a2x -f manpage --no-xmllint -a encoding=UTF-8
+A2XH=a2x -f xhtml --no-xmllint -a encoding=UTF-8
+helper=./bin/build-helper
+
+MANDIR=docs/man
+SPEECHDIR=docs/speeches
+TYPEDIR=cdist/conf/type
+
+WEBSRCDIR=docs/web
+
+WEBDIR=$$HOME/www.nico.schottelius.org
+WEBBLOG=$(WEBDIR)/blog
+WEBBASE=$(WEBDIR)/software/cdist
+WEBPAGE=$(WEBBASE).mdwn
+
+CHANGELOG_VERSION=$(shell $(helper) changelog-version)
+CHANGELOG_FILE=docs/changelog
+
+PYTHON_VERSION=cdist/version.py
+
+################################################################################
+# Manpages
+#
+MAN1DSTDIR=$(MANDIR)/man1
+MAN7DSTDIR=$(MANDIR)/man7
+
+# Manpages #1: Types
+# Use shell / ls to get complete list - $(TYPEDIR)/*/man.text does not work
+MANTYPESRC=$(shell ls $(TYPEDIR)/*/man.text)
+
+# replace first path component
+MANTYPEPREFIX=$(subst $(TYPEDIR)/,$(MAN7DSTDIR)/cdist-type,$(MANTYPESRC))
+
+# replace man.text with .7 or .html
+MANTYPEMAN=$(subst /man.text,.7,$(MANTYPEPREFIX))
+MANTYPEHTML=$(subst /man.text,.html,$(MANTYPEPREFIX))
+MANTYPEALL=$(MANTYPEMAN) $(MANTYPEHTML)
+
+# Link manpage so A2XH does not create man.html but correct named file
+$(MAN7DSTDIR)/cdist-type%.text: $(TYPEDIR)/%/man.text
+ ln -sf "../../../$^" $@
+
+# Manpages #2: reference
+MANREF=$(MAN7DSTDIR)/cdist-reference.text
+MANREFSH=$(MANDIR)/cdist-reference.text.sh
+MANREFMAN=$(MANREF:.text=.7)
+MANREFHTML=$(MANREF:.text=.html)
+MANREFALL=$(MANREFMAN) $(MANREFHTML)
+
+$(MANREF): $(MANREFSH)
+ $(MANREFSH)
+
+# Manpages #3: static pages
+MAN1STATIC=$(shell ls $(MAN1DSTDIR)/*.text)
+MAN7STATIC=$(shell ls $(MAN7DSTDIR)/*.text)
+MANSTATICMAN=$(MAN1STATIC:.text=.1) $(MAN7STATIC:.text=.7)
+MANSTATICHTML=$(MAN1STATIC:.text=.html) $(MAN7STATIC:.text=.html)
+MANSTATICALL=$(MANSTATICMAN) $(MANSTATICHTML)
+
+# Manpages #4: generic part
+
+# Creating the type manpage
+%.1 %.7: %.text
+ $(A2XM) $^
+
+# Creating the type html page
+%.html: %.text
+ $(A2XH) $^
+
+man: $(MANTYPEALL) $(MANREFALL) $(MANSTATICALL)
+
+# Manpages #5: release part
+MANWEBDIR=$(WEBBASE)/man/$(CHANGELOG_VERSION)
+
+man-dist: man check-date
+ rm -rf "${MANWEBDIR}"
+ mkdir -p "${MANWEBDIR}/man1" "${MANWEBDIR}/man7"
+ cp ${MAN1DSTDIR}/*.html ${MAN1DSTDIR}/*.css ${MANWEBDIR}/man1
+ cp ${MAN7DSTDIR}/*.html ${MAN7DSTDIR}/*.css ${MANWEBDIR}/man7
+ cd ${MANWEBDIR} && git add . && git commit -m "cdist manpages update: $(CHANGELOG_VERSION)" || true
+
+man-fix-link: web-pub
+ # 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 "$(CHANGELOG_VERSION)" latest"
+
+################################################################################
+# Speeches
+#
+SPEECHESOURCES=$(SPEECHDIR)/*.tex
+SPEECHES=$(SPEECHESOURCES:.tex=.pdf)
+SPEECHESWEBDIR=$(WEBBASE)/speeches
+
+# Create speeches and ensure Toc is up-to-date
+$(SPEECHDIR)/%.pdf: $(SPEECHDIR)/%.tex
+ pdflatex -output-directory $(SPEECHDIR) $^
+ pdflatex -output-directory $(SPEECHDIR) $^
+ pdflatex -output-directory $(SPEECHDIR) $^
+
+speeches: $(SPEECHES)
+
+speeches-dist: speeches
+ rm -rf "${SPEECHESWEBDIR}"
+ mkdir -p "${SPEECHESWEBDIR}"
+ cp ${SPEECHES} "${SPEECHESWEBDIR}"
+ cd ${SPEECHESWEBDIR} && git add . && git commit -m "cdist speeches updated" || true
+
+################################################################################
+# Website
+#
+
+BLOGFILE=$(WEBBLOG)/cdist-$(CHANGELOG_VERSION)-released.mdwn
+
+$(BLOGFILE): $(CHANGELOG_FILE)
+ $(helper) blog $(CHANGELOG_VERSION) $(BLOGFILE)
+
+web-blog: $(BLOGFILE)
+
+web-doc:
+ # Go to top level, because of cdist.mdwn
+ rsync -av "$(WEBSRCDIR)/" "${WEBBASE}/.."
+ cd "${WEBBASE}/.." && git add cdist* && git commit -m "cdist doc update" cdist* || true
+
+web-dist: web-blog web-doc
+
+web-pub: web-dist man-dist speeches-dist
+ cd "${WEBDIR}" && make pub
+
+web-release-all: man-fix-link
+
+################################################################################
+# Release: Mailinglist
+#
+ML_FILE=.lock-ml
+
+# Only send mail once - lock until new changelog things happened
+$(ML_FILE): $(CHANGELOG_FILE)
+ $(helper) ml-release $(CHANGELOG_VERSION)
+ touch $@
+
+ml-release: $(ML_FILE)
+
+
+################################################################################
+# Release: Freecode
+#
+FREECODE_FILE=.lock-freecode
+
+$(FREECODE_FILE): $(CHANGELOG_FILE)
+ $(helper) freecode-release $(CHANGELOG_VERSION)
+ touch $@
+
+freecode-release: $(FREECODE_FILE)
+
+################################################################################
+# pypi
+#
+PYPI_FILE=.pypi-release
+$(PYPI_FILE): man $(PYTHON_VERSION)
+ python3 setup.py sdist upload
+ touch $@
+
+pypi-release: $(PYPI_FILE)
+################################################################################
+# archlinux
+#
+ARCHLINUX_FILE=.lock-archlinux
+ARCHLINUXTAR=cdist-$(CHANGELOG_VERSION)-1.src.tar.gz
+
+$(ARCHLINUXTAR): PKGBUILD
+ makepkg -c --source
+
+PKGBUILD: PKGBUILD.in $(PYTHON_VERSION)
+ ./PKGBUILD.in $(CHANGELOG_VERSION)
+
+$(ARCHLINUX_FILE): $(ARCHLINUXTAR) $(PYTHON_VERSION)
+ burp -c system $(ARCHLINUXTAR)
+ touch $@
+
+archlinux-release: $(ARCHLINUX_FILE)
+
+################################################################################
+# Release
+#
+
+$(PYTHON_VERSION): .git/refs/heads/master
+ $(helper) version
+
+# Code that is better handled in a shell script
+check-%:
+ $(helper) $@
+
+release:
+ $(helper) $@
+
+################################################################################
+# Cleanup
+#
+
+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
+
+ # Archlinux
+ rm -f cdist-*.pkg.tar.xz cdist-*.tar.gz
+ rm -rf pkg/ src/
+
+ rm -f MANIFEST PKGBUILD
+ rm -rf dist/
+
+distclean: clean
+ rm -f cdist/version.py
+
+################################################################################
+# Misc
+#
+
+# The pub is Nico's "push to all git remotes" way ("make pub")
+pub:
+ for remote in "" github sf; do \
+ echo "Pushing to $$remote"; \
+ git push --mirror $$remote; \
+ done
+
+test:
+ $(helper) $@
diff --git a/PKGBUILD.in b/PKGBUILD.in
index 68bd6add..e3ae4619 100755
--- a/PKGBUILD.in
+++ b/PKGBUILD.in
@@ -1,6 +1,6 @@
#!/bin/sh
-version=$(git describe)
+version="$1"
outfile=${0%.in}
cat << eof > "${outfile}"
diff --git a/bin/build-helper b/bin/build-helper
new file mode 100755
index 00000000..bfd7d31c
--- /dev/null
+++ b/bin/build-helper
@@ -0,0 +1,311 @@
+#!/bin/sh
+#
+# 2011-2013 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 file contains the heavy lifting found usually in the Makefile
+#
+
+basedir=${0%/*}/../
+# Change to checkout directory
+cd "$basedir"
+
+version=$(git describe)
+
+option=$1; shift
+
+case "$option" in
+ changelog-changes)
+ if [ "$#" -eq 1 ]; then
+ start=$1
+ else
+ start="[[:digit:]]"
+ fi
+
+ end="[[:digit:]]"
+
+ awk -F: "BEGIN { start=0 }
+ {
+ if(start == 0) {
+ if (\$0 ~ /^$start/) {
+ start = 1
+ }
+ } else {
+ if (\$0 ~ /^$end/) {
+ exit
+ } else {
+ print \$0
+ }
+ }
+ }" "$basedir/docs/changelog"
+ ;;
+
+ changelog-version)
+ # get version from changelog
+ grep '^[[:digit:]]' "$basedir/docs/changelog" | head -n1 | sed 's/:.*//'
+ ;;
+
+ check-date)
+ # verify date in changelog is today
+ 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
+ ;;
+
+ check-unittest)
+ "$0" test
+ ;;
+
+ blog)
+ version=$1; shift
+ blogfile=$1; shift
+ dir=${blogfile%/*}
+ file=${blogfile##*/}
+
+
+ cat << eof > "$blogfile"
+[[!meta title="Cdist $version released"]]
+
+Here's a short overview about the changes found in version ${version}:
+
+eof
+
+ $0 changelog-changes "$version" >> "$blogfile"
+
+ cat << eof >> "$blogfile"
+For more information visit the [[cdist homepage|software/cdist]].
+
+[[!tag cdist config unix]]
+eof
+ cd "$dir"
+ git add "$file"
+ # Allow git commit to fail if there are no changes
+ git commit -m "cdist blog update: $version" "$blogfile" || true
+ ;;
+
+ ml-release)
+ version=$1; shift
+
+ 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 "$version"
+ cat << eof
+
+Cheers,
+
+Nico
+
+--
+Automatisation at its best level. With cdist.
+eof
+ ) | /usr/sbin/sendmail -f "$from" "$to"
+ ;;
+
+
+ freecode-release)
+ version=$1; shift
+ api_token=$(awk '/machine freecode login/ { print $8 }' ~/.netrc)
+
+ printf "Enter tag list for freecode release %s> " "$version"
+ read taglist
+
+ printf "Enter changelog for freecode release %s> " "$version"
+ read changelog
+
+ echo "Submit preview"
+ cat << eof
+tag_list = $taglist
+changelog = $changelog
+version = $version
+eof
+ printf "Press enter to submit to freecode> "
+ read dummy
+
+ cat << eof | cfreecode-api release-add cdist
+ {
+ "auth_code": "$api_token",
+ "release": {
+ "tag_list": "$taglist",
+ "version": "$version",
+ "changelog": "$changelog",
+ "hidden_from_frontpage": false
+ }
+ }
+eof
+
+ ;;
+
+ release-git-tag)
+ target_version=$($0 changelog-version)
+ if git rev-parse --verify refs/tags/$target_version; then
+ echo "Tag for $target_version exists, aborting"
+ exit 1
+ fi
+ printf "Enter tag description for ${target_version}: "
+ read tagmessage
+ git tag "$target_version" -m "$$tagmessage"
+ ;;
+
+ release)
+ set -e
+ target_version=$($0 changelog-version)
+ target_branch=$($0 version-branch)
+
+ echo "Beginning release process for $target_version"
+
+ # First check everything is sane
+ "$0" check-date
+ "$0" check-unittest
+
+ # Generate version file to be included in packaging
+ "$0" version
+
+ # Ensure the git status is clean, else abort
+ if ! git diff-index --name-only --exit-code HEAD ; then
+ echo "Unclean tree, see files above, aborting"
+ exit 1
+ fi
+
+ # Ensure we are on the master branch
+ masterbranch=yes
+ if [ "$(git rev-parse --abbrev-ref HEAD)" != "master" ]; then
+ echo "Releases are happening from the master branch, aborting"
+
+ echo "Enter the magic word to release anyway"
+ read magicword
+
+ if [ "$magicword" = "iknowwhatido" ]; then
+ masterbranch=no
+ else
+ exit 1
+ fi
+ fi
+
+ if [ "$masterbranch" = yes ]; then
+ # Ensure version branch exists
+ if ! git rev-parse --verify refs/heads/$target_branch 2>/dev/null; then
+ git branch "$target_branch"
+ fi
+
+ # Merge master branch into version branch
+ git checkout "$target_branch"
+ git merge master
+ fi
+
+ # Verify that after the merge everything works
+ "$0" check-date
+ "$0" check-unittest
+
+ # Generate man pages (indirect check if they build)
+ make man
+
+ # Generate speeches (indirect check if they build)
+ make speeches
+
+ #############################################################
+ # Everything green, let's do the release
+
+ # Tag the current commit
+ "$0" release-git-tag
+
+ # Also merge back the version branch
+ if [ "$masterbranch" = yes ]; then
+ git checkout master
+ git merge "$target_branch"
+ fi
+
+ # Publish git changes
+ make pub
+
+ # publish man, speeches, website
+ make web-release-all
+
+ # Ensure that pypi release has the right version
+ "$0" version
+
+ # Create and publish package for pypi
+ make pypi-release
+
+ # Archlinux release is based on pypi
+ make archlinux-release
+
+ # Announce change on Freecode
+ make freecode-release
+
+ # Announce change on ML
+ make ml-release
+
+ cat << eof
+Manual steps post release:
+
+ - linkedin
+ - hackernews
+ - reddit
+ - twitter
+
+eof
+
+ ;;
+
+ test)
+ export PYTHONPATH="$(pwd -P)"
+
+ if [ $# -lt 1 ]; then
+ python3 -m cdist.test
+ else
+ python3 -m unittest "$@"
+ fi
+ ;;
+
+ version-branch)
+ "$0" changelog-version | cut -d. -f '1,2'
+ ;;
+
+ version)
+ echo "VERSION = \"$(git describe)\"" > cdist/version.py
+ ;;
+
+ *)
+ echo "Unknown helper target $@ - aborting"
+ exit 1
+ ;;
+
+esac
diff --git a/bin/cdist b/bin/cdist
index dfe4fa00..645020a1 100755
--- a/bin/cdist
+++ b/bin/cdist
@@ -25,7 +25,7 @@ dir=${0%/*}
# Ensure version is present - the bundled/shipped version contains a static version,
# the git version contains a dynamic version
-"$dir/../build" version
+"$dir/build-helper" version
libdir=$(cd "${dir}/../" && pwd -P)
export PYTHONPATH="${libdir}"
diff --git a/build b/build
deleted file mode 100755
index 1f408b94..00000000
--- a/build
+++ /dev/null
@@ -1,414 +0,0 @@
-#!/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 .
-#
-#
-# Push a directory to a target, both sides have the same name (i.e. explorers)
-# or
-# Pull a directory from a target, both sides have the same name (i.e. explorers)
-#
-
-# exit on any error
-#set -e
-
-basedir=${0%/*}
-version=$(cd "$basedir" && git describe)
-
-# Manpage and HTML
-A2XM="a2x -f manpage --no-xmllint -a encoding=UTF-8"
-A2XH="a2x -f xhtml --no-xmllint -a encoding=UTF-8"
-
-# Developer webbase
-WEBDIR=$HOME/www.nico.schottelius.org
-WEBBLOG=$WEBDIR/blog
-WEBTOPDIR=$WEBDIR/software
-WEBBASE=$WEBTOPDIR/cdist
-WEBMAN=$WEBBASE/man/$version
-WEBPAGE=${WEBBASE}.mdwn
-
-# Documentation
-MANDIR=docs/man
-MAN1DSTDIR=${MANDIR}/man1
-MAN7DSTDIR=${MANDIR}/man7
-SPEECHESDIR=docs/speeches
-
-# Change to checkout directory
-cd "$basedir"
-
-case "$1" in
- 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
- ;;
-
- dist-archlinux)
- $0 dist-archlinux-makepkg
- $0 dist-archlinux-aur-upload
- ;;
-
- dist-archlinux-makepkg)
- ./PKGBUILD.in
- makepkg -c --source
- ;;
-
- dist-archlinux-aur-upload)
- version=$($0 changelog-version)
- tar=cdist-${version}-1.src.tar.gz
- burp -c system "$tar"
- ;;
-
- dist-freecode)
- version=$($0 changelog-version)
- api_token=$(awk '/machine freecode login/ { print $8 }' ~/.netrc)
-
- printf "Enter tag list for freecode release %s> " "$version"
- read taglist
-
- printf "Enter changelog for freecode release %s> " "$version"
- read changelog
-
- echo "Submit preview"
- cat << eof
-tag_list = $taglist
-changelog = $changelog
-version = $version
-eof
- printf "Press enter to submit to freecode> "
- read dummy
-
- cat << eof | cfreecode-api release-add cdist
- {
- "auth_code": "$api_token",
- "release": {
- "tag_list": "$taglist",
- "version": "$version",
- "changelog": "$changelog",
- "hidden_from_frontpage": false
- }
- }
-eof
-
- ;;
-
- dist-pypi)
- $0 man
- $0 version
- python3 setup.py sdist upload
- ;;
-
- speeches)
- cd "$SPEECHESDIR"
- for speech in *tex; do
- pdflatex "$speech"
- pdflatex "$speech"
- pdflatex "$speech"
- done
- ;;
-
- web-doc)
- rsync -av "${basedir}/docs/web/" "${WEBTOPDIR}"
-
- cd "${WEBDIR}" && git add "${WEBBASE}"
- cd "${WEBDIR}" && git commit -m "cdist update" "${WEBBASE}" "${WEBPAGE}"
- cd "${WEBDIR}" && make pub
- ;;
-
- web)
- set -e
- "$0" web-doc
- # 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; 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
- ;;
-
-esac
diff --git a/cdist/__init__.py b/cdist/__init__.py
index 02d708b1..20c76b31 100644
--- a/cdist/__init__.py
+++ b/cdist/__init__.py
@@ -40,13 +40,20 @@ BANNER = """
"8888P' `"888*"" R888" ` ^"F 'Y"
"P' "" ""
"""
+
DOT_CDIST = ".cdist"
+REMOTE_COPY = "scp -o User=root -q"
+REMOTE_EXEC = "ssh -o User=root -q"
class Error(Exception):
"""Base exception class for this project"""
pass
+class UnresolvableRequirementsError(cdist.Error):
+ """Resolving requirements failed"""
+ pass
+
class CdistObjectError(Error):
"""Something went wrong with an object"""
diff --git a/cdist/conf/explorer/hostname b/cdist/conf/explorer/hostname
index 2ae23759..7715c6b0 100755
--- a/cdist/conf/explorer/hostname
+++ b/cdist/conf/explorer/hostname
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
+# 2010-2014 Nico Schottelius (nico-cdist at schottelius.org)
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
@@ -20,6 +20,6 @@
#
#
-if command -v hostname; then
- hostname
+if command -v uname >/dev/null; then
+ uname -n
fi
diff --git a/cdist/conf/explorer/machine b/cdist/conf/explorer/machine
index bb6e0beb..d4a0e106 100755
--- a/cdist/conf/explorer/machine
+++ b/cdist/conf/explorer/machine
@@ -22,6 +22,6 @@
#
#
-if command -v uname; then
+if command -v uname 2>&1 >/dev/null; then
uname -m
fi
diff --git a/cdist/conf/explorer/os b/cdist/conf/explorer/os
index e67d87ab..053177eb 100755
--- a/cdist/conf/explorer/os
+++ b/cdist/conf/explorer/os
@@ -88,6 +88,11 @@ if [ -f /etc/SuSE-release ]; then
exit 0
fi
+if [ -f /etc/slackware-version ]; then
+ echo slackware
+ exit 0
+fi
+
uname_s="$(uname -s)"
# Assume there is no tr on the client -> do lower case ourselves
diff --git a/cdist/conf/explorer/os_version b/cdist/conf/explorer/os_version
index 8e6d37d3..50889429 100755
--- a/cdist/conf/explorer/os_version
+++ b/cdist/conf/explorer/os_version
@@ -54,6 +54,9 @@ case "$($__explorer/os)" in
redhat|centos)
cat /etc/redhat-release
;;
+ slackware)
+ cat /etc/slackware-version
+ ;;
suse)
cat /etc/SuSE-release
;;
diff --git a/cdist/conf/type/__apt_key/explorer/state b/cdist/conf/type/__apt_key/explorer/state
new file mode 100755
index 00000000..f7940741
--- /dev/null
+++ b/cdist/conf/type/__apt_key/explorer/state
@@ -0,0 +1,32 @@
+#!/bin/sh
+#
+# 2011-2014 Steven Armstrong (steven-cdist at armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+#
+# Get the current state of the apt key.
+#
+
+if [ -f "$__object/parameter/keyid" ]; then
+ keyid="$(cat "$__object/parameter/keyid")"
+else
+ keyid="$__object_id"
+fi
+
+apt-key export "$keyid" | head -n 1 | grep -Fqe "BEGIN PGP PUBLIC KEY BLOCK" \
+ && echo present \
+ || echo absent
diff --git a/cdist/conf/type/__apt_key/gencode-remote b/cdist/conf/type/__apt_key/gencode-remote
new file mode 100755
index 00000000..c6ead91c
--- /dev/null
+++ b/cdist/conf/type/__apt_key/gencode-remote
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# 2011-2014 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 .
+#
+
+if [ -f "$__object/parameter/keyid" ]; then
+ keyid="$(cat "$__object/parameter/keyid")"
+else
+ keyid="$__object_id"
+fi
+state_should="$(cat "$__object/parameter/state")"
+state_is="$(cat "$__object/explorer/state")"
+
+if [ "$state_should" = "$state_is" ]; then
+ # nothing to do
+ exit 0
+fi
+
+case "$state_should" in
+ present)
+ keyserver="$(cat "$__object/parameter/keyserver")"
+ echo "apt-key adv --keyserver \"$keyserver\" --recv-keys \"$keyid\""
+ ;;
+ absent)
+ echo "apt-key del \"$keyid\""
+ ;;
+esac
diff --git a/cdist/conf/type/__apt_key/man.text b/cdist/conf/type/__apt_key/man.text
new file mode 100644
index 00000000..1a33e732
--- /dev/null
+++ b/cdist/conf/type/__apt_key/man.text
@@ -0,0 +1,61 @@
+cdist-type__apt_key(7)
+======================
+Steven Armstrong
+
+
+NAME
+----
+cdist-type__apt_key - manage the list of keys used by apt
+
+
+DESCRIPTION
+-----------
+Manages the list of keys used by apt to authenticate packages.
+
+
+REQUIRED PARAMETERS
+-------------------
+None.
+
+
+OPTIONAL PARAMETERS
+-------------------
+state::
+ 'present' or 'absent'. Defaults to 'present'
+
+keyid::
+ the id of the key to add. Defaults to __object_id
+
+keyserver::
+ the keyserver from which to fetch the key. If omitted the default set in
+ ./parameter/default/keyserver is used.
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+# Add Ubuntu Archive Automatic Signing Key
+__apt_key 437D05B5
+# Same thing
+__apt_key 437D05B5 --state present
+# Get rid of it
+__apt_key 437D05B5 --state absent
+
+# same thing with human readable name and explicit keyid
+__apt_key UbuntuArchiveKey --keyid 437D05B5
+
+# same thing with other keyserver
+__apt_key UbuntuArchiveKey --keyid 437D05B5 --keyserver keyserver.ubuntu.com
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+
+
+COPYING
+-------
+Copyright \(C) 2011-2014 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/__apt_key/parameter/default/keyserver b/cdist/conf/type/__apt_key/parameter/default/keyserver
new file mode 100644
index 00000000..f851282c
--- /dev/null
+++ b/cdist/conf/type/__apt_key/parameter/default/keyserver
@@ -0,0 +1 @@
+subkeys.pgp.net
diff --git a/cdist/conf/type/__apt_key/parameter/default/state b/cdist/conf/type/__apt_key/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__apt_key/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__apt_key/parameter/optional b/cdist/conf/type/__apt_key/parameter/optional
new file mode 100644
index 00000000..18cf2586
--- /dev/null
+++ b/cdist/conf/type/__apt_key/parameter/optional
@@ -0,0 +1,3 @@
+state
+keyid
+keyserver
diff --git a/cdist/conf/type/__apt_key_uri/explorer/state b/cdist/conf/type/__apt_key_uri/explorer/state
new file mode 100755
index 00000000..15d6e653
--- /dev/null
+++ b/cdist/conf/type/__apt_key_uri/explorer/state
@@ -0,0 +1,32 @@
+#!/bin/sh
+#
+# 2011-2014 Steven Armstrong (steven-cdist at armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+#
+# Get the current state of the apt key.
+#
+
+if [ -f "$__object/parameter/name" ]; then
+ name="$(cat "$__object/parameter/name")"
+else
+ name="$__object_id"
+fi
+
+apt-key list | grep -Fqe "$name" \
+ && echo present \
+ || echo absent
diff --git a/cdist/conf/type/__apt_key_uri/gencode-remote b/cdist/conf/type/__apt_key_uri/gencode-remote
new file mode 100755
index 00000000..078b8695
--- /dev/null
+++ b/cdist/conf/type/__apt_key_uri/gencode-remote
@@ -0,0 +1,45 @@
+#!/bin/sh
+#
+# 2011-2014 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 .
+#
+
+if [ -f "$__object/parameter/name" ]; then
+ name="$(cat "$__object/parameter/name")"
+else
+ name="$__object_id"
+fi
+state_should="$(cat "$__object/parameter/state")"
+state_is="$(cat "$__object/explorer/state")"
+
+if [ "$state_should" = "$state_is" ]; then
+ # nothing to do
+ exit 0
+fi
+
+case "$state_should" in
+ present)
+ uri="$(cat "$__object/parameter/uri")"
+ printf 'curl -s -L "%s" | apt-key add -\n' "$uri"
+ ;;
+ absent)
+ cat << DONE
+keyid=\$(apt-key list | grep -B1 "$name" | awk '/pub/ { print \$2 }' | cut -d'/' -f 2)
+apt-key del \$keyid
+DONE
+ ;;
+esac
diff --git a/cdist/conf/type/__apt_key_uri/man.text b/cdist/conf/type/__apt_key_uri/man.text
new file mode 100644
index 00000000..fe9c3a25
--- /dev/null
+++ b/cdist/conf/type/__apt_key_uri/man.text
@@ -0,0 +1,51 @@
+cdist-type__apt_key_uri(7)
+==========================
+Steven Armstrong
+
+
+NAME
+----
+cdist-type__apt_key_uri - add apt key from uri
+
+
+DESCRIPTION
+-----------
+Download a key from an uri and add it to the apt keyring.
+
+
+REQUIRED PARAMETERS
+-------------------
+uri::
+ the uri from which to download the key
+
+
+OPTIONAL PARAMETERS
+-------------------
+state::
+ 'present' or 'absent', defaults to 'present'
+
+name::
+ a name for this key, used when testing if it is already installed.
+ Defaults to __object_id
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+__apt_key_uri rabbitmq \
+ --name 'RabbitMQ Release Signing Key ' \
+ --uri http://www.rabbitmq.com/rabbitmq-signing-key-public.asc \
+ --state present
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+
+
+COPYING
+-------
+Copyright \(C) 2011-2014 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/__apt_key_uri/manifest b/cdist/conf/type/__apt_key_uri/manifest
new file mode 100755
index 00000000..8dddde56
--- /dev/null
+++ b/cdist/conf/type/__apt_key_uri/manifest
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# 2013-2014 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 .
+#
+
+__package curl
diff --git a/cdist/conf/type/__apt_key_uri/parameter/default/state b/cdist/conf/type/__apt_key_uri/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__apt_key_uri/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__apt_key_uri/parameter/optional b/cdist/conf/type/__apt_key_uri/parameter/optional
new file mode 100644
index 00000000..72c84b88
--- /dev/null
+++ b/cdist/conf/type/__apt_key_uri/parameter/optional
@@ -0,0 +1,2 @@
+state
+name
diff --git a/cdist/conf/type/__apt_key_uri/parameter/required b/cdist/conf/type/__apt_key_uri/parameter/required
new file mode 100644
index 00000000..c7954952
--- /dev/null
+++ b/cdist/conf/type/__apt_key_uri/parameter/required
@@ -0,0 +1 @@
+uri
diff --git a/cdist/conf/type/__apt_norecommends/man.text b/cdist/conf/type/__apt_norecommends/man.text
new file mode 100644
index 00000000..3b65e72f
--- /dev/null
+++ b/cdist/conf/type/__apt_norecommends/man.text
@@ -0,0 +1,42 @@
+cdist-type__apt_norecommends(7)
+===============================
+Steven Armstrong
+
+
+NAME
+----
+cdist-type__apt_norecommends - configure apt to not install recommended packages
+
+
+DESCRIPTION
+-----------
+Configure apt to not install any recommended or suggested packages.
+
+
+REQUIRED PARAMETERS
+-------------------
+None.
+
+
+OPTIONAL PARAMETERS
+-------------------
+None.
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+__apt_norecommends
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+
+
+COPYING
+-------
+Copyright \(C) 2014 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/__apt_norecommends/manifest b/cdist/conf/type/__apt_norecommends/manifest
new file mode 100755
index 00000000..881c2427
--- /dev/null
+++ b/cdist/conf/type/__apt_norecommends/manifest
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+
+os=$(cat "$__global/explorer/os")
+
+case "$os" in
+ ubuntu|debian)
+ # No stinking recommends thank you very much.
+ # If I want something installed I will do so myself.
+ __file /etc/apt/apt.conf.d/99-no-recommends \
+ --owner root --group root --mode 644 \
+ --source - << DONE
+APT::Install-Recommends "0";
+APT::Install-Suggests "0";
+DONE
+ ;;
+ *)
+ cat >&2 << DONE
+The developer of this type (${__type##*/}) did not think your operating system
+($os) would have any use for it. If you think otherwise please submit a patch.
+DONE
+ exit 1
+ ;;
+esac
diff --git a/cdist/test/type/fixtures/__singleton/singleton b/cdist/conf/type/__apt_norecommends/singleton
similarity index 100%
rename from cdist/test/type/fixtures/__singleton/singleton
rename to cdist/conf/type/__apt_norecommends/singleton
diff --git a/cdist/conf/type/__apt_ppa/gencode-remote b/cdist/conf/type/__apt_ppa/gencode-remote
index 0ea8011c..300a0e1e 100755
--- a/cdist/conf/type/__apt_ppa/gencode-remote
+++ b/cdist/conf/type/__apt_ppa/gencode-remote
@@ -22,7 +22,7 @@ name="$__object_id"
state_should="$(cat "$__object/parameter/state")"
state_is="$(cat "$__object/explorer/state")"
-if [ "$state_should" == "$state_is" ]; then
+if [ "$state_should" = "$state_is" ]; then
# Nothing to do, move along
exit 0
fi
diff --git a/cdist/conf/type/__apt_ppa/man.text b/cdist/conf/type/__apt_ppa/man.text
index 6a5990d5..da18e9f0 100644
--- a/cdist/conf/type/__apt_ppa/man.text
+++ b/cdist/conf/type/__apt_ppa/man.text
@@ -16,7 +16,8 @@ This cdist type allows manage ubuntu ppa repositories.
REQUIRED PARAMETERS
-------------------
state::
- The state the ppa should be in, either "present" or "absent".
+ The state the ppa should be in, either 'present' or 'absent'.
+ Defaults to 'present'
OPTIONAL PARAMETERS
@@ -29,6 +30,8 @@ EXAMPLES
--------------------------------------------------------------------------------
# Enable a ppa repository
+__apt_ppa ppa:sans-intern/missing-bits
+# same as
__apt_ppa ppa:sans-intern/missing-bits --state present
# Disable a ppa repository
@@ -43,5 +46,5 @@ SEE ALSO
COPYING
-------
-Copyright \(C) 2011 Steven Armstrong. Free use of this software is
+Copyright \(C) 2011-2014 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/__apt_ppa/manifest b/cdist/conf/type/__apt_ppa/manifest
index e7ad0c26..1d90e9c4 100755
--- a/cdist/conf/type/__apt_ppa/manifest
+++ b/cdist/conf/type/__apt_ppa/manifest
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
+# 2011-2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
@@ -20,9 +20,10 @@
name="$__object_id"
-__package python-software-properties --state present
+__package software-properties-common
+__package python-software-properties
-require="__package/python-software-properties" \
+require="__package/software-properties-common __package/python-software-properties" \
__file /usr/local/bin/remove-apt-repository \
--source "$__type/files/remove-apt-repository" \
--mode 0755
diff --git a/cdist/conf/type/__apt_ppa/parameter/default/state b/cdist/conf/type/__apt_ppa/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__apt_ppa/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__apt_ppa/parameter/required b/cdist/conf/type/__apt_ppa/parameter/optional
similarity index 100%
rename from cdist/conf/type/__apt_ppa/parameter/required
rename to cdist/conf/type/__apt_ppa/parameter/optional
diff --git a/cdist/conf/type/__apt_source/files/source.list.template b/cdist/conf/type/__apt_source/files/source.list.template
new file mode 100755
index 00000000..d4420e96
--- /dev/null
+++ b/cdist/conf/type/__apt_source/files/source.list.template
@@ -0,0 +1,15 @@
+#!/bin/sh
+set -u
+
+entry="$uri $distribution $component"
+cat << DONE
+# Created by cdist ${__type##*/}
+# Do not change. Changes will be overwritten.
+#
+
+# $name
+deb ${forcedarch} $entry
+DONE
+if [ -f "$__object/parameter/include-src" ]; then
+ echo "deb-src $entry"
+fi
diff --git a/cdist/conf/type/__apt_source/man.text b/cdist/conf/type/__apt_source/man.text
new file mode 100644
index 00000000..03b2b311
--- /dev/null
+++ b/cdist/conf/type/__apt_source/man.text
@@ -0,0 +1,69 @@
+cdist-type__apt_source(7)
+=========================
+Steven Armstrong
+
+
+NAME
+----
+cdist-type__apt_source - manage apt sources
+
+
+DESCRIPTION
+-----------
+This cdist type allows you to manage apt sources.
+
+
+REQUIRED PARAMETERS
+-------------------
+uri::
+ the uri to the apt repository
+
+
+OPTIONAL PARAMETERS
+-------------------
+arch::
+ set this if you need to force and specific arch (ubuntu specific)
+
+state::
+ 'present' or 'absent', defaults to 'present'
+
+distribution::
+ the distribution codename to use. Defaults to DISTRIB_CODENAME from
+ the targets /etc/lsb-release
+
+component::
+ space delimited list of components to enable. Defaults to an empty string.
+
+
+BOOLEAN PARAMETERS
+------------------
+include-src::
+ include deb-src entries
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+__apt_source rabbitmq \
+ --uri http://www.rabbitmq.com/debian/ \
+ --distribution testing \
+ --component main \
+ --include-src \
+ --state present
+
+__apt_source canonical_partner \
+ --uri http://archive.canonical.com/ \
+ --component partner --state present
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+
+
+COPYING
+-------
+Copyright \(C) 2011-2014 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/__apt_source/manifest b/cdist/conf/type/__apt_source/manifest
new file mode 100755
index 00000000..0e782716
--- /dev/null
+++ b/cdist/conf/type/__apt_source/manifest
@@ -0,0 +1,56 @@
+#!/bin/sh
+#
+# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+name="$__object_id"
+state="$(cat "$__object/parameter/state")"
+uri="$(cat "$__object/parameter/uri")"
+
+if [ -f "$__object/parameter/distribution" ]; then
+ distribution="$(cat "$__object/parameter/distribution")"
+else
+ distribution="$(cat "$__global/explorer/lsb_codename")"
+fi
+if [ -f "$__object/parameter/component" ]; then
+ component="$(cat "$__object/parameter/component")"
+else
+ component=""
+fi
+if [ -f "$__object/parameter/arch" ]; then
+ forcedarch="[arch=$(cat "$__object/parameter/arch")]"
+else
+ forcedarch=""
+fi
+
+# export variables for use in template
+export name
+export uri
+export distribution
+export component
+export forcedarch
+
+# generate file from template
+mkdir "$__object/files"
+"$__type/files/source.list.template" > "$__object/files/source.list"
+__file "/etc/apt/sources.list.d/${name}.list" \
+ --source "$__object/files/source.list" \
+ --owner root --group root --mode 0644 \
+ --state "$state"
+
+require="$__object_name" __apt_update_index
diff --git a/cdist/conf/type/__apt_source/parameter/boolean b/cdist/conf/type/__apt_source/parameter/boolean
new file mode 100644
index 00000000..8fa49177
--- /dev/null
+++ b/cdist/conf/type/__apt_source/parameter/boolean
@@ -0,0 +1 @@
+include-src
diff --git a/cdist/conf/type/__apt_source/parameter/default/state b/cdist/conf/type/__apt_source/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__apt_source/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__apt_source/parameter/optional b/cdist/conf/type/__apt_source/parameter/optional
new file mode 100644
index 00000000..87537335
--- /dev/null
+++ b/cdist/conf/type/__apt_source/parameter/optional
@@ -0,0 +1,4 @@
+state
+distribution
+component
+arch
\ No newline at end of file
diff --git a/cdist/conf/type/__apt_source/parameter/required b/cdist/conf/type/__apt_source/parameter/required
new file mode 100644
index 00000000..c7954952
--- /dev/null
+++ b/cdist/conf/type/__apt_source/parameter/required
@@ -0,0 +1 @@
+uri
diff --git a/cdist/conf/type/__block/explorer/block b/cdist/conf/type/__block/explorer/block
new file mode 100755
index 00000000..6c35bc46
--- /dev/null
+++ b/cdist/conf/type/__block/explorer/block
@@ -0,0 +1,21 @@
+#!/bin/sh
+# 2013 Steven Armstrong (steven-cdist at armstrong.cc)
+
+file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")"
+
+# file does not exist, nothing we could do
+[ -f "$file" ] || exit 0
+
+prefix=$(cat "$__object/parameter/prefix" 2>/dev/null || echo "#cdist:__block/$__object_id")
+suffix=$(cat "$__object/parameter/suffix" 2>/dev/null || echo "#/cdist:__block/$__object_id")
+awk -v prefix="$prefix" -v suffix="$suffix" '{
+ if (index($0,prefix)) {
+ triggered=1
+ }
+ if (triggered) {
+ if (index($0,suffix)) {
+ triggered=0
+ }
+ print
+ }
+}' "$file"
diff --git a/cdist/conf/type/__block/gencode-remote b/cdist/conf/type/__block/gencode-remote
new file mode 100755
index 00000000..0a5eea18
--- /dev/null
+++ b/cdist/conf/type/__block/gencode-remote
@@ -0,0 +1,84 @@
+#!/bin/sh
+#
+# 2013 Steven Armstrong (steven-cdist at armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")"
+state_should=$(cat "$__object/parameter/state")
+prefix=$(cat "$__object/parameter/prefix" 2>/dev/null || echo "#cdist:__block/$__object_id")
+suffix=$(cat "$__object/parameter/suffix" 2>/dev/null || echo "#/cdist:__block/$__object_id")
+
+block="$__object/files/block"
+if [ ! -s "$__object/explorer/block" ]; then
+ state_is='absent'
+else
+ state_is=$(diff -q "$block" "$__object/explorer/block" >/dev/null \
+ && echo present \
+ || echo changed
+ )
+fi
+
+state_should="$(cat "$__object/parameter/state")"
+if [ "$state_should" = "$state_is" ]; then
+ # Nothing to do, move along
+ exit 0
+fi
+
+remove_block() {
+ cat << DONE
+tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX)
+# preserve ownership and permissions of existing file
+if [ -f "$file" ]; then
+ cp -p "$file" "\$tmpfile"
+fi
+awk -v prefix="$prefix" -v suffix="$suffix" '
+{
+ if (index(\$0,prefix)) {
+ triggered=1
+ }
+ if (triggered) {
+ if (index(\$0,suffix)) {
+ triggered=0
+ }
+ } else {
+ print
+ }
+}' "$file" > "\$tmpfile"
+mv -f "\$tmpfile" "$file"
+DONE
+}
+
+case "$state_should" in
+ present)
+ if [ "$state_is" = "changed" ]; then
+ echo update >> "$__messages_out"
+ remove_block
+ else
+ echo add >> "$__messages_out"
+ fi
+ cat << DONE
+cat >> "$file" << ${__type##*/}_DONE
+$(cat "$block")
+${__type##*/}_DONE
+DONE
+ ;;
+ absent)
+ echo remove >> "$__messages_out"
+ remove_block
+ ;;
+esac
diff --git a/cdist/conf/type/__block/man.text b/cdist/conf/type/__block/man.text
new file mode 100644
index 00000000..2312d293
--- /dev/null
+++ b/cdist/conf/type/__block/man.text
@@ -0,0 +1,82 @@
+cdist-type__block(7)
+====================
+Steven Armstrong
+
+
+NAME
+----
+cdist-type__block - Manage blocks of text in files
+
+
+DESCRIPTION
+-----------
+Manage a block of text in an existing file.
+The block is identified using the prefix and suffix parameters.
+Everything between prefix and suffix is considered to be a managed block
+of text.
+
+
+REQUIRED PARAMETERS
+-------------------
+text::
+ the text to manage.
+ If text is '-' (dash), take what was written to stdin as the text.
+
+
+OPTIONAL PARAMETERS
+-------------------
+file::
+ the file in which to manage the text block.
+ Defaults to object_id.
+
+prefix::
+ the prefix to add before the text.
+ Defaults to #cdist:__block/$__object_id
+
+suffix::
+ the prefix to add after the text.
+ Defaults to #/cdist:__block/$__object_id
+
+state::
+ 'present' or 'absent', defaults to 'present'
+
+
+MESSAGES
+--------
+add::
+ block was added
+update::
+ block was updated/changed
+remove::
+ block was removed
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+# text from argument
+__block /path/to/file \
+ --prefix '#start' \
+ --suffix '#end' \
+ --text 'some\nblock of\ntext'
+
+# text from stdin
+__block some-id \
+ --file /path/to/file \
+ --text - << DONE
+here some block
+of text
+DONE
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+
+
+COPYING
+-------
+Copyright \(C) 2013 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/__block/manifest b/cdist/conf/type/__block/manifest
new file mode 100755
index 00000000..1fc9ec79
--- /dev/null
+++ b/cdist/conf/type/__block/manifest
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# 2013-2014 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 .
+#
+
+
+file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")"
+prefix=$(cat "$__object/parameter/prefix" 2>/dev/null || echo "#cdist:__block/$__object_id")
+suffix=$(cat "$__object/parameter/suffix" 2>/dev/null || echo "#/cdist:__block/$__object_id")
+text=$(cat "$__object/parameter/text")
+
+mkdir "$__object/files"
+# Generate text block for inclusion in file
+block="$__object/files/block"
+echo "$prefix" > "$block"
+if [ "$text" = "-" ]; then
+ cat "$__object/stdin" >> "$block"
+else
+ cat "$text" >> "$block"
+fi
+echo "$suffix" >> "$block"
diff --git a/cdist/conf/type/__block/parameter/default/state b/cdist/conf/type/__block/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__block/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__block/parameter/optional b/cdist/conf/type/__block/parameter/optional
new file mode 100644
index 00000000..fa3abebf
--- /dev/null
+++ b/cdist/conf/type/__block/parameter/optional
@@ -0,0 +1,4 @@
+file
+prefix
+state
+suffix
diff --git a/cdist/conf/type/__block/parameter/required b/cdist/conf/type/__block/parameter/required
new file mode 100644
index 00000000..8e27be7d
--- /dev/null
+++ b/cdist/conf/type/__block/parameter/required
@@ -0,0 +1 @@
+text
diff --git a/cdist/conf/type/__ccollect_source/explorer/cksum b/cdist/conf/type/__ccollect_source/explorer/cksum
new file mode 100755
index 00000000..335e4e7a
--- /dev/null
+++ b/cdist/conf/type/__ccollect_source/explorer/cksum
@@ -0,0 +1,34 @@
+#!/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 .
+#
+#
+# Retrieve the md5sum of a file to be created, if it is already existing.
+#
+
+destination="/$__object_id"
+
+if [ -e "$destination" ]; then
+ if [ -f "$destination" ]; then
+ cksum < "$destination"
+ else
+ echo "NO REGULAR FILE"
+ fi
+else
+ echo "NO FILE FOUND, NO CHECKSUM CALCULATED."
+fi
diff --git a/cdist/conf/type/__ccollect_source/explorer/stat b/cdist/conf/type/__ccollect_source/explorer/stat
new file mode 100755
index 00000000..298221b7
--- /dev/null
+++ b/cdist/conf/type/__ccollect_source/explorer/stat
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# 2013 Steven Armstrong (steven-cdist armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+destination="/$__object_id"
+
+# nothing to work with, nothing we could do
+[ -e "$destination" ] || exit 0
+
+os=$("$__explorer/os")
+case "$os" in
+ "freebsd")
+ # FIXME: should be something like this based on man page, but can not test
+ stat -f "type: %ST
+owner: %Du %Su
+group: %Dg %Sg
+mode: %Op %Sp
+size: %Dz
+links: %Dl
+" "$destination"
+ ;;
+ *)
+ stat --printf="type: %F
+owner: %u %U
+group: %g %G
+mode: %a %A
+size: %s
+links: %h
+" "$destination"
+ ;;
+esac
diff --git a/cdist/conf/type/__ccollect_source/explorer/type b/cdist/conf/type/__ccollect_source/explorer/type
new file mode 100755
index 00000000..e723047c
--- /dev/null
+++ b/cdist/conf/type/__ccollect_source/explorer/type
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# 2013 Steven Armstrong (steven-cdist armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+destination="/$__object_id"
+
+if [ ! -e "$destination" ]; then
+ echo none
+elif [ -h "$destination" ]; then
+ echo symlink
+elif [ -f "$destination" ]; then
+ echo file
+elif [ -d "$destination" ]; then
+ echo directory
+else
+ echo unknown
+fi
diff --git a/cdist/conf/type/__ccollect_source/gencode-remote b/cdist/conf/type/__ccollect_source/gencode-remote
new file mode 100755
index 00000000..c41b5179
--- /dev/null
+++ b/cdist/conf/type/__ccollect_source/gencode-remote
@@ -0,0 +1,93 @@
+#!/bin/sh
+#
+# 2014 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")"
+type="$(cat "$__object/explorer/type")"
+stat_file="$__object/explorer/stat"
+
+
+get_current_value() {
+ if [ -s "$stat_file" ]; then
+ _name="$1"
+ _value="$2"
+ case "$_value" in
+ [0-9]*)
+ _index=2
+ ;;
+ *)
+ _index=3
+ ;;
+ esac
+ awk '/'"$_name"':/ { print $'$_index' }' "$stat_file"
+ unset _name _value _index
+ fi
+}
+
+set_group() {
+ echo chgrp \"$1\" \"$destination\"
+ echo chgrp $1 >> "$__messages_out"
+}
+
+set_owner() {
+ echo chown \"$1\" \"$destination\"
+ echo chown $1 >> "$__messages_out"
+}
+
+set_mode() {
+ echo chmod \"$1\" \"$destination\"
+ echo chmod $1 >> "$__messages_out"
+}
+
+set_attributes=
+case "$state_should" in
+ present|exists)
+ # Note: Mode - needs to happen last as a chown/chgrp can alter mode by
+ # clearing S_ISUID and S_ISGID bits (see chown(2))
+ for attribute in group owner mode; do
+ if [ -f "$__object/parameter/$attribute" ]; then
+ value_should="$(cat "$__object/parameter/$attribute")"
+
+ # change 0xxx format to xxx format => same as stat returns
+ if [ "$attribute" = mode ]; then
+ value_should="$(echo $value_should | sed 's/^0\(...\)/\1/')"
+ fi
+
+ value_is="$(get_current_value "$attribute" "$value_should")"
+ if [ -f "$__object/files/set-attributes" -o "$value_should" != "$value_is" ]; then
+ "set_$attribute" "$value_should"
+ fi
+ fi
+ done
+
+ ;;
+
+ absent)
+ if [ "$type" = "file" ]; then
+ echo rm -f \"$destination\"
+ echo remove >> "$__messages_out"
+ fi
+ ;;
+
+ *)
+ echo "Unknown state: $state_should" >&2
+ exit 1
+ ;;
+esac
diff --git a/cdist/conf/type/__ccollect_source/man.text b/cdist/conf/type/__ccollect_source/man.text
new file mode 100644
index 00000000..32a7467e
--- /dev/null
+++ b/cdist/conf/type/__ccollect_source/man.text
@@ -0,0 +1,64 @@
+cdist-type__ccollect_source(7)
+==============================
+Nico Schottelius
+
+
+NAME
+----
+cdist-type__ccollect_source - Manage ccollect sources
+
+
+DESCRIPTION
+-----------
+This cdist type allows you to create or delete ccollect sources.
+
+REQUIRED PARAMETERS
+-------------------
+source::
+ The source from which to backup
+destination::
+ The destination directory
+
+
+OPTIONAL PARAMETERS
+-------------------
+state::
+ 'present' or 'absent', defaults to 'present'
+ccollectconf::
+ The CCOLLECT_CONF directory. Defaults to /etc/ccollect.
+
+
+OPTIONAL MULTIPLE PARAMETERS
+----------------------------
+exclude::
+ Paths to exclude of backup
+
+BOOLEAN PARAMETERS
+------------------
+verbose::
+ Whether to report backup verbosely
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+__ccollect_source doc.ungleich.ch \
+ --source doc.ungleich.ch:/ \
+ --destination /backup/doc.ungleich.ch \
+ --exclude '/proc/*' --exclude '/sys/*' \
+ --verbose
+
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+- ccollect(1)
+- http://www.nico.schottelius.org/software/ccollect/
+
+
+COPYING
+-------
+Copyright \(C) 2014 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/__ccollect_source/manifest b/cdist/conf/type/__ccollect_source/manifest
new file mode 100755
index 00000000..89c2ef2b
--- /dev/null
+++ b/cdist/conf/type/__ccollect_source/manifest
@@ -0,0 +1,53 @@
+#!/bin/sh
+#
+# 2014 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 .
+#
+
+name="$__object_id"
+state="$(cat "$__object/parameter/state")"
+source="$(cat "$__object/parameter/source")"
+destination="$(cat "$__object/parameter/destination")"
+ccollectconf="$(cat "$__object/parameter/ccollectconf" | sed 's,/$,,')"
+
+sourcedir="$ccollectconf/sources"
+basedir="$sourcedir/$name"
+
+destination_file="$basedir/destination"
+source_file="$basedir/source"
+exclude_file="$basedir/exclude"
+verbose_file="$basedir/verbose"
+
+__directory "$basedir" --state "$state"
+
+export require="__directory$basedir"
+echo "$destination" | __file "$destination_file" --source - --state "$state"
+echo "$source" | __file "$source_file" --source - --state "$state"
+
+################################################################################
+# Booleans
+if [ -f "$__object/parameter/verbose" ]; then
+ verbosestate="present"
+else
+ verbosestate="absent"
+fi
+__file "$verbose_file" --state "$verbosestate"
+
+if [ -f "$__object/parameter/exclude" ]; then
+ __file "$exclude_file" --source - --state "$state" \
+ < "$__object/parameter/exclude"
+fi
diff --git a/cdist/conf/type/__ccollect_source/parameter/boolean b/cdist/conf/type/__ccollect_source/parameter/boolean
new file mode 100644
index 00000000..c00ee94a
--- /dev/null
+++ b/cdist/conf/type/__ccollect_source/parameter/boolean
@@ -0,0 +1 @@
+verbose
diff --git a/cdist/conf/type/__ccollect_source/parameter/default/ccollectconf b/cdist/conf/type/__ccollect_source/parameter/default/ccollectconf
new file mode 100644
index 00000000..a9fda009
--- /dev/null
+++ b/cdist/conf/type/__ccollect_source/parameter/default/ccollectconf
@@ -0,0 +1 @@
+/etc/ccollect
diff --git a/cdist/conf/type/__ccollect_source/parameter/default/state b/cdist/conf/type/__ccollect_source/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__ccollect_source/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__ccollect_source/parameter/optional b/cdist/conf/type/__ccollect_source/parameter/optional
new file mode 100644
index 00000000..0249d11e
--- /dev/null
+++ b/cdist/conf/type/__ccollect_source/parameter/optional
@@ -0,0 +1,2 @@
+ccollectconf
+state
diff --git a/cdist/conf/type/__ccollect_source/parameter/optional_multiple b/cdist/conf/type/__ccollect_source/parameter/optional_multiple
new file mode 100644
index 00000000..9ba870ea
--- /dev/null
+++ b/cdist/conf/type/__ccollect_source/parameter/optional_multiple
@@ -0,0 +1 @@
+exclude
diff --git a/cdist/conf/type/__ccollect_source/parameter/required b/cdist/conf/type/__ccollect_source/parameter/required
new file mode 100644
index 00000000..9239646e
--- /dev/null
+++ b/cdist/conf/type/__ccollect_source/parameter/required
@@ -0,0 +1,2 @@
+source
+destination
diff --git a/cdist/conf/type/__cdist/man.text b/cdist/conf/type/__cdist/man.text
new file mode 100644
index 00000000..0805598e
--- /dev/null
+++ b/cdist/conf/type/__cdist/man.text
@@ -0,0 +1,63 @@
+cdist-type__cdist(7)
+====================
+Nico Schottelius
+
+
+NAME
+----
+cdist-type__cdist - Manage cdist installations
+
+
+DESCRIPTION
+-----------
+This cdist type allows you to easily setup cdist
+on another box, to allow the other box to configure
+systems.
+
+This type is *NOT* required by target hosts.
+It is only helpful to build FROM which you configure
+other hosts.
+
+This type will use git to clone
+
+
+REQUIRED PARAMETERS
+-------------------
+
+OPTIONAL PARAMETERS
+-------------------
+username::
+ Select the user to create for the cdist installation.
+ Defaults to "cdist".
+
+source::
+ Select the source from which to clone cdist from.
+ Defaults to "git://github.com/telmich/cdist.git".
+
+
+branch::
+ Select the branch to checkout from.
+ Defaults to "master".
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+# Install cdist for user cdist in her home as subfolder cdist
+__cdist /home/cdist/cdist
+
+# Use alternative source
+__cdist --source "git://git.schottelius.org/cdist" /home/cdist/cdist
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+
+
+COPYING
+-------
+Copyright \(C) 2013 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/__cdist/manifest b/cdist/conf/type/__cdist/manifest
new file mode 100755
index 00000000..7c0ae60e
--- /dev/null
+++ b/cdist/conf/type/__cdist/manifest
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# 2013 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 .
+#
+#
+
+directory="$__object_id"
+
+if [ -f "$__object/parameter/shell" ]; then
+ shell="--shell $(cat "$__object/parameter/shell")"
+else
+ shell=""
+fi
+
+username="$(cat "$__object/parameter/username")"
+
+branch="$(cat "$__object/parameter/branch")"
+
+source="$(cat "$__object/parameter/source")"
+
+# Currently hardcoded - if anyone cares, make a parameter
+# out of it
+home=/home/$username
+
+__user "$username" --home "$home" $shell
+
+require="__user/$username" __directory "$home" \
+ --owner "$username"
+
+require="__user/$username __directory/$home" __git "$directory" \
+ --source "$source" \
+ --owner "$username" --branch "$branch"
diff --git a/cdist/conf/type/__cdist/parameter/default/branch b/cdist/conf/type/__cdist/parameter/default/branch
new file mode 100644
index 00000000..1f7391f9
--- /dev/null
+++ b/cdist/conf/type/__cdist/parameter/default/branch
@@ -0,0 +1 @@
+master
diff --git a/cdist/conf/type/__cdist/parameter/default/source b/cdist/conf/type/__cdist/parameter/default/source
new file mode 100644
index 00000000..d669308f
--- /dev/null
+++ b/cdist/conf/type/__cdist/parameter/default/source
@@ -0,0 +1 @@
+git://github.com/telmich/cdist.git
diff --git a/cdist/conf/type/__cdist/parameter/default/username b/cdist/conf/type/__cdist/parameter/default/username
new file mode 100644
index 00000000..a585e141
--- /dev/null
+++ b/cdist/conf/type/__cdist/parameter/default/username
@@ -0,0 +1 @@
+cdist
diff --git a/cdist/conf/type/__cdist/parameter/optional b/cdist/conf/type/__cdist/parameter/optional
new file mode 100644
index 00000000..a5f14343
--- /dev/null
+++ b/cdist/conf/type/__cdist/parameter/optional
@@ -0,0 +1,4 @@
+branch
+source
+username
+shell
diff --git a/cdist/conf/type/__cron/explorer/entry b/cdist/conf/type/__cron/explorer/entry
old mode 100755
new mode 100644
index 1b4bec42..c3bf02d2
--- a/cdist/conf/type/__cron/explorer/entry
+++ b/cdist/conf/type/__cron/explorer/entry
@@ -1,6 +1,7 @@
#!/bin/sh
#
-# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
+# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc)
+# 2013 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@@ -18,22 +19,7 @@
# along with cdist. If not, see .
#
-name="$__object_id"
+name="$__object_name"
user="$(cat "$__object/parameter/user")"
-prefix="#cdist:__cron/$name"
-suffix="#/cdist:__cron/$name"
-
-crontab -u $user -l 2>/dev/null | awk -v prefix="$prefix" -v suffix="$suffix" '
-{
- if (index($0,prefix)) {
- triggered=1
- }
- if (triggered) {
- if (index($0,suffix)) {
- triggered=0
- }
- print
- }
-}
-'
+crontab -u $user -l 2>/dev/null | grep "# $name\$" || true
diff --git a/cdist/conf/type/__cron/gencode-remote b/cdist/conf/type/__cron/gencode-remote
index 37e0dc15..77a63b9b 100755
--- a/cdist/conf/type/__cron/gencode-remote
+++ b/cdist/conf/type/__cron/gencode-remote
@@ -1,6 +1,8 @@
#!/bin/sh
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
+# 2013 Nico Schottelius (nico-cdist at schottelius.org)
+# 2013 Thomas Oettli (otho at sfs.biz)
#
# This file is part of cdist.
#
@@ -18,40 +20,47 @@
# along with cdist. If not, see .
#
-os="$(cat "$__global/explorer/os")"
+name="$__object_name"
user="$(cat "$__object/parameter/user")"
-state_should="$(cat "$__object/parameter/state")"
-state_is=$(diff -q "$__object/parameter/entry" "$__object/explorer/entry" \
- && echo present \
- || echo absent
-)
+command="$(cat "$__object/parameter/command")"
-# FreeBSD mktemp doesn't allow execution without at least one param
-if [ "$os" = "freebsd" ]; then
- mktemp="mktemp -t tmp"
+if [ -f "$__object/parameter/raw" ]; then
+ raw="$(cat "$__object/parameter/raw")"
+ entry="$raw $command"
+elif [ -f "$__object/parameter/raw_command" ]; then
+ entry="$command"
else
- mktemp="mktemp"
+ minute="$(cat "$__object/parameter/minute" 2>/dev/null || echo "*")"
+ hour="$(cat "$__object/parameter/hour" 2>/dev/null || echo "*")"
+ day_of_month="$(cat "$__object/parameter/day_of_month" 2>/dev/null || echo "*")"
+ month="$(cat "$__object/parameter/month" 2>/dev/null || echo "*")"
+ day_of_week="$(cat "$__object/parameter/day_of_week" 2>/dev/null || echo "*")"
+ entry="$minute $hour $day_of_month $month $day_of_week $command"
fi
-if [ "$state_is" != "$state_should" ]; then
- case "$state_should" in
- present)
- cat << DONE
-tmp=\$($mktemp)
-crontab -u $user -l > \$tmp
-cat >> \$tmp << EOC
-$(cat "$__object/parameter/entry")
-EOC
-crontab -u $user \$tmp
-rm \$tmp
-DONE
- ;;
- absent)
- # defined in type manifest
- prefix="$(cat "$__object/parameter/prefix")"
- suffix="$(cat "$__object/parameter/suffix")"
- cat << DONE
-crontab -u $user -l | awk -v prefix="$prefix" -v suffix="$suffix" '
+entry="$entry # $name"
+mkdir "$__object/files"
+echo "$entry" > "$__object/files/entry"
+
+if diff -q "$__object/files/entry" "$__object/explorer/entry" >/dev/null; then
+ state_is=present
+else
+ state_is=absent
+fi
+
+state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")"
+
+[ "$state_is" = "$state_should" ] && exit 0
+
+# If anything is going to change, ensure the old entries are
+# not present anymore
+
+# These are the old markers
+prefix="#cdist:__cron/$__object_id"
+suffix="#/cdist:__cron/$__object_id"
+filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V"
+cat << DONE
+crontab -u $user -l 2>/dev/null | grep -v -E "$filter" | awk -v prefix="$prefix" -v suffix="$suffix" '
{
if (index(\$0,prefix)) {
triggered=1
@@ -66,6 +75,17 @@ crontab -u $user -l | awk -v prefix="$prefix" -v suffix="$suffix" '
}
' | crontab -u $user -
DONE
- ;;
- esac
-fi
+
+case "$state_should" in
+ present)
+ # if we insert new entry, filter also all entrys out with the same id
+ echo "("
+ echo "crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" | grep -v \"# $name\\$\" 2>/dev/null || true"
+ echo "echo '$entry'"
+ echo ") | crontab -u $user -"
+ ;;
+ absent)
+ echo "( crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" 2>/dev/null || true ) | \\"
+ echo "grep -v \"# $name\\$\" | crontab -u $user -"
+ ;;
+esac
diff --git a/cdist/conf/type/__cron/man.text b/cdist/conf/type/__cron/man.text
index 47f47456..f4e80a08 100644
--- a/cdist/conf/type/__cron/man.text
+++ b/cdist/conf/type/__cron/man.text
@@ -41,6 +41,10 @@ raw::
Can for example be used to specify cron EXTENSIONS like reboot, yearly etc.
See crontab(5) for the extensions if any that your cron implementation
implements.
+raw_command::
+ Take whatever the user has given in the commmand and ignore everything else.
+ If given, the command will be added to crontab.
+ Can for example be used to define variables like SHELL or MAILTO.
EXAMPLES
@@ -57,6 +61,10 @@ __cron some-id --user root --command "/path/to/script" \
# remove cronjob
__cron some-id --user root --command "/path/to/script" --state absent
+
+# define default shell
+__cron some-id --user root --raw_command --command "SHELL=/bin/bash" \
+ --state present
--------------------------------------------------------------------------------
@@ -68,5 +76,5 @@ SEE ALSO
COPYING
-------
-Copyright \(C) 2011 Steven Armstrong. Free use of this software is
+Copyright \(C) 2011-2013 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/__cron/manifest b/cdist/conf/type/__cron/manifest
old mode 100755
new mode 100644
index 7aca41ff..9992df25
--- a/cdist/conf/type/__cron/manifest
+++ b/cdist/conf/type/__cron/manifest
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
+# 2013 Thomas Oettli (otho at sfs.biz)
#
# This file is part of cdist.
#
@@ -18,28 +18,7 @@
# along with cdist. If not, see .
#
-name="$__object_id"
-user="$(cat "$__object/parameter/user")"
-command="$(cat "$__object/parameter/command")"
-
-# set defaults
-test -f "$__object/parameter/state" || echo "present" > "$__object/parameter/state"
-
-if [ -f "$__object/parameter/raw" ]; then
- raw="$(cat "$__object/parameter/raw")"
- entry="$raw $command"
-else
- minute="$(cat "$__object/parameter/minute" 2>/dev/null || echo "*")"
- hour="$(cat "$__object/parameter/hour" 2>/dev/null || echo "*")"
- day_of_month="$(cat "$__object/parameter/day_of_month" 2>/dev/null || echo "*")"
- month="$(cat "$__object/parameter/month" 2>/dev/null || echo "*")"
- day_of_week="$(cat "$__object/parameter/day_of_week" 2>/dev/null || echo "*")"
- entry="$minute $hour $day_of_month $month $day_of_week $command"
+if [ -f "$__object/parameter/raw" ] && [ -f "$__object/parameter/raw_command" ]; then
+ echo "ERROR: both raw and raw_command specified" >&2
+ exit 1
fi
-
-# NOTE: if changed, also change in explorers
-prefix="#cdist:__cron/$name"
-suffix="#/cdist:__cron/$name"
-echo "$prefix" | tee "$__object/parameter/prefix" > "$__object/parameter/entry"
-echo "$entry" >> "$__object/parameter/entry"
-echo "$suffix" | tee "$__object/parameter/suffix" >> "$__object/parameter/entry"
diff --git a/cdist/conf/type/__cron/parameter/boolean b/cdist/conf/type/__cron/parameter/boolean
new file mode 100644
index 00000000..54cfb0b3
--- /dev/null
+++ b/cdist/conf/type/__cron/parameter/boolean
@@ -0,0 +1 @@
+raw_command
diff --git a/cdist/conf/type/__debconf_set_selections/gencode-remote b/cdist/conf/type/__debconf_set_selections/gencode-remote
index 62be6a12..bb719c46 100755
--- a/cdist/conf/type/__debconf_set_selections/gencode-remote
+++ b/cdist/conf/type/__debconf_set_selections/gencode-remote
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# 2011 Nico Schottelius (nico-cdist at schottelius.org)
+# 2011-2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@@ -21,6 +21,12 @@
# Setup selections
#
+filename="$(cat "$__object/parameter/file")"
+
+if [ "$filename" = "-" ]; then
+ filename="$__object/stdin"
+fi
+
echo "debconf-set-selections << __file-eof"
-cat "$(cat "$__object/parameter/file")"
+cat "$filename"
echo "__file-eof"
diff --git a/cdist/conf/type/__debconf_set_selections/man.text b/cdist/conf/type/__debconf_set_selections/man.text
index b6b2ad18..e36ebaa3 100644
--- a/cdist/conf/type/__debconf_set_selections/man.text
+++ b/cdist/conf/type/__debconf_set_selections/man.text
@@ -17,7 +17,8 @@ to setup configuration parameters.
REQUIRED PARAMETERS
-------------------
file::
- If supplied, use the given filename as input for debconf-set-selections(1)
+ Use the given filename as input for debconf-set-selections(1)
+ If filename is "-", read from stdin.
EXAMPLES
@@ -29,15 +30,21 @@ __debconf_set_selections nslcd --file /path/to/file
# Setup configuration for nslcd from another type
__debconf_set_selections nslcd --file "$__type/files/preseed/nslcd"
+
+__debconf_set_selections nslcd --file - << eof
+gitolite gitolite/gituser string git
+eof
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
+- cdist-type__update_alternatives(7)
+- debconf-set-selections(1)
COPYING
-------
-Copyright \(C) 2011 Nico Schottelius. Free use of this software is
+Copyright \(C) 2011-2014 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/__directory/explorer/stat b/cdist/conf/type/__directory/explorer/stat
new file mode 100755
index 00000000..d8cdbb9e
--- /dev/null
+++ b/cdist/conf/type/__directory/explorer/stat
@@ -0,0 +1,43 @@
+#!/bin/sh
+#
+# 2013 Steven Armstrong (steven-cdist armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+destination="/$__object_id"
+
+# nothing to work with, nothing we could do
+[ -e "$destination" ] || exit 0
+
+os=$("$__explorer/os")
+case "$os" in
+ "freebsd")
+ # FIXME: should be something like this based on man page, but can not test
+ stat -f "type: %ST
+owner: %Du %Su
+group: %Dg %Sg
+mode: %Op %Sp
+" "$destination"
+ ;;
+ *)
+ stat --printf="type: %F
+owner: %u %U
+group: %g %G
+mode: %a %A
+" "$destination"
+ ;;
+esac
diff --git a/cdist/conf/type/__directory/explorer/type b/cdist/conf/type/__directory/explorer/type
new file mode 100755
index 00000000..e723047c
--- /dev/null
+++ b/cdist/conf/type/__directory/explorer/type
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# 2013 Steven Armstrong (steven-cdist armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+destination="/$__object_id"
+
+if [ ! -e "$destination" ]; then
+ echo none
+elif [ -h "$destination" ]; then
+ echo symlink
+elif [ -f "$destination" ]; then
+ echo file
+elif [ -d "$destination" ]; then
+ echo directory
+else
+ echo unknown
+fi
diff --git a/cdist/conf/type/__directory/gencode-remote b/cdist/conf/type/__directory/gencode-remote
index 21f4c5b6..aba618ac 100755
--- a/cdist/conf/type/__directory/gencode-remote
+++ b/cdist/conf/type/__directory/gencode-remote
@@ -1,6 +1,8 @@
#!/bin/sh
#
-# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
+# 2013 Steven Armstrong (steven-cdist armstrong.cc)
+# 2014 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
#
@@ -18,42 +20,97 @@
# 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"
+state_should="$(cat "$__object/parameter/state")"
+type="$(cat "$__object/explorer/type")"
+stat_file="$__object/explorer/stat"
+
+# variable to keep track if we have to set directory attributes
+set_attributes=
mkdiropt=""
[ -f "$__object/parameter/parents" ] && mkdiropt="-p"
+
recursive=""
-[ -f "$__object/parameter/recursive" ] && recursive="-R"
+if [ -f "$__object/parameter/recursive" ]; then
+ recursive="-R"
+ # need to allways set attributes when recursive is given
+ # as we don't want to check all subfolders/files
+ set_attributes=1
+fi
+
+get_current_value() {
+ if [ -s "$stat_file" ]; then
+ _name="$1"
+ _value="$2"
+ case "$_value" in
+ [0-9]*)
+ _index=2
+ ;;
+ *)
+ _index=3
+ ;;
+ esac
+ awk '/'"$_name"':/ { print $'$_index' }' "$stat_file"
+ unset _name _value _index
+ fi
+}
+
+set_group() {
+ echo chgrp $recursive \"$1\" \"$destination\"
+ echo chgrp $recursive $1 >> "$__messages_out"
+}
+
+set_owner() {
+ echo chown $recursive \"$1\" \"$destination\"
+ echo chown $recursive $1 >> "$__messages_out"
+}
+
+set_mode() {
+ echo chmod $recursive \"$1\" \"$destination\"
+ echo chmod $recursive $1 >> "$__messages_out"
+}
case "$state_should" in
- present)
- echo mkdir $mkdiropt \"$destination\"
+ present)
+ if [ "$type" != "directory" ]; then
+ set_attributes=1
+ if [ "$type" != "none" ]; then
+ # our destination is not a directory, remove whatever is there
+ # and then create our directory and set all attributes
+ echo rm -f "\"$destination\""
+ echo "remove non directory" >> "$__messages_out"
+ fi
+ echo "mkdir $mkdiropt \"$destination\""
+ echo "create" >> "$__messages_out"
+ fi
- # Mode settings
- if [ -f "$__object/parameter/mode" ]; then
- echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\"
- fi
+ # Note: Mode - needs to happen last as a chown/chgrp can alter mode by
+ # clearing S_ISUID and S_ISGID bits (see chown(2))
+ for attribute in group owner mode; do
+ if [ -f "$__object/parameter/$attribute" ]; then
+ value_should="$(cat "$__object/parameter/$attribute")"
+ value_is="$(get_current_value "$attribute" "$value_should")"
- # Group
- if [ -f "$__object/parameter/group" ]; then
- echo chgrp $recursive \"$(cat "$__object/parameter/group")\" \"$destination\"
- fi
+ # change 0xxx format to xxx format => same as stat returns
+ if [ "$attribute" = mode ]; then
+ value_should="$(echo $value_should | sed 's/^0\(...\)/\1/')"
+ fi
- # Owner
- if [ -f "$__object/parameter/owner" ]; then
- echo chown $recursive \"$(cat "$__object/parameter/owner")\" \"$destination\"
+ if [ "$set_attributes" = 1 ] || [ "$value_should" != "$value_is" ]; then
+ "set_$attribute" "$value_should"
+ fi
+ fi
+ done
+ ;;
+ absent)
+ if [ "$type" = "directory" ]; then
+ echo rm -rf \"$destination\"
+ echo remove >> "$__messages_out"
fi
- ;;
- absent)
- echo rm -rf \"$destination\"
- ;;
- *)
- echo "Unknown state: $state_should" >&2
- exit 1
- ;;
+ ;;
+ *)
+ echo "Unknown state: $state_should" >&2
+ exit 1
+ ;;
esac
diff --git a/cdist/conf/type/__directory/man.text b/cdist/conf/type/__directory/man.text
index 1f4def7d..a0bf8062 100644
--- a/cdist/conf/type/__directory/man.text
+++ b/cdist/conf/type/__directory/man.text
@@ -36,12 +36,31 @@ owner::
BOOLEAN PARAMETERS
------------------
parents::
- Whether to create parents as well (mkdir -p behaviour)
+ Whether to create parents as well (mkdir -p behaviour).
+ Warning: all intermediate directory permissions default
+ to whatever mkdir -p does.
+
+ Usually this means root:root, 0700.
recursive::
If supplied the chgrp and chown call will run recursively.
This does *not* influence the behaviour of chmod.
+MESSAGES
+--------
+chgrp ::
+ Changed group membership
+chown ::
+ Changed owner
+chmod ::
+ Changed mode
+create::
+ Empty directory was created
+remove::
+ Directory exists, but state is absent, directory will be removed by generated code.
+remove non directory::
+ Someting other than a directory with the same name exists and was removed prior to create.
+
EXAMPLES
--------
diff --git a/cdist/conf/type/__directory/parameter/default/state b/cdist/conf/type/__directory/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__directory/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__file/explorer/stat b/cdist/conf/type/__file/explorer/stat
new file mode 100755
index 00000000..298221b7
--- /dev/null
+++ b/cdist/conf/type/__file/explorer/stat
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# 2013 Steven Armstrong (steven-cdist armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+destination="/$__object_id"
+
+# nothing to work with, nothing we could do
+[ -e "$destination" ] || exit 0
+
+os=$("$__explorer/os")
+case "$os" in
+ "freebsd")
+ # FIXME: should be something like this based on man page, but can not test
+ stat -f "type: %ST
+owner: %Du %Su
+group: %Dg %Sg
+mode: %Op %Sp
+size: %Dz
+links: %Dl
+" "$destination"
+ ;;
+ *)
+ stat --printf="type: %F
+owner: %u %U
+group: %g %G
+mode: %a %A
+size: %s
+links: %h
+" "$destination"
+ ;;
+esac
diff --git a/cdist/conf/type/__file/explorer/type b/cdist/conf/type/__file/explorer/type
new file mode 100755
index 00000000..e723047c
--- /dev/null
+++ b/cdist/conf/type/__file/explorer/type
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# 2013 Steven Armstrong (steven-cdist armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+destination="/$__object_id"
+
+if [ ! -e "$destination" ]; then
+ echo none
+elif [ -h "$destination" ]; then
+ echo symlink
+elif [ -f "$destination" ]; then
+ echo file
+elif [ -d "$destination" ]; then
+ echo directory
+else
+ echo unknown
+fi
diff --git a/cdist/conf/type/__file/gencode-local b/cdist/conf/type/__file/gencode-local
index 087011c4..601705c8 100755
--- a/cdist/conf/type/__file/gencode-local
+++ b/cdist/conf/type/__file/gencode-local
@@ -1,6 +1,7 @@
#!/bin/sh
#
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2013 Steven Armstrong (steven-cdist armstrong.cc)
#
# This file is part of cdist.
#
@@ -17,34 +18,61 @@
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see .
#
-#
-# __file is a very basic type, which will probably be reused quite often
-#
destination="/$__object_id"
-state_should=present
-[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
-exists="$(cat "$__object/explorer/exists")"
+state_should="$(cat "$__object/parameter/state")"
+type="$(cat "$__object/explorer/type")"
-[ "$state_should" = "exists" -a "$exists" = "yes" ] && exit 0 # nothing to do
+[ "$state_should" = "exists" -a "$type" = "file" ] && exit 0 # nothing to do
+upload_file=
+create_file=
if [ "$state_should" = "present" -o "$state_should" = "exists" ]; then
- if [ -f "$__object/parameter/source" ]; then
+ if [ ! -f "$__object/parameter/source" ]; then
+ create_file=1
+ echo create >> "$__messages_out"
+ else
source="$(cat "$__object/parameter/source")"
if [ "$source" = "-" ]; then
source="$__object/stdin"
fi
-
- if [ -f "$source" ]; then
- local_cksum="$(cksum < "$source")"
- remote_cksum="$(cat "$__object/explorer/cksum")"
-
- if [ "$local_cksum" != "$remote_cksum" ]; then
- echo "$__remote_copy" "$source" "${__target_host}:${destination}"
- fi
- else
+ if [ ! -f "$source" ]; then
echo "Source \"$source\" does not exist." >&2
exit 1
+ else
+ if [ "$type" != "file" ]; then
+ # destination is not a regular file, upload source to replace it
+ upload_file=1
+ else
+ local_cksum="$(cksum < "$source")"
+ remote_cksum="$(cat "$__object/explorer/cksum")"
+ if [ "$local_cksum" != "$remote_cksum" ]; then
+ # destination is a regular file, but not the right one
+ upload_file=1
+ fi
+ fi
fi
fi
+ if [ "$create_file" -o "$upload_file" ]; then
+ # tell gencode-remote that we created or uploaded a file and that it must
+ # set all attributes no matter what the explorer retreived
+ mkdir "$__object/files"
+ touch "$__object/files/set-attributes"
+
+ # upload file to temp location
+ tempfile_template="${destination}.cdist.XXXXXXXXXX"
+ cat << DONE
+destination_upload="\$($__remote_exec $__target_host "mktemp $tempfile_template")"
+DONE
+ if [ "$upload_file" ]; then
+ echo upload >> "$__messages_out"
+ cat << DONE
+$__remote_copy $source ${__target_host}:\$destination_upload
+DONE
+ fi
+# move uploaded file into place
+cat << DONE
+$__remote_exec $__target_host "rm -rf \"$destination\"; mv \"\$destination_upload\" \"$destination\""
+DONE
+ fi
fi
diff --git a/cdist/conf/type/__file/gencode-remote b/cdist/conf/type/__file/gencode-remote
index 8b03e919..dcf3857b 100755
--- a/cdist/conf/type/__file/gencode-remote
+++ b/cdist/conf/type/__file/gencode-remote
@@ -1,6 +1,7 @@
#!/bin/sh
#
-# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
+# 2013 Steven Armstrong (steven-cdist armstrong.cc)
#
# This file is part of cdist.
#
@@ -17,52 +18,77 @@
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see .
#
-#
-# __file is a very basic type, which will probably be reused quite often
-#
destination="/$__object_id"
-state_should=present
-[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
-exists="$(cat "$__object/explorer/exists")"
+state_should="$(cat "$__object/parameter/state")"
+type="$(cat "$__object/explorer/type")"
+stat_file="$__object/explorer/stat"
+
+get_current_value() {
+ if [ -s "$stat_file" ]; then
+ _name="$1"
+ _value="$2"
+ case "$_value" in
+ [0-9]*)
+ _index=2
+ ;;
+ *)
+ _index=3
+ ;;
+ esac
+ awk '/'"$_name"':/ { print $'$_index' }' "$stat_file"
+ unset _name _value _index
+ fi
+}
+
+set_group() {
+ echo chgrp \"$1\" \"$destination\"
+ echo chgrp $1 >> "$__messages_out"
+}
+
+set_owner() {
+ echo chown \"$1\" \"$destination\"
+ echo chown $1 >> "$__messages_out"
+}
+
+set_mode() {
+ echo chmod \"$1\" \"$destination\"
+ echo chmod $1 >> "$__messages_out"
+}
+
+set_attributes=
case "$state_should" in
- present|exists)
- # No source? Create empty file
- if [ ! -f "$__object/parameter/source" ]; then
- if [ "$exists" = "no" ]; then
- echo touch \"$destination\"
- fi
- fi
+ present|exists)
+ # Note: Mode - needs to happen last as a chown/chgrp can alter mode by
+ # clearing S_ISUID and S_ISGID bits (see chown(2))
+ for attribute in group owner mode; do
+ if [ -f "$__object/parameter/$attribute" ]; then
+ value_should="$(cat "$__object/parameter/$attribute")"
- # Group
- if [ -f "$__object/parameter/group" ]; then
- echo chgrp \"$(cat "$__object/parameter/group")\" \"$destination\"
- fi
+ # change 0xxx format to xxx format => same as stat returns
+ if [ "$attribute" = mode ]; then
+ value_should="$(echo $value_should | sed 's/^0\(...\)/\1/')"
+ fi
+
+ value_is="$(get_current_value "$attribute" "$value_should")"
+ if [ -f "$__object/files/set-attributes" -o "$value_should" != "$value_is" ]; then
+ "set_$attribute" "$value_should"
+ fi
+ fi
+ done
- # Owner
- if [ -f "$__object/parameter/owner" ]; then
- echo chown \"$(cat "$__object/parameter/owner")\" \"$destination\"
- fi
+ ;;
- # Mode - needs to happen last as a chown/chgrp can alter mode by
- # clearing S_ISUID and S_ISGID bits (see chown(2))
- if [ -f "$__object/parameter/mode" ]; then
- echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\"
- fi
- ;;
-
- absent)
-
- if [ "$exists" = "yes" ]; then
- echo rm -f \"$destination\"
- fi
-
- ;;
-
- *)
- echo "Unknown state: $state_should" >&2
- exit 1
- ;;
+ absent)
+ if [ "$type" = "file" ]; then
+ echo rm -f \"$destination\"
+ echo remove >> "$__messages_out"
+ fi
+ ;;
+ *)
+ echo "Unknown state: $state_should" >&2
+ exit 1
+ ;;
esac
diff --git a/cdist/conf/type/__file/man.text b/cdist/conf/type/__file/man.text
index 1c61fd51..a582b27b 100644
--- a/cdist/conf/type/__file/man.text
+++ b/cdist/conf/type/__file/man.text
@@ -13,6 +13,15 @@ DESCRIPTION
This cdist type allows you to create files, remove files and set file
attributes on the target.
+If the file already exists on the target, then if it is a:
+- regular file, and state is:
+ present: replace it with the source file if they are not equal
+ exists: do nothing
+- symlink: replace it with the source file
+- directory: replace it with the source file
+
+In any case, make sure that the file attributes are as specified.
+
REQUIRED PARAMETERS
-------------------
@@ -41,6 +50,21 @@ source::
If not supplied, an empty file or directory will be created.
If source is '-' (dash), take what was written to stdin as the file content.
+MESSAGES
+--------
+chgrp ::
+ Changed group membership
+chown ::
+ Changed owner
+chmod ::
+ Changed mode
+create::
+ Empty file was created (no --source specified)
+remove::
+ File exists, but state is absent, file will be removed by generated code.
+upload::
+ File was uploaded
+
EXAMPLES
--------
@@ -81,5 +105,5 @@ SEE ALSO
COPYING
-------
-Copyright \(C) 2011-2012 Nico Schottelius. Free use of this software is
+Copyright \(C) 2011-2013 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/__file/parameter/default/state b/cdist/conf/type/__file/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__file/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__git/explorer/group b/cdist/conf/type/__git/explorer/group
new file mode 100644
index 00000000..1308c710
--- /dev/null
+++ b/cdist/conf/type/__git/explorer/group
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+destination="/$__object_id/.git"
+
+stat --print "%G" ${destination} 2>/dev/null || exit 0
diff --git a/cdist/conf/type/__git/explorer/owner b/cdist/conf/type/__git/explorer/owner
new file mode 100644
index 00000000..8c36b035
--- /dev/null
+++ b/cdist/conf/type/__git/explorer/owner
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+destination="/$__object_id/.git"
+
+stat --print "%U" ${destination} 2>/dev/null || exit 0
diff --git a/cdist/conf/type/__git/gencode-remote b/cdist/conf/type/__git/gencode-remote
index 0f665d59..c4fc1ef2 100644
--- a/cdist/conf/type/__git/gencode-remote
+++ b/cdist/conf/type/__git/gencode-remote
@@ -20,21 +20,39 @@
#
state_is="$(cat "$__object/explorer/state")"
-state_should=present
-[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
+owner_is="$(cat "$__object/explorer/owner")"
+group_is="$(cat "$__object/explorer/group")"
-branch=master
-[ -f "$__object/parameter/branch" ] && branch="$(cat "$__object/parameter/branch")"
+state_should="$(cat "$__object/parameter/state")"
+
+branch="$(cat "$__object/parameter/branch")"
source="$(cat "$__object/parameter/source")"
destination="/$__object_id"
-[ "$state_should" = "$state_is" ] && exit 0
+owner="$(cat "$__object/parameter/owner")"
+group="$(cat "$__object/parameter/group")"
+mode="$(cat "$__object/parameter/mode")"
+
+[ "$state_should" = "$state_is" -a \
+ "$owner" = "$owner_is" -a \
+ "$group" = "$group_is" -a \
+ -n "$mode" ] && exit 0
case $state_should in
present)
- echo git clone --quiet --branch "$branch" "$source" "$destination"
+
+ if [ "$state_should" != "$state_is" ]; then
+ echo git clone --quiet --branch "$branch" "$source" "$destination"
+ fi
+ if [ \( -n "$owner" -a "$owner_is" != "$owner" \) -o \
+ \( -n "$group" -a "$group_is" != "$group" \) ]; then
+ echo chown -R "${owner}:${group}" "$destination"
+ fi
+ if [ -n "$mode" ]; then
+ echo chmod -R "$mode" "$destination"
+ fi
;;
# Handled in manifest
absent)
diff --git a/cdist/conf/type/__git/man.text b/cdist/conf/type/__git/man.text
index 5597a52d..5f74108b 100644
--- a/cdist/conf/type/__git/man.text
+++ b/cdist/conf/type/__git/man.text
@@ -26,6 +26,16 @@ state::
branch::
Create this branch by checking out the remote branch of this name
+ Default branch is "master"
+
+group::
+ Group to chgrp to.
+
+mode::
+ Unix permissions, suitable for chmod.
+
+owner::
+ User to chown to.
EXAMPLES
diff --git a/cdist/conf/type/__git/manifest b/cdist/conf/type/__git/manifest
index e8c9b233..7f6fee84 100644
--- a/cdist/conf/type/__git/manifest
+++ b/cdist/conf/type/__git/manifest
@@ -23,17 +23,13 @@
__package git --state present
-state_should=present
-[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
-
-[ -f "$__object/parameter/owner" ] && dirparams="$dirparams --owner $(cat "$__object/parameter/owner")"
-[ -f "$__object/parameter/group" ] && dirparams="$dirparams --group $(cat "$__object/parameter/group")"
+state_should="$(cat "$__object/parameter/state")"
# Let __directory handle removal of git repos
case "$state_should" in
present)
- __directory "$__object_id" --state present $dirparams --recursive
+ :
;;
absent)
diff --git a/cdist/conf/type/__git/parameter/default/branch b/cdist/conf/type/__git/parameter/default/branch
new file mode 100644
index 00000000..1f7391f9
--- /dev/null
+++ b/cdist/conf/type/__git/parameter/default/branch
@@ -0,0 +1 @@
+master
diff --git a/cdist/conf/type/__git/parameter/default/group b/cdist/conf/type/__git/parameter/default/group
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/cdist/conf/type/__git/parameter/default/group
@@ -0,0 +1 @@
+
diff --git a/cdist/conf/type/__git/parameter/default/mode b/cdist/conf/type/__git/parameter/default/mode
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/cdist/conf/type/__git/parameter/default/mode
@@ -0,0 +1 @@
+
diff --git a/cdist/conf/type/__git/parameter/default/owner b/cdist/conf/type/__git/parameter/default/owner
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/cdist/conf/type/__git/parameter/default/owner
@@ -0,0 +1 @@
+
diff --git a/cdist/conf/type/__git/parameter/default/state b/cdist/conf/type/__git/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__git/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__git/parameter/optional b/cdist/conf/type/__git/parameter/optional
index d9684aaa..3c409162 100644
--- a/cdist/conf/type/__git/parameter/optional
+++ b/cdist/conf/type/__git/parameter/optional
@@ -2,3 +2,4 @@ state
branch
group
owner
+mode
diff --git a/cdist/conf/type/__group/gencode-remote b/cdist/conf/type/__group/gencode-remote
index bb6797c2..1cffa8d4 100755
--- a/cdist/conf/type/__group/gencode-remote
+++ b/cdist/conf/type/__group/gencode-remote
@@ -58,10 +58,12 @@ if grep -q "^${name}:" "$__object/explorer/group"; then
if [ "$new_value" != "$current_value" ]; then
set -- "$@" "$proparg" \"$new_value\"
+ echo change $property $new_value $current_value >> "$__messages_out"
fi
done
if [ $# -gt 0 ]; then
+ echo mod >> "$__messages_out"
case $os in
freebsd)
echo pw group mod "$@" "$name"
@@ -72,6 +74,7 @@ if grep -q "^${name}:" "$__object/explorer/group"; then
esac
fi
else
+ echo add >> "$__messages_out"
for property in $(ls .); do
new_value="$(cat "$property")"
if [ "$os" = "freebsd" ]; then
@@ -95,6 +98,7 @@ else
fi
set -- "$@" "$proparg" \"$new_value\"
+ echo set $property $new_value >> "$__messages_out"
done
case $os in
diff --git a/cdist/conf/type/__group/man.text b/cdist/conf/type/__group/man.text
index c57ae337..def0232f 100644
--- a/cdist/conf/type/__group/man.text
+++ b/cdist/conf/type/__group/man.text
@@ -26,6 +26,18 @@ password::
see above
+MESSAGES
+--------
+mod::
+ group is modified
+add::
+ New group added
+change ::
+ Changed group property from current_value to new_value
+set ::
+ set property to new value, property was not set bevore
+
+
EXAMPLES
--------
diff --git a/cdist/conf/type/__hostname/explorer/has_hostnamectl b/cdist/conf/type/__hostname/explorer/has_hostnamectl
new file mode 100755
index 00000000..9040023d
--- /dev/null
+++ b/cdist/conf/type/__hostname/explorer/has_hostnamectl
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# 2014 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 system has hostnamectl
+#
+
+command -v hostnamectl || true
diff --git a/cdist/conf/type/__file/explorer/exists b/cdist/conf/type/__hostname/explorer/hostname_file
similarity index 78%
rename from cdist/conf/type/__file/explorer/exists
rename to cdist/conf/type/__hostname/explorer/hostname_file
index c319cb5d..ed28c8a8 100755
--- a/cdist/conf/type/__file/explorer/exists
+++ b/cdist/conf/type/__hostname/explorer/hostname_file
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@@ -18,13 +18,9 @@
# along with cdist. If not, see .
#
#
-# Check whether file exists or not
+# Retrieve the contents of /etc/hostname
#
-destination="/$__object_id"
-
-if [ -e "$destination" ]; then
- echo yes
-else
- echo no
+if [ -f /etc/hostname ]; then
+ cat /etc/hostname
fi
diff --git a/cdist/conf/type/__hostname/gencode-remote b/cdist/conf/type/__hostname/gencode-remote
new file mode 100755
index 00000000..3d208cbe
--- /dev/null
+++ b/cdist/conf/type/__hostname/gencode-remote
@@ -0,0 +1,50 @@
+#!/bin/sh
+#
+# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
+# 2014 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 .
+#
+
+if [ -f "$__object/parameter/name" ]; then
+ name_should="$(cat "$__object/parameter/name")"
+else
+ name_should="$(echo "${__target_host%%.*}")"
+fi
+
+os=$(cat "$__global/explorer/os")
+name_running=$(cat "$__global/explorer/hostname")
+name_config=$(cat "$__object/explorer/hostname_file")
+has_hostnamectl=$(cat "$__object/explorer/has_hostnamectl")
+
+################################################################################
+# If everything is ok -> exit
+#
+if [ "$name_config" = "$name_should" -a "$name_running" = "$name_should" ]; then
+ exit 0
+fi
+
+################################################################################
+# Setup hostname
+#
+echo changed >> "$__messages_out"
+
+if [ "$has_hostnamectl" ]; then
+ echo "hostnamectl set-hostname '$name_should'"
+else
+ echo "hostname '$name_should'"
+ echo "printf '%s\n' '$name_should' > /etc/hostname"
+fi
diff --git a/cdist/conf/type/__hostname/man.text b/cdist/conf/type/__hostname/man.text
new file mode 100644
index 00000000..ac44d426
--- /dev/null
+++ b/cdist/conf/type/__hostname/man.text
@@ -0,0 +1,52 @@
+cdist-type__hostname(7)
+=======================
+Steven Armstrong
+
+
+NAME
+----
+cdist-type__hostname - set the hostname
+
+
+DESCRIPTION
+-----------
+Set's the hostname on various operating systems.
+
+
+REQUIRED PARAMETERS
+-------------------
+None.
+
+OPTIONAL PARAMETERS
+-------------------
+name::
+ The hostname to set. Defaults to the first segment of __target_host
+ (${__target_host%%.*})
+
+
+MESSAGES
+--------
+changed::
+ Changed the hostname
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+# take hostname from __target_host
+__hostname
+
+# set hostname explicitly
+__hostname --name some-static-hostname
+--------------------------------------------------------------------------------
+
+
+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/__hostname/manifest b/cdist/conf/type/__hostname/manifest
new file mode 100755
index 00000000..0544a6f9
--- /dev/null
+++ b/cdist/conf/type/__hostname/manifest
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
+# 2014 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 .
+#
+
+os=$(cat "$__global/explorer/os")
+
+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
+ archlinux|debian|ubuntu)
+ # handled in gencode-remote
+ :
+ ;;
+ *)
+ not_supported
+ ;;
+esac
diff --git a/cdist/conf/type/__hostname/parameter/optional b/cdist/conf/type/__hostname/parameter/optional
new file mode 100644
index 00000000..f121bdbf
--- /dev/null
+++ b/cdist/conf/type/__hostname/parameter/optional
@@ -0,0 +1 @@
+name
diff --git a/cdist/test/autorequire/fixtures/conf/explorer/.keep b/cdist/conf/type/__hostname/singleton
similarity index 100%
rename from cdist/test/autorequire/fixtures/conf/explorer/.keep
rename to cdist/conf/type/__hostname/singleton
diff --git a/cdist/conf/type/__iptables_apply/files/init-script b/cdist/conf/type/__iptables_apply/files/init-script
new file mode 100644
index 00000000..2dc952e9
--- /dev/null
+++ b/cdist/conf/type/__iptables_apply/files/init-script
@@ -0,0 +1,48 @@
+#!/bin/sh
+# Nico Schottelius
+# Zürisee, Mon Sep 2 18:38:27 CEST 2013
+#
+### BEGIN INIT INFO
+# Provides: iptables
+# Required-Start: $local_fs $remote_fs
+# Required-Stop: $local_fs $remote_fs
+# X-Start-Before: fail2ban
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Applies iptables ruleset
+# Description: Applies all rules found in /etc/iptables.d
+# and saves/restores previous status
+### END INIT INFO
+
+
+basedir=/etc/iptables.d
+status="${basedir}/.pre-start"
+
+case $1 in
+ start)
+ # Save status
+ iptables-save > "$status"
+
+ # Apply our ruleset
+ cd "$basedir"
+ count="$(ls -1 | wc -l)"
+
+ # Only do something if there are rules
+ if [ "$count" -ge 1 ]; then
+ for rule in *; do
+ echo "Applying iptables rule $rule ..."
+ iptables $(cat "$rule")
+ done
+ fi
+ ;;
+
+ stop)
+ # Restore from status before, if there is something to restore
+ if [ -f "$status" ]; then
+ iptables-restore < "$status"
+ fi
+ ;;
+ restart)
+ "$0" stop && "$0" start
+ ;;
+esac
diff --git a/cdist/conf/type/__iptables_apply/gencode-remote b/cdist/conf/type/__iptables_apply/gencode-remote
new file mode 100644
index 00000000..9cdf28cf
--- /dev/null
+++ b/cdist/conf/type/__iptables_apply/gencode-remote
@@ -0,0 +1,3 @@
+if grep -q "^__file/etc/iptables.d/" "$__messages_in"; then
+ echo /etc/init.d/iptables restart
+fi
diff --git a/cdist/conf/type/__iptables_apply/man.text b/cdist/conf/type/__iptables_apply/man.text
new file mode 100644
index 00000000..87f4b4ee
--- /dev/null
+++ b/cdist/conf/type/__iptables_apply/man.text
@@ -0,0 +1,42 @@
+cdist-type__iptables_apply(7)
+=============================
+Nico Schottelius
+
+
+NAME
+----
+cdist-type__iptables_apply - Apply the rules
+
+
+DESCRIPTION
+-----------
+This cdist type deploys an init script that triggers
+the configured rules and also re-applies them on
+configuration.
+
+
+REQUIRED PARAMETERS
+-------------------
+None
+
+OPTIONAL PARAMETERS
+-------------------
+None
+
+EXAMPLES
+--------
+
+None (__iptables_apply is used by __iptables_rule)
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+- cdist-type__iptables_rule(7)
+- iptables(8)
+
+
+COPYING
+-------
+Copyright \(C) 2013 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/__iptables_apply/manifest b/cdist/conf/type/__iptables_apply/manifest
new file mode 100644
index 00000000..a22901ba
--- /dev/null
+++ b/cdist/conf/type/__iptables_apply/manifest
@@ -0,0 +1,26 @@
+#
+# 2013 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 /etc/init.d/iptables \
+ --source "$__type/files/init-script" \
+ --state present \
+ --mode 0755
+
+require="__file/etc/init.d/iptables" __start_on_boot iptables
diff --git a/cdist/test/autorequire/fixtures/conf/type/__addifnosuchline/.keep b/cdist/conf/type/__iptables_apply/singleton
similarity index 100%
rename from cdist/test/autorequire/fixtures/conf/type/__addifnosuchline/.keep
rename to cdist/conf/type/__iptables_apply/singleton
diff --git a/cdist/conf/type/__iptables_rule/man.text b/cdist/conf/type/__iptables_rule/man.text
new file mode 100644
index 00000000..eb230093
--- /dev/null
+++ b/cdist/conf/type/__iptables_rule/man.text
@@ -0,0 +1,64 @@
+cdist-type__iptables_rule(7)
+============================
+Nico Schottelius
+
+
+NAME
+----
+cdist-type__iptables_rule - Deploy iptable rulesets
+
+
+DESCRIPTION
+-----------
+This cdist type allows you to manage iptable rules
+in a distribution independent manner.
+
+
+REQUIRED PARAMETERS
+-------------------
+rule::
+ The rule to apply. Essentially an iptables command
+ line without iptables in front of it.
+
+
+OPTIONAL PARAMETERS
+-------------------
+state::
+ 'present' or 'absent', defaults to 'present'
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+# Deploy some policies
+__iptables_rule policy-in --rule "-P INPUT DROP"
+__iptables_rule policy-out --rule "-P OUTPUT ACCEPT"
+__iptables_rule policy-fwd --rule "-P FORWARD DROP"
+
+# The usual established rule
+__iptables_rule established --rule "-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT"
+
+# Some service rules
+__iptables_rule http --rule "-A INPUT -p tcp --dport 80 -j ACCEPT"
+__iptables_rule ssh --rule "-A INPUT -p tcp --dport 80 -j ACCEPT"
+__iptables_rule https --rule "-A INPUT -p tcp --dport 443 -j ACCEPT"
+
+# Ensure some rules are not present anymore
+__iptables_rule munin --rule "-A INPUT -p tcp --dport 4949 -j ACCEPT" \
+ --state absent
+
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+- cdist-type__iptables_apply(7)
+- iptables(8)
+
+
+COPYING
+-------
+Copyright \(C) 2013 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/__iptables_rule/manifest b/cdist/conf/type/__iptables_rule/manifest
new file mode 100644
index 00000000..f02ab18b
--- /dev/null
+++ b/cdist/conf/type/__iptables_rule/manifest
@@ -0,0 +1,41 @@
+#
+# 2013 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 .
+#
+#
+
+base_dir=/etc/iptables.d
+
+name="$__object_id"
+state="$(cat "$__object/parameter/state")"
+
+################################################################################
+# Basic setup
+#
+
+__directory "$base_dir" --state present
+
+# Have apply do the real job
+require="$__object_name" __iptables_apply
+
+################################################################################
+# The rule
+#
+
+require="__directory/$base_dir" __file "$base_dir/${name}" \
+ --source "$__object/parameter/rule" \
+ --state "$state"
diff --git a/cdist/conf/type/__iptables_rule/parameter/default/state b/cdist/conf/type/__iptables_rule/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__iptables_rule/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__jail/parameter/required b/cdist/conf/type/__iptables_rule/parameter/optional
similarity index 100%
rename from cdist/conf/type/__jail/parameter/required
rename to cdist/conf/type/__iptables_rule/parameter/optional
diff --git a/cdist/conf/type/__iptables_rule/parameter/required b/cdist/conf/type/__iptables_rule/parameter/required
new file mode 100644
index 00000000..2b254dff
--- /dev/null
+++ b/cdist/conf/type/__iptables_rule/parameter/required
@@ -0,0 +1 @@
+rule
diff --git a/cdist/conf/type/__jail/gencode-local b/cdist/conf/type/__jail/gencode-local
index 075a6ef1..08c7b7bf 100755
--- a/cdist/conf/type/__jail/gencode-local
+++ b/cdist/conf/type/__jail/gencode-local
@@ -22,17 +22,9 @@
# virtual machines.
#
-if [ -f "$__object/parameter/jaildir" ]; then
- jaildir="$(cat "$__object/parameter/name")"
-else
- jaildir="/usr/jail"
-fi
+jaildir="$(cat "$__object/parameter/jaildir")"
-if [ -f "$__object/parameter/jailbase" ]; then
- jailbase="$(cat "$__object/parameter/jailbase")"
-else
- jailbase=""
-fi
+jailbase="$(cat "$__object/parameter/jailbase")"
state="$(cat "$__object/parameter/state")"
diff --git a/cdist/conf/type/__jail/gencode-remote b/cdist/conf/type/__jail/gencode-remote
index 7491754c..141c8150 100755
--- a/cdist/conf/type/__jail/gencode-remote
+++ b/cdist/conf/type/__jail/gencode-remote
@@ -66,11 +66,7 @@ else
devfsenable="true"
fi
-if [ -f "$__object/parameter/devfs-ruleset" ]; then
- devfsruleset="$(cat "$__object/parameter/devfs-ruleset")"
-else
- devfsruleset="jailrules"
-fi
+devfsruleset="$(cat "$__object/parameter/devfs-ruleset")"
# devfs_ruleset being defined without devfs_enable being true
# is pointless. Treat this as an error.
@@ -84,15 +80,26 @@ if [ -f "$__object/parameter/onboot" ]; then
onboot="true"
fi
-if [ -f "$__object/parameter/jaildir" ]; then
- jaildir="$(cat "$__object/parameter/name")"
-else
- jaildir="/usr/jail"
-fi
+jaildir="$(cat "$__object/parameter/jaildir")"
present="$(cat "$__object/explorer/present")"
status="$(cat "$__object/explorer/status")"
+# Handle ip="iface|addr, iface|addr" format
+if [ $(expr "${ip}" : ".*|.*") -gt "0" ]; then
+ # If we have multiple IPs defined, $interface doesn't make sense because ip="iface|addr, iface|addr" implies it
+ interface=""
+ SAVE_IFS="$IFS"
+ IFS=", "
+ for cur_ip in ${ip}; do
+ # Just get the last IP address for SSH to listen on
+ mgmt_ip=$(echo "${ip}" | sed -E -e 's/^.*\|(.*)\/[0-9]+$/\1/')
+ done
+ IFS="$SAVE_IFS"
+else
+ mgmt_ip=$(echo "${ip}" | cut '-d ' -f1)
+fi
+
stopJail() {
# Check $status before issuing command
if [ "$status" = "STARTED" ]; then
@@ -160,10 +167,10 @@ EOF
createJail() {
# Create the jail directory
cat <>/etc/rc.conf <>"${jaildir}/rw/${name}/etc/rc.conf"
EOF
# Configure SSHd's listening address
cat < \"$file.cdist-tmp\""
- echo "mv \"$file.cdist-tmp\" \"$file\""
+ cat << DONE
+tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX)
+# preserve ownership and permissions by copying existing file over tmpfile
+cp -p "$file" "\$tmpfile"
+sed '/^$key\($delimiter\+\)/d' "$file" > "\$tmpfile"
+mv -f "\$tmpfile" "$file"
+DONE
;;
present)
case "$state_is" in
absent)
# add new key and value
- echo "echo \"${key}${delimiter}${value}\" >> \"$file\""
+ printf 'echo "%s%s%s" >> "%s"' "$key" "$delimiter" "$value_escaped" "$file"
;;
wrongvalue)
# change exisiting value
- echo "sed \"s|^$key\($delimiter\+\).*|$key\1$value|\" \"$file\" > \"$file.cdist-tmp\""
- echo "mv \"$file.cdist-tmp\" \"$file\""
+ cat << DONE
+tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX)
+# preserve ownership and permissions by copying existing file over tmpfile
+cp -p "$file" "\$tmpfile"
+sed "s|^$key\($delimiter\+\).*|$key\\1$value_escaped|" "$file" > "\$tmpfile"
+mv -f "\$tmpfile" "$file"
+DONE
;;
*)
echo "Unknown explorer state: $state_is" >&2
@@ -57,4 +67,4 @@ case "$state_should" in
*)
echo "Unknown state: $state_should" >&2
exit 1
-esac
+esac
diff --git a/cdist/conf/type/__key_value/manifest b/cdist/conf/type/__key_value/manifest
index 8ed9cc9c..56f4c874 100755
--- a/cdist/conf/type/__key_value/manifest
+++ b/cdist/conf/type/__key_value/manifest
@@ -19,8 +19,7 @@
# along with cdist. If not, see .
#
-state_should=present
-[ -f "$__object/parameter/state" ] && state_should="$(cat "$__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
diff --git a/cdist/conf/type/__key_value/parameter/default/state b/cdist/conf/type/__key_value/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__key_value/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__line/explorer/state b/cdist/conf/type/__line/explorer/state
index d240bf4d..d04d5d09 100755
--- a/cdist/conf/type/__line/explorer/state
+++ b/cdist/conf/type/__line/explorer/state
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# 2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2012-2013 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@@ -24,16 +24,18 @@ file="/$__object_id"
if [ -f "$__object/parameter/regex" ]; then
regex=$(cat "$__object/parameter/regex")
+ greparg=""
else
if [ ! -f "$__object/parameter/line" ]; then
echo "Parameter line and regex missing - cannot explore" >&2
exit 1
fi
- regex="^$(cat "$__object/parameter/line")\$"
+ regex="$(cat "$__object/parameter/line")"
+ greparg="-F -x"
fi
# Allow missing file - thus 2>/dev/null
-if grep -q "$regex" "$file" 2>/dev/null; then
+if grep -q $greparg "$regex" "$file" 2>/dev/null; then
echo present
else
echo absent
diff --git a/cdist/conf/type/__line/gencode-remote b/cdist/conf/type/__line/gencode-remote
index 8ac273e2..1fadf454 100755
--- a/cdist/conf/type/__line/gencode-remote
+++ b/cdist/conf/type/__line/gencode-remote
@@ -38,7 +38,27 @@ case "$state_should" in
exit 1
fi
- echo "echo \"$line\" >> $file"
+ #echo "echo \"$line\" >> $file"
+ #line_sanitised=$(cat "$__object/parameter/line" | sed 's/"/\"/g')
+ # Idea: replace ' in the string:
+ # '"'"'
+ # |------> ': end the string
+ # |-|---> "'": create ' in the output string
+ # |--> ': continue the string
+ #
+ # Replace all \ so \t and other combinations are not interpreted
+ #
+
+
+ # line_sanitised=$(cat "$__object/parameter/line" | sed -e "s/'/'\"'\"'/g" -e 's/\\/\\\\/g')
+ # The one above does not work:
+ # --line "PS1='[\t] \[\033[1m\]\h\[\033[0m\]:\w\\$ '"
+ # becomes
+ # PS1='[\\t] \\[\\033[1m\\]\\h\\[\\033[0m\\]:\\w\\$ '
+
+ # Only replace ' with '"'"' and keep \ as they are
+ line_sanitised=$(cat "$__object/parameter/line" | sed -e "s/'/'\"'\"'/g")
+ printf '%s' "printf '%s\n' '$line_sanitised' >> $file"
;;
absent)
@@ -47,13 +67,16 @@ case "$state_should" in
exit 1
fi
- [ "$line" ] && regex="^$line\$"
+ greparg=""
+ if [ "$line" ]; then
+ regex="$line"
+ greparg="-F -x"
+ fi
cat << eof
tmp=\$(mktemp)
-sed '/$regex/d' "$file" > \$tmp && cat "\$tmp" > "$file" && rm -f "\$tmp"
+grep -v $greparg '$regex' '$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
diff --git a/cdist/conf/type/__line/man.text b/cdist/conf/type/__line/man.text
index e1a5941c..f39ee929 100644
--- a/cdist/conf/type/__line/man.text
+++ b/cdist/conf/type/__line/man.text
@@ -32,11 +32,11 @@ regex::
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).
+ regular expression are absent.
- If the regular expression contains / (slashes), they need
- to be escaped with \ (backslash): / becomes \/.
+ The regular expression is interpreted by grep.
+
+ Must not be combined with line, if state is absent.
file::
If supplied, use this as the destination file.
@@ -64,9 +64,10 @@ __line legacy_timezone --file /etc/rc.conf --regex 'TIMEZONE=.*' --state absent
SEE ALSO
--------
- cdist-type(7)
+- grep(1)
COPYING
-------
-Copyright \(C) 2012 Nico Schottelius. Free use of this software is
+Copyright \(C) 2012-2013 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/__link/explorer/type b/cdist/conf/type/__link/explorer/type
new file mode 100755
index 00000000..579fd081
--- /dev/null
+++ b/cdist/conf/type/__link/explorer/type
@@ -0,0 +1,46 @@
+#!/bin/sh
+#
+# 2013 Steven Armstrong (steven-cdist 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 .
+#
+#
+# Mostly a wrapper for ln
+#
+
+destination="/$__object_id"
+
+if [ ! -e "$destination" ]; then
+ echo none
+elif [ -h "$destination" ]; then
+ echo symlink
+elif [ -f "$destination" ]; then
+ type="$(cat "$__object/parameter/type")"
+ case "$type" in
+ hard)
+ link_count=$(ls -l "$destination" | awk '{ print $2 }')
+ if [ $link_count -gt 1 ]; then
+ echo hardlink
+ exit 0
+ fi
+ ;;
+ esac
+ echo file
+elif [ -d "$destination" ]; then
+ echo directory
+else
+ echo unknown
+fi
diff --git a/cdist/conf/type/__link/gencode-remote b/cdist/conf/type/__link/gencode-remote
index 2975ef69..cbdfd30f 100755
--- a/cdist/conf/type/__link/gencode-remote
+++ b/cdist/conf/type/__link/gencode-remote
@@ -1,6 +1,7 @@
#!/bin/sh
#
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2013 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
@@ -40,17 +41,30 @@ case "$type" in
esac
state_is="$(cat "$__object/explorer/state")"
-state_should=present
-[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
+state_should="$(cat "$__object/parameter/state")"
[ "$state_should" = "$state_is" ] && exit 0
+file_type="$(cat "$__object/explorer/type")"
case "$state_should" in
present)
- echo ln ${lnopt} -f \"$source\" \"$destination\"
+ if [ "$file_type" = "directory" ]; then
+ # our destination is currently a directory, delete it
+ cat << DONE
+rm -rf "$destination"
+DONE
+ fi
+
+ # create our link
+ cat << DONE
+ln ${lnopt} -f "$source" "$destination"
+DONE
;;
absent)
- echo rm -f \"$destination\"
+ # only delete if it is a sym/hard link
+ if [ "$file_type" = "symlink" -o "$file_type" = "hardlink" ]; then
+ echo rm -f \"$destination\"
+ fi
;;
*)
echo "Unknown state: $state_should" >&2
diff --git a/cdist/conf/type/__link/parameter/default/state b/cdist/conf/type/__link/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__link/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__locale/files/locale.gen b/cdist/conf/type/__locale/files/locale.gen
new file mode 100644
index 00000000..cf8e8651
--- /dev/null
+++ b/cdist/conf/type/__locale/files/locale.gen
@@ -0,0 +1,3 @@
+de_CH.UTF-8 UTF-8
+de_DE.UTF-8 UTF-8
+en_US.UTF-8 UTF-8
diff --git a/cdist/conf/type/__locale/gencode-remote b/cdist/conf/type/__locale/gencode-remote
new file mode 100644
index 00000000..538ce2cd
--- /dev/null
+++ b/cdist/conf/type/__locale/gencode-remote
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+# 2013 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 .
+#
+#
+# Let localedef do the magic
+#
+
+locale="$__object_id"
+
+# Hardcoded, create a pull request with
+# branching on $os in case it is at another location
+alias=/usr/share/locale/locale.alias
+
+input=$(echo "$locale" | cut -d . -f 1)
+charmap=$(echo "$locale" | cut -d . -f 2)
+
+# Adding locale? The name is de_CH.UTF-8
+# Removing locale? The name is de_CH.utf8.
+# W-T-F!
+locale_remove=$(echo "$locale" | sed 's/UTF-8/utf8/')
+
+state=$(cat "$__object/parameter/state")
+
+case "$state" in
+ present)
+ echo localedef -A "$alias" -f "$charmap" -i "$input" "$locale"
+ ;;
+ absent)
+ echo localedef --delete-from-archive "$locale_remove"
+ ;;
+ *)
+ echo "Unsupported state: $state" >&2
+ exit 1
+ ;;
+esac
diff --git a/cdist/conf/type/__locale/man.text b/cdist/conf/type/__locale/man.text
new file mode 100644
index 00000000..5ccd3eab
--- /dev/null
+++ b/cdist/conf/type/__locale/man.text
@@ -0,0 +1,47 @@
+cdist-type__locale(7)
+=====================
+Nico Schottelius
+
+
+NAME
+----
+cdist-type__locale - Configure locales
+
+
+DESCRIPTION
+-----------
+This cdist type allows you to setup locales.
+
+
+OPTIONAL PARAMETERS
+-------------------
+state::
+ 'present' or 'absent', defaults to present
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+# Add locale de_CH.UTF-8
+__locale de_CH.UTF-8
+
+# Same as above, but more explicit
+__locale de_CH.UTF-8 --state present
+
+# Remove colourful British English
+__locale en_GB.UTF-8 --state absent
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- locale(1)
+- localedef(1)
+- cdist-type(7)
+
+
+COPYING
+-------
+Copyright \(C) 2013-2014 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/__locale/manifest b/cdist/conf/type/__locale/manifest
new file mode 100644
index 00000000..f3d75d59
--- /dev/null
+++ b/cdist/conf/type/__locale/manifest
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# 2013-2014 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 .
+#
+#
+# Install required packages
+#
+
+os=$(cat "$__global/explorer/os")
+
+
+case "$os" in
+ debian)
+ # Debian needs a seperate package
+ __package locales --state present
+ ;;
+ *)
+ echo "Sorry, do not know how to handle os: $os" >&2
+ echo "Please edit the type ${__type##*/} to fix this." >&2
+ exit 1
+ ;;
+esac
diff --git a/cdist/conf/type/__locale/parameter/default/state b/cdist/conf/type/__locale/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__locale/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__pf_ruleset/parameter/required b/cdist/conf/type/__locale/parameter/optional
similarity index 100%
rename from cdist/conf/type/__pf_ruleset/parameter/required
rename to cdist/conf/type/__locale/parameter/optional
diff --git a/cdist/conf/type/__motd/gencode-remote b/cdist/conf/type/__motd/gencode-remote
new file mode 100755
index 00000000..2aa84902
--- /dev/null
+++ b/cdist/conf/type/__motd/gencode-remote
@@ -0,0 +1,33 @@
+# 2013 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 .
+#
+#
+
+os=$(cat "$__global/explorer/os")
+
+case "$os" in
+ debian|ubuntu)
+
+ # Debian and Ubuntu need to be updated,
+ # as seen in /etc/init.d/bootlogs
+ echo "uname -snrvm > /var/run/motd"
+ echo "cat /etc/motd.tail >> /var/run/motd"
+ ;;
+ *)
+ exit 0
+ ;;
+esac
diff --git a/cdist/conf/type/__directory/explorer/state b/cdist/conf/type/__mount/explorer/mounted
similarity index 78%
rename from cdist/conf/type/__directory/explorer/state
rename to cdist/conf/type/__mount/explorer/mounted
index 9bdd9024..81f8e454 100755
--- a/cdist/conf/type/__directory/explorer/state
+++ b/cdist/conf/type/__mount/explorer/mounted
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# 2011 Nico Schottelius (nico-cdist at schottelius.org)
+# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
@@ -17,14 +17,11 @@
# 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"
+path="$(cat "$__object/parameter/path" 2>/dev/null || echo "/$__object_id")"
-if [ -e "$destination" ]; then
- echo present
+if mountpoint -q "$path"; then
+ echo yes
else
- echo absent
+ echo no
fi
diff --git a/cdist/conf/type/__mount/gencode-remote b/cdist/conf/type/__mount/gencode-remote
new file mode 100755
index 00000000..2626f3de
--- /dev/null
+++ b/cdist/conf/type/__mount/gencode-remote
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+# 2014 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 .
+#
+
+path="$(cat "$__object/parameter/path" 2>/dev/null || echo "/$__object_id")"
+state_should="$(cat "$__object/parameter/state")"
+state_is="$(grep -q -x yes "$__object/explorer/mounted" && echo present || echo absent)"
+
+if [ "$state_should" = "$state_is" ]; then
+ # nothing to do
+ exit 0
+fi
+
+case "$state_should" in
+ present)
+ if [ -f "$__object/parameter/nofstab" ]; then
+ # mount manually
+ printf 'mount'
+ if [ -f "$__object/parameter/type" ]; then
+ printf ' -t %s' "$(cat "$__object/parameter/type")"
+ fi
+ if [ -f "$__object/parameter/options" ]; then
+ printf ' -o %s' "$(cat "$__object/parameter/options")"
+ fi
+ printf ' %s' "$(cat "$__object/parameter/device")"
+ printf " %s\n" "$path"
+ else
+ # mount using existing fstab entry
+ printf 'mount "%s"\n' "$path"
+ fi
+ ;;
+ absent)
+ printf 'umount "%s"\n' "$path"
+ ;;
+esac
diff --git a/cdist/conf/type/__mount/man.text b/cdist/conf/type/__mount/man.text
new file mode 100644
index 00000000..7299bdf3
--- /dev/null
+++ b/cdist/conf/type/__mount/man.text
@@ -0,0 +1,84 @@
+cdist-type__mount(7)
+====================
+Steven Armstrong
+
+
+NAME
+----
+cdist-type__mount - manage filesystem mounts
+
+
+DESCRIPTION
+-----------
+Manage filesystem mounts either via /etc/fstab or manually.
+
+
+REQUIRED PARAMETERS
+-------------------
+None.
+
+
+OPTIONAL PARAMETERS
+-------------------
+device::
+ device to mount at path, defaults to 'none'. see mount(8)
+
+dump::
+ value for the dump field in fstab. see fstab(5)
+ defaults to 0.
+
+ This parameter is ignored, if the nofstab parameter is given.
+
+options::
+ comma separated string of options, see mount(8)
+
+pass::
+ value for the pass field in fstab. see fstab(5)
+ defaults to 0.
+
+ This parameter is ignored, if the nofstab parameter is given.
+
+path::
+ mount point where to mount the device, see mount(8).
+ Defaults to __object_id
+
+state::
+ either present or absent. Defaults to present.
+
+type::
+ vfstype, see mount(8)
+
+
+BOOLEAN PARAMETERS
+------------------
+nofstab::
+ do not manage an entry in /etc/fstab
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+__mount /some/dir \
+ --device /dev/sdc3 \
+ --type xfs \
+ --options "defaults,ro"
+ --dump 0 \
+ --pass 1
+
+__mount /var/lib/one \
+ --device mfsmount \
+ --type fuse \
+ --options "mfsmaster=mfsmaster.domain.tld,mfssubfolder=/one,nonempty,_netdev"
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+
+
+COPYING
+-------
+Copyright \(C) 2014 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/__mount/manifest b/cdist/conf/type/__mount/manifest
new file mode 100755
index 00000000..8a1fa234
--- /dev/null
+++ b/cdist/conf/type/__mount/manifest
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# 2014 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 .
+#
+
+path="$(cat "$__object/parameter/path" 2>/dev/null || echo "/$__object_id")"
+state="$(cat "$__object/parameter/state")"
+
+if [ ! -f "$__object/parameter/nofstab" ]; then
+ # Generate an entry for /etc/fstab
+ (
+printf "%s" "$(cat "$__object/parameter/device")"
+printf " %s" "$path"
+type="$(cat "$__object/parameter/type" 2>/dev/null || echo "auto")"
+printf " %s" "$type"
+options="$(cat "$__object/parameter/options" 2>/dev/null || echo "defaults")"
+printf " %s" "$options"
+printf " %s" "$(cat "$__object/parameter/dump")"
+printf " %s\n" "$(cat "$__object/parameter/pass")"
+) | \
+__block "$__object_name" \
+ --file "/etc/fstab" \
+ --prefix "#cdist:$__object_name" \
+ --suffix "#/cdist:$__object_name" \
+ --state "$state" \
+ --text -
+fi
diff --git a/cdist/conf/type/__mount/parameter/boolean b/cdist/conf/type/__mount/parameter/boolean
new file mode 100644
index 00000000..ac6f41a8
--- /dev/null
+++ b/cdist/conf/type/__mount/parameter/boolean
@@ -0,0 +1 @@
+nofstab
diff --git a/cdist/conf/type/__mount/parameter/default/device b/cdist/conf/type/__mount/parameter/default/device
new file mode 100644
index 00000000..621e94f0
--- /dev/null
+++ b/cdist/conf/type/__mount/parameter/default/device
@@ -0,0 +1 @@
+none
diff --git a/cdist/conf/type/__mount/parameter/default/dump b/cdist/conf/type/__mount/parameter/default/dump
new file mode 100644
index 00000000..573541ac
--- /dev/null
+++ b/cdist/conf/type/__mount/parameter/default/dump
@@ -0,0 +1 @@
+0
diff --git a/cdist/conf/type/__mount/parameter/default/pass b/cdist/conf/type/__mount/parameter/default/pass
new file mode 100644
index 00000000..573541ac
--- /dev/null
+++ b/cdist/conf/type/__mount/parameter/default/pass
@@ -0,0 +1 @@
+0
diff --git a/cdist/conf/type/__mount/parameter/default/state b/cdist/conf/type/__mount/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__mount/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__mount/parameter/optional b/cdist/conf/type/__mount/parameter/optional
new file mode 100644
index 00000000..29d3e5ef
--- /dev/null
+++ b/cdist/conf/type/__mount/parameter/optional
@@ -0,0 +1,7 @@
+device
+dump
+options
+pass
+path
+state
+type
diff --git a/cdist/conf/type/__package/manifest b/cdist/conf/type/__package/manifest
index 6a84cb7f..0ebf0099 100755
--- a/cdist/conf/type/__package/manifest
+++ b/cdist/conf/type/__package/manifest
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
+# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
@@ -44,10 +44,12 @@ else
esac
fi
-set -- "$@" "$__object_id"
+state="$(cat "$__object/parameter/state")"
+
+set -- "$@" "$__object_id" "--state" "$state"
cd "$__object/parameter"
for property in $(ls .); do
- if [ "$property" != "type" ]; then
+ if [ "$property" != "type" -a "$property" != "state" ]; then
set -- "$@" "--$property" "$(cat "$property")"
fi
done
diff --git a/cdist/conf/type/__package/parameter/default/state b/cdist/conf/type/__package/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__package/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__package/parameter/optional b/cdist/conf/type/__package/parameter/optional
index 9982507e..d674f32e 100644
--- a/cdist/conf/type/__package/parameter/optional
+++ b/cdist/conf/type/__package/parameter/optional
@@ -3,3 +3,4 @@ version
type
pkgsite
state
+ptype
diff --git a/cdist/conf/type/__package_apt/gencode-remote b/cdist/conf/type/__package_apt/gencode-remote
index a80d707e..57339db3 100755
--- a/cdist/conf/type/__package_apt/gencode-remote
+++ b/cdist/conf/type/__package_apt/gencode-remote
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@@ -42,7 +42,9 @@ case "$state_is" in
;;
esac
-aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes"
+# Hint if we need to avoid questions at some point:
+# DEBIAN_PRIORITY=critical can reduce the number of questions
+aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes --no-install-recommends -o DPkg::Options::=\"--force-confold\""
[ "$state_is" = "$state_should" ] && exit 0
diff --git a/cdist/conf/type/__package_emerge/explorer/pkg_version b/cdist/conf/type/__package_emerge/explorer/pkg_version
new file mode 100644
index 00000000..7053eaff
--- /dev/null
+++ b/cdist/conf/type/__package_emerge/explorer/pkg_version
@@ -0,0 +1,35 @@
+#!/bin/sh
+#
+# 2013 Thomas Oettli (otho at sfs.biz)
+#
+# 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 .
+#
+#
+# Retrieve the status of a package
+#
+
+if [ ! -x /usr/bin/equery ]; then
+ echo "gentoolkit not installed!" 1>&2
+ exit 1
+fi
+
+if [ -f "$__object/parameter/name" ]; then
+ name="$(cat "$__object/parameter/name")"
+else
+ name="$__object_id"
+fi
+
+equery -q l -F '$cp $fullversion' "$name" || true
diff --git a/cdist/conf/type/__package_emerge/gencode-remote b/cdist/conf/type/__package_emerge/gencode-remote
new file mode 100644
index 00000000..d4cee37e
--- /dev/null
+++ b/cdist/conf/type/__package_emerge/gencode-remote
@@ -0,0 +1,72 @@
+#!/bin/sh
+#
+# 2013 Thomas Oettli (otho at sfs.biz)
+#
+# 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 packages with Portage (mostly gentoo)
+#
+
+if [ -f "$__object/parameter/name" ]; then
+ name="$__object/parameter/name"
+else
+ name="$__object_id"
+fi
+
+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
+ state_is="absent"
+elif [ $(echo "$pkg_version" | wc -l) -gt 1 ]; then
+ echo "Package name is not unique! The following packages are installed:"
+ echo "$pkg_version"
+ exit 1
+else
+ state_is="present"
+ installed_version="$(echo "$pkg_version" | cut -d " " -f 2)"
+fi
+
+if [ -f "$__object/parameter/version" ]; then
+ version="$(cat "$__object/parameter/version")"
+ if [ ! -z "$version" ]; then
+ name="=$name-$version"
+ fi
+else
+ version=""
+fi
+
+# Exit if nothing is needed to be done
+[ "$state_is" = "$state_should" ] && ( [ -z "$version" ] || [ "$installed_version" = "$version" ] ) && exit 0
+[ "$state_should" = "absent" ] && [ ! -z "$version" ] && [ "$installed_version" != "$version" ] && exit 0
+
+case "$state_should" in
+ present)
+ echo "emerge \"$name\" &>/dev/null || exit 1"
+ ;;
+ absent)
+ echo "emerge -C \"$name\" &>/dev/null || exit 1"
+ ;;
+ *)
+ echo "Unknown state: $state_should" >&2
+ exit 1
+ ;;
+esac
diff --git a/cdist/conf/type/__package_emerge/man.text b/cdist/conf/type/__package_emerge/man.text
new file mode 100644
index 00000000..983b49a8
--- /dev/null
+++ b/cdist/conf/type/__package_emerge/man.text
@@ -0,0 +1,60 @@
+cdist-type__package_emerge(7)
+=============================
+Thomas Oettli
+
+
+NAME
+----
+cdist-type__package_emerge - Manage packages with portage
+
+
+DESCRIPTION
+-----------
+Portage is usually used on the gentoo distribution to manage packages.
+This type requires app-portage/gentoolkit installed on the target host.
+cdist-type__package_emerge_dependencies is supposed to install the needed
+packages on the target host.
+
+
+REQUIRED PARAMETERS
+-------------------
+None
+
+
+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".
+
+version::
+ If supplied, use to install or uninstall a specific version of the package named.
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+# Ensure sys-devel/gcc is installed
+__package_emerge sys-devel/gcc --state present
+
+# If you want a specific version of a package
+__package_emerge app-portage/gentoolkit --state present --version 0.3.0.8-r2
+
+# Remove package
+__package_emerge sys-devel/gcc --state absent
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+- cdist-type__package(7)
+- cdist-type__package_emerge_dependencies(7)
+
+
+COPYING
+-------
+Copyright \(C) 2013 Thomas Oettli. 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_emerge/parameter/optional b/cdist/conf/type/__package_emerge/parameter/optional
new file mode 100644
index 00000000..f5c897df
--- /dev/null
+++ b/cdist/conf/type/__package_emerge/parameter/optional
@@ -0,0 +1,3 @@
+name
+state
+version
diff --git a/cdist/conf/type/__package_emerge_dependencies/explorer/flaggie_installed b/cdist/conf/type/__package_emerge_dependencies/explorer/flaggie_installed
new file mode 100644
index 00000000..1652ffc3
--- /dev/null
+++ b/cdist/conf/type/__package_emerge_dependencies/explorer/flaggie_installed
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ -x /usr/bin/flaggie ]; then
+ echo "true"
+else
+ echo "false"
+fi
diff --git a/cdist/conf/type/__package_emerge_dependencies/explorer/gentoolkit_installed b/cdist/conf/type/__package_emerge_dependencies/explorer/gentoolkit_installed
new file mode 100644
index 00000000..74c2378d
--- /dev/null
+++ b/cdist/conf/type/__package_emerge_dependencies/explorer/gentoolkit_installed
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ -x /usr/bin/q ]; then
+ echo "true"
+else
+ echo "false"
+fi
diff --git a/cdist/conf/type/__package_emerge_dependencies/gencode-remote b/cdist/conf/type/__package_emerge_dependencies/gencode-remote
new file mode 100644
index 00000000..0c84e53d
--- /dev/null
+++ b/cdist/conf/type/__package_emerge_dependencies/gencode-remote
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+gentoolkit_installed="$(cat "$__object/explorer/gentoolkit_installed")"
+flaggie_installed="$(cat "$__object/explorer/flaggie_installed")"
+
+if [ "${gentoolkit_installed}" != "true" ]; then
+ # emerge app-portage/gentoolkit
+ echo "emerge app-portage/gentoolkit &> /dev/null || exit 1"
+fi
+
+if [ "${flaggie_installed}" != "true" ]; then
+ # emerge app-portage/flaggie
+ echo "emerge app-portage/flaggie &> /dev/null || exit 1"
+fi
+
diff --git a/cdist/conf/type/__package_emerge_dependencies/man.text b/cdist/conf/type/__package_emerge_dependencies/man.text
new file mode 100644
index 00000000..0862256b
--- /dev/null
+++ b/cdist/conf/type/__package_emerge_dependencies/man.text
@@ -0,0 +1,48 @@
+cdist-type__package_emerge_dependencies(7)
+==========================================
+Thomas Oettli
+
+
+NAME
+----
+cdist-type__package_emerge_dependencies - Install dependencies for __package_emerge
+
+
+DESCRIPTION
+-----------
+Portage is usually used on the gentoo distribution to manage packages.
+This type installs the following tools which are required by __package_emerge to work:
+app-portage/flaggie
+app-portage/gentoolkit
+
+
+REQUIRED PARAMETERS
+-------------------
+None
+
+
+OPTIONAL PARAMETERS
+-------------------
+None
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+# Ensure app-portage/flaggie and app-portage/gentoolkit are installed
+__package_emerge_dependencies
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+- cdist-type__package(7)
+- cdist-type__package_emerge(7)
+
+
+COPYING
+-------
+Copyright \(C) 2013 Thomas Oettli. Free use of this software is
+granted under the terms of the GNU General Public License version 3 (GPLv3).
diff --git a/cdist/test/autorequire/fixtures/conf/type/__directory/.keep b/cdist/conf/type/__package_emerge_dependencies/singleton
similarity index 100%
rename from cdist/test/autorequire/fixtures/conf/type/__directory/.keep
rename to cdist/conf/type/__package_emerge_dependencies/singleton
diff --git a/cdist/conf/type/__package_opkg/gencode-remote b/cdist/conf/type/__package_opkg/gencode-remote
index 43f1ad8a..1fb78fbe 100755
--- a/cdist/conf/type/__package_opkg/gencode-remote
+++ b/cdist/conf/type/__package_opkg/gencode-remote
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# 2011 Nico Schottelius (nico-cdist at schottelius.org)
+# 2011,2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2012 Giel van Schijndel (giel plus cdist at mortis dot eu)
#
# This file is part of cdist.
@@ -42,20 +42,20 @@ case "$state_is" in
;;
esac
-if [ "$state_is" != "$state_should" ]; then
- case "$state_should" in
- present)
- if [ "$present" = "notpresent" ]; then
+[ "$state_is" = "$state_should" ] && exit 0
+
+case "$state_should" in
+ present)
+ if [ "$present" = "notpresent" ]; then
echo opkg --verbosity=0 update
- fi
- echo opkg --verbosity=0 install \"$name\"
- ;;
- absent)
- echo opkg --verbosity=0 remove \"$name\"
- ;;
- *)
- echo "Unknown state: $state" >&2
- exit 1
- ;;
- esac
-fi
+ fi
+ echo opkg --verbosity=0 install \"$name\"
+ ;;
+ absent)
+ echo opkg --verbosity=0 remove \"$name\"
+ ;;
+ *)
+ echo "Unknown state: $state" >&2
+ exit 1
+ ;;
+esac
diff --git a/cdist/conf/type/__package_yum/gencode-remote b/cdist/conf/type/__package_yum/gencode-remote
index 9c98c257..5f0e8ac8 100755
--- a/cdist/conf/type/__package_yum/gencode-remote
+++ b/cdist/conf/type/__package_yum/gencode-remote
@@ -27,11 +27,7 @@ else
name="$__object_id"
fi
-if [ -f "$__object/parameter/state" ]; then
- state_should="$(cat "$__object/parameter/state")"
-else
- state_should="present"
-fi
+state_should="$(cat "$__object/parameter/state")"
if grep -q -E "(centos|redhat|amazon)" "$__global/explorer/os"; then
opts="-y --quiet"
diff --git a/cdist/conf/type/__package_yum/parameter/default/state b/cdist/conf/type/__package_yum/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__package_yum/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__package_zypper/explorer/pkg_version b/cdist/conf/type/__package_zypper/explorer/pkg_version
old mode 100755
new mode 100644
index fb3b7753..7f203067
--- a/cdist/conf/type/__package_zypper/explorer/pkg_version
+++ b/cdist/conf/type/__package_zypper/explorer/pkg_version
@@ -1,6 +1,7 @@
#!/bin/sh
#
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2013 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
#
@@ -18,7 +19,7 @@
# along with cdist. If not, see .
#
#
-# Retrieve the status of a package
+# Retrieve the status of a package of different types
#
if [ -f "$__object/parameter/name" ]; then
@@ -27,4 +28,21 @@ else
name="$__object_id"
fi
-rpm -q --whatprovides "$name" 2>/dev/null || true
+if [ -f "$__object/parameter/ptype" ]; then
+ ptype="$(cat "$__object/parameter/ptype")"
+else
+ ptype="package"
+fi
+
+case "$ptype" in
+ package)
+ zypper search --details --match-exact --installed-only --type "$ptype" "$name" | grep -E '^i' | cut -d " " -f 3,7 || true
+ ;;
+ patch|pattern|product|srcpackage)
+ zypper search --match-exact --installed-only --type "$ptype" "$name" | grep -E '^i' | cut -d " " -f 3 || true
+ ;;
+ *)
+ echo "unknown ptype in __package_zypper explorer" &>2
+ exit 1
+ ;;
+esac
diff --git a/cdist/conf/type/__package_zypper/gencode-remote b/cdist/conf/type/__package_zypper/gencode-remote
old mode 100755
new mode 100644
index ca9aec33..d9f16f8d
--- a/cdist/conf/type/__package_zypper/gencode-remote
+++ b/cdist/conf/type/__package_zypper/gencode-remote
@@ -1,6 +1,7 @@
#!/bin/sh
#
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2013 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
#
@@ -28,29 +29,50 @@
globalopts="--quiet --non-interactive"
if [ -f "$__object/parameter/name" ]; then
- name="$__object/parameter/name"
+ name="$__object/parameter/name"
else
- name="$__object_id"
+ name="$__object_id"
fi
-if [ -f "$__object/parameter/state" ]; then
- state_should="$(cat "$__object/parameter/state")"
+state_should="$(cat "$__object/parameter/state")"
+ptype="$(cat "$__object/parameter/ptype")"
+
+if [ -f "$__object/parameter/version" ]; then
+ version_should="$(cat "$__object/parameter/version")"
+ if [ "$ptype" != "package" ]; then
+ echo "version support only for type package implemented" >&2
+ exit 2
+ fi
else
- state_should="present"
+ version_should=""
+fi
+
+pkg_version="$(cat "$__object/explorer/pkg_version")"
+if [ -z "$pkg_version" ]; then
+ state_is="absent"
+ version_is=""
+else
+ state_is="present"
+ version_is=${pkg_version##* }
fi
-# Exit if nothing is needed to be done
-[ "$state_is" = "$state_should" ] && exit 0
case "$state_should" in
- present)
- echo zypper "$globalopts" install --auto-agree-with-licenses \"$name\"
- ;;
- absent)
- echo pacman "$globalopts" remove \"$name\"
- ;;
- *)
- echo "Unknown state: $state_should" >&2
- exit 1
- ;;
+ present)
+ if [ -z "$version_should" ]; then
+ [ "$state_is" = "present" ] && exit 0 # if state is present, we dont need to do anything
+ echo zypper $globalopts install --type \"$ptype\" --auto-agree-with-licenses \"$name\" ">/dev/null"
+ else
+ [ "$state_is" = "present" ] && [ "$version_should" = "$version_is" ] && exit 0 # if state is present and version is correct, we dont need to do anything
+ echo zypper $globalopts install --oldpackage --type \"$ptype\" --auto-agree-with-licenses \"$name\" = \"$version_should\" ">/dev/null"
+ fi
+ ;;
+ absent)
+ [ "$state_is" = "absent" ] && exit 0 # if state is absent, we dont need to do anything
+ echo zypper $globalopts remove --type \"$ptype\" \"$name\" ">/dev/null"
+ ;;
+ *)
+ echo "Unknown state: $state_should" >&2
+ exit 1
+ ;;
esac
diff --git a/cdist/conf/type/__package_zypper/man.text b/cdist/conf/type/__package_zypper/man.text
index e2261d33..104d3a7a 100644
--- a/cdist/conf/type/__package_zypper/man.text
+++ b/cdist/conf/type/__package_zypper/man.text
@@ -1,6 +1,6 @@
cdist-type__package_zypper(7)
=============================
-Nico Schottelius
+Daniel Heule
NAME
@@ -26,19 +26,33 @@ name::
state::
Either "present" or "absent", defaults to "present"
+version::
+ The version of the package to install. Default is to install the version
+ choosen by the local package manager. For a list of available versions,
+ have a look at the output of "zypper se -s packagename"
+
+ptype::
+ Either "package", "patch", "pattern", "product" or "srcpackage", defaults to "package". For a description see man zypper.
+
EXAMPLES
--------
--------------------------------------------------------------------------------
-# Ensure zsh in installed
+# Ensure zsh is installed
__package_zypper zsh --state present
# If you don't want to follow pythonX packages, but always use python
__package_zypper python --state present --name python2
+# Ensure binutils is installed and the version is forced to be 2.23.1-0.19.2
+__package_zypper binutils --state present --version 2.23.1-0.19.2
+
# Remove package
__package_zypper cfengine --state absent
+
+# install all packages which belongs to pattern x11
+__package_zypper x11 --ptype pattern --state present
--------------------------------------------------------------------------------
@@ -50,5 +64,6 @@ SEE ALSO
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).
+Copyright \(C) 2012 Nico Schottelius.
+Copyright \(C) 2013 Daniel Heule.
+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/default/ptype b/cdist/conf/type/__package_zypper/parameter/default/ptype
new file mode 100644
index 00000000..ba3bd787
--- /dev/null
+++ b/cdist/conf/type/__package_zypper/parameter/default/ptype
@@ -0,0 +1 @@
+package
diff --git a/cdist/conf/type/__package_zypper/parameter/default/state b/cdist/conf/type/__package_zypper/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__package_zypper/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__package_zypper/parameter/optional b/cdist/conf/type/__package_zypper/parameter/optional
index 1b423dc4..bc8565fc 100644
--- a/cdist/conf/type/__package_zypper/parameter/optional
+++ b/cdist/conf/type/__package_zypper/parameter/optional
@@ -1,2 +1,4 @@
name
state
+ptype
+version
diff --git a/cdist/conf/type/__pf_ruleset/man.text b/cdist/conf/type/__pf_ruleset/man.text
index 0dc07f71..29efe065 100644
--- a/cdist/conf/type/__pf_ruleset/man.text
+++ b/cdist/conf/type/__pf_ruleset/man.text
@@ -16,7 +16,7 @@ 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"
+ Either "absent" (no ruleset at all) or "present", defaults to "present".
OPTIONAL PARAMETERS
diff --git a/cdist/conf/type/__pf_ruleset/parameter/default/state b/cdist/conf/type/__pf_ruleset/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__pf_ruleset/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__pf_ruleset/parameter/optional b/cdist/conf/type/__pf_ruleset/parameter/optional
index 5a18cd2f..d77f3048 100644
--- a/cdist/conf/type/__pf_ruleset/parameter/optional
+++ b/cdist/conf/type/__pf_ruleset/parameter/optional
@@ -1 +1,2 @@
source
+state
diff --git a/cdist/conf/type/__postfix/man.text b/cdist/conf/type/__postfix/man.text
new file mode 100644
index 00000000..1a91723a
--- /dev/null
+++ b/cdist/conf/type/__postfix/man.text
@@ -0,0 +1,42 @@
+cdist-type__postfix(7)
+======================
+Steven Armstrong
+
+
+NAME
+----
+cdist-type__postfix - install postfix
+
+
+DESCRIPTION
+-----------
+This space intentionally left blank.
+
+
+REQUIRED PARAMETERS
+-------------------
+None.
+
+
+OPTIONAL PARAMETERS
+-------------------
+None.
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+__postfix
+--------------------------------------------------------------------------------
+
+
+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/__postfix/manifest b/cdist/conf/type/__postfix/manifest
new file mode 100755
index 00000000..52a13919
--- /dev/null
+++ b/cdist/conf/type/__postfix/manifest
@@ -0,0 +1,33 @@
+#!/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 .
+#
+
+
+os=$(cat "$__global/explorer/os")
+
+case "$os" in
+ ubuntu|debian|archlinux|suse)
+ __package postfix --state present
+ ;;
+ *)
+ echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
+ echo "Please contribute an implementation for it if you can." >&2
+ exit 1
+ ;;
+esac
diff --git a/cdist/test/autorequire/fixtures/conf/type/__package_special/.keep b/cdist/conf/type/__postfix/singleton
similarity index 100%
rename from cdist/test/autorequire/fixtures/conf/type/__package_special/.keep
rename to cdist/conf/type/__postfix/singleton
diff --git a/cdist/conf/type/__ssh_authorized_keys/explorer/entry b/cdist/conf/type/__postfix_master/explorer/entry
similarity index 66%
rename from cdist/conf/type/__ssh_authorized_keys/explorer/entry
rename to cdist/conf/type/__postfix_master/explorer/entry
index 9992d32d..9d6b1514 100755
--- a/cdist/conf/type/__ssh_authorized_keys/explorer/entry
+++ b/cdist/conf/type/__postfix_master/explorer/entry
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
+# 2011 - 2012 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
@@ -18,18 +18,12 @@
# along with cdist. If not, see .
#
-owner="$(cat "$__object/parameter/owner" 2>/dev/null || echo "$__object_id")"
-if [ -f "$__object/parameter/file" ]; then
- file="$(cat "$__object/parameter/file")"
-else
- home="$("$__type_explorer/passwd" | cut -d':' -f 6)"
- file="$home/.ssh/authorized_keys"
-fi
+config="/etc/postfix/master.cf"
-# no authorized_keys file, nothing we could do
-[ -f "$file" ] || exit 0
+# no master.cf, nothing we could do
+[ -f "$config" ] || exit 0
-# NOTE: keep variables in sync in manifest/explorer/gencode-*
+# NOTE: keep variables in sync in manifest,explorer,gencode-*
prefix="#cdist:$__object_name"
suffix="#/cdist:$__object_name"
awk -v prefix="$prefix" -v suffix="$suffix" '{
@@ -42,4 +36,4 @@ awk -v prefix="$prefix" -v suffix="$suffix" '{
}
print
}
-}' "$file"
+}' "$config"
diff --git a/cdist/conf/type/__ssh_authorized_keys/gencode-remote b/cdist/conf/type/__postfix_master/gencode-remote
similarity index 78%
rename from cdist/conf/type/__ssh_authorized_keys/gencode-remote
rename to cdist/conf/type/__postfix_master/gencode-remote
index cc86cc19..51edc668 100755
--- a/cdist/conf/type/__ssh_authorized_keys/gencode-remote
+++ b/cdist/conf/type/__postfix_master/gencode-remote
@@ -18,15 +18,9 @@
# along with cdist. If not, see .
#
-owner="$(cat "$__object/parameter/owner" 2>/dev/null || echo "$__object_id")"
-if [ -f "$__object/parameter/file" ]; then
- file="$(cat "$__object/parameter/file")"
-else
- home="$(cut -d':' -f 6 "$__object/explorer/passwd")"
- file="$home/.ssh/authorized_keys"
-fi
-
+config="/etc/postfix/master.cf"
entry="$__object/files/entry"
+state_should="$(cat "$__object/parameter/state")"
if [ ! -s "$__object/explorer/entry" ]; then
state_is='absent'
else
@@ -36,18 +30,20 @@ else
)
fi
-state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo present)"
if [ "$state_should" = "$state_is" ]; then
# Nothing to do, move along
exit 0
fi
+
remove_entry() {
# NOTE: keep variables in sync in manifest/explorer/gencode-*
prefix="#cdist:$__object_name"
suffix="#/cdist:$__object_name"
cat << DONE
-tmpfile=\$(mktemp)
+tmpfile=\$(mktemp ${config}.cdist.XXXXXXXXXX)
+# preserve ownership and permissions of existing file
+cp -p "$config" "\$tmpfile"
awk -v prefix="$prefix" -v suffix="$suffix" '
{
if (index(\$0,prefix)) {
@@ -60,8 +56,8 @@ awk -v prefix="$prefix" -v suffix="$suffix" '
} else {
print
}
-}' "$file" > "\$tmpfile"
-mv -f "\$tmpfile" "$file"
+}' "$config" > "\$tmpfile"
+mv -f "\$tmpfile" "$config"
DONE
}
@@ -71,7 +67,7 @@ case "$state_should" in
remove_entry
fi
cat << DONE
-cat >> "$file" << ${__type##*/}_DONE
+cat >> "$config" << ${__type##*/}_DONE
$(cat "$entry")
${__type##*/}_DONE
DONE
diff --git a/cdist/conf/type/__postfix_master/man.text b/cdist/conf/type/__postfix_master/man.text
new file mode 100644
index 00000000..0ec78752
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/man.text
@@ -0,0 +1,73 @@
+cdist-type__postfix_master(7)
+=============================
+Steven Armstrong
+
+
+NAME
+----
+cdist-type__postfix_master - configure postfix master.cf
+
+
+DESCRIPTION
+-----------
+See master(5) for more information.
+
+
+REQUIRED PARAMETERS
+-------------------
+type::
+ See master(5)
+command::
+ See master(5)
+
+
+BOOLEAN PARAMETERS
+------------------
+noreload::
+ don't reload postfix after changes
+
+
+OPTIONAL PARAMETERS
+-------------------
+state::
+ present or absent, defaults to present
+service::
+private::
+unpriv::
+chroot::
+wakeup::
+maxproc::
+option::
+ Pass an option to a service. Same as using -o in master.cf.
+ Can be specified multiple times.
+comment::
+ a textual comment to add with the master.cf entry
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+__postfix_master smtp --type inet --command smtpd
+
+__postfix_master smtp --type inet --chroot y --command smtpd \
+ --option smtpd_enforce_tls=yes \
+ --option smtpd_sasl_auth_enable=yes \
+ --option smtpd_client_restrictions=permit_sasl_authenticated,reject
+
+__postfix_master submission --type inet --command smtpd \
+ --comment "Run alternative smtp on submission port"
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+- master(5)
+
+
+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/__postfix_master/manifest b/cdist/conf/type/__postfix_master/manifest
new file mode 100755
index 00000000..87e2329b
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/manifest
@@ -0,0 +1,82 @@
+#!/bin/sh
+#
+# 2012 - 2013 Steven Armstrong (steven-cdist at armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+
+os=$(cat "$__global/explorer/os")
+
+case "$os" in
+ ubuntu|debian|archlinux)
+ :
+ ;;
+ *)
+ echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
+ echo "Please contribute an implementation for it if you can." >&2
+ exit 1
+ ;;
+esac
+
+__postfix
+
+# Default to object_id
+service="$(cat "$__object/parameter/service" 2>/dev/null || echo "$__object_id")"
+state="$(cat "$__object/parameter/state")"
+
+# NOTE: keep variables in sync in manifest,explorer,gencode-*
+prefix="#cdist:$__object_name"
+suffix="#/cdist:$__object_name"
+
+# Generate entry for inclusion in master.cf
+mkdir "$__object/files"
+entry="$__object/files/entry"
+(
+ echo "$prefix"
+ if [ -f "$__object/parameter/comment" ]; then
+ echo "# $(cat "$__object/parameter/comment")"
+ fi
+ printf "%s " "$service"
+ printf "%s " "$type"
+ for parameter in type private unpriv chroot wakeup maxproc; do
+ printf "%s " "$(cat "$__object/parameter/$parameter")"
+ done
+ command="$(cat "$__object/parameter/command")"
+ # ensure we have a trailing newline
+ echo "$command"
+ options="$(cat "$__object/parameter/option" 2>/dev/null || true)"
+ for option in $options; do
+ echo " -o $option"
+ done
+ echo "$suffix"
+) > "$entry"
+
+# Reload postfix after changes
+if [ ! -f "$__object/parameter/noreload" ]; then
+ state_should="$(cat "$__object/parameter/state")"
+ 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" __postfix_reload
+ fi
+fi
diff --git a/cdist/conf/type/__postfix_master/parameter/boolean b/cdist/conf/type/__postfix_master/parameter/boolean
new file mode 100644
index 00000000..862edc87
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/parameter/boolean
@@ -0,0 +1 @@
+noreload
diff --git a/cdist/conf/type/__postfix_master/parameter/default/chroot b/cdist/conf/type/__postfix_master/parameter/default/chroot
new file mode 100644
index 00000000..39cdd0de
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/parameter/default/chroot
@@ -0,0 +1 @@
+-
diff --git a/cdist/conf/type/__postfix_master/parameter/default/maxproc b/cdist/conf/type/__postfix_master/parameter/default/maxproc
new file mode 100644
index 00000000..39cdd0de
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/parameter/default/maxproc
@@ -0,0 +1 @@
+-
diff --git a/cdist/conf/type/__postfix_master/parameter/default/private b/cdist/conf/type/__postfix_master/parameter/default/private
new file mode 100644
index 00000000..39cdd0de
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/parameter/default/private
@@ -0,0 +1 @@
+-
diff --git a/cdist/conf/type/__postfix_master/parameter/default/state b/cdist/conf/type/__postfix_master/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__postfix_master/parameter/default/unpriv b/cdist/conf/type/__postfix_master/parameter/default/unpriv
new file mode 100644
index 00000000..39cdd0de
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/parameter/default/unpriv
@@ -0,0 +1 @@
+-
diff --git a/cdist/conf/type/__postfix_master/parameter/default/wakeup b/cdist/conf/type/__postfix_master/parameter/default/wakeup
new file mode 100644
index 00000000..39cdd0de
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/parameter/default/wakeup
@@ -0,0 +1 @@
+-
diff --git a/cdist/conf/type/__postfix_master/parameter/optional b/cdist/conf/type/__postfix_master/parameter/optional
new file mode 100644
index 00000000..792b42c5
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/parameter/optional
@@ -0,0 +1,9 @@
+service
+private
+unpriv
+chroot
+wakeup
+maxproc
+option
+comment
+state
diff --git a/cdist/conf/type/__postfix_master/parameter/required b/cdist/conf/type/__postfix_master/parameter/required
new file mode 100644
index 00000000..24c14146
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/parameter/required
@@ -0,0 +1,2 @@
+type
+command
diff --git a/cdist/conf/type/__postfix_postconf/explorer/value b/cdist/conf/type/__postfix_postconf/explorer/value
new file mode 100755
index 00000000..e08c6da6
--- /dev/null
+++ b/cdist/conf/type/__postfix_postconf/explorer/value
@@ -0,0 +1,37 @@
+#!/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 .
+#
+
+
+os=$("$__explorer/os")
+
+case "$os" in
+ ubuntu|debian|archlinux|suse)
+ :
+ ;;
+ *)
+ echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
+ echo "Please contribute an implementation for it if you can." >&2
+ exit 1
+ ;;
+esac
+
+key="$(cat "$__object/parameter/key" 2>/dev/null || echo "$__object_id")"
+
+postconf -h "$key"
diff --git a/cdist/conf/type/__postfix_postconf/gencode-remote b/cdist/conf/type/__postfix_postconf/gencode-remote
new file mode 100755
index 00000000..43c0482e
--- /dev/null
+++ b/cdist/conf/type/__postfix_postconf/gencode-remote
@@ -0,0 +1,60 @@
+#!/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 .
+#
+
+os=$(cat "$__global/explorer/os")
+
+case "$os" in
+ ubuntu|debian|archlinux|suse)
+ :
+ ;;
+ *)
+ echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
+ echo "Please contribute an implementation for it if you can." >&2
+ exit 1
+ ;;
+esac
+
+state_should="$(cat "$__object/parameter/state")"
+if [ ! -s "$__object/explorer/value" ]; then
+ state_is='absent'
+else
+ state_is=$(diff -q "$__object/parameter/value" "$__object/explorer/value" >/dev/null \
+ && echo present \
+ || echo changed
+ )
+fi
+
+if [ "$state_should" = "$state_is" ]; then
+ # Nothing to do, move along
+ exit 0
+fi
+
+key="$(cat "$__object/parameter/key" 2>/dev/null || echo "$__object_id")"
+value="$(cat "$__object/parameter/value")"
+
+case "$state_should" in
+ absent)
+ # revert parameter to its default value
+ echo "postconf -# $key"
+ ;;
+ present)
+ echo "postconf -e '$key=$value'"
+ ;;
+esac
diff --git a/cdist/conf/type/__postfix_postconf/man.text b/cdist/conf/type/__postfix_postconf/man.text
new file mode 100644
index 00000000..727637b1
--- /dev/null
+++ b/cdist/conf/type/__postfix_postconf/man.text
@@ -0,0 +1,51 @@
+cdist-type__postfix_postconf(7)
+===============================
+Steven Armstrong
+
+
+NAME
+----
+cdist-type__postfix_postconf - configure postfix main.cf
+
+
+DESCRIPTION
+-----------
+See postconf(5) for possible keys and values.
+
+Note that this type directly runs the postconf executable.
+It does not make changes to /etc/postfix/main.cf itself.
+
+
+REQUIRED PARAMETERS
+-------------------
+value::
+ the value for the postfix parameter
+
+
+OPTIONAL PARAMETERS
+-------------------
+key::
+ the name of the parameter. Defaults to __object_id
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+__postfix_postconf mydomain --value somedomain.com
+
+__postfix_postconf bind-to-special-ip --key smtp_bind_address --value 127.0.0.5
+
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+- postconf(5)
+
+
+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/__postfix_postconf/manifest b/cdist/conf/type/__postfix_postconf/manifest
new file mode 100755
index 00000000..0dde64e9
--- /dev/null
+++ b/cdist/conf/type/__postfix_postconf/manifest
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# 2012 - 2013 Steven Armstrong (steven-cdist at armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+__postfix
diff --git a/cdist/conf/type/__postfix_postconf/parameter/default/state b/cdist/conf/type/__postfix_postconf/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__postfix_postconf/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__rvm/parameter/required b/cdist/conf/type/__postfix_postconf/parameter/optional
similarity index 60%
rename from cdist/conf/type/__rvm/parameter/required
rename to cdist/conf/type/__postfix_postconf/parameter/optional
index ff72b5c7..6ada755a 100644
--- a/cdist/conf/type/__rvm/parameter/required
+++ b/cdist/conf/type/__postfix_postconf/parameter/optional
@@ -1 +1,2 @@
+key
state
diff --git a/cdist/conf/type/__postfix_postconf/parameter/required b/cdist/conf/type/__postfix_postconf/parameter/required
new file mode 100644
index 00000000..6d4e1507
--- /dev/null
+++ b/cdist/conf/type/__postfix_postconf/parameter/required
@@ -0,0 +1 @@
+value
diff --git a/cdist/conf/type/__postfix_postmap/gencode-remote b/cdist/conf/type/__postfix_postmap/gencode-remote
new file mode 100755
index 00000000..1b370001
--- /dev/null
+++ b/cdist/conf/type/__postfix_postmap/gencode-remote
@@ -0,0 +1,21 @@
+#!/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 .
+#
+
+echo "postmap /$__object_id"
diff --git a/cdist/conf/type/__postfix_postmap/man.text b/cdist/conf/type/__postfix_postmap/man.text
new file mode 100644
index 00000000..37060d04
--- /dev/null
+++ b/cdist/conf/type/__postfix_postmap/man.text
@@ -0,0 +1,42 @@
+cdist-type__postfix_postmap(7)
+==============================
+Steven Armstrong
+
+
+NAME
+----
+cdist-type__postfix_postmap - run postmap on the given file
+
+
+DESCRIPTION
+-----------
+This space intentionally left blank.
+
+
+REQUIRED PARAMETERS
+-------------------
+None.
+
+
+OPTIONAL PARAMETERS
+-------------------
+None.
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+__postfix_postmap /etc/postfix/generic
+--------------------------------------------------------------------------------
+
+
+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/__postfix_postmap/manifest b/cdist/conf/type/__postfix_postmap/manifest
new file mode 100755
index 00000000..0dde64e9
--- /dev/null
+++ b/cdist/conf/type/__postfix_postmap/manifest
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# 2012 - 2013 Steven Armstrong (steven-cdist at armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+__postfix
diff --git a/cdist/conf/type/__postfix_reload/gencode-remote b/cdist/conf/type/__postfix_reload/gencode-remote
new file mode 100755
index 00000000..5822f1e3
--- /dev/null
+++ b/cdist/conf/type/__postfix_reload/gencode-remote
@@ -0,0 +1,33 @@
+#!/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 .
+#
+
+
+os=$(cat "$__global/explorer/os")
+
+case "$os" in
+ ubuntu|debian|archlinux)
+ echo "postfix reload"
+ ;;
+ *)
+ echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
+ echo "Please contribute an implementation for it if you can." >&2
+ exit 1
+ ;;
+esac
diff --git a/cdist/conf/type/__postfix_reload/man.text b/cdist/conf/type/__postfix_reload/man.text
new file mode 100644
index 00000000..c63356b5
--- /dev/null
+++ b/cdist/conf/type/__postfix_reload/man.text
@@ -0,0 +1,42 @@
+cdist-type__postfix_reload(7)
+=============================
+Steven Armstrong
+
+
+NAME
+----
+cdist-type__postfix_reload - tell postfix to reload its configuration
+
+
+DESCRIPTION
+-----------
+This space intentionally left blank.
+
+
+REQUIRED PARAMETERS
+-------------------
+None.
+
+
+OPTIONAL PARAMETERS
+-------------------
+None.
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+__postfix_reload
+--------------------------------------------------------------------------------
+
+
+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/__postfix_reload/manifest b/cdist/conf/type/__postfix_reload/manifest
new file mode 100755
index 00000000..0dde64e9
--- /dev/null
+++ b/cdist/conf/type/__postfix_reload/manifest
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# 2012 - 2013 Steven Armstrong (steven-cdist at armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+__postfix
diff --git a/cdist/test/autorequire/fixtures/conf/type/__user/.keep b/cdist/conf/type/__postfix_reload/singleton
similarity index 100%
rename from cdist/test/autorequire/fixtures/conf/type/__user/.keep
rename to cdist/conf/type/__postfix_reload/singleton
diff --git a/cdist/conf/type/__postgres_database/man.text b/cdist/conf/type/__postgres_database/man.text
index d01ca8f6..c7c0d3cd 100644
--- a/cdist/conf/type/__postgres_database/man.text
+++ b/cdist/conf/type/__postgres_database/man.text
@@ -13,14 +13,11 @@ DESCRIPTION
This cdist type allows you to create or drop postgres databases.
-REQUIRED PARAMETERS
--------------------
-state::
- either 'present' or 'absent'
-
-
OPTIONAL PARAMETERS
-------------------
+state::
+ either 'present' or 'absent', defaults to 'present'.
+
owner::
the role owning this database
@@ -29,7 +26,7 @@ EXAMPLES
--------
--------------------------------------------------------------------------------
-__postgres_database mydbname --state present --owner mydbusername
+__postgres_database mydbname --owner mydbusername
--------------------------------------------------------------------------------
diff --git a/cdist/conf/type/__postgres_database/parameter/default/state b/cdist/conf/type/__postgres_database/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__postgres_database/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__postgres_database/parameter/optional b/cdist/conf/type/__postgres_database/parameter/optional
index 7ee3bde8..d86b6469 100644
--- a/cdist/conf/type/__postgres_database/parameter/optional
+++ b/cdist/conf/type/__postgres_database/parameter/optional
@@ -1 +1,2 @@
+state
owner
diff --git a/cdist/conf/type/__postgres_role/gencode-remote b/cdist/conf/type/__postgres_role/gencode-remote
index c9de4707..0230e48e 100755
--- a/cdist/conf/type/__postgres_role/gencode-remote
+++ b/cdist/conf/type/__postgres_role/gencode-remote
@@ -27,7 +27,7 @@ state_should="$(cat "$__object/parameter/state")"
case "$state_should" in
present)
if [ -f "$__object/parameter/password" ]; then
- password="$(cat "$__object/parameter/$parameter")"
+ password="$(cat "$__object/parameter/password")"
fi
booleans=""
for boolean in login createdb createrole superuser; do
diff --git a/cdist/conf/type/__postgres_role/man.text b/cdist/conf/type/__postgres_role/man.text
index 904f0831..ac87754b 100644
--- a/cdist/conf/type/__postgres_role/man.text
+++ b/cdist/conf/type/__postgres_role/man.text
@@ -13,15 +13,12 @@ DESCRIPTION
This cdist type allows you to create or drop postgres roles.
-REQUIRED PARAMETERS
+OPTIONAL PARAMETERS
-------------------
state::
Either "present" or "absent", defaults to "present"
-
-OPTIONAL PARAMETERS
--------------------
-All parameter map directly to the corresponding postgres createrole
+All other parameters map directly to the corresponding postgres createrole
parameters.
password::
@@ -41,13 +38,13 @@ EXAMPLES
--------
--------------------------------------------------------------------------------
-__postgres_role myrole --state present
+__postgres_role myrole
-__postgres_role myrole --state present --password 'secret'
+__postgres_role myrole --password 'secret'
-__postgres_role admin --state present --password 'very-secret' --superuser
+__postgres_role admin --password 'very-secret' --superuser
-__postgres_role dbcustomer --state present --password 'bla' --createdb
+__postgres_role dbcustomer --password 'bla' --createdb
--------------------------------------------------------------------------------
diff --git a/cdist/conf/type/__postgres_role/parameter/default/state b/cdist/conf/type/__postgres_role/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__postgres_role/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__postgres_role/parameter/optional b/cdist/conf/type/__postgres_role/parameter/optional
index f3097ab1..cb9b2c48 100644
--- a/cdist/conf/type/__postgres_role/parameter/optional
+++ b/cdist/conf/type/__postgres_role/parameter/optional
@@ -1 +1,2 @@
+state
password
diff --git a/cdist/conf/type/__process/gencode-remote b/cdist/conf/type/__process/gencode-remote
index fdb6033a..639940d9 100755
--- a/cdist/conf/type/__process/gencode-remote
+++ b/cdist/conf/type/__process/gencode-remote
@@ -1,6 +1,7 @@
#!/bin/sh
#
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
@@ -17,7 +18,6 @@
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see .
#
-#
if [ -f "$__object/parameter/name" ]; then
name="$(cat "$__object/parameter/name")"
@@ -27,14 +27,16 @@ fi
state_should="$(cat "$__object/parameter/state")"
-runs="$(cat "$__object/explorer/runs")"
-if [ "$runs" ]; then
+if [ -s "$__object/explorer/runs" ]; then
state_is="present"
else
state_is="absent"
fi
-[ "$state_is" = "$state_should" ] && exit 0
+if [ "$state_is" = "$state_should" ]; then
+ # nothing to do
+ exit 0
+fi
case "$state_should" in
present)
diff --git a/cdist/conf/type/__process/man.text b/cdist/conf/type/__process/man.text
index 0d457ead..2fdd27aa 100644
--- a/cdist/conf/type/__process/man.text
+++ b/cdist/conf/type/__process/man.text
@@ -13,14 +13,11 @@ DESCRIPTION
This cdist type allows you to define the state of a process.
-REQUIRED PARAMETERS
+OPTIONAL PARAMETERS
-------------------
state::
Either "present" or "absent", defaults to "present"
-
-OPTIONAL PARAMETERS
--------------------
name::
Process name to match on when using pgrep -f -x.
diff --git a/cdist/conf/type/__process/parameter/default/state b/cdist/conf/type/__process/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__process/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__process/parameter/optional b/cdist/conf/type/__process/parameter/optional
index 3411afb4..85fe8805 100644
--- a/cdist/conf/type/__process/parameter/optional
+++ b/cdist/conf/type/__process/parameter/optional
@@ -1,3 +1,4 @@
name
stop
start
+state
diff --git a/cdist/conf/type/__qemu_img/gencode-remote b/cdist/conf/type/__qemu_img/gencode-remote
index 2a76cf8f..6e4bb4d0 100644
--- a/cdist/conf/type/__qemu_img/gencode-remote
+++ b/cdist/conf/type/__qemu_img/gencode-remote
@@ -2,8 +2,7 @@
# 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="$(cat "$__object/parameter/state")"
[ "$state" = "absent" ] && exit 0
exists="$(cat "$__object/explorer/exists")"
@@ -13,8 +12,7 @@ exists="$(cat "$__object/explorer/exists")"
# Still there? Create image
#
-format=qcow2
-[ -f "$__object/parameter/format" ] && format="$(cat "$__object/parameter/format")"
+format="$(cat "$__object/parameter/format")"
size="$(cat "$__object/parameter/size")"
diskimage="/$__object_id"
diff --git a/cdist/conf/type/__qemu_img/manifest b/cdist/conf/type/__qemu_img/manifest
index b835301d..6d50037f 100644
--- a/cdist/conf/type/__qemu_img/manifest
+++ b/cdist/conf/type/__qemu_img/manifest
@@ -2,10 +2,8 @@
# Default settings
#
-format=qcow2
-state=present
-[ -f "$__object/parameter/format" ] && format="$(cat "$__object/parameter/format")"
-[ -f "$__object/parameter/state" ] && state="$(cat "$__object/parameter/state")"
+format="$(cat "$__object/parameter/format")"
+state="$(cat "$__object/parameter/state")"
diskimage="/$__object_id"
diff --git a/cdist/conf/type/__qemu_img/parameter/default/format b/cdist/conf/type/__qemu_img/parameter/default/format
new file mode 100644
index 00000000..e0a90ab9
--- /dev/null
+++ b/cdist/conf/type/__qemu_img/parameter/default/format
@@ -0,0 +1 @@
+qcow2
diff --git a/cdist/conf/type/__qemu_img/parameter/default/state b/cdist/conf/type/__qemu_img/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__qemu_img/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__qemu_img/parameter/optional b/cdist/conf/type/__qemu_img/parameter/optional
index 0e8469e7..71b9a32b 100644
--- a/cdist/conf/type/__qemu_img/parameter/optional
+++ b/cdist/conf/type/__qemu_img/parameter/optional
@@ -1 +1,2 @@
format
+state
diff --git a/cdist/conf/type/__rvm/man.text b/cdist/conf/type/__rvm/man.text
index c1f83e60..0408d125 100644
--- a/cdist/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 "present" or "absent".
+ Either "present" or "absent", defaults to "present".
EXAMPLES
diff --git a/cdist/conf/type/__rvm/parameter/default/state b/cdist/conf/type/__rvm/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__rvm/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__postgres_database/parameter/required b/cdist/conf/type/__rvm/parameter/optional
similarity index 100%
rename from cdist/conf/type/__postgres_database/parameter/required
rename to cdist/conf/type/__rvm/parameter/optional
diff --git a/cdist/conf/type/__rvm_gem/man.text b/cdist/conf/type/__rvm_gem/man.text
index 2b72e7ae..d7eff3be 100644
--- a/cdist/conf/type/__rvm_gem/man.text
+++ b/cdist/conf/type/__rvm_gem/man.text
@@ -20,7 +20,7 @@ user::
gemset::
The gemset to use
state::
- Either "present" or "absent"
+ Either "present" or "absent", defaults to "present".
OPTIONAL PARAMETERS
-------------------
diff --git a/cdist/conf/type/__rvm_gem/parameter/default/state b/cdist/conf/type/__rvm_gem/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__rvm_gem/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__rvm_gem/parameter/optional b/cdist/conf/type/__rvm_gem/parameter/optional
index 4ad96d51..96983811 100644
--- a/cdist/conf/type/__rvm_gem/parameter/optional
+++ b/cdist/conf/type/__rvm_gem/parameter/optional
@@ -1 +1,2 @@
default
+state
diff --git a/cdist/conf/type/__rvm_gem/parameter/required b/cdist/conf/type/__rvm_gem/parameter/required
index 75f60bb8..58243a95 100644
--- a/cdist/conf/type/__rvm_gem/parameter/required
+++ b/cdist/conf/type/__rvm_gem/parameter/required
@@ -1,3 +1,2 @@
-state
gemset
user
diff --git a/cdist/conf/type/__rvm_gemset/man.text b/cdist/conf/type/__rvm_gemset/man.text
index 44c0c555..e85425f3 100644
--- a/cdist/conf/type/__rvm_gemset/man.text
+++ b/cdist/conf/type/__rvm_gemset/man.text
@@ -18,7 +18,7 @@ REQUIRED PARAMETERS
user::
The remote user account to use
state::
- Either "present" or "absent".
+ Either "present" or "absent", defaults to "present".
BOOLEAN PARAMETERS
-------------------
diff --git a/cdist/conf/type/__rvm_gemset/parameter/default/state b/cdist/conf/type/__rvm_gemset/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__rvm_gemset/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__postgres_role/parameter/required b/cdist/conf/type/__rvm_gemset/parameter/optional
similarity index 100%
rename from cdist/conf/type/__postgres_role/parameter/required
rename to cdist/conf/type/__rvm_gemset/parameter/optional
diff --git a/cdist/conf/type/__rvm_gemset/parameter/required b/cdist/conf/type/__rvm_gemset/parameter/required
index 5aea6f1e..4eb8387f 100644
--- a/cdist/conf/type/__rvm_gemset/parameter/required
+++ b/cdist/conf/type/__rvm_gemset/parameter/required
@@ -1,2 +1 @@
-state
user
diff --git a/cdist/conf/type/__rvm_ruby/man.text b/cdist/conf/type/__rvm_ruby/man.text
index dbbab85e..6419a4d4 100644
--- a/cdist/conf/type/__rvm_ruby/man.text
+++ b/cdist/conf/type/__rvm_ruby/man.text
@@ -18,7 +18,7 @@ REQUIRED PARAMETERS
user::
The remote user account to use
state::
- Either "present" or "absent".
+ Either "present" or "absent", defaults to "present".
BOOLEAN PARAMETERS
------------------
diff --git a/cdist/conf/type/__rvm_ruby/parameter/default/state b/cdist/conf/type/__rvm_ruby/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__rvm_ruby/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__process/parameter/required b/cdist/conf/type/__rvm_ruby/parameter/optional
similarity index 100%
rename from cdist/conf/type/__process/parameter/required
rename to cdist/conf/type/__rvm_ruby/parameter/optional
diff --git a/cdist/conf/type/__rvm_ruby/parameter/required b/cdist/conf/type/__rvm_ruby/parameter/required
index 5aea6f1e..4eb8387f 100644
--- a/cdist/conf/type/__rvm_ruby/parameter/required
+++ b/cdist/conf/type/__rvm_ruby/parameter/required
@@ -1,2 +1 @@
-state
user
diff --git a/cdist/conf/type/__ssh_authorized_keys/manifest b/cdist/conf/type/__ssh_authorized_keys/manifest
index 268b1fbe..5a9cfbb3 100755
--- a/cdist/conf/type/__ssh_authorized_keys/manifest
+++ b/cdist/conf/type/__ssh_authorized_keys/manifest
@@ -19,7 +19,7 @@
#
owner="$(cat "$__object/parameter/owner" 2>/dev/null || echo "$__object_id")"
-state="$(cat "$__object/parameter/present" 2>/dev/null || echo "present")"
+state="$(cat "$__object/parameter/state" 2>/dev/null)"
if [ -f "$__object/parameter/file" ]; then
file="$(cat "$__object/parameter/file")"
else
@@ -39,7 +39,7 @@ if [ ! -f "$__object/parameter/noparent" -o ! -f "$__object/parameter/nofile" ];
fi
if [ ! -f "$__object/parameter/noparent" ]; then
- # Ensure that the directory in which the authorized_keys shall be exists and
+ # Ensure that the directory in which the authorized_keys shall be exists and
# has the right permissions.
ssh_directory="${file%/*}"
__directory "$ssh_directory" --state present --parents \
@@ -56,19 +56,16 @@ if [ ! -f "$__object/parameter/noparent" -o ! -f "$__object/parameter/nofile" ];
fi
fi
-# 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 authorized_keys file
-entry="$__object/files/entry"
-echo "$prefix" > "$entry"
+(
if [ -f "$__object/parameter/comment" ]; then
- echo "# $(cat "$__object/parameter/comment")" >> "$entry"
+ echo "# $(cat "$__object/parameter/comment")"
fi
-cat "$__object/parameter/key" >> "$entry"
-# ensure we have a newline after keys
-echo >> "$entry"
-echo "$suffix" >> "$entry"
+cat "$__object/parameter/key"
+) | \
+__block "$__object_name" \
+ --file "$file" \
+ --prefix "#cdist:$__object_name" \
+ --suffix "#/cdist:$__object_name" \
+ --state "$state" \
+ --text -
diff --git a/cdist/conf/type/__ssh_authorized_keys/parameter/default/state b/cdist/conf/type/__ssh_authorized_keys/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__ssh_authorized_keys/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__start_on_boot/explorer/state b/cdist/conf/type/__start_on_boot/explorer/state
index 6fd0ea92..e9e4318e 100755
--- a/cdist/conf/type/__start_on_boot/explorer/state
+++ b/cdist/conf/type/__start_on_boot/explorer/state
@@ -1,6 +1,7 @@
#!/bin/sh
#
-# 2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2012-2013 Nico Schottelius (nico-cdist at schottelius.org)
+# 2013 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
#
@@ -23,25 +24,14 @@
os=$("$__explorer/os")
runlevel=$("$__explorer/runlevel")
+target_runlevel="$(cat "$__object/parameter/target_runlevel")"
name="$__object_id"
-
case "$os" in
archlinux)
- # convert bash array to shell
- daemons=$(grep ^DAEMONS /etc/rc.conf | sed -e 's/^.*=(//' -e 's/)$//')
-
- # absent, as long as not found
- state="absent"
-
- # iterate, last one wins.
- for daemon in $daemons; do
- if [ "$daemon" = "$name" -o "$daemon" = "@${name}" ]; then
- state="present"
- elif [ "$daemon" = "!${name}" ]; then
- state="absent"
- fi
- done
+ state=$(systemctl is-enabled "$name" >/dev/null 2>&1 \
+ && echo present \
+ || echo absent)
;;
debian|ubuntu|openwrt)
@@ -49,12 +39,24 @@ case "$os" in
[ -f "/etc/rc$runlevel.d/S"??"$name" ] || state="absent"
;;
- amazon|centos|fedora|owl|redhat|suse)
+ amazon|centos|fedora|owl|redhat)
state=$(chkconfig --level "$runlevel" "$name" || echo absent)
[ "$state" ] || state="present"
;;
-
- *)
+ suse)
+ # check for target if set, usable for boot. services in runlevel B
+ if [ "$target_runlevel" != 'default' ]; then
+ runlevel="$target_runlevel"
+ fi
+ # suses chkconfig has the same name, but works different ...
+ state=$(chkconfig --check "$name" "$runlevel" || echo absent)
+ [ "$state" ] || state="present"
+ ;;
+ gentoo)
+ state="present"
+ [ -f "/etc/runlevels/${target_runlevel}/${name}" ] || state="absent"
+ ;;
+ *)
echo "Unsupported os: $os" >&2
exit 1
;;
diff --git a/cdist/conf/type/__start_on_boot/gencode-remote b/cdist/conf/type/__start_on_boot/gencode-remote
index 7724e8c7..61b2b9fe 100755
--- a/cdist/conf/type/__start_on_boot/gencode-remote
+++ b/cdist/conf/type/__start_on_boot/gencode-remote
@@ -1,6 +1,7 @@
#!/bin/sh
#
-# 2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2012-2013 Nico Schottelius (nico-cdist at schottelius.org)
+# 2013 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
#
@@ -19,8 +20,9 @@
#
#
-state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo present)"
+state_should="$(cat "$__object/parameter/state")"
state_is=$(cat "$__object/explorer/state")
+target_runlevel="$(cat "$__object/parameter/target_runlevel")"
# Short circuit if nothing is to be done
[ "$state_should" = "$state_is" ] && exit 0
@@ -32,17 +34,15 @@ case "$state_should" in
present)
case "$os" in
archlinux)
- echo "sed 's/^\\(DAEMONS=.*\\))/\\1 $name)/' /etc/rc.conf > /etc/rc.conf.cdist-tmp"
- echo "mv /etc/rc.conf.cdist-tmp /etc/rc.conf"
+ echo "systemctl enable \"$name\""
;;
debian|ubuntu)
echo "update-rc.d \"$name\" defaults >/dev/null"
;;
-# FIXME: Disabled until the explorer is checked
-# gentoo)
-# echo rc-update add \"$name\" default
-# ;;
+ gentoo)
+ echo rc-update add \"$name\" \"$target_runlevel\"
+ ;;
amazon|centos|fedora|owl|redhat|suse)
echo chkconfig \"$name\" on
@@ -65,19 +65,15 @@ case "$state_should" in
absent)
case "$os" 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 /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"
+ echo "systemctl disable \"$name\""
;;
debian|ubuntu)
echo update-rc.d -f \"$name\" remove
;;
-# FIXME: Disabled until the explorer is checked
-# gentoo)
-# echo rc-update del \"$name\"
-# ;;
+ gentoo)
+ echo rc-update del \"$name\" \"$target_runlevel\"
+ ;;
centos|fedora|owl|redhat|suse)
echo chkconfig \"$name\" off
diff --git a/cdist/conf/type/__start_on_boot/man.text b/cdist/conf/type/__start_on_boot/man.text
index 6d804884..dfada6d8 100644
--- a/cdist/conf/type/__start_on_boot/man.text
+++ b/cdist/conf/type/__start_on_boot/man.text
@@ -14,7 +14,7 @@ This cdist type allows you to enable or disable stuff to be started
at boot of your operating system.
Warning: This type has not been tested intensively and is not fully
-supported (i.e. gentoo and *bsd are not implemented).
+supported (i.e. *bsd are not implemented).
REQUIRED PARAMETERS
@@ -25,6 +25,8 @@ OPTIONAL PARAMETERS
-------------------
state::
Either "present" or "absent", defaults to "present"
+target_runlevel::
+ Runlevel which should be modified, defaults to "default" (only used on gentoo systems).
EXAMPLES
diff --git a/cdist/conf/type/__start_on_boot/parameter/default/state b/cdist/conf/type/__start_on_boot/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__start_on_boot/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__start_on_boot/parameter/default/target_runlevel b/cdist/conf/type/__start_on_boot/parameter/default/target_runlevel
new file mode 100644
index 00000000..4ad96d51
--- /dev/null
+++ b/cdist/conf/type/__start_on_boot/parameter/default/target_runlevel
@@ -0,0 +1 @@
+default
diff --git a/cdist/conf/type/__start_on_boot/parameter/optional b/cdist/conf/type/__start_on_boot/parameter/optional
index ff72b5c7..91685caf 100644
--- a/cdist/conf/type/__start_on_boot/parameter/optional
+++ b/cdist/conf/type/__start_on_boot/parameter/optional
@@ -1 +1,2 @@
state
+target_runlevel
diff --git a/cdist/conf/type/__update_alternatives/gencode-remote b/cdist/conf/type/__update_alternatives/gencode-remote
new file mode 100755
index 00000000..19ea9968
--- /dev/null
+++ b/cdist/conf/type/__update_alternatives/gencode-remote
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# 2013 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 .
+#
+#
+# Setup alternative - no standard way to create, always set
+#
+
+path="$(cat "$__object/parameter/path")"
+name="$__object_id"
+echo "update-alternatives --quiet --set '$name' '$path'"
diff --git a/cdist/conf/type/__update_alternatives/man.text b/cdist/conf/type/__update_alternatives/man.text
new file mode 100644
index 00000000..2bcc1874
--- /dev/null
+++ b/cdist/conf/type/__update_alternatives/man.text
@@ -0,0 +1,43 @@
+cdist-type__update_alternatives(7)
+==================================
+Nico Schottelius
+
+
+NAME
+----
+cdist-type__update_alternatives - Configure alternatives
+
+
+DESCRIPTION
+-----------
+On Debian and alike systems update-alternatives(1) can be used
+to setup alternatives for various programs.
+One of the most common used targets is the "editor".
+
+
+REQUIRED PARAMETERS
+-------------------
+path::
+ Use this path for the given alternative
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+# Setup vim as the default editor
+__update_alternatives editor --path /usr/bin/vim.basic
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+- cdist-type__debconf_set_selections(7)
+- update-alternatives(8)
+
+
+COPYING
+-------
+Copyright \(C) 2013 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/__update_alternatives/parameter/required b/cdist/conf/type/__update_alternatives/parameter/required
new file mode 100644
index 00000000..e7a8fd4d
--- /dev/null
+++ b/cdist/conf/type/__update_alternatives/parameter/required
@@ -0,0 +1 @@
+path
diff --git a/cdist/conf/type/__user/TODO b/cdist/conf/type/__user/TODO
deleted file mode 100644
index fa6aeee7..00000000
--- a/cdist/conf/type/__user/TODO
+++ /dev/null
@@ -1,2 +0,0 @@
-- delete users
-
diff --git a/cdist/conf/type/__user/gencode-remote b/cdist/conf/type/__user/gencode-remote
index baa6f354..463fbe49 100755
--- a/cdist/conf/type/__user/gencode-remote
+++ b/cdist/conf/type/__user/gencode-remote
@@ -2,6 +2,7 @@
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
+# 2013 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
#
@@ -21,11 +22,14 @@
#
# Manage users.
#
+#set -x
name="$__object_id"
os="$(cat "$__global/explorer/os")"
+state=$(cat "$__object/parameter/state")
+
# 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.
@@ -39,75 +43,100 @@ shorten_property() {
password) ret="-p";;
shell) ret="-s";;
uid) ret="-u";;
+ create-home) ret="-m";;
+ system) ret="-r";;
esac
echo "$ret"
}
-cd "$__object/parameter"
-if grep -q "^${name}:" "$__object/explorer/passwd"; then
- for property in $(ls .); do
- new_value="$(cat "$property")"
- unset current_value
+if [ "$state" = "present" ]; then
+ cd "$__object/parameter"
+ if grep -q "^${name}:" "$__object/explorer/passwd"; then
+ for property in $(ls .); do
+ new_value="$(cat "$property")"
+ unset current_value
- file="$__object/explorer/passwd"
+ file="$__object/explorer/passwd"
- case "$property" in
- gid)
- if $(echo "$new_value" | grep -q '^[0-9][0-9]*$'); then
- field=4
+ case "$property" in
+ gid)
+ if $(echo "$new_value" | grep -q '^[0-9][0-9]*$'); then
+ field=4
+ else
+ # We were passed a group name. Compare the gid in
+ # the user's /etc/passwd entry with the gid of the
+ # group returned by the group explorer.
+ gid_from_group=$(awk -F: '{ print $3 }' "$__object/explorer/group")
+ gid_from_passwd=$(awk -F: '{ print $4 }' "$file")
+ if [ "$gid_from_group" != "$gid_from_passwd" ]; then
+ current_value="$gid_from_passwd"
+ else
+ current_value="$new_value"
+ fi
+ fi
+ ;;
+ password)
+ field=2
+ file="$__object/explorer/shadow"
+ ;;
+ comment) field=5 ;;
+ home) field=6 ;;
+ shell) field=7 ;;
+ uid) field=3 ;;
+ create-home) continue;; # Does not apply to user modification
+ system) continue;; # Does not apply to user modification
+ state) continue;; # Does not apply to user modification
+ remove-home) continue;; # Does not apply to user modification
+ esac
+
+ # If we haven't already set $current_value above, pull it from the
+ # appropriate file/field.
+ if [ -z "$current_value" ]; then
+ export field
+ current_value="$(awk -F: '{ print $ENVIRON["field"] }' < "$file")"
+ fi
+
+ if [ "$new_value" != "$current_value" ]; then
+ set -- "$@" "$(shorten_property $property)" \'$new_value\'
+ fi
+ done
+
+ if [ $# -gt 0 ]; then
+ echo mod >> "$__messages_out"
+ if [ "$os" = "freebsd" ]; then
+ echo pw usermod "$@" "$name"
+ else
+ echo usermod "$@" "$name"
+ fi
+ else
+ true
+ fi
+ else
+ echo add >> "$__messages_out"
+ for property in $(ls .); do
+ [ "$property" = "state" ] && continue
+ [ "$property" = "remove-home" ] && continue
+ new_value="$(cat "$property")"
+ if [ -z "$new_value" ];then # Boolean values have no value
+ set -- "$@" "$(shorten_property $property)"
else
- # We were passed a group name. Compare the gid in
- # the user's /etc/passwd entry with the gid of the
- # group returned by the group explorer.
- gid_from_group=$(awk -F: '{ print $3 }' "$__object/explorer/group")
- gid_from_passwd=$(awk -F: '{ print $4 }' "$file")
- if [ "$gid_from_group" != "$gid_from_passwd" ]; then
- current_value="$gid_from_passwd"
- else
- current_value="$new_value"
- fi
+ set -- "$@" "$(shorten_property $property)" \'$new_value\'
fi
- ;;
- password)
- field=2
- file="$__object/explorer/shadow"
- ;;
- comment) field=5 ;;
- home) field=6 ;;
- shell) field=7 ;;
- uid) field=3 ;;
- esac
+ done
- # If we haven't already set $current_value above, pull it from the
- # appropriate file/field.
- if [ -z "$current_value" ]; then
- export field
- current_value="$(awk -F: '{ print $ENVIRON["field"] }' < "$file")"
- fi
-
- if [ "$new_value" != "$current_value" ]; then
- set -- "$@" "$(shorten_property $property)" \'$new_value\'
- fi
- done
-
- if [ $# -gt 0 ]; then
- if [ "$os" = "freebsd" ]; then
- echo pw usermod "$@" "$name"
- else
- echo usermod "$@" "$name"
- fi
- else
- true
- fi
+ if [ "$os" = "freebsd" ]; then
+ echo pw useradd "$@" "$name"
+ else
+ echo useradd "$@" "$name"
+ fi
+ fi
else
- for property in $(ls .); do
- new_value="$(cat "$property")"
- set -- "$@" "$(shorten_property $property)" \'$new_value\'
- done
-
- if [ "$os" = "freebsd" ]; then
- echo pw useradd "$@" "$name"
- else
- echo useradd "$@" "$name"
- fi
+ if grep -q "^${name}:" "$__object/explorer/passwd"; then
+ #user exists, but state != present, so delete it
+ if [ -f "$__object/parameter/remove-home" ]; then
+ echo userdel -r "${name}"
+ else
+ echo userdel "${name}"
+ fi
+ fi
fi
diff --git a/cdist/conf/type/__user/man.text b/cdist/conf/type/__user/man.text
index 9db4a9f0..be70ec12 100644
--- a/cdist/conf/type/__user/man.text
+++ b/cdist/conf/type/__user/man.text
@@ -20,18 +20,37 @@ None.
OPTIONAL PARAMETERS
-------------------
+state::
+ absent or present, defaults to present
comment::
- see usermod(8)
+ see usermod(8)
home::
- see above
+ see above
gid::
- see above
+ see above
password::
- see above
+ see above
shell::
- see above
+ see above
uid::
- see above
+ see above
+
+BOOLEAN PARAMETERS
+------------------
+system::
+ see useradd(8), apply only on user create
+create-home::
+ see useradd(8), apply only on user create
+remove-home::
+ see userdel(8), apply only on user delete
+
+
+MESSAGES
+--------
+mod::
+ User is modified
+add::
+ New user added
EXAMPLES
@@ -44,8 +63,14 @@ __user foobar
# Same but with a different shell
__user foobar --shell /bin/zsh
+# Same but for a system account
+__user foobar --system
+
# Set explicit uid and home
__user foobar --uid 1001 --shell /bin/zsh --home /home/foobar
+
+# Drop user if exists
+__user foobar --state absent
--------------------------------------------------------------------------------
diff --git a/cdist/conf/type/__user/parameter/boolean b/cdist/conf/type/__user/parameter/boolean
new file mode 100644
index 00000000..83afdebe
--- /dev/null
+++ b/cdist/conf/type/__user/parameter/boolean
@@ -0,0 +1,3 @@
+create-home
+remove-home
+system
diff --git a/cdist/conf/type/__user/parameter/default/state b/cdist/conf/type/__user/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__user/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__user/parameter/optional b/cdist/conf/type/__user/parameter/optional
index e3cf52d5..de6c3838 100644
--- a/cdist/conf/type/__user/parameter/optional
+++ b/cdist/conf/type/__user/parameter/optional
@@ -1,3 +1,4 @@
+state
comment
home
gid
diff --git a/cdist/conf/type/__user_groups/gencode-remote b/cdist/conf/type/__user_groups/gencode-remote
index c5e4a35e..9f11dd16 100755
--- a/cdist/conf/type/__user_groups/gencode-remote
+++ b/cdist/conf/type/__user_groups/gencode-remote
@@ -19,7 +19,7 @@
#
user="$(cat "$__object/parameter/user" 2>/dev/null || echo "$__object_id")"
-state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")"
+state_should="$(cat "$__object/parameter/state")"
mkdir "$__object/files"
# file has to be sorted for comparison with `comm`
diff --git a/cdist/conf/type/__user_groups/parameter/default/state b/cdist/conf/type/__user_groups/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__user_groups/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__zypper_repo/explorer/all_repo_ids b/cdist/conf/type/__zypper_repo/explorer/all_repo_ids
new file mode 100644
index 00000000..b37d8ac5
--- /dev/null
+++ b/cdist/conf/type/__zypper_repo/explorer/all_repo_ids
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# 2013 Daniel Heule (hda at sfs.biz)
+#
+# 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 .
+#
+#
+# Retrieve all repo id nummbers - parsed zypper output
+#
+#
+echo $(zypper lr | cut -d'|' -f 1 | grep -E '^[0-9]')
diff --git a/cdist/conf/type/__zypper_repo/explorer/enabled_repo_ids b/cdist/conf/type/__zypper_repo/explorer/enabled_repo_ids
new file mode 100644
index 00000000..2dfb946f
--- /dev/null
+++ b/cdist/conf/type/__zypper_repo/explorer/enabled_repo_ids
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# 2013 Daniel Heule (hda at sfs.biz)
+#
+# 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 .
+#
+#
+# Retrieve all repo id nummbers from enabled repos - parsed zypper output
+#
+#
+# simpler command which works only on SLES11 SP3 or newer:
+# echo $(zypper lr -E | cut -d'|' -f 1 | grep -E '^[0-9]')
+echo $(zypper lr | grep -E '^[0-9]([^|]+\|){3,3} Yes' | cut -d'|' -f 1)
diff --git a/cdist/conf/type/__zypper_repo/explorer/repo_id b/cdist/conf/type/__zypper_repo/explorer/repo_id
new file mode 100644
index 00000000..83a698b7
--- /dev/null
+++ b/cdist/conf/type/__zypper_repo/explorer/repo_id
@@ -0,0 +1,29 @@
+#!/bin/sh
+#
+# 2013 Daniel Heule (hda at sfs.biz)
+#
+# 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 .
+#
+#
+# Retrieve the id from the repo with the uri from parameter repo_uri - parsed zypper output
+#
+#
+if [ -f "$__object/parameter/repo_uri" ]; then
+ uri="$(cat "$__object/parameter/repo_uri")"
+else
+ uri="$__object_id"
+fi
+echo $(zypper lr -u | grep -E "\<$uri\>" | cut -d'|' -f 1 | grep -E '^[0-9]' )
diff --git a/cdist/conf/type/__zypper_repo/gencode-remote b/cdist/conf/type/__zypper_repo/gencode-remote
new file mode 100644
index 00000000..f678552b
--- /dev/null
+++ b/cdist/conf/type/__zypper_repo/gencode-remote
@@ -0,0 +1,98 @@
+#!/bin/sh
+#
+# 2013 Daniel Heule (hda at sfs.biz)
+#
+# 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 repo services with Zypper (mostly suse)
+#
+
+# Debug
+#exec >&2
+#set -x
+
+zypper_def_opts=" -q "
+
+if [ -f "$__object/parameter/repo_desc" ]; then
+ desc="$(cat "$__object/parameter/repo_desc")"
+else
+ desc="$__object_id"
+fi
+
+if [ -f "$__object/parameter/repo_uri" ]; then
+ uri="$(cat "$__object/parameter/repo_uri")"
+else
+ uri="$__object_id"
+fi
+
+if [ -f "$__object/parameter/repo_id" ]; then
+ id="$(cat "$__object/parameter/repo_id")"
+else
+ id="$__object_id"
+fi
+
+state="$(cat "$__object/parameter/state")"
+
+repo_id="$(cat "$__object/explorer/repo_id")"
+
+act_id=""
+if grep -q "$id" "$__object/explorer/all_repo_ids"; then
+ act_id="$id"
+elif grep -q "$repo_id" "$__object/explorer/all_repo_ids"; then
+ act_id="$repo_id"
+fi
+
+repostate="disabled"
+if grep -q "$act_id" "$__object/explorer/enabled_repo_ids"; then
+ repostate="enabled"
+fi
+
+
+case "$state" in
+ present)
+ if [ -z "$desc" ] || [ -z "$uri" ]; then
+ echo "parameter repo_desc and repo_uri for $state needed" >&2
+ exit 4
+ fi
+ if [ -z "$repo_id" ]; then
+ # Repo not present, so we need to create it
+ echo zypper $zypper_def_opts addrepo "'$uri'" "'$desc'"
+ fi
+ ;;
+ absent)
+ if [ ! -z "$act_id" ]; then
+ # Repo present (act_id not ""), so we ned to delete it
+ echo zypper $zypper_def_opts removerepo "$act_id"
+ fi
+ ;;
+ enabled)
+ if [ ! -z "$act_id" ] && [ "$repostate" = "disabled" ]; then
+ # Repo present (act_id not "") and repostate not enabled, so a enable call is needed
+ echo zypper $zypper_def_opts modifyrepo -e "$act_id"
+ fi
+ ;;
+ disabled)
+ if [ ! -z "$act_id" ] && [ "$repostate" = "enabled" ]; then
+ # Repo present (act_id not "") and repostate enabled, so a disable call is needed
+ echo zypper $zypper_def_opts modifyrepo -d "$act_id"
+ fi
+ ;;
+ *)
+ echo "Unknown state: $state" >&2
+ exit 1
+ ;;
+esac
diff --git a/cdist/conf/type/__zypper_repo/man.text b/cdist/conf/type/__zypper_repo/man.text
new file mode 100644
index 00000000..6ea88f16
--- /dev/null
+++ b/cdist/conf/type/__zypper_repo/man.text
@@ -0,0 +1,73 @@
+cdist-type__zypper_repo(7)
+==========================
+Daniel Heule
+
+
+NAME
+----
+cdist-type__zypper_repo - repository management with zypper
+
+
+DESCRIPTION
+-----------
+zypper is usually used on the SuSE distribution to manage repositories.
+
+
+REQUIRED PARAMETERS
+-------------------
+None
+
+
+OPTIONAL PARAMETERS
+-------------------
+state::
+ Either "present" or "absent" or "enabled" or "disabled", defaults to "present" +
+ #present# - make sure that the repo is aviable, needs repo_uri and repo_desc +
+ for all following states, the repo can be searched via repo_id or repo_uri +
+ #absent# - drop the repo if found +
+ #enabled# - a repo can have state disabled if installed via zypper service (ris), in this case, you can enable the repo +
+ #disabled# - instead of absent (drop), a repo can also set to disabled, wich makes it inaccessible +
+
+repo_uri::
+ If supplied, use the uri and not the object id as repo uri.
+
+repo_desc::
+ If supplied, use the description and not the object id as repo description, only used if the state is present and the repo has to be created
+
+repo_id::
+ If supplied, use the id and not the object id as repo id, can be used with state absent, enabled and disabled
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+# Ensure testrepo in installed
+__zypper_repo testrepo --state present --repo_uri http://url.to.your.repo/with/path
+
+# Drop repo by repo uri
+__zypper_repo testrepo --state absent --repo_uri http://url.to.your.repo/with/path
+
+# Drop repo by id number (attention: repos are always numbered from 1 to max)
+__zypper_repo testrepo --state absent --repo_id 1
+
+# enable repo by id
+__zypper_repo testrepo2 --state enabled --repo_id 2
+
+# enable repo by uri
+__zypper_repo testrepo3 --state enabled --repo_uri http://url.to.your.repo/with/path
+
+# disable a repo works like enabling it
+__zypper_repo testrepo4 --state disabled --repo_id 4
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+
+
+COPYING
+-------
+Copyright \(C) 2013 Daniel Heule. 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/__zypper_repo/parameter/default/state b/cdist/conf/type/__zypper_repo/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__zypper_repo/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__zypper_repo/parameter/optional b/cdist/conf/type/__zypper_repo/parameter/optional
new file mode 100644
index 00000000..6f5a8325
--- /dev/null
+++ b/cdist/conf/type/__zypper_repo/parameter/optional
@@ -0,0 +1,4 @@
+state
+repo_uri
+repo_desc
+repo_id
diff --git a/cdist/conf/type/__zypper_service/explorer/repo_ids b/cdist/conf/type/__zypper_service/explorer/repo_ids
new file mode 100644
index 00000000..e831b76c
--- /dev/null
+++ b/cdist/conf/type/__zypper_service/explorer/repo_ids
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# 2013 Daniel Heule (hda at sfs.biz)
+#
+# 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 services with Zypper (mostly suse)
+#
+#
+# simpler command which works only on SLES11 SP3 or newer:
+# echo $(zypper lr -u -E | cut -d'|' -f 1 | grep -E '^[0-9]')
+# on older systems, zypper doesn't know the parameter -E
+echo $(zypper lr -u | grep -E '^([^|]+\|){3,3} Yes' | cut -d'|' -f 1 | grep -E '^[0-9]')
diff --git a/cdist/conf/type/__zypper_service/explorer/service_id b/cdist/conf/type/__zypper_service/explorer/service_id
new file mode 100644
index 00000000..9c3d3a2d
--- /dev/null
+++ b/cdist/conf/type/__zypper_service/explorer/service_id
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# 2013 Daniel Heule (hda at sfs.biz)
+#
+# 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 services with Zypper (mostly suse)
+#
+if [ -f "$__object/parameter/service_uri" ]; then
+ uri="$(cat "$__object/parameter/service_uri")"
+else
+ uri="/$__object_id"
+fi
+# simpler command which works only on SLES11 SP3 or newer:
+# echo $(zypper ls -u -E | grep -E "\<$uri\>" | cut -d'|' -f 1 )
+echo $(zypper ls -u | grep -E '^([^|]+\|){3,3} Yes' | grep -E "\<$uri\>" | cut -d'|' -f 1 )
diff --git a/cdist/conf/type/__zypper_service/explorer/service_ids b/cdist/conf/type/__zypper_service/explorer/service_ids
new file mode 100644
index 00000000..0f1f4186
--- /dev/null
+++ b/cdist/conf/type/__zypper_service/explorer/service_ids
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# 2013 Daniel Heule (hda at sfs.biz)
+#
+# 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 services with Zypper (mostly suse)
+#
+# simpler command which works only on SLES11 SP3 or newer:
+# echo $(zypper ls -u -E | cut -d'|' -f 1 | grep -E '^[0-9]')
+echo $(zypper ls -u | grep -E '^([^|]+\|){3,3} Yes' | cut -d'|' -f 1 | grep -E '^[0-9]')
diff --git a/cdist/conf/type/__zypper_service/explorer/service_uri b/cdist/conf/type/__zypper_service/explorer/service_uri
new file mode 100644
index 00000000..2f4f8960
--- /dev/null
+++ b/cdist/conf/type/__zypper_service/explorer/service_uri
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# 2013 Daniel Heule (hda at sfs.biz)
+#
+# 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 services with Zypper (mostly suse)
+#
+if [ -f "$__object/parameter/service_uri" ]; then
+ uri="$(cat "$__object/parameter/service_uri")"
+else
+ uri="/$__object_id"
+fi
+# simpler command which works only on SLES11 SP3 or newer:
+# echo $(zypper ls -u -E | grep -E "\<$uri\>" | cut -d'|' -f 7)
+echo $(zypper ls -u | grep -E '^([^|]+\|){3,3} Yes' | grep -E "\<$uri\>" | cut -d'|' -f 7 )
diff --git a/cdist/conf/type/__zypper_service/gencode-remote b/cdist/conf/type/__zypper_service/gencode-remote
new file mode 100644
index 00000000..df8d1660
--- /dev/null
+++ b/cdist/conf/type/__zypper_service/gencode-remote
@@ -0,0 +1,85 @@
+#!/bin/sh
+#
+# 2013 Daniel Heule (hda at sfs.biz)
+#
+# 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 services with Zypper (mostly suse)
+#
+
+# Debug
+#exec >&2
+#set -x
+
+zypper_def_opts=" -q "
+
+if [ -f "$__object/parameter/service_desc" ]; then
+ desc="$(cat "$__object/parameter/service_desc")"
+else
+ desc="$__object_id"
+fi
+
+if [ -f "$__object/parameter/service_uri" ]; then
+ uri="$(cat "$__object/parameter/service_uri")"
+else
+ uri="$__object_id"
+fi
+
+state_should="$(cat "$__object/parameter/state")"
+stype="$(cat "$__object/parameter/type")"
+
+exp_uri="$(cat "$__object/explorer/service_uri")"
+exp_id="$(cat "$__object/explorer/service_id")"
+
+# we need this list to remove ids, but we must do this in reverse order
+exp_ids="$(cat "$__object/explorer/service_ids" | rev)"
+
+if [ "$uri" = "$exp_uri" ] ; then
+ state_is="present"
+else
+ state_is="absent"
+fi
+
+# remove all other services if needed ...
+if [ -f "$__object/parameter/remove-all-other-services" ]; then
+ # file exists -> True
+ for i in $exp_ids; do
+ if [ "$i" != "$exp_id" ] ; then
+ echo zypper $zypper_def_opts removeservice "$i" "&>/dev/null"
+ fi
+ done
+ echo zypper $zypper_def_opts refs "&>/dev/null"
+fi
+
+
+# Exit if nothing is needed to be done
+[ "$state_is" = "$state_should" ] && exit 0
+
+case "$state_should" in
+ present)
+ echo zypper $zypper_def_opts addservice -t "$stype" "$uri" \"$desc\"
+ echo zypper $zypper_def_opts refs
+ ;;
+ absent)
+ echo zypper $zypper_def_opts removeservice "$service_id"
+ echo zypper $zypper_def_opts refs
+ ;;
+ *)
+ echo "Unknown state: $state_should" >&2
+ exit 1
+ ;;
+esac
diff --git a/cdist/conf/type/__zypper_service/man.text b/cdist/conf/type/__zypper_service/man.text
new file mode 100644
index 00000000..31543d93
--- /dev/null
+++ b/cdist/conf/type/__zypper_service/man.text
@@ -0,0 +1,67 @@
+cdist-type__zypper_service(7)
+=============================
+Daniel Heule
+
+
+NAME
+----
+cdist-type__zypper_service - service management with zypper
+
+
+DESCRIPTION
+-----------
+zypper is usually used on SuSE systems to manage services.
+
+
+REQUIRED PARAMETERS
+-------------------
+service_uri::
+ Uri of the service
+
+
+OPTIONAL PARAMETERS
+-------------------
+service_desc::
+ If supplied, use the service_desc and not the object id as descritpion for the service.
+
+state::
+ Either "present" or "absent", defaults to "present"
+
+type::
+ Defaults to "ris", the standard type of services at SLES11. For other values, see manpage of zypper.
+
+
+BOOLEAN PARAMETERS
+------------------
+remove-all-other-services::
+ Drop all other services found on the target host before adding the new one.
+
+remove-all-repos::
+ If supplied, remove all existing repos prior to setup the new service.
+
+
+EXAMPLES
+--------
+
+--------------------------------------------------------------------------------
+# Ensure that internal SLES11 SP3 RIS is in installed and all other services and repos are discarded
+__zypper_service INTERNAL_SLES11_SP3 --service_desc "Internal SLES11 SP3 RIS" --service_uri "http://path/to/your/ris/dir" --remove-all-other-services --remove-all-repos
+
+# Ensure that internal SLES11 SP3 RIS is in installed, no changes to ohter services or repos
+__zypper_service INTERNAL_SLES11_SP3 --service_desc "Internal SLES11 SP3 RIS" --service_uri "http://path/to/your/ris/dir"
+
+# Drop service by uri, no changes to ohter services or repos
+__zypper_service INTERNAL_SLES11_SP3 --state absent --service_uri "http://path/to/your/ris/dir"
+
+--------------------------------------------------------------------------------
+
+
+SEE ALSO
+--------
+- cdist-type(7)
+
+
+COPYING
+-------
+Copyright \(C) 2013 Daniel Heule. 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/__zypper_service/manifest b/cdist/conf/type/__zypper_service/manifest
new file mode 100644
index 00000000..aa4a39a3
--- /dev/null
+++ b/cdist/conf/type/__zypper_service/manifest
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# 2013 Daniel Heule (hda at sfs.biz)
+#
+# 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 services with Zypper (mostly suse)
+#
+
+# Debug
+#exec >&2
+#set -x
+
+zypper_def_opts=" -q "
+
+if [ -f "$__object/parameter/service_uri" ]; then
+ uri="$(cat "$__object/parameter/service_uri")"
+else
+ uri="$__object_id"
+fi
+
+state_should="$(cat "$__object/parameter/state")"
+
+exp_uri="$(cat "$__object/explorer/service_uri")"
+
+if [ "$uri" = "$exp_uri" ] ; then
+ state_is="present"
+else
+ state_is="absent"
+fi
+
+
+# Exit if nothing is needed to be done
+[ "$state_is" = "$state_should" ] && exit 0
+
+# we need this list to remove ids, but we must do this in reverse order
+exp_repos="$(cat "$__object/explorer/repo_ids" | rev)"
+
+# boolean parameter
+if [ -f "$__object/parameter/remove-all-repos" ]; then
+ # file exists -> True
+ for i in $exp_repos; do
+ __zypper_repo "droprepo${i}" --state absent --repo_id "${i}"
+ done
+fi
diff --git a/cdist/conf/type/__zypper_service/parameter/boolean b/cdist/conf/type/__zypper_service/parameter/boolean
new file mode 100644
index 00000000..ca711ded
--- /dev/null
+++ b/cdist/conf/type/__zypper_service/parameter/boolean
@@ -0,0 +1,2 @@
+remove-all-other-services
+remove-all-repos
diff --git a/cdist/conf/type/__zypper_service/parameter/default/state b/cdist/conf/type/__zypper_service/parameter/default/state
new file mode 100644
index 00000000..e7f6134f
--- /dev/null
+++ b/cdist/conf/type/__zypper_service/parameter/default/state
@@ -0,0 +1 @@
+present
diff --git a/cdist/conf/type/__zypper_service/parameter/default/type b/cdist/conf/type/__zypper_service/parameter/default/type
new file mode 100644
index 00000000..b928830f
--- /dev/null
+++ b/cdist/conf/type/__zypper_service/parameter/default/type
@@ -0,0 +1 @@
+ris
diff --git a/cdist/conf/type/__zypper_service/parameter/optional b/cdist/conf/type/__zypper_service/parameter/optional
new file mode 100644
index 00000000..b26c78d8
--- /dev/null
+++ b/cdist/conf/type/__zypper_service/parameter/optional
@@ -0,0 +1,3 @@
+service_desc
+state
+type
diff --git a/cdist/conf/type/__zypper_service/parameter/required b/cdist/conf/type/__zypper_service/parameter/required
new file mode 100644
index 00000000..2b4645ee
--- /dev/null
+++ b/cdist/conf/type/__zypper_service/parameter/required
@@ -0,0 +1 @@
+service_uri
diff --git a/cdist/config.py b/cdist/config.py
index 9af25b75..73ba4710 100644
--- a/cdist/config.py
+++ b/cdist/config.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
-# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
+# 2010-2013 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@@ -20,7 +20,258 @@
#
#
-import cdist.config_install
+import logging
+import os
+import shutil
+import sys
+import time
+import pprint
-class Config(cdist.config_install.ConfigInstall):
- pass
+import cdist
+
+import cdist.exec.local
+import cdist.exec.remote
+
+from cdist import core
+
+class Config(object):
+ """Cdist main class to hold arbitrary data"""
+
+ def __init__(self, local, remote, dry_run=False):
+
+ self.local = local
+ self.remote = remote
+ self.log = logging.getLogger(self.local.target_host)
+ self.dry_run = dry_run
+
+ self.explorer = core.Explorer(self.local.target_host, self.local, self.remote)
+ self.manifest = core.Manifest(self.local.target_host, self.local)
+ self.code = core.Code(self.local.target_host, self.local, self.remote)
+
+ def _init_files_dirs(self):
+ """Prepare files and directories for the run"""
+ self.local.create_files_dirs()
+ self.remote.create_files_dirs()
+
+ @classmethod
+ def commandline(cls, args):
+ """Configure remote system"""
+ import multiprocessing
+
+ # FIXME: Refactor relict - remove later
+ log = logging.getLogger("cdist")
+
+ 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=cls.onehost, args=(host, args, True))
+ process[host].start()
+ else:
+ try:
+ cls.onehost(host, args, 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 configure the following hosts: " +
+ " ".join(failed_hosts))
+
+ @classmethod
+ def onehost(cls, host, args, parallel):
+ """Configure ONE system"""
+
+ log = logging.getLogger(host)
+
+ try:
+ local = cdist.exec.local.Local(
+ target_host=host,
+ initial_manifest=args.manifest,
+ base_path=args.out_path,
+ add_conf_dirs=args.conf_dir)
+
+ remote = cdist.exec.remote.Remote(
+ target_host=host,
+ remote_exec=args.remote_exec,
+ remote_copy=args.remote_copy)
+
+ c = cls(local, remote, dry_run=args.dry_run)
+ c.run()
+
+ except cdist.Error as e:
+ log.error(e)
+ if parallel:
+ # We are running in our own process here, need to sys.exit!
+ 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 run(self):
+ """Do what is most often done: deploy & cleanup"""
+ start_time = time.time()
+
+ self._init_files_dirs()
+
+ self.explorer.run_global_explorers(self.local.global_explorer_out_path)
+ self.manifest.run_initial_manifest(self.local.initial_manifest)
+ self.iterate_until_finished()
+
+ self.local.save_cache()
+ self.log.info("Finished successful run in %s seconds", time.time() - start_time)
+
+
+ def object_list(self):
+ """Short name for object list retrieval"""
+ for cdist_object in core.CdistObject.list_objects(self.local.object_path,
+ self.local.type_path):
+ if cdist_object.cdist_type.is_install:
+ self.log.debug("Running in config mode, ignoring install object: {0}".format(cdist_object))
+ else:
+ yield cdist_object
+
+
+ def iterate_once(self):
+ """
+ Iterate over the objects once - helper method for
+ iterate_until_finished
+ """
+ objects_changed = False
+
+ for cdist_object in self.object_list():
+ if cdist_object.requirements_unfinished(cdist_object.requirements):
+ """We cannot do anything for this poor object"""
+ continue
+
+ if cdist_object.state == core.CdistObject.STATE_UNDEF:
+ """Prepare the virgin object"""
+
+ self.object_prepare(cdist_object)
+ objects_changed = True
+
+ if cdist_object.requirements_unfinished(cdist_object.autorequire):
+ """The previous step created objects we depend on - wait for them"""
+ continue
+
+ if cdist_object.state == core.CdistObject.STATE_PREPARED:
+ self.object_run(cdist_object)
+ objects_changed = True
+
+ return objects_changed
+
+
+ def iterate_until_finished(self):
+ """
+ Go through all objects and solve them
+ one after another
+ """
+
+ objects_changed = True
+
+ while objects_changed:
+ objects_changed = self.iterate_once()
+
+ # Check whether all objects have been finished
+ unfinished_objects = []
+ for cdist_object in self.object_list():
+ if not cdist_object.state == cdist_object.STATE_DONE:
+ unfinished_objects.append(cdist_object)
+
+ if unfinished_objects:
+ info_string = []
+
+ for cdist_object in unfinished_objects:
+
+ requirement_names = []
+ autorequire_names = []
+
+ for requirement in cdist_object.requirements_unfinished(cdist_object.requirements):
+ requirement_names.append(requirement.name)
+
+ for requirement in cdist_object.requirements_unfinished(cdist_object.autorequire):
+ autorequire_names.append(requirement.name)
+
+ requirements = ", ".join(requirement_names)
+ autorequire = ", ".join(autorequire_names)
+ info_string.append("%s requires: %s autorequires: %s" % (cdist_object.name, requirements, autorequire))
+
+ raise cdist.UnresolvableRequirementsError("The requirements of the following objects could not be resolved: %s" %
+ ("; ".join(info_string)))
+
+ def object_prepare(self, cdist_object):
+ """Prepare object: Run type explorer + manifest"""
+ self.log.info("Running manifest and explorers for " + cdist_object.name)
+ self.explorer.run_type_explorers(cdist_object)
+ self.manifest.run_type_manifest(cdist_object)
+ cdist_object.state = core.CdistObject.STATE_PREPARED
+
+ def object_run(self, cdist_object):
+ """Run gencode and code for an object"""
+
+ self.log.debug("Trying to run object %s" % (cdist_object.name))
+ if cdist_object.state == core.CdistObject.STATE_DONE:
+ raise cdist.Error("Attempting to run an already finished object: %s", cdist_object)
+
+ cdist_type = cdist_object.cdist_type
+
+ # Generate
+ self.log.info("Generating code for %s" % (cdist_object.name))
+ cdist_object.code_local = self.code.run_gencode_local(cdist_object)
+ cdist_object.code_remote = self.code.run_gencode_remote(cdist_object)
+ if cdist_object.code_local or cdist_object.code_remote:
+ cdist_object.changed = True
+
+ # Execute
+ if not self.dry_run:
+ if cdist_object.code_local or cdist_object.code_remote:
+ self.log.info("Executing code for %s" % (cdist_object.name))
+ if cdist_object.code_local:
+ self.code.run_code_local(cdist_object)
+ if cdist_object.code_remote:
+ self.code.transfer_code_remote(cdist_object)
+ self.code.run_code_remote(cdist_object)
+ else:
+ self.log.info("Skipping code execution due to DRY RUN")
+
+
+ # Mark this object as done
+ self.log.debug("Finishing run of " + cdist_object.name)
+ cdist_object.state = core.CdistObject.STATE_DONE
diff --git a/cdist/config_install.py b/cdist/config_install.py
deleted file mode 100644
index f1529cc1..00000000
--- a/cdist/config_install.py
+++ /dev/null
@@ -1,182 +0,0 @@
-#!/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 .
-#
-#
-
-import logging
-import os
-import stat
-import shutil
-import sys
-import tempfile
-import time
-import itertools
-import pprint
-
-import cdist
-from cdist import core
-from cdist import resolver
-
-
-class ConfigInstall(object):
- """Cdist main class to hold arbitrary data"""
-
- def __init__(self, context):
-
- self.context = context
- self.log = logging.getLogger(self.context.target_host)
-
- # Initialise local directory structure
- self.context.local.create_files_dirs()
- # Initialise remote directory structure
- self.context.remote.create_files_dirs()
-
- self.explorer = core.Explorer(self.context.target_host, self.context.local, self.context.remote)
- self.manifest = core.Manifest(self.context.target_host, self.context.local)
- self.code = core.Code(self.context.target_host, self.context.local, self.context.remote)
-
- # Add switch to disable code execution
- self.dry_run = False
-
- def cleanup(self):
- # FIXME: move to local?
- destination = os.path.join(self.context.local.cache_path, self.context.target_host)
- self.log.debug("Saving " + self.context.local.out_path + " to " + destination)
- if os.path.exists(destination):
- shutil.rmtree(destination)
- shutil.move(self.context.local.out_path, destination)
-
- def deploy_to(self):
- """Mimic the old deploy to: Deploy to one host"""
- self.stage_prepare()
- self.stage_run()
-
- def deploy_and_cleanup(self):
- """Do what is most often done: deploy & cleanup"""
- start_time = time.time()
- self.deploy_to()
- self.cleanup()
- self.log.info("Finished successful run in %s seconds",
- time.time() - start_time)
-
- def stage_prepare(self):
- """Do everything for a deploy, minus the actual code stage"""
- self.explorer.run_global_explorers(self.context.local.global_explorer_out_path)
- self.manifest.run_initial_manifest(self.context.initial_manifest)
-
- self.log.info("Running object manifests and type explorers")
-
- # Continue process until no new objects are created anymore
- new_objects_created = True
- while new_objects_created:
- new_objects_created = False
- for cdist_object in core.CdistObject.list_objects(self.context.local.object_path,
- self.context.local.type_path):
- if cdist_object.state == core.CdistObject.STATE_PREPARED:
- self.log.debug("Skipping re-prepare of object %s", cdist_object)
- continue
- else:
- self.object_prepare(cdist_object)
- new_objects_created = True
-
- def object_prepare(self, cdist_object):
- """Prepare object: Run type explorer + manifest"""
- self.log.info("Running manifest and explorers for " + cdist_object.name)
- self.explorer.run_type_explorers(cdist_object)
- self.manifest.run_type_manifest(cdist_object)
- cdist_object.state = core.CdistObject.STATE_PREPARED
-
- def object_run(self, cdist_object, dry_run=False):
- """Run gencode and code for an object"""
- self.log.debug("Trying to run object " + cdist_object.name)
- if cdist_object.state == core.CdistObject.STATE_DONE:
- raise cdist.Error("Attempting to run an already finished object: %s", cdist_object)
-
- cdist_type = cdist_object.cdist_type
-
- # Generate
- self.log.info("Generating and executing code for " + cdist_object.name)
- cdist_object.code_local = self.code.run_gencode_local(cdist_object)
- cdist_object.code_remote = self.code.run_gencode_remote(cdist_object)
- if cdist_object.code_local or cdist_object.code_remote:
- cdist_object.changed = True
-
- # Execute
- if not dry_run:
- if cdist_object.code_local:
- self.code.run_code_local(cdist_object)
- if cdist_object.code_remote:
- self.code.transfer_code_remote(cdist_object)
- self.code.run_code_remote(cdist_object)
-
- # Mark this object as done
- self.log.debug("Finishing run of " + cdist_object.name)
- cdist_object.state = core.CdistObject.STATE_DONE
-
- def stage_run(self):
- """The final (and real) step of deployment"""
- self.log.info("Generating and executing code")
-
- # FIXME: think about parallel execution (same for stage_prepare)
- self.all_resolved = False
- while not self.all_resolved:
- self.stage_run_iterate()
-
- def stage_run_iterate(self):
- """
- Run one iteration of the run
-
- To be repeated until all objects are done
- """
- objects = list(core.CdistObject.list_objects(self.context.local.object_path, self.context.local.type_path))
- object_state_list=' '.join('%s:%s:%s:%s' % (o, o.state, o.all_requirements, o.satisfied_requirements) for o in objects)
-
- self.log.debug("Object state (name:state:requirements:satisfied): %s" % object_state_list)
-
- objects_changed = False
- self.all_resolved = True
- for cdist_object in objects:
- if not cdist_object.state == cdist_object.STATE_DONE:
- self.all_resolved = False
- self.log.debug("Object %s not done" % cdist_object.name)
- if cdist_object.satisfied_requirements:
- self.log.debug("Running object %s with satisfied requirements" % cdist_object.name)
- self.object_run(cdist_object, self.dry_run)
- objects_changed = True
-
- self.log.debug("All resolved: %s Objects changed: %s" % (self.all_resolved, objects_changed))
-
- # Not all are resolved, but nothing has been changed => bad dependencies!
- if not objects_changed and not self.all_resolved:
- # Create list of unfinished objects + their requirements for print
-
- evil_objects = []
- good_objects = []
- for cdist_object in objects:
- if not cdist_object.state == cdist_object.STATE_DONE:
- evil_objects.append("%s: required: %s, autorequired: %s" %
- (cdist_object.name, cdist_object.requirements, cdist_object.autorequire))
- else:
- evil_objects.append("%s (%s): required: %s, autorequired: %s" %
- (cdist_object.state, cdist_object.name,
- cdist_object.requirements, cdist_object.autorequire))
-
- errormessage = "Cannot solve requirements for the following objects: %s - solved: %s" % (",".join(evil_objects), ",".join(good_objects))
- raise cdist.Error(errormessage)
diff --git a/cdist/context.py b/cdist/context.py
deleted file mode 100644
index e0391be8..00000000
--- a/cdist/context.py
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/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 .
-#
-#
-
-import logging
-import os
-import sys
-import tempfile
-import shutil
-
-from cdist.exec import local
-from cdist.exec import remote
-
-
-class Context(object):
- """Hold information about current context"""
-
- def __init__(self,
- target_host,
- remote_copy,
- remote_exec,
- initial_manifest=False,
- add_conf_dirs=None,
- exec_path=sys.argv[0],
- debug=False):
-
- self.debug = debug
- self.target_host = target_host
- self.exec_path = exec_path
-
- # Context logging
- self.log = logging.getLogger(self.target_host)
- self.log.addFilter(self)
-
- # 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:
- self.out_path = os.environ['__cdist_out_dir']
- self.temp_dir = None
- else:
- self.temp_dir = tempfile.mkdtemp()
- self.out_path = os.path.join(self.temp_dir, "out")
-
- 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"))
-
- 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_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)
-
- def cleanup(self):
- """Remove temp stuff"""
- if self.temp_dir:
- shutil.rmtree(self.temp_dir)
-
- def filter(self, record):
- """Add hostname to logs via logging Filter"""
-
- record.msg = self.target_host + ": " + str(record.msg)
-
- return True
diff --git a/cdist/core/cdist_object.py b/cdist/core/cdist_object.py
index 7beea130..e8c58a67 100644
--- a/cdist/core/cdist_object.py
+++ b/cdist/core/cdist_object.py
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
-# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
+# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
+# 2014 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
#
@@ -42,6 +43,13 @@ class IllegalObjectIdError(cdist.Error):
def __str__(self):
return '%s: %s' % (self.message, self.object_id)
+class MissingObjectIdError(cdist.Error):
+ def __init__(self, type_name):
+ self.type_name = type_name
+ self.message = "Type %s requires object id (is not a singleton type)" % self.type_name
+
+ def __str__(self):
+ return '%s' % (self.message)
class CdistObject(object):
"""Represents a cdist object.
@@ -53,11 +61,12 @@ class CdistObject(object):
"""
# Constants for use with Object.state
+ STATE_UNDEF = ""
STATE_PREPARED = "prepared"
STATE_RUNNING = "running"
STATE_DONE = "done"
- def __init__(self, cdist_type, base_path, object_id=None):
+ def __init__(self, cdist_type, base_path, object_id=''):
self.cdist_type = cdist_type # instance of Type
self.base_path = base_path
self.object_id = object_id
@@ -99,7 +108,6 @@ class CdistObject(object):
"""
type_name = object_name.split(os.sep)[0]
- # FIXME: allow object without object_id? e.g. for singleton
object_id = os.sep.join(object_name.split(os.sep)[1:])
return type_name, object_id
@@ -113,7 +121,8 @@ class CdistObject(object):
return os.path.join(type_name, object_id)
def validate_object_id(self):
- # FIXME: also check that there is no object ID when type is singleton?
+ if self.cdist_type.is_singleton and self.object_id:
+ raise IllegalObjectIdError('singleton objects can\'t have a object_id')
"""Validate the given object_id and raise IllegalObjectIdError if it's not valid.
"""
@@ -122,11 +131,17 @@ class CdistObject(object):
raise IllegalObjectIdError(self.object_id, 'object_id may not contain \'%s\'' % OBJECT_MARKER)
if '//' in self.object_id:
raise IllegalObjectIdError(self.object_id, 'object_id may not contain //')
+ if self.object_id == '.':
+ raise IllegalObjectIdError(self.object_id, 'object_id may not be a .')
# If no object_id and type is not singleton => error out
if not self.object_id and not self.cdist_type.is_singleton:
- raise IllegalObjectIdError(self.object_id,
- "Missing object_id and type is not a singleton.")
+ raise MissingObjectIdError(self.cdist_type.name)
+
+ # Does not work: AttributeError: 'CdistObject' object has no attribute 'parameter_path'
+
+ #"Type %s is not a singleton type - missing object id (parameters: %s)" %
+ # (self.cdist_type.name, self.parameters))
def object_from_name(self, object_name):
"""Convenience method for creating an object instance from an object name.
@@ -190,7 +205,6 @@ class CdistObject(object):
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"))
state = fsproperty.FileStringProperty(lambda obj: os.path.join(obj.absolute_path, "state"))
source = fsproperty.FileListProperty(lambda obj: os.path.join(obj.absolute_path, "source"))
code_local = fsproperty.FileStringProperty(lambda obj: os.path.join(obj.base_path, obj.code_local_path))
@@ -201,76 +215,25 @@ class CdistObject(object):
"""Checks wether this cdist object exists on the file systems."""
return os.path.exists(self.absolute_path)
- def create(self):
+ def create(self, allow_overwrite=False):
"""Create this cdist object on the filesystem.
"""
try:
- os.makedirs(self.absolute_path, exist_ok=False)
+ os.makedirs(self.absolute_path, exist_ok=allow_overwrite)
absolute_parameter_path = os.path.join(self.base_path, self.parameter_path)
- os.makedirs(absolute_parameter_path, exist_ok=False)
+ os.makedirs(absolute_parameter_path, exist_ok=allow_overwrite)
except EnvironmentError as error:
raise cdist.Error('Error creating directories for cdist object: %s: %s' % (self, error))
- @property
- def satisfied_requirements(self):
- """Return state whether all of our dependencies have been resolved already"""
+ def requirements_unfinished(self, requirements):
+ """Return state whether requirements are satisfied"""
- satisfied = True
+ object_list = []
- for requirement in self.all_requirements:
- log.debug("%s: Checking requirement %s (%s) .." % (self.name, requirement.name, requirement.state))
- if not requirement.state == self.STATE_DONE:
- satisfied = False
- break
- log.debug("%s is satisfied: %s" % (self.name, satisfied))
+ for requirement in requirements:
+ cdist_object = self.object_from_name(requirement)
- return satisfied
+ if not cdist_object.state == self.STATE_DONE:
+ object_list.append(cdist_object)
-
- def find_requirements_by_name(self, requirements):
- """Takes a list of requirement patterns and returns a list of matching object instances.
-
- Patterns are expected to be Unix shell-style wildcards for use with fnmatch.filter.
-
- find_requirements_by_name(['__type/object_id', '__other_type/*']) ->
- [