diff --git a/.gitignore b/.gitignore
index 6e2d4437..76ed1fcb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,3 +26,6 @@ cdist/version.py
/cdist-*.tar.gz
/pkg
/src
+build
+.lock-*
+.git-current-branch
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..5910ab2e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,252 @@
+#
+# 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-release: man $(PYTHON_VERSION)
+ python3 setup.py sdist upload
+ touch $@
+
+################################################################################
+# 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..b97528f1
--- /dev/null
+++ b/bin/build-helper
@@ -0,0 +1,298 @@
+#!/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
+ if [ "$(git rev-parse --abbrev-ref HEAD)" != "master" ]; then
+ echo "Releases are happening from the master branch, aborting"
+ exit 1
+ fi
+
+ # 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
+
+ # 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
+ git checkout master
+ git merge "$target_branch"
+
+ # 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..881c910a 100755
--- a/cdist/conf/explorer/hostname
+++ b/cdist/conf/explorer/hostname
@@ -20,6 +20,6 @@
#
#
-if command -v hostname; then
- hostname
+if command -v hostname >/dev/null; then
+ hostname -f
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_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/__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..44d62f6c
--- /dev/null
+++ b/cdist/conf/type/__cdist/manifest
@@ -0,0 +1,59 @@
+#!/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
+
+if [ -f "$__object/parameter/username" ]; then
+ username="$(cat "$__object/parameter/username")"
+else
+ username="cdist"
+fi
+
+if [ -f "$__object/parameter/branch" ]; then
+ branch="$(cat "$__object/parameter/branch")"
+else
+ branch="master"
+fi
+
+if [ -f "$__object/parameter/source" ]; then
+ source="$(cat "$__object/parameter/source")"
+else
+ source="git://github.com/telmich/cdist.git"
+fi
+
+# 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/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
index 1b4bec42..c3bf02d2 100755
--- 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..c04a7245 100755
--- a/cdist/conf/type/__cron/gencode-remote
+++ b/cdist/conf/type/__cron/gencode-remote
@@ -1,6 +1,7 @@
#!/bin/sh
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
+# 2013 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@@ -18,39 +19,43 @@
# 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"
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
+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"
+cat << DONE
crontab -u $user -l | awk -v prefix="$prefix" -v suffix="$suffix" '
{
if (index(\$0,prefix)) {
@@ -66,6 +71,16 @@ crontab -u $user -l | awk -v prefix="$prefix" -v suffix="$suffix" '
}
' | crontab -u $user -
DONE
- ;;
- esac
-fi
+
+case "$state_should" in
+ present)
+ echo "("
+ echo "crontab -u $user -l 2>/dev/null || true"
+ echo "echo '$entry'"
+ echo ") | crontab -u $user -"
+ ;;
+ absent)
+ echo "( crontab -u $user -l 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..22627234 100644
--- a/cdist/conf/type/__cron/man.text
+++ b/cdist/conf/type/__cron/man.text
@@ -68,5 +68,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
deleted file mode 100755
index 7aca41ff..00000000
--- a/cdist/conf/type/__cron/manifest
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/bin/sh
-#
-# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
-#
-# This file is part of cdist.
-#
-# cdist is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# cdist is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with cdist. If not, see .
-#
-
-name="$__object_id"
-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"
-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/__debconf_set_selections/man.text b/cdist/conf/type/__debconf_set_selections/man.text
index b6b2ad18..f1e13a8e 100644
--- a/cdist/conf/type/__debconf_set_selections/man.text
+++ b/cdist/conf/type/__debconf_set_selections/man.text
@@ -17,7 +17,7 @@ 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)
EXAMPLES
@@ -35,9 +35,11 @@ __debconf_set_selections nslcd --file "$__type/files/preseed/nslcd"
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-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/__directory/explorer/group b/cdist/conf/type/__directory/explorer/group
new file mode 100644
index 00000000..e5be37da
--- /dev/null
+++ b/cdist/conf/type/__directory/explorer/group
@@ -0,0 +1,39 @@
+#!/bin/sh
+#
+# 2011 Nico Schottelius (nico-cdist at schottelius.org)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+#
+# Check whether file exists or not
+#
+
+destination="/$__object_id"
+os=$("$__explorer/os")
+
+case "$os" in
+ "freebsd")
+ cmd="stat -f %Sg"
+ ;;
+ *)
+ cmd="stat -c %G"
+ ;;
+esac
+
+if [ -e "$destination" ]; then
+ $cmd "$destination"
+fi
+
diff --git a/cdist/conf/type/__directory/explorer/mode b/cdist/conf/type/__directory/explorer/mode
new file mode 100644
index 00000000..f75b282b
--- /dev/null
+++ b/cdist/conf/type/__directory/explorer/mode
@@ -0,0 +1,39 @@
+#!/bin/sh
+#
+# 2011 Nico Schottelius (nico-cdist at schottelius.org)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+#
+# Check whether file exists or not
+#
+
+destination="/$__object_id"
+os=$("$__explorer/os")
+
+case "$os" in
+ "freebsd")
+ cmd="stat -f %Op"
+ ;;
+ *)
+ cmd="stat -c %a"
+ ;;
+esac
+
+if [ -e "$destination" ]; then
+ $cmd "$destination"
+fi
+
diff --git a/cdist/conf/type/__directory/explorer/owner b/cdist/conf/type/__directory/explorer/owner
new file mode 100644
index 00000000..cebd199b
--- /dev/null
+++ b/cdist/conf/type/__directory/explorer/owner
@@ -0,0 +1,39 @@
+#!/bin/sh
+#
+# 2011 Nico Schottelius (nico-cdist at schottelius.org)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+#
+# Check whether file exists or not
+#
+
+destination="/$__object_id"
+os=$("$__explorer/os")
+
+case "$os" in
+ "freebsd")
+ cmd="stat -f %Su"
+ ;;
+ *)
+ cmd="stat -c %U"
+ ;;
+esac
+
+if [ -e "$destination" ]; then
+ $cmd "$destination"
+fi
+
diff --git a/cdist/conf/type/__directory/gencode-remote b/cdist/conf/type/__directory/gencode-remote
index 21f4c5b6..f46a5967 100755
--- a/cdist/conf/type/__directory/gencode-remote
+++ b/cdist/conf/type/__directory/gencode-remote
@@ -18,39 +18,51 @@
# 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_is="$(cat "$__object/explorer/state")"
+owner_is="$(cat "$__object/explorer/owner")"
+group_is="$(cat "$__object/explorer/group")"
+mode_is="$(cat "$__object/explorer/mode")"
+
+state_should="present"
+[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
+mode=""
+[ -f "$__object/parameter/mode" ] && mode="$(cat "$__object/parameter/mode")"
+owner=""
+[ -f "$__object/parameter/owner" ] && owner="$(cat "$__object/parameter/owner")"
+group=""
+[ -f "$__object/parameter/group" ] && group="$(cat "$__object/parameter/group")"
mkdiropt=""
-[ -f "$__object/parameter/parents" ] && mkdiropt="-p"
+[ -f "$__object/parameter/parents" ] && mkdiropt="-p"
recursive=""
[ -f "$__object/parameter/recursive" ] && recursive="-R"
case "$state_should" in
present)
- echo mkdir $mkdiropt \"$destination\"
+ if [ "$state_is" != "present" ]; then
+ echo mkdir $mkdiropt \"$destination\"
+ fi
# Mode settings
- if [ -f "$__object/parameter/mode" ]; then
- echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\"
+ if [ "$mode" ] && [ "$mode_is" != "$mode" -o -n "$recursive" ]; then
+ echo chmod $recursive \"$mode\" \"$destination\"
fi
# Group
- if [ -f "$__object/parameter/group" ]; then
- echo chgrp $recursive \"$(cat "$__object/parameter/group")\" \"$destination\"
+ if [ "$group" ] && [ "$group_is" != "$group" -o -n "$recursive" ]; then
+ echo chgrp $recursive \"$group\" \"$destination\"
fi
# Owner
- if [ -f "$__object/parameter/owner" ]; then
- echo chown $recursive \"$(cat "$__object/parameter/owner")\" \"$destination\"
+ if [ "$owner" ] && [ "$owner_is" != "$owner" -o -n "$recursive" ]; then
+ echo chown $recursive \"$owner\" \"$destination\"
fi
;;
absent)
- echo rm -rf \"$destination\"
+ if [ "$state_is" != "absent" ]; then
+ echo rm -rf \"$destination\"
+ fi
;;
*)
echo "Unknown state: $state_should" >&2
diff --git a/cdist/conf/type/__directory/man.text b/cdist/conf/type/__directory/man.text
index 1f4def7d..cc327af2 100644
--- a/cdist/conf/type/__directory/man.text
+++ b/cdist/conf/type/__directory/man.text
@@ -36,7 +36,11 @@ 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.
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..d719a492 100644
--- a/cdist/conf/type/__git/gencode-remote
+++ b/cdist/conf/type/__git/gencode-remote
@@ -20,6 +20,9 @@
#
state_is="$(cat "$__object/explorer/state")"
+owner_is="$(cat "$__object/explorer/owner")"
+group_is="$(cat "$__object/explorer/group")"
+
state_should=present
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
@@ -30,11 +33,31 @@ source="$(cat "$__object/parameter/source")"
destination="/$__object_id"
-[ "$state_should" = "$state_is" ] && exit 0
+owner=""
+[ -f "$__object/parameter/owner" ] && owner="$(cat "$__object/parameter/owner")"
+group=""
+[ -f "$__object/parameter/group" ] && group="$(cat "$__object/parameter/group")"
+mode=""
+[ -f "$__object/parameter/mode" ] && 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..7c6b83cd 100644
--- a/cdist/conf/type/__git/man.text
+++ b/cdist/conf/type/__git/man.text
@@ -27,6 +27,15 @@ state::
branch::
Create this branch by checking out the remote branch of this name
+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..8d6a29e4 100644
--- a/cdist/conf/type/__git/manifest
+++ b/cdist/conf/type/__git/manifest
@@ -26,14 +26,11 @@ __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")"
-
# 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/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/__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..0773b452
--- /dev/null
+++ b/cdist/conf/type/__iptables_apply/gencode-remote
@@ -0,0 +1,2 @@
+# Rebuild rules - FIXME: do conditionally as soon as cdist supports it
+echo /etc/init.d/iptables restart
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/type/fixtures/__singleton/singleton b/cdist/conf/type/__iptables_apply/singleton
similarity index 100%
rename from cdist/test/type/fixtures/__singleton/singleton
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..a6abbd5e
--- /dev/null
+++ b/cdist/conf/type/__iptables_rule/manifest
@@ -0,0 +1,46 @@
+#
+# 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"
+
+if [ -f "$__object/parameter/state" ]; then
+ state="$(cat "$__object/parameter/state")"
+else
+ state="present"
+fi
+
+################################################################################
+# 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/__postgres_database/parameter/required b/cdist/conf/type/__iptables_rule/parameter/optional
similarity index 100%
rename from cdist/conf/type/__postgres_database/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-remote b/cdist/conf/type/__jail/gencode-remote
index 7491754c..b044e4b0 100755
--- a/cdist/conf/type/__jail/gencode-remote
+++ b/cdist/conf/type/__jail/gencode-remote
@@ -92,6 +92,20 @@ fi
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
@@ -160,10 +174,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\""
+ printf 'sed "s|^%s\(%s\+\).*|%s\\1%s|" "%s" > "%s.cdist-tmp"\n' \
+ "$key" "$delimiter" "$key" "$value" "$file" "$file"
echo "mv \"$file.cdist-tmp\" \"$file\""
;;
*)
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..1c46c16c 100755
--- a/cdist/conf/type/__line/gencode-remote
+++ b/cdist/conf/type/__line/gencode-remote
@@ -38,7 +38,19 @@ 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')
+ echo "printf '%s\n' '$line_sanitised' >> $file"
;;
absent)
@@ -47,13 +59,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/__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..f76c2059
--- /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'
+
+
+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 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..5dd5fd8f
--- /dev/null
+++ b/cdist/conf/type/__locale/manifest
@@ -0,0 +1,32 @@
+#!/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 .
+#
+#
+# Install required packages
+#
+
+os=$(cat "$__global/explorer/os")
+
+
+case "$os" in
+ debian)
+ # Debian needs a seperate package
+ __package locales --state present
+ ;;
+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/__postgres_role/parameter/required b/cdist/conf/type/__locale/parameter/optional
similarity index 100%
rename from cdist/conf/type/__postgres_role/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/__package_apt/gencode-remote b/cdist/conf/type/__package_apt/gencode-remote
index a80d707e..7aba76d5 100755
--- a/cdist/conf/type/__package_apt/gencode-remote
+++ b/cdist/conf/type/__package_apt/gencode-remote
@@ -42,7 +42,7 @@ case "$state_is" in
;;
esac
-aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes"
+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_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/__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..2dc70ce2
--- /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)
+ __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/explorer/.keep b/cdist/conf/type/__postfix/singleton
similarity index 100%
rename from cdist/test/autorequire/fixtures/conf/explorer/.keep
rename to cdist/conf/type/__postfix/singleton
diff --git a/cdist/conf/type/__postfix_master/explorer/entry b/cdist/conf/type/__postfix_master/explorer/entry
new file mode 100755
index 00000000..9d6b1514
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/explorer/entry
@@ -0,0 +1,39 @@
+#!/bin/sh
+#
+# 2011 - 2012 Steven Armstrong (steven-cdist at armstrong.cc)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see .
+#
+
+config="/etc/postfix/master.cf"
+
+# no master.cf, nothing we could do
+[ -f "$config" ] || exit 0
+
+# NOTE: keep variables in sync in manifest,explorer,gencode-*
+prefix="#cdist:$__object_name"
+suffix="#/cdist:$__object_name"
+awk -v prefix="$prefix" -v suffix="$suffix" '{
+ if (index($0,prefix)) {
+ triggered=1
+ }
+ if (triggered) {
+ if (index($0,suffix)) {
+ triggered=0
+ }
+ print
+ }
+}' "$config"
diff --git a/cdist/conf/type/__postfix_master/gencode-remote b/cdist/conf/type/__postfix_master/gencode-remote
new file mode 100755
index 00000000..51edc668
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/gencode-remote
@@ -0,0 +1,78 @@
+#!/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 .
+#
+
+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
+ state_is=$(diff -q "$entry" "$__object/explorer/entry" >/dev/null \
+ && echo present \
+ || echo changed
+ )
+fi
+
+if [ "$state_should" = "$state_is" ]; then
+ # Nothing to do, move along
+ exit 0
+fi
+
+
+remove_entry() {
+ # NOTE: keep variables in sync in manifest/explorer/gencode-*
+ prefix="#cdist:$__object_name"
+ suffix="#/cdist:$__object_name"
+ cat << DONE
+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)) {
+ triggered=1
+ }
+ if (triggered) {
+ if (index(\$0,suffix)) {
+ triggered=0
+ }
+ } else {
+ print
+ }
+}' "$config" > "\$tmpfile"
+mv -f "\$tmpfile" "$config"
+DONE
+}
+
+case "$state_should" in
+ present)
+ if [ "$state_is" = "changed" ]; then
+ remove_entry
+ fi
+ cat << DONE
+cat >> "$config" << ${__type##*/}_DONE
+$(cat "$entry")
+${__type##*/}_DONE
+DONE
+ ;;
+ absent)
+ remove_entry
+ ;;
+esac
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..1642e91b
--- /dev/null
+++ b/cdist/conf/type/__postfix_master/manifest
@@ -0,0 +1,81 @@
+#!/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 "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
+
+
+# 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..edf48b48
--- /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)
+ :
+ ;;
+ *)
+ 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..60143590
--- /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)
+ :
+ ;;
+ *)
+ 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/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/__process/parameter/required b/cdist/conf/type/__postfix_postconf/parameter/optional
similarity index 60%
rename from cdist/conf/type/__process/parameter/required
rename to cdist/conf/type/__postfix_postconf/parameter/optional
index ff72b5c7..6ada755a 100644
--- a/cdist/conf/type/__process/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_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/test/autorequire/fixtures/conf/type/__addifnosuchline/.keep b/cdist/conf/type/__postfix_reload/singleton
similarity index 100%
rename from cdist/test/autorequire/fixtures/conf/type/__addifnosuchline/.keep
rename to cdist/conf/type/__postfix_reload/singleton
diff --git a/cdist/conf/type/__postgres_database/gencode-remote b/cdist/conf/type/__postgres_database/gencode-remote
index c097efce..0ffc842a 100755
--- a/cdist/conf/type/__postgres_database/gencode-remote
+++ b/cdist/conf/type/__postgres_database/gencode-remote
@@ -19,7 +19,8 @@
#
name="$__object_id"
-state_should="$(cat "$__object/parameter/state")"
+state_should="present"
+[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
state_is="$(cat "$__object/explorer/state")"
if [ "$state_should" != "$state_is" ]; then
diff --git a/cdist/conf/type/__postgres_database/man.text b/cdist/conf/type/__postgres_database/man.text
index d01ca8f6..88259b6f 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
+OPTIONAL PARAMETERS
-------------------
state::
either 'present' or 'absent'
-
-OPTIONAL PARAMETERS
--------------------
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/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..65a9d588 100755
--- a/cdist/conf/type/__postgres_role/gencode-remote
+++ b/cdist/conf/type/__postgres_role/gencode-remote
@@ -20,14 +20,15 @@
name="$__object_id"
state_is="$(cat "$__object/explorer/state")"
-state_should="$(cat "$__object/parameter/state")"
+state_should="present"
+[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
[ "$state_is" = "$state_should" ] && exit 0
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/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..41bc5381 100755
--- a/cdist/conf/type/__process/gencode-remote
+++ b/cdist/conf/type/__process/gencode-remote
@@ -25,7 +25,12 @@ else
name="$__object_id"
fi
-state_should="$(cat "$__object/parameter/state")"
+parameter_state="$__object/parameter/state"
+if [ -f "$_parameter_state" ]; then
+ state_should=$(cat "$__object/parameter/state")
+else
+ state_should="present"
+fi
runs="$(cat "$__object/explorer/runs")"
if [ "$runs" ]; then
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/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/__ssh_authorized_keys/gencode-remote b/cdist/conf/type/__ssh_authorized_keys/gencode-remote
index cc86cc19..7fcb59c6 100755
--- a/cdist/conf/type/__ssh_authorized_keys/gencode-remote
+++ b/cdist/conf/type/__ssh_authorized_keys/gencode-remote
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
+# 2012-2013 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
@@ -24,7 +24,7 @@ if [ -f "$__object/parameter/file" ]; then
else
home="$(cut -d':' -f 6 "$__object/explorer/passwd")"
file="$home/.ssh/authorized_keys"
-fi
+fi
entry="$__object/files/entry"
if [ ! -s "$__object/explorer/entry" ]; then
@@ -47,7 +47,9 @@ remove_entry() {
prefix="#cdist:$__object_name"
suffix="#/cdist:$__object_name"
cat << DONE
-tmpfile=\$(mktemp)
+tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX)
+# preserve ownership and permissions by copying existing file over tmpfile
+cp -p "$file" "\$tmpfile"
awk -v prefix="$prefix" -v suffix="$suffix" '
{
if (index(\$0,prefix)) {
diff --git a/cdist/conf/type/__ssh_authorized_keys/manifest b/cdist/conf/type/__ssh_authorized_keys/manifest
index 268b1fbe..47cdf746 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 || echo "present")"
if [ -f "$__object/parameter/file" ]; then
file="$(cat "$__object/parameter/file")"
else
diff --git a/cdist/conf/type/__start_on_boot/explorer/state b/cdist/conf/type/__start_on_boot/explorer/state
index 6fd0ea92..4e0c82c2 100755
--- a/cdist/conf/type/__start_on_boot/explorer/state
+++ b/cdist/conf/type/__start_on_boot/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.
#
@@ -28,20 +28,9 @@ 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)
@@ -54,7 +43,7 @@ case "$os" in
[ "$state" ] || state="present"
;;
- *)
+ *)
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..58ff6a4a 100755
--- a/cdist/conf/type/__start_on_boot/gencode-remote
+++ b/cdist/conf/type/__start_on_boot/gencode-remote
@@ -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.
#
@@ -32,8 +32,7 @@ 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"
@@ -65,10 +64,7 @@ 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
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/gencode-remote b/cdist/conf/type/__user/gencode-remote
index baa6f354..a2cdfd22 100755
--- a/cdist/conf/type/__user/gencode-remote
+++ b/cdist/conf/type/__user/gencode-remote
@@ -39,6 +39,7 @@ shorten_property() {
password) ret="-p";;
shell) ret="-s";;
uid) ret="-u";;
+ create-home) ret="-m";;
esac
echo "$ret"
}
@@ -76,6 +77,7 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then
home) field=6 ;;
shell) field=7 ;;
uid) field=3 ;;
+ create-home) continue;; # Does not apply to user modification
esac
# If we haven't already set $current_value above, pull it from the
@@ -102,7 +104,11 @@ if grep -q "^${name}:" "$__object/explorer/passwd"; then
else
for property in $(ls .); do
new_value="$(cat "$property")"
- set -- "$@" "$(shorten_property $property)" \'$new_value\'
+ if [ -z "$new_value" ];then # Boolean values have no value
+ set -- "$@" "$(shorten_property $property)"
+ else
+ set -- "$@" "$(shorten_property $property)" \'$new_value\'
+ fi
done
if [ "$os" = "freebsd" ]; then
diff --git a/cdist/conf/type/__user/parameter/boolean b/cdist/conf/type/__user/parameter/boolean
new file mode 100644
index 00000000..e0517c6a
--- /dev/null
+++ b/cdist/conf/type/__user/parameter/boolean
@@ -0,0 +1 @@
+create-home
diff --git a/cdist/config.py b/cdist/config.py
index 9af25b75..7e003835 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,252 @@
#
#
-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):
+ 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 and executing 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:
+ 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..e3c1c532 100644
--- a/cdist/core/cdist_object.py
+++ b/cdist/core/cdist_object.py
@@ -1,7 +1,7 @@
# -*- 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)
#
# This file is part of cdist.
#
@@ -42,6 +42,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 +60,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 +107,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
@@ -125,8 +132,12 @@ class CdistObject(object):
# 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.
@@ -211,66 +222,15 @@ class CdistObject(object):
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/*']) ->
- [