Merge branch 'master' into type__rbenv

This commit is contained in:
Nico Schottelius 2014-02-14 20:13:18 +01:00
commit 490bad7b26
446 changed files with 8668 additions and 2109 deletions

5
.gitignore vendored
View file

@ -26,3 +26,8 @@ cdist/version.py
/cdist-*.tar.gz
/pkg
/src
build
.lock-*
.git-current-branch
.lock*
.pypi-release

254
Makefile Normal file
View file

@ -0,0 +1,254 @@
#
# 2013 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
A2XM=a2x -f manpage --no-xmllint -a encoding=UTF-8
A2XH=a2x -f xhtml --no-xmllint -a encoding=UTF-8
helper=./bin/build-helper
MANDIR=docs/man
SPEECHDIR=docs/speeches
TYPEDIR=cdist/conf/type
WEBSRCDIR=docs/web
WEBDIR=$$HOME/www.nico.schottelius.org
WEBBLOG=$(WEBDIR)/blog
WEBBASE=$(WEBDIR)/software/cdist
WEBPAGE=$(WEBBASE).mdwn
CHANGELOG_VERSION=$(shell $(helper) changelog-version)
CHANGELOG_FILE=docs/changelog
PYTHON_VERSION=cdist/version.py
################################################################################
# Manpages
#
MAN1DSTDIR=$(MANDIR)/man1
MAN7DSTDIR=$(MANDIR)/man7
# Manpages #1: Types
# Use shell / ls to get complete list - $(TYPEDIR)/*/man.text does not work
MANTYPESRC=$(shell ls $(TYPEDIR)/*/man.text)
# replace first path component
MANTYPEPREFIX=$(subst $(TYPEDIR)/,$(MAN7DSTDIR)/cdist-type,$(MANTYPESRC))
# replace man.text with .7 or .html
MANTYPEMAN=$(subst /man.text,.7,$(MANTYPEPREFIX))
MANTYPEHTML=$(subst /man.text,.html,$(MANTYPEPREFIX))
MANTYPEALL=$(MANTYPEMAN) $(MANTYPEHTML)
# Link manpage so A2XH does not create man.html but correct named file
$(MAN7DSTDIR)/cdist-type%.text: $(TYPEDIR)/%/man.text
ln -sf "../../../$^" $@
# Manpages #2: reference
MANREF=$(MAN7DSTDIR)/cdist-reference.text
MANREFSH=$(MANDIR)/cdist-reference.text.sh
MANREFMAN=$(MANREF:.text=.7)
MANREFHTML=$(MANREF:.text=.html)
MANREFALL=$(MANREFMAN) $(MANREFHTML)
$(MANREF): $(MANREFSH)
$(MANREFSH)
# Manpages #3: static pages
MAN1STATIC=$(shell ls $(MAN1DSTDIR)/*.text)
MAN7STATIC=$(shell ls $(MAN7DSTDIR)/*.text)
MANSTATICMAN=$(MAN1STATIC:.text=.1) $(MAN7STATIC:.text=.7)
MANSTATICHTML=$(MAN1STATIC:.text=.html) $(MAN7STATIC:.text=.html)
MANSTATICALL=$(MANSTATICMAN) $(MANSTATICHTML)
# Manpages #4: generic part
# Creating the type manpage
%.1 %.7: %.text
$(A2XM) $^
# Creating the type html page
%.html: %.text
$(A2XH) $^
man: $(MANTYPEALL) $(MANREFALL) $(MANSTATICALL)
# Manpages #5: release part
MANWEBDIR=$(WEBBASE)/man/$(CHANGELOG_VERSION)
man-dist: man check-date
rm -rf "${MANWEBDIR}"
mkdir -p "${MANWEBDIR}/man1" "${MANWEBDIR}/man7"
cp ${MAN1DSTDIR}/*.html ${MAN1DSTDIR}/*.css ${MANWEBDIR}/man1
cp ${MAN7DSTDIR}/*.html ${MAN7DSTDIR}/*.css ${MANWEBDIR}/man7
cd ${MANWEBDIR} && git add . && git commit -m "cdist manpages update: $(CHANGELOG_VERSION)" || true
man-fix-link: web-pub
# Fix ikiwiki, which does not like symlinks for pseudo security
ssh tee.schottelius.org \
"cd /home/services/www/nico/www.nico.schottelius.org/www/software/cdist/man && rm -f latest && ln -sf "$(CHANGELOG_VERSION)" latest"
################################################################################
# Speeches
#
SPEECHESOURCES=$(SPEECHDIR)/*.tex
SPEECHES=$(SPEECHESOURCES:.tex=.pdf)
SPEECHESWEBDIR=$(WEBBASE)/speeches
# Create speeches and ensure Toc is up-to-date
$(SPEECHDIR)/%.pdf: $(SPEECHDIR)/%.tex
pdflatex -output-directory $(SPEECHDIR) $^
pdflatex -output-directory $(SPEECHDIR) $^
pdflatex -output-directory $(SPEECHDIR) $^
speeches: $(SPEECHES)
speeches-dist: speeches
rm -rf "${SPEECHESWEBDIR}"
mkdir -p "${SPEECHESWEBDIR}"
cp ${SPEECHES} "${SPEECHESWEBDIR}"
cd ${SPEECHESWEBDIR} && git add . && git commit -m "cdist speeches updated" || true
################################################################################
# Website
#
BLOGFILE=$(WEBBLOG)/cdist-$(CHANGELOG_VERSION)-released.mdwn
$(BLOGFILE): $(CHANGELOG_FILE)
$(helper) blog $(CHANGELOG_VERSION) $(BLOGFILE)
web-blog: $(BLOGFILE)
web-doc:
# Go to top level, because of cdist.mdwn
rsync -av "$(WEBSRCDIR)/" "${WEBBASE}/.."
cd "${WEBBASE}/.." && git add cdist* && git commit -m "cdist doc update" cdist* || true
web-dist: web-blog web-doc
web-pub: web-dist man-dist speeches-dist
cd "${WEBDIR}" && make pub
web-release-all: man-fix-link
################################################################################
# Release: Mailinglist
#
ML_FILE=.lock-ml
# Only send mail once - lock until new changelog things happened
$(ML_FILE): $(CHANGELOG_FILE)
$(helper) ml-release $(CHANGELOG_VERSION)
touch $@
ml-release: $(ML_FILE)
################################################################################
# Release: Freecode
#
FREECODE_FILE=.lock-freecode
$(FREECODE_FILE): $(CHANGELOG_FILE)
$(helper) freecode-release $(CHANGELOG_VERSION)
touch $@
freecode-release: $(FREECODE_FILE)
################################################################################
# pypi
#
PYPI_FILE=.pypi-release
$(PYPI_FILE): man $(PYTHON_VERSION)
python3 setup.py sdist upload
touch $@
pypi-release: $(PYPI_FILE)
################################################################################
# archlinux
#
ARCHLINUX_FILE=.lock-archlinux
ARCHLINUXTAR=cdist-$(CHANGELOG_VERSION)-1.src.tar.gz
$(ARCHLINUXTAR): PKGBUILD
makepkg -c --source
PKGBUILD: PKGBUILD.in $(PYTHON_VERSION)
./PKGBUILD.in $(CHANGELOG_VERSION)
$(ARCHLINUX_FILE): $(ARCHLINUXTAR) $(PYTHON_VERSION)
burp -c system $(ARCHLINUXTAR)
touch $@
archlinux-release: $(ARCHLINUX_FILE)
################################################################################
# Release
#
$(PYTHON_VERSION): .git/refs/heads/master
$(helper) version
# Code that is better handled in a shell script
check-%:
$(helper) $@
release:
$(helper) $@
################################################################################
# Cleanup
#
clean:
rm -f $(MAN7DSTDIR)/cdist-reference.text
find "$(MANDIR)" -mindepth 2 -type l \
-o -name "*.1" \
-o -name "*.7" \
-o -name "*.html" \
-o -name "*.xml" \
| xargs rm -f
find * -name __pycache__ | xargs rm -rf
# Archlinux
rm -f cdist-*.pkg.tar.xz cdist-*.tar.gz
rm -rf pkg/ src/
rm -f MANIFEST PKGBUILD
rm -rf dist/
distclean: clean
rm -f cdist/version.py
################################################################################
# Misc
#
# The pub is Nico's "push to all git remotes" way ("make pub")
pub:
for remote in "" github sf; do \
echo "Pushing to $$remote"; \
git push --mirror $$remote; \
done
test:
$(helper) $@

View file

@ -1,6 +1,6 @@
#!/bin/sh
version=$(git describe)
version="$1"
outfile=${0%.in}
cat << eof > "${outfile}"

311
bin/build-helper Executable file
View file

@ -0,0 +1,311 @@
#!/bin/sh
#
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# This file contains the heavy lifting found usually in the Makefile
#
basedir=${0%/*}/../
# Change to checkout directory
cd "$basedir"
version=$(git describe)
option=$1; shift
case "$option" in
changelog-changes)
if [ "$#" -eq 1 ]; then
start=$1
else
start="[[:digit:]]"
fi
end="[[:digit:]]"
awk -F: "BEGIN { start=0 }
{
if(start == 0) {
if (\$0 ~ /^$start/) {
start = 1
}
} else {
if (\$0 ~ /^$end/) {
exit
} else {
print \$0
}
}
}" "$basedir/docs/changelog"
;;
changelog-version)
# get version from changelog
grep '^[[:digit:]]' "$basedir/docs/changelog" | head -n1 | sed 's/:.*//'
;;
check-date)
# verify date in changelog is today
date_today="$(date +%Y-%m-%d)"
date_changelog=$(grep '^[[:digit:]]' "$basedir/docs/changelog" | head -n1 | sed 's/.*: //')
if [ "$date_today" != "$date_changelog" ]; then
echo "Date in changelog is not today"
echo "Changelog: $date_changelog"
exit 1
fi
;;
check-unittest)
"$0" test
;;
blog)
version=$1; shift
blogfile=$1; shift
dir=${blogfile%/*}
file=${blogfile##*/}
cat << eof > "$blogfile"
[[!meta title="Cdist $version released"]]
Here's a short overview about the changes found in version ${version}:
eof
$0 changelog-changes "$version" >> "$blogfile"
cat << eof >> "$blogfile"
For more information visit the [[cdist homepage|software/cdist]].
[[!tag cdist config unix]]
eof
cd "$dir"
git add "$file"
# Allow git commit to fail if there are no changes
git commit -m "cdist blog update: $version" "$blogfile" || true
;;
ml-release)
version=$1; shift
to_a=cdist
to_d=l.schottelius.org
to=${to_a}@${to_d}
from_a=nico-cdist
from_d=schottelius.org
from=${from_a}@${from_d}
(
cat << eof
From: Nico -telmich- Schottelius <$from>
To: cdist mailing list <$to>
Subject: cdist $version released
Hello .*,
cdist $version has been released with the following changes:
eof
"$0" changelog-changes "$version"
cat << eof
Cheers,
Nico
--
Automatisation at its best level. With cdist.
eof
) | /usr/sbin/sendmail -f "$from" "$to"
;;
freecode-release)
version=$1; shift
api_token=$(awk '/machine freecode login/ { print $8 }' ~/.netrc)
printf "Enter tag list for freecode release %s> " "$version"
read taglist
printf "Enter changelog for freecode release %s> " "$version"
read changelog
echo "Submit preview"
cat << eof
tag_list = $taglist
changelog = $changelog
version = $version
eof
printf "Press enter to submit to freecode> "
read dummy
cat << eof | cfreecode-api release-add cdist
{
"auth_code": "$api_token",
"release": {
"tag_list": "$taglist",
"version": "$version",
"changelog": "$changelog",
"hidden_from_frontpage": false
}
}
eof
;;
release-git-tag)
target_version=$($0 changelog-version)
if git rev-parse --verify refs/tags/$target_version; then
echo "Tag for $target_version exists, aborting"
exit 1
fi
printf "Enter tag description for ${target_version}: "
read tagmessage
git tag "$target_version" -m "$$tagmessage"
;;
release)
set -e
target_version=$($0 changelog-version)
target_branch=$($0 version-branch)
echo "Beginning release process for $target_version"
# First check everything is sane
"$0" check-date
"$0" check-unittest
# Generate version file to be included in packaging
"$0" version
# Ensure the git status is clean, else abort
if ! git diff-index --name-only --exit-code HEAD ; then
echo "Unclean tree, see files above, aborting"
exit 1
fi
# Ensure we are on the master branch
masterbranch=yes
if [ "$(git rev-parse --abbrev-ref HEAD)" != "master" ]; then
echo "Releases are happening from the master branch, aborting"
echo "Enter the magic word to release anyway"
read magicword
if [ "$magicword" = "iknowwhatido" ]; then
masterbranch=no
else
exit 1
fi
fi
if [ "$masterbranch" = yes ]; then
# Ensure version branch exists
if ! git rev-parse --verify refs/heads/$target_branch 2>/dev/null; then
git branch "$target_branch"
fi
# Merge master branch into version branch
git checkout "$target_branch"
git merge master
fi
# Verify that after the merge everything works
"$0" check-date
"$0" check-unittest
# Generate man pages (indirect check if they build)
make man
# Generate speeches (indirect check if they build)
make speeches
#############################################################
# Everything green, let's do the release
# Tag the current commit
"$0" release-git-tag
# Also merge back the version branch
if [ "$masterbranch" = yes ]; then
git checkout master
git merge "$target_branch"
fi
# Publish git changes
make pub
# publish man, speeches, website
make web-release-all
# Ensure that pypi release has the right version
"$0" version
# Create and publish package for pypi
make pypi-release
# Archlinux release is based on pypi
make archlinux-release
# Announce change on Freecode
make freecode-release
# Announce change on ML
make ml-release
cat << eof
Manual steps post release:
- linkedin
- hackernews
- reddit
- twitter
eof
;;
test)
export PYTHONPATH="$(pwd -P)"
if [ $# -lt 1 ]; then
python3 -m cdist.test
else
python3 -m unittest "$@"
fi
;;
version-branch)
"$0" changelog-version | cut -d. -f '1,2'
;;
version)
echo "VERSION = \"$(git describe)\"" > cdist/version.py
;;
*)
echo "Unknown helper target $@ - aborting"
exit 1
;;
esac

View file

@ -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}"

414
build
View file

@ -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 <http://www.gnu.org/licenses/>.
#
#
# 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

View file

@ -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"""

View file

@ -1,6 +1,6 @@
#!/bin/sh
#
# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
# 2010-2014 Nico Schottelius (nico-cdist at schottelius.org)
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
@ -20,6 +20,6 @@
#
#
if command -v hostname; then
hostname
if command -v uname >/dev/null; then
uname -n
fi

View file

@ -22,6 +22,6 @@
#
#
if command -v uname; then
if command -v uname 2>&1 >/dev/null; then
uname -m
fi

View file

@ -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

View file

@ -54,6 +54,9 @@ case "$($__explorer/os)" in
redhat|centos)
cat /etc/redhat-release
;;
slackware)
cat /etc/slackware-version
;;
suse)
cat /etc/SuSE-release
;;

View file

@ -0,0 +1,32 @@
#!/bin/sh
#
# 2011-2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Get the current state of the apt key.
#
if [ -f "$__object/parameter/keyid" ]; then
keyid="$(cat "$__object/parameter/keyid")"
else
keyid="$__object_id"
fi
apt-key export "$keyid" | head -n 1 | grep -Fqe "BEGIN PGP PUBLIC KEY BLOCK" \
&& echo present \
|| echo absent

View file

@ -0,0 +1,42 @@
#!/bin/sh
#
# 2011-2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
if [ -f "$__object/parameter/keyid" ]; then
keyid="$(cat "$__object/parameter/keyid")"
else
keyid="$__object_id"
fi
state_should="$(cat "$__object/parameter/state")"
state_is="$(cat "$__object/explorer/state")"
if [ "$state_should" = "$state_is" ]; then
# nothing to do
exit 0
fi
case "$state_should" in
present)
keyserver="$(cat "$__object/parameter/keyserver")"
echo "apt-key adv --keyserver \"$keyserver\" --recv-keys \"$keyid\""
;;
absent)
echo "apt-key del \"$keyid\""
;;
esac

View file

@ -0,0 +1,61 @@
cdist-type__apt_key(7)
======================
Steven Armstrong <steven-cdist--@--armstrong.cc>
NAME
----
cdist-type__apt_key - manage the list of keys used by apt
DESCRIPTION
-----------
Manages the list of keys used by apt to authenticate packages.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
state::
'present' or 'absent'. Defaults to 'present'
keyid::
the id of the key to add. Defaults to __object_id
keyserver::
the keyserver from which to fetch the key. If omitted the default set in
./parameter/default/keyserver is used.
EXAMPLES
--------
--------------------------------------------------------------------------------
# Add Ubuntu Archive Automatic Signing Key
__apt_key 437D05B5
# Same thing
__apt_key 437D05B5 --state present
# Get rid of it
__apt_key 437D05B5 --state absent
# same thing with human readable name and explicit keyid
__apt_key UbuntuArchiveKey --keyid 437D05B5
# same thing with other keyserver
__apt_key UbuntuArchiveKey --keyid 437D05B5 --keyserver keyserver.ubuntu.com
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2011-2014 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -0,0 +1 @@
subkeys.pgp.net

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,3 @@
state
keyid
keyserver

View file

@ -0,0 +1,32 @@
#!/bin/sh
#
# 2011-2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Get the current state of the apt key.
#
if [ -f "$__object/parameter/name" ]; then
name="$(cat "$__object/parameter/name")"
else
name="$__object_id"
fi
apt-key list | grep -Fqe "$name" \
&& echo present \
|| echo absent

View file

@ -0,0 +1,45 @@
#!/bin/sh
#
# 2011-2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
if [ -f "$__object/parameter/name" ]; then
name="$(cat "$__object/parameter/name")"
else
name="$__object_id"
fi
state_should="$(cat "$__object/parameter/state")"
state_is="$(cat "$__object/explorer/state")"
if [ "$state_should" = "$state_is" ]; then
# nothing to do
exit 0
fi
case "$state_should" in
present)
uri="$(cat "$__object/parameter/uri")"
printf 'curl -s -L "%s" | apt-key add -\n' "$uri"
;;
absent)
cat << DONE
keyid=\$(apt-key list | grep -B1 "$name" | awk '/pub/ { print \$2 }' | cut -d'/' -f 2)
apt-key del \$keyid
DONE
;;
esac

View file

@ -0,0 +1,51 @@
cdist-type__apt_key_uri(7)
==========================
Steven Armstrong <steven-cdist--@--armstrong.cc>
NAME
----
cdist-type__apt_key_uri - add apt key from uri
DESCRIPTION
-----------
Download a key from an uri and add it to the apt keyring.
REQUIRED PARAMETERS
-------------------
uri::
the uri from which to download the key
OPTIONAL PARAMETERS
-------------------
state::
'present' or 'absent', defaults to 'present'
name::
a name for this key, used when testing if it is already installed.
Defaults to __object_id
EXAMPLES
--------
--------------------------------------------------------------------------------
__apt_key_uri rabbitmq \
--name 'RabbitMQ Release Signing Key <info@rabbitmq.com>' \
--uri http://www.rabbitmq.com/rabbitmq-signing-key-public.asc \
--state present
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2011-2014 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -0,0 +1,21 @@
#!/bin/sh
#
# 2013-2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
__package curl

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,2 @@
state
name

View file

@ -0,0 +1 @@
uri

View file

@ -0,0 +1,42 @@
cdist-type__apt_norecommends(7)
===============================
Steven Armstrong <steven-cdist--@--armstrong.cc>
NAME
----
cdist-type__apt_norecommends - configure apt to not install recommended packages
DESCRIPTION
-----------
Configure apt to not install any recommended or suggested packages.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
None.
EXAMPLES
--------
--------------------------------------------------------------------------------
__apt_norecommends
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2014 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -0,0 +1,42 @@
#!/bin/sh
#
# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
os=$(cat "$__global/explorer/os")
case "$os" in
ubuntu|debian)
# No stinking recommends thank you very much.
# If I want something installed I will do so myself.
__file /etc/apt/apt.conf.d/99-no-recommends \
--owner root --group root --mode 644 \
--source - << DONE
APT::Install-Recommends "0";
APT::Install-Suggests "0";
DONE
;;
*)
cat >&2 << DONE
The developer of this type (${__type##*/}) did not think your operating system
($os) would have any use for it. If you think otherwise please submit a patch.
DONE
exit 1
;;
esac

View file

@ -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

View file

@ -16,7 +16,8 @@ This cdist type allows manage ubuntu ppa repositories.
REQUIRED PARAMETERS
-------------------
state::
The state the ppa should be in, either "present" or "absent".
The state the ppa should be in, either 'present' or 'absent'.
Defaults to 'present'
OPTIONAL PARAMETERS
@ -29,6 +30,8 @@ EXAMPLES
--------------------------------------------------------------------------------
# Enable a ppa repository
__apt_ppa ppa:sans-intern/missing-bits
# same as
__apt_ppa ppa:sans-intern/missing-bits --state present
# Disable a ppa repository
@ -43,5 +46,5 @@ SEE ALSO
COPYING
-------
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
Copyright \(C) 2011-2014 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -1,6 +1,6 @@
#!/bin/sh
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
@ -20,9 +20,10 @@
name="$__object_id"
__package python-software-properties --state present
__package software-properties-common
__package python-software-properties
require="__package/python-software-properties" \
require="__package/software-properties-common __package/python-software-properties" \
__file /usr/local/bin/remove-apt-repository \
--source "$__type/files/remove-apt-repository" \
--mode 0755

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,15 @@
#!/bin/sh
set -u
entry="$uri $distribution $component"
cat << DONE
# Created by cdist ${__type##*/}
# Do not change. Changes will be overwritten.
#
# $name
deb ${forcedarch} $entry
DONE
if [ -f "$__object/parameter/include-src" ]; then
echo "deb-src $entry"
fi

View file

@ -0,0 +1,69 @@
cdist-type__apt_source(7)
=========================
Steven Armstrong <steven-cdist--@--armstrong.cc>
NAME
----
cdist-type__apt_source - manage apt sources
DESCRIPTION
-----------
This cdist type allows you to manage apt sources.
REQUIRED PARAMETERS
-------------------
uri::
the uri to the apt repository
OPTIONAL PARAMETERS
-------------------
arch::
set this if you need to force and specific arch (ubuntu specific)
state::
'present' or 'absent', defaults to 'present'
distribution::
the distribution codename to use. Defaults to DISTRIB_CODENAME from
the targets /etc/lsb-release
component::
space delimited list of components to enable. Defaults to an empty string.
BOOLEAN PARAMETERS
------------------
include-src::
include deb-src entries
EXAMPLES
--------
--------------------------------------------------------------------------------
__apt_source rabbitmq \
--uri http://www.rabbitmq.com/debian/ \
--distribution testing \
--component main \
--include-src \
--state present
__apt_source canonical_partner \
--uri http://archive.canonical.com/ \
--component partner --state present
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2011-2014 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -0,0 +1,56 @@
#!/bin/sh
#
# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
name="$__object_id"
state="$(cat "$__object/parameter/state")"
uri="$(cat "$__object/parameter/uri")"
if [ -f "$__object/parameter/distribution" ]; then
distribution="$(cat "$__object/parameter/distribution")"
else
distribution="$(cat "$__global/explorer/lsb_codename")"
fi
if [ -f "$__object/parameter/component" ]; then
component="$(cat "$__object/parameter/component")"
else
component=""
fi
if [ -f "$__object/parameter/arch" ]; then
forcedarch="[arch=$(cat "$__object/parameter/arch")]"
else
forcedarch=""
fi
# export variables for use in template
export name
export uri
export distribution
export component
export forcedarch
# generate file from template
mkdir "$__object/files"
"$__type/files/source.list.template" > "$__object/files/source.list"
__file "/etc/apt/sources.list.d/${name}.list" \
--source "$__object/files/source.list" \
--owner root --group root --mode 0644 \
--state "$state"
require="$__object_name" __apt_update_index

View file

@ -0,0 +1 @@
include-src

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,4 @@
state
distribution
component
arch

View file

@ -0,0 +1 @@
uri

View file

@ -0,0 +1,21 @@
#!/bin/sh
# 2013 Steven Armstrong (steven-cdist at armstrong.cc)
file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")"
# file does not exist, nothing we could do
[ -f "$file" ] || exit 0
prefix=$(cat "$__object/parameter/prefix" 2>/dev/null || echo "#cdist:__block/$__object_id")
suffix=$(cat "$__object/parameter/suffix" 2>/dev/null || echo "#/cdist:__block/$__object_id")
awk -v prefix="$prefix" -v suffix="$suffix" '{
if (index($0,prefix)) {
triggered=1
}
if (triggered) {
if (index($0,suffix)) {
triggered=0
}
print
}
}' "$file"

View file

@ -0,0 +1,84 @@
#!/bin/sh
#
# 2013 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")"
state_should=$(cat "$__object/parameter/state")
prefix=$(cat "$__object/parameter/prefix" 2>/dev/null || echo "#cdist:__block/$__object_id")
suffix=$(cat "$__object/parameter/suffix" 2>/dev/null || echo "#/cdist:__block/$__object_id")
block="$__object/files/block"
if [ ! -s "$__object/explorer/block" ]; then
state_is='absent'
else
state_is=$(diff -q "$block" "$__object/explorer/block" >/dev/null \
&& echo present \
|| echo changed
)
fi
state_should="$(cat "$__object/parameter/state")"
if [ "$state_should" = "$state_is" ]; then
# Nothing to do, move along
exit 0
fi
remove_block() {
cat << DONE
tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX)
# preserve ownership and permissions of existing file
if [ -f "$file" ]; then
cp -p "$file" "\$tmpfile"
fi
awk -v prefix="$prefix" -v suffix="$suffix" '
{
if (index(\$0,prefix)) {
triggered=1
}
if (triggered) {
if (index(\$0,suffix)) {
triggered=0
}
} else {
print
}
}' "$file" > "\$tmpfile"
mv -f "\$tmpfile" "$file"
DONE
}
case "$state_should" in
present)
if [ "$state_is" = "changed" ]; then
echo update >> "$__messages_out"
remove_block
else
echo add >> "$__messages_out"
fi
cat << DONE
cat >> "$file" << ${__type##*/}_DONE
$(cat "$block")
${__type##*/}_DONE
DONE
;;
absent)
echo remove >> "$__messages_out"
remove_block
;;
esac

View file

@ -0,0 +1,82 @@
cdist-type__block(7)
====================
Steven Armstrong <steven-cdist--@--armstrong.cc>
NAME
----
cdist-type__block - Manage blocks of text in files
DESCRIPTION
-----------
Manage a block of text in an existing file.
The block is identified using the prefix and suffix parameters.
Everything between prefix and suffix is considered to be a managed block
of text.
REQUIRED PARAMETERS
-------------------
text::
the text to manage.
If text is '-' (dash), take what was written to stdin as the text.
OPTIONAL PARAMETERS
-------------------
file::
the file in which to manage the text block.
Defaults to object_id.
prefix::
the prefix to add before the text.
Defaults to #cdist:__block/$__object_id
suffix::
the prefix to add after the text.
Defaults to #/cdist:__block/$__object_id
state::
'present' or 'absent', defaults to 'present'
MESSAGES
--------
add::
block was added
update::
block was updated/changed
remove::
block was removed
EXAMPLES
--------
--------------------------------------------------------------------------------
# text from argument
__block /path/to/file \
--prefix '#start' \
--suffix '#end' \
--text 'some\nblock of\ntext'
# text from stdin
__block some-id \
--file /path/to/file \
--text - << DONE
here some block
of text
DONE
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2013 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -0,0 +1,36 @@
#!/bin/sh
#
# 2013-2014 Steven Armstrong (steven-cdist at armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
file="$(cat "$__object/parameter/file" 2>/dev/null || echo "/$__object_id")"
prefix=$(cat "$__object/parameter/prefix" 2>/dev/null || echo "#cdist:__block/$__object_id")
suffix=$(cat "$__object/parameter/suffix" 2>/dev/null || echo "#/cdist:__block/$__object_id")
text=$(cat "$__object/parameter/text")
mkdir "$__object/files"
# Generate text block for inclusion in file
block="$__object/files/block"
echo "$prefix" > "$block"
if [ "$text" = "-" ]; then
cat "$__object/stdin" >> "$block"
else
cat "$text" >> "$block"
fi
echo "$suffix" >> "$block"

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,4 @@
file
prefix
state
suffix

View file

@ -0,0 +1 @@
text

View file

@ -0,0 +1,34 @@
#!/bin/sh
#
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Retrieve the md5sum of a file to be created, if it is already existing.
#
destination="/$__object_id"
if [ -e "$destination" ]; then
if [ -f "$destination" ]; then
cksum < "$destination"
else
echo "NO REGULAR FILE"
fi
else
echo "NO FILE FOUND, NO CHECKSUM CALCULATED."
fi

View file

@ -0,0 +1,47 @@
#!/bin/sh
#
# 2013 Steven Armstrong (steven-cdist armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
destination="/$__object_id"
# nothing to work with, nothing we could do
[ -e "$destination" ] || exit 0
os=$("$__explorer/os")
case "$os" in
"freebsd")
# FIXME: should be something like this based on man page, but can not test
stat -f "type: %ST
owner: %Du %Su
group: %Dg %Sg
mode: %Op %Sp
size: %Dz
links: %Dl
" "$destination"
;;
*)
stat --printf="type: %F
owner: %u %U
group: %g %G
mode: %a %A
size: %s
links: %h
" "$destination"
;;
esac

View file

@ -0,0 +1,33 @@
#!/bin/sh
#
# 2013 Steven Armstrong (steven-cdist armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
destination="/$__object_id"
if [ ! -e "$destination" ]; then
echo none
elif [ -h "$destination" ]; then
echo symlink
elif [ -f "$destination" ]; then
echo file
elif [ -d "$destination" ]; then
echo directory
else
echo unknown
fi

View file

@ -0,0 +1,93 @@
#!/bin/sh
#
# 2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
destination="/$__object_id"
state_should="$(cat "$__object/parameter/state")"
type="$(cat "$__object/explorer/type")"
stat_file="$__object/explorer/stat"
get_current_value() {
if [ -s "$stat_file" ]; then
_name="$1"
_value="$2"
case "$_value" in
[0-9]*)
_index=2
;;
*)
_index=3
;;
esac
awk '/'"$_name"':/ { print $'$_index' }' "$stat_file"
unset _name _value _index
fi
}
set_group() {
echo chgrp \"$1\" \"$destination\"
echo chgrp $1 >> "$__messages_out"
}
set_owner() {
echo chown \"$1\" \"$destination\"
echo chown $1 >> "$__messages_out"
}
set_mode() {
echo chmod \"$1\" \"$destination\"
echo chmod $1 >> "$__messages_out"
}
set_attributes=
case "$state_should" in
present|exists)
# Note: Mode - needs to happen last as a chown/chgrp can alter mode by
# clearing S_ISUID and S_ISGID bits (see chown(2))
for attribute in group owner mode; do
if [ -f "$__object/parameter/$attribute" ]; then
value_should="$(cat "$__object/parameter/$attribute")"
# change 0xxx format to xxx format => same as stat returns
if [ "$attribute" = mode ]; then
value_should="$(echo $value_should | sed 's/^0\(...\)/\1/')"
fi
value_is="$(get_current_value "$attribute" "$value_should")"
if [ -f "$__object/files/set-attributes" -o "$value_should" != "$value_is" ]; then
"set_$attribute" "$value_should"
fi
fi
done
;;
absent)
if [ "$type" = "file" ]; then
echo rm -f \"$destination\"
echo remove >> "$__messages_out"
fi
;;
*)
echo "Unknown state: $state_should" >&2
exit 1
;;
esac

View file

@ -0,0 +1,64 @@
cdist-type__ccollect_source(7)
==============================
Nico Schottelius <nico-cdist--@--schottelius.org>
NAME
----
cdist-type__ccollect_source - Manage ccollect sources
DESCRIPTION
-----------
This cdist type allows you to create or delete ccollect sources.
REQUIRED PARAMETERS
-------------------
source::
The source from which to backup
destination::
The destination directory
OPTIONAL PARAMETERS
-------------------
state::
'present' or 'absent', defaults to 'present'
ccollectconf::
The CCOLLECT_CONF directory. Defaults to /etc/ccollect.
OPTIONAL MULTIPLE PARAMETERS
----------------------------
exclude::
Paths to exclude of backup
BOOLEAN PARAMETERS
------------------
verbose::
Whether to report backup verbosely
EXAMPLES
--------
--------------------------------------------------------------------------------
__ccollect_source doc.ungleich.ch \
--source doc.ungleich.ch:/ \
--destination /backup/doc.ungleich.ch \
--exclude '/proc/*' --exclude '/sys/*' \
--verbose
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
- ccollect(1)
- http://www.nico.schottelius.org/software/ccollect/
COPYING
-------
Copyright \(C) 2014 Nico Schottelius. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -0,0 +1,53 @@
#!/bin/sh
#
# 2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
name="$__object_id"
state="$(cat "$__object/parameter/state")"
source="$(cat "$__object/parameter/source")"
destination="$(cat "$__object/parameter/destination")"
ccollectconf="$(cat "$__object/parameter/ccollectconf" | sed 's,/$,,')"
sourcedir="$ccollectconf/sources"
basedir="$sourcedir/$name"
destination_file="$basedir/destination"
source_file="$basedir/source"
exclude_file="$basedir/exclude"
verbose_file="$basedir/verbose"
__directory "$basedir" --state "$state"
export require="__directory$basedir"
echo "$destination" | __file "$destination_file" --source - --state "$state"
echo "$source" | __file "$source_file" --source - --state "$state"
################################################################################
# Booleans
if [ -f "$__object/parameter/verbose" ]; then
verbosestate="present"
else
verbosestate="absent"
fi
__file "$verbose_file" --state "$verbosestate"
if [ -f "$__object/parameter/exclude" ]; then
__file "$exclude_file" --source - --state "$state" \
< "$__object/parameter/exclude"
fi

View file

@ -0,0 +1 @@
verbose

View file

@ -0,0 +1 @@
/etc/ccollect

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,2 @@
ccollectconf
state

View file

@ -0,0 +1 @@
exclude

View file

@ -0,0 +1,2 @@
source
destination

View file

@ -0,0 +1,63 @@
cdist-type__cdist(7)
====================
Nico Schottelius <nico-cdist--@--schottelius.org>
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).

View file

@ -0,0 +1,47 @@
#!/bin/sh
#
# 2013 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
directory="$__object_id"
if [ -f "$__object/parameter/shell" ]; then
shell="--shell $(cat "$__object/parameter/shell")"
else
shell=""
fi
username="$(cat "$__object/parameter/username")"
branch="$(cat "$__object/parameter/branch")"
source="$(cat "$__object/parameter/source")"
# Currently hardcoded - if anyone cares, make a parameter
# out of it
home=/home/$username
__user "$username" --home "$home" $shell
require="__user/$username" __directory "$home" \
--owner "$username"
require="__user/$username __directory/$home" __git "$directory" \
--source "$source" \
--owner "$username" --branch "$branch"

View file

@ -0,0 +1 @@
master

View file

@ -0,0 +1 @@
git://github.com/telmich/cdist.git

View file

@ -0,0 +1 @@
cdist

View file

@ -0,0 +1,4 @@
branch
source
username
shell

22
cdist/conf/type/__cron/explorer/entry Executable file → Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
#
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

View file

@ -1,6 +1,8 @@
#!/bin/sh
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2013 Thomas Oettli (otho at sfs.biz)
#
# This file is part of cdist.
#
@ -18,40 +20,47 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
os="$(cat "$__global/explorer/os")"
name="$__object_name"
user="$(cat "$__object/parameter/user")"
state_should="$(cat "$__object/parameter/state")"
state_is=$(diff -q "$__object/parameter/entry" "$__object/explorer/entry" \
&& echo present \
|| echo absent
)
command="$(cat "$__object/parameter/command")"
# FreeBSD mktemp doesn't allow execution without at least one param
if [ "$os" = "freebsd" ]; then
mktemp="mktemp -t tmp"
if [ -f "$__object/parameter/raw" ]; then
raw="$(cat "$__object/parameter/raw")"
entry="$raw $command"
elif [ -f "$__object/parameter/raw_command" ]; then
entry="$command"
else
mktemp="mktemp"
minute="$(cat "$__object/parameter/minute" 2>/dev/null || echo "*")"
hour="$(cat "$__object/parameter/hour" 2>/dev/null || echo "*")"
day_of_month="$(cat "$__object/parameter/day_of_month" 2>/dev/null || echo "*")"
month="$(cat "$__object/parameter/month" 2>/dev/null || echo "*")"
day_of_week="$(cat "$__object/parameter/day_of_week" 2>/dev/null || echo "*")"
entry="$minute $hour $day_of_month $month $day_of_week $command"
fi
if [ "$state_is" != "$state_should" ]; then
case "$state_should" in
present)
cat << DONE
tmp=\$($mktemp)
crontab -u $user -l > \$tmp
cat >> \$tmp << EOC
$(cat "$__object/parameter/entry")
EOC
crontab -u $user \$tmp
rm \$tmp
DONE
;;
absent)
# defined in type manifest
prefix="$(cat "$__object/parameter/prefix")"
suffix="$(cat "$__object/parameter/suffix")"
cat << DONE
crontab -u $user -l | awk -v prefix="$prefix" -v suffix="$suffix" '
entry="$entry # $name"
mkdir "$__object/files"
echo "$entry" > "$__object/files/entry"
if diff -q "$__object/files/entry" "$__object/explorer/entry" >/dev/null; then
state_is=present
else
state_is=absent
fi
state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")"
[ "$state_is" = "$state_should" ] && exit 0
# If anything is going to change, ensure the old entries are
# not present anymore
# These are the old markers
prefix="#cdist:__cron/$__object_id"
suffix="#/cdist:__cron/$__object_id"
filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V"
cat << DONE
crontab -u $user -l 2>/dev/null | grep -v -E "$filter" | awk -v prefix="$prefix" -v suffix="$suffix" '
{
if (index(\$0,prefix)) {
triggered=1
@ -66,6 +75,17 @@ crontab -u $user -l | awk -v prefix="$prefix" -v suffix="$suffix" '
}
' | crontab -u $user -
DONE
;;
esac
fi
case "$state_should" in
present)
# if we insert new entry, filter also all entrys out with the same id
echo "("
echo "crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" | grep -v \"# $name\\$\" 2>/dev/null || true"
echo "echo '$entry'"
echo ") | crontab -u $user -"
;;
absent)
echo "( crontab -u $user -l 2>/dev/null | grep -v -E \"$filter\" 2>/dev/null || true ) | \\"
echo "grep -v \"# $name\\$\" | crontab -u $user -"
;;
esac

View file

@ -41,6 +41,10 @@ raw::
Can for example be used to specify cron EXTENSIONS like reboot, yearly etc.
See crontab(5) for the extensions if any that your cron implementation
implements.
raw_command::
Take whatever the user has given in the commmand and ignore everything else.
If given, the command will be added to crontab.
Can for example be used to define variables like SHELL or MAILTO.
EXAMPLES
@ -57,6 +61,10 @@ __cron some-id --user root --command "/path/to/script" \
# remove cronjob
__cron some-id --user root --command "/path/to/script" --state absent
# define default shell
__cron some-id --user root --raw_command --command "SHELL=/bin/bash" \
--state present
--------------------------------------------------------------------------------
@ -68,5 +76,5 @@ SEE ALSO
COPYING
-------
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
Copyright \(C) 2011-2013 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

29
cdist/conf/type/__cron/manifest Executable file → Normal file
View file

@ -1,6 +1,6 @@
#!/bin/sh
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2013 Thomas Oettli (otho at sfs.biz)
#
# This file is part of cdist.
#
@ -18,28 +18,7 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
name="$__object_id"
user="$(cat "$__object/parameter/user")"
command="$(cat "$__object/parameter/command")"
# set defaults
test -f "$__object/parameter/state" || echo "present" > "$__object/parameter/state"
if [ -f "$__object/parameter/raw" ]; then
raw="$(cat "$__object/parameter/raw")"
entry="$raw $command"
else
minute="$(cat "$__object/parameter/minute" 2>/dev/null || echo "*")"
hour="$(cat "$__object/parameter/hour" 2>/dev/null || echo "*")"
day_of_month="$(cat "$__object/parameter/day_of_month" 2>/dev/null || echo "*")"
month="$(cat "$__object/parameter/month" 2>/dev/null || echo "*")"
day_of_week="$(cat "$__object/parameter/day_of_week" 2>/dev/null || echo "*")"
entry="$minute $hour $day_of_month $month $day_of_week $command"
if [ -f "$__object/parameter/raw" ] && [ -f "$__object/parameter/raw_command" ]; then
echo "ERROR: both raw and raw_command specified" >&2
exit 1
fi
# NOTE: if changed, also change in explorers
prefix="#cdist:__cron/$name"
suffix="#/cdist:__cron/$name"
echo "$prefix" | tee "$__object/parameter/prefix" > "$__object/parameter/entry"
echo "$entry" >> "$__object/parameter/entry"
echo "$suffix" | tee "$__object/parameter/suffix" >> "$__object/parameter/entry"

View file

@ -0,0 +1 @@
raw_command

View file

@ -1,6 +1,6 @@
#!/bin/sh
#
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
# 2011-2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@ -21,6 +21,12 @@
# Setup selections
#
filename="$(cat "$__object/parameter/file")"
if [ "$filename" = "-" ]; then
filename="$__object/stdin"
fi
echo "debconf-set-selections << __file-eof"
cat "$(cat "$__object/parameter/file")"
cat "$filename"
echo "__file-eof"

View file

@ -17,7 +17,8 @@ to setup configuration parameters.
REQUIRED PARAMETERS
-------------------
file::
If supplied, use the given filename as input for debconf-set-selections(1)
Use the given filename as input for debconf-set-selections(1)
If filename is "-", read from stdin.
EXAMPLES
@ -29,15 +30,21 @@ __debconf_set_selections nslcd --file /path/to/file
# Setup configuration for nslcd from another type
__debconf_set_selections nslcd --file "$__type/files/preseed/nslcd"
__debconf_set_selections nslcd --file - << eof
gitolite gitolite/gituser string git
eof
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
- cdist-type__update_alternatives(7)
- debconf-set-selections(1)
COPYING
-------
Copyright \(C) 2011 Nico Schottelius. Free use of this software is
Copyright \(C) 2011-2014 Nico Schottelius. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -0,0 +1,43 @@
#!/bin/sh
#
# 2013 Steven Armstrong (steven-cdist armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
destination="/$__object_id"
# nothing to work with, nothing we could do
[ -e "$destination" ] || exit 0
os=$("$__explorer/os")
case "$os" in
"freebsd")
# FIXME: should be something like this based on man page, but can not test
stat -f "type: %ST
owner: %Du %Su
group: %Dg %Sg
mode: %Op %Sp
" "$destination"
;;
*)
stat --printf="type: %F
owner: %u %U
group: %g %G
mode: %a %A
" "$destination"
;;
esac

View file

@ -0,0 +1,33 @@
#!/bin/sh
#
# 2013 Steven Armstrong (steven-cdist armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
destination="/$__object_id"
if [ ! -e "$destination" ]; then
echo none
elif [ -h "$destination" ]; then
echo symlink
elif [ -f "$destination" ]; then
echo file
elif [ -d "$destination" ]; then
echo directory
else
echo unknown
fi

View file

@ -1,6 +1,8 @@
#!/bin/sh
#
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2013 Steven Armstrong (steven-cdist armstrong.cc)
# 2014 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
#
@ -18,42 +20,97 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
state_should="present"
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
state_is="$(cat "$__object/explorer/state")"
[ "$state_should" = "$state_is" ] && exit 0
destination="/$__object_id"
state_should="$(cat "$__object/parameter/state")"
type="$(cat "$__object/explorer/type")"
stat_file="$__object/explorer/stat"
# variable to keep track if we have to set directory attributes
set_attributes=
mkdiropt=""
[ -f "$__object/parameter/parents" ] && mkdiropt="-p"
recursive=""
[ -f "$__object/parameter/recursive" ] && recursive="-R"
if [ -f "$__object/parameter/recursive" ]; then
recursive="-R"
# need to allways set attributes when recursive is given
# as we don't want to check all subfolders/files
set_attributes=1
fi
get_current_value() {
if [ -s "$stat_file" ]; then
_name="$1"
_value="$2"
case "$_value" in
[0-9]*)
_index=2
;;
*)
_index=3
;;
esac
awk '/'"$_name"':/ { print $'$_index' }' "$stat_file"
unset _name _value _index
fi
}
set_group() {
echo chgrp $recursive \"$1\" \"$destination\"
echo chgrp $recursive $1 >> "$__messages_out"
}
set_owner() {
echo chown $recursive \"$1\" \"$destination\"
echo chown $recursive $1 >> "$__messages_out"
}
set_mode() {
echo chmod $recursive \"$1\" \"$destination\"
echo chmod $recursive $1 >> "$__messages_out"
}
case "$state_should" in
present)
echo mkdir $mkdiropt \"$destination\"
present)
if [ "$type" != "directory" ]; then
set_attributes=1
if [ "$type" != "none" ]; then
# our destination is not a directory, remove whatever is there
# and then create our directory and set all attributes
echo rm -f "\"$destination\""
echo "remove non directory" >> "$__messages_out"
fi
echo "mkdir $mkdiropt \"$destination\""
echo "create" >> "$__messages_out"
fi
# Mode settings
if [ -f "$__object/parameter/mode" ]; then
echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\"
fi
# Note: Mode - needs to happen last as a chown/chgrp can alter mode by
# clearing S_ISUID and S_ISGID bits (see chown(2))
for attribute in group owner mode; do
if [ -f "$__object/parameter/$attribute" ]; then
value_should="$(cat "$__object/parameter/$attribute")"
value_is="$(get_current_value "$attribute" "$value_should")"
# Group
if [ -f "$__object/parameter/group" ]; then
echo chgrp $recursive \"$(cat "$__object/parameter/group")\" \"$destination\"
fi
# change 0xxx format to xxx format => same as stat returns
if [ "$attribute" = mode ]; then
value_should="$(echo $value_should | sed 's/^0\(...\)/\1/')"
fi
# Owner
if [ -f "$__object/parameter/owner" ]; then
echo chown $recursive \"$(cat "$__object/parameter/owner")\" \"$destination\"
if [ "$set_attributes" = 1 ] || [ "$value_should" != "$value_is" ]; then
"set_$attribute" "$value_should"
fi
fi
done
;;
absent)
if [ "$type" = "directory" ]; then
echo rm -rf \"$destination\"
echo remove >> "$__messages_out"
fi
;;
absent)
echo rm -rf \"$destination\"
;;
*)
echo "Unknown state: $state_should" >&2
exit 1
;;
;;
*)
echo "Unknown state: $state_should" >&2
exit 1
;;
esac

View file

@ -36,12 +36,31 @@ owner::
BOOLEAN PARAMETERS
------------------
parents::
Whether to create parents as well (mkdir -p behaviour)
Whether to create parents as well (mkdir -p behaviour).
Warning: all intermediate directory permissions default
to whatever mkdir -p does.
Usually this means root:root, 0700.
recursive::
If supplied the chgrp and chown call will run recursively.
This does *not* influence the behaviour of chmod.
MESSAGES
--------
chgrp <group>::
Changed group membership
chown <owner>::
Changed owner
chmod <mode>::
Changed mode
create::
Empty directory was created
remove::
Directory exists, but state is absent, directory will be removed by generated code.
remove non directory::
Someting other than a directory with the same name exists and was removed prior to create.
EXAMPLES
--------

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,47 @@
#!/bin/sh
#
# 2013 Steven Armstrong (steven-cdist armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
destination="/$__object_id"
# nothing to work with, nothing we could do
[ -e "$destination" ] || exit 0
os=$("$__explorer/os")
case "$os" in
"freebsd")
# FIXME: should be something like this based on man page, but can not test
stat -f "type: %ST
owner: %Du %Su
group: %Dg %Sg
mode: %Op %Sp
size: %Dz
links: %Dl
" "$destination"
;;
*)
stat --printf="type: %F
owner: %u %U
group: %g %G
mode: %a %A
size: %s
links: %h
" "$destination"
;;
esac

View file

@ -0,0 +1,33 @@
#!/bin/sh
#
# 2013 Steven Armstrong (steven-cdist armstrong.cc)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
destination="/$__object_id"
if [ ! -e "$destination" ]; then
echo none
elif [ -h "$destination" ]; then
echo symlink
elif [ -f "$destination" ]; then
echo file
elif [ -d "$destination" ]; then
echo directory
else
echo unknown
fi

View file

@ -1,6 +1,7 @@
#!/bin/sh
#
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
# 2013 Steven Armstrong (steven-cdist armstrong.cc)
#
# This file is part of cdist.
#
@ -17,34 +18,61 @@
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# __file is a very basic type, which will probably be reused quite often
#
destination="/$__object_id"
state_should=present
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
exists="$(cat "$__object/explorer/exists")"
state_should="$(cat "$__object/parameter/state")"
type="$(cat "$__object/explorer/type")"
[ "$state_should" = "exists" -a "$exists" = "yes" ] && exit 0 # nothing to do
[ "$state_should" = "exists" -a "$type" = "file" ] && exit 0 # nothing to do
upload_file=
create_file=
if [ "$state_should" = "present" -o "$state_should" = "exists" ]; then
if [ -f "$__object/parameter/source" ]; then
if [ ! -f "$__object/parameter/source" ]; then
create_file=1
echo create >> "$__messages_out"
else
source="$(cat "$__object/parameter/source")"
if [ "$source" = "-" ]; then
source="$__object/stdin"
fi
if [ -f "$source" ]; then
local_cksum="$(cksum < "$source")"
remote_cksum="$(cat "$__object/explorer/cksum")"
if [ "$local_cksum" != "$remote_cksum" ]; then
echo "$__remote_copy" "$source" "${__target_host}:${destination}"
fi
else
if [ ! -f "$source" ]; then
echo "Source \"$source\" does not exist." >&2
exit 1
else
if [ "$type" != "file" ]; then
# destination is not a regular file, upload source to replace it
upload_file=1
else
local_cksum="$(cksum < "$source")"
remote_cksum="$(cat "$__object/explorer/cksum")"
if [ "$local_cksum" != "$remote_cksum" ]; then
# destination is a regular file, but not the right one
upload_file=1
fi
fi
fi
fi
if [ "$create_file" -o "$upload_file" ]; then
# tell gencode-remote that we created or uploaded a file and that it must
# set all attributes no matter what the explorer retreived
mkdir "$__object/files"
touch "$__object/files/set-attributes"
# upload file to temp location
tempfile_template="${destination}.cdist.XXXXXXXXXX"
cat << DONE
destination_upload="\$($__remote_exec $__target_host "mktemp $tempfile_template")"
DONE
if [ "$upload_file" ]; then
echo upload >> "$__messages_out"
cat << DONE
$__remote_copy $source ${__target_host}:\$destination_upload
DONE
fi
# move uploaded file into place
cat << DONE
$__remote_exec $__target_host "rm -rf \"$destination\"; mv \"\$destination_upload\" \"$destination\""
DONE
fi
fi

View file

@ -1,6 +1,7 @@
#!/bin/sh
#
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2013 Steven Armstrong (steven-cdist armstrong.cc)
#
# This file is part of cdist.
#
@ -17,52 +18,77 @@
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# __file is a very basic type, which will probably be reused quite often
#
destination="/$__object_id"
state_should=present
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
exists="$(cat "$__object/explorer/exists")"
state_should="$(cat "$__object/parameter/state")"
type="$(cat "$__object/explorer/type")"
stat_file="$__object/explorer/stat"
get_current_value() {
if [ -s "$stat_file" ]; then
_name="$1"
_value="$2"
case "$_value" in
[0-9]*)
_index=2
;;
*)
_index=3
;;
esac
awk '/'"$_name"':/ { print $'$_index' }' "$stat_file"
unset _name _value _index
fi
}
set_group() {
echo chgrp \"$1\" \"$destination\"
echo chgrp $1 >> "$__messages_out"
}
set_owner() {
echo chown \"$1\" \"$destination\"
echo chown $1 >> "$__messages_out"
}
set_mode() {
echo chmod \"$1\" \"$destination\"
echo chmod $1 >> "$__messages_out"
}
set_attributes=
case "$state_should" in
present|exists)
# No source? Create empty file
if [ ! -f "$__object/parameter/source" ]; then
if [ "$exists" = "no" ]; then
echo touch \"$destination\"
fi
fi
present|exists)
# Note: Mode - needs to happen last as a chown/chgrp can alter mode by
# clearing S_ISUID and S_ISGID bits (see chown(2))
for attribute in group owner mode; do
if [ -f "$__object/parameter/$attribute" ]; then
value_should="$(cat "$__object/parameter/$attribute")"
# Group
if [ -f "$__object/parameter/group" ]; then
echo chgrp \"$(cat "$__object/parameter/group")\" \"$destination\"
fi
# change 0xxx format to xxx format => same as stat returns
if [ "$attribute" = mode ]; then
value_should="$(echo $value_should | sed 's/^0\(...\)/\1/')"
fi
# Owner
if [ -f "$__object/parameter/owner" ]; then
echo chown \"$(cat "$__object/parameter/owner")\" \"$destination\"
fi
value_is="$(get_current_value "$attribute" "$value_should")"
if [ -f "$__object/files/set-attributes" -o "$value_should" != "$value_is" ]; then
"set_$attribute" "$value_should"
fi
fi
done
# Mode - needs to happen last as a chown/chgrp can alter mode by
# clearing S_ISUID and S_ISGID bits (see chown(2))
if [ -f "$__object/parameter/mode" ]; then
echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\"
fi
;;
;;
absent)
if [ "$exists" = "yes" ]; then
echo rm -f \"$destination\"
fi
;;
*)
echo "Unknown state: $state_should" >&2
exit 1
;;
absent)
if [ "$type" = "file" ]; then
echo rm -f \"$destination\"
echo remove >> "$__messages_out"
fi
;;
*)
echo "Unknown state: $state_should" >&2
exit 1
;;
esac

View file

@ -13,6 +13,15 @@ DESCRIPTION
This cdist type allows you to create files, remove files and set file
attributes on the target.
If the file already exists on the target, then if it is a:
- regular file, and state is:
present: replace it with the source file if they are not equal
exists: do nothing
- symlink: replace it with the source file
- directory: replace it with the source file
In any case, make sure that the file attributes are as specified.
REQUIRED PARAMETERS
-------------------
@ -41,6 +50,21 @@ source::
If not supplied, an empty file or directory will be created.
If source is '-' (dash), take what was written to stdin as the file content.
MESSAGES
--------
chgrp <group>::
Changed group membership
chown <owner>::
Changed owner
chmod <mode>::
Changed mode
create::
Empty file was created (no --source specified)
remove::
File exists, but state is absent, file will be removed by generated code.
upload::
File was uploaded
EXAMPLES
--------
@ -81,5 +105,5 @@ SEE ALSO
COPYING
-------
Copyright \(C) 2011-2012 Nico Schottelius. Free use of this software is
Copyright \(C) 2011-2013 Nico Schottelius. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1,5 @@
#!/bin/sh
destination="/$__object_id/.git"
stat --print "%G" ${destination} 2>/dev/null || exit 0

View file

@ -0,0 +1,5 @@
#!/bin/sh
destination="/$__object_id/.git"
stat --print "%U" ${destination} 2>/dev/null || exit 0

View file

@ -20,21 +20,39 @@
#
state_is="$(cat "$__object/explorer/state")"
state_should=present
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
owner_is="$(cat "$__object/explorer/owner")"
group_is="$(cat "$__object/explorer/group")"
branch=master
[ -f "$__object/parameter/branch" ] && branch="$(cat "$__object/parameter/branch")"
state_should="$(cat "$__object/parameter/state")"
branch="$(cat "$__object/parameter/branch")"
source="$(cat "$__object/parameter/source")"
destination="/$__object_id"
[ "$state_should" = "$state_is" ] && exit 0
owner="$(cat "$__object/parameter/owner")"
group="$(cat "$__object/parameter/group")"
mode="$(cat "$__object/parameter/mode")"
[ "$state_should" = "$state_is" -a \
"$owner" = "$owner_is" -a \
"$group" = "$group_is" -a \
-n "$mode" ] && exit 0
case $state_should in
present)
echo git clone --quiet --branch "$branch" "$source" "$destination"
if [ "$state_should" != "$state_is" ]; then
echo git clone --quiet --branch "$branch" "$source" "$destination"
fi
if [ \( -n "$owner" -a "$owner_is" != "$owner" \) -o \
\( -n "$group" -a "$group_is" != "$group" \) ]; then
echo chown -R "${owner}:${group}" "$destination"
fi
if [ -n "$mode" ]; then
echo chmod -R "$mode" "$destination"
fi
;;
# Handled in manifest
absent)

View file

@ -26,6 +26,16 @@ state::
branch::
Create this branch by checking out the remote branch of this name
Default branch is "master"
group::
Group to chgrp to.
mode::
Unix permissions, suitable for chmod.
owner::
User to chown to.
EXAMPLES

View file

@ -23,17 +23,13 @@
__package git --state present
state_should=present
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
[ -f "$__object/parameter/owner" ] && dirparams="$dirparams --owner $(cat "$__object/parameter/owner")"
[ -f "$__object/parameter/group" ] && dirparams="$dirparams --group $(cat "$__object/parameter/group")"
state_should="$(cat "$__object/parameter/state")"
# Let __directory handle removal of git repos
case "$state_should" in
present)
__directory "$__object_id" --state present $dirparams --recursive
:
;;
absent)

View file

@ -0,0 +1 @@
master

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@
present

View file

@ -2,3 +2,4 @@ state
branch
group
owner
mode

View file

@ -58,10 +58,12 @@ if grep -q "^${name}:" "$__object/explorer/group"; then
if [ "$new_value" != "$current_value" ]; then
set -- "$@" "$proparg" \"$new_value\"
echo change $property $new_value $current_value >> "$__messages_out"
fi
done
if [ $# -gt 0 ]; then
echo mod >> "$__messages_out"
case $os in
freebsd)
echo pw group mod "$@" "$name"
@ -72,6 +74,7 @@ if grep -q "^${name}:" "$__object/explorer/group"; then
esac
fi
else
echo add >> "$__messages_out"
for property in $(ls .); do
new_value="$(cat "$property")"
if [ "$os" = "freebsd" ]; then
@ -95,6 +98,7 @@ else
fi
set -- "$@" "$proparg" \"$new_value\"
echo set $property $new_value >> "$__messages_out"
done
case $os in

View file

@ -26,6 +26,18 @@ password::
see above
MESSAGES
--------
mod::
group is modified
add::
New group added
change <property> <new_value> <current_value>::
Changed group property from current_value to new_value
set <property> <new_value>::
set property to new value, property was not set bevore
EXAMPLES
--------

View file

@ -0,0 +1,24 @@
#!/bin/sh
#
# 2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Check whether system has hostnamectl
#
command -v hostnamectl || true

View file

@ -1,6 +1,6 @@
#!/bin/sh
#
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
# 2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@ -18,13 +18,9 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Check whether file exists or not
# Retrieve the contents of /etc/hostname
#
destination="/$__object_id"
if [ -e "$destination" ]; then
echo yes
else
echo no
if [ -f /etc/hostname ]; then
cat /etc/hostname
fi

View file

@ -0,0 +1,50 @@
#!/bin/sh
#
# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
# 2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
if [ -f "$__object/parameter/name" ]; then
name_should="$(cat "$__object/parameter/name")"
else
name_should="$(echo "${__target_host%%.*}")"
fi
os=$(cat "$__global/explorer/os")
name_running=$(cat "$__global/explorer/hostname")
name_config=$(cat "$__object/explorer/hostname_file")
has_hostnamectl=$(cat "$__object/explorer/has_hostnamectl")
################################################################################
# If everything is ok -> exit
#
if [ "$name_config" = "$name_should" -a "$name_running" = "$name_should" ]; then
exit 0
fi
################################################################################
# Setup hostname
#
echo changed >> "$__messages_out"
if [ "$has_hostnamectl" ]; then
echo "hostnamectl set-hostname '$name_should'"
else
echo "hostname '$name_should'"
echo "printf '%s\n' '$name_should' > /etc/hostname"
fi

View file

@ -0,0 +1,52 @@
cdist-type__hostname(7)
=======================
Steven Armstrong <steven-cdist--@--armstrong.cc>
NAME
----
cdist-type__hostname - set the hostname
DESCRIPTION
-----------
Set's the hostname on various operating systems.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
name::
The hostname to set. Defaults to the first segment of __target_host
(${__target_host%%.*})
MESSAGES
--------
changed::
Changed the hostname
EXAMPLES
--------
--------------------------------------------------------------------------------
# take hostname from __target_host
__hostname
# set hostname explicitly
__hostname --name some-static-hostname
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2012 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -0,0 +1,38 @@
#!/bin/sh
#
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
# 2014 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
os=$(cat "$__global/explorer/os")
not_supported() {
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
echo "Please contribute an implementation for it if you can." >&2
exit 1
}
case "$os" in
archlinux|debian|ubuntu)
# handled in gencode-remote
:
;;
*)
not_supported
;;
esac

Some files were not shown because too many files have changed in this diff Show more