Merge branch 'master' into 2.1_doc_restructure
This commit is contained in:
commit
eb6478ce58
113 changed files with 1074 additions and 1136 deletions
|
@ -26,4 +26,8 @@ dir=${0%/*}
|
||||||
# Ensure version is present - the bundled/shipped version contains a static version,
|
# Ensure version is present - the bundled/shipped version contains a static version,
|
||||||
# the git version contains a dynamic version
|
# the git version contains a dynamic version
|
||||||
"$dir/../build" version
|
"$dir/../build" version
|
||||||
PYTHONPATH="${dir}/../" "$dir/../scripts/cdist" "$@"
|
|
||||||
|
libdir=$(cd "${dir}/../" && pwd -P)
|
||||||
|
export PYTHONPATH="${libdir}"
|
||||||
|
|
||||||
|
"$dir/../scripts/cdist" "$@"
|
||||||
|
|
88
build
88
build
|
@ -35,6 +35,7 @@ A2XH="a2x -f xhtml --no-xmllint -a encoding=UTF-8"
|
||||||
|
|
||||||
# Developer webbase
|
# Developer webbase
|
||||||
WEBDIR=$HOME/niconetz
|
WEBDIR=$HOME/niconetz
|
||||||
|
WEBBLOG=$WEBDIR/blog
|
||||||
WEBBASE=$WEBDIR/software/cdist
|
WEBBASE=$WEBDIR/software/cdist
|
||||||
WEBMAN=$WEBBASE/man/$version
|
WEBMAN=$WEBBASE/man/$version
|
||||||
WEBPAGE=${WEBBASE}.mdwn
|
WEBPAGE=${WEBBASE}.mdwn
|
||||||
|
@ -108,7 +109,14 @@ case "$1" in
|
||||||
|
|
||||||
$0 pub
|
$0 pub
|
||||||
|
|
||||||
$0 dist-post
|
$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)
|
changelog-version)
|
||||||
|
@ -142,15 +150,78 @@ case "$1" in
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
dist-post)
|
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
|
cat << notes
|
||||||
|
|
||||||
To be done manually...
|
To be done manually...
|
||||||
|
|
||||||
- freecode release
|
|
||||||
- blog entry
|
|
||||||
- linkedin entry
|
- linkedin entry
|
||||||
- mailinglist update
|
|
||||||
notes
|
notes
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
@ -214,13 +285,13 @@ eof
|
||||||
printf "Press enter to submit to freecode> "
|
printf "Press enter to submit to freecode> "
|
||||||
read dummy
|
read dummy
|
||||||
|
|
||||||
cat << eof | cfreecode-api release cdist
|
cat << eof | cfreecode-api release-add cdist
|
||||||
{
|
{
|
||||||
"auth_code": "$api_token",
|
"auth_code": "$api_token",
|
||||||
"release": {
|
"release": {
|
||||||
"tag_list": "REPLACEME",
|
"tag_list": "$taglist",
|
||||||
"version": "$version",
|
"version": "$version",
|
||||||
"changelog": "REPLACEMETOO",
|
"changelog": "$changelog",
|
||||||
"hidden_from_frontpage": false
|
"hidden_from_frontpage": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,6 +373,7 @@ eof
|
||||||
|
|
||||||
test)
|
test)
|
||||||
shift # skip t
|
shift # skip t
|
||||||
|
export PYTHONPATH="$(pwd -P)"
|
||||||
|
|
||||||
if [ $# -lt 1 ]; then
|
if [ $# -lt 1 ]; then
|
||||||
python3 -m cdist.test
|
python3 -m cdist.test
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
name="$__object_id"
|
name="$__object_id"
|
||||||
|
|
||||||
__package python-software-properties --state installed
|
__package python-software-properties --state present
|
||||||
|
|
||||||
require="__package/python-software-properties" \
|
require="__package/python-software-properties" \
|
||||||
__file /usr/local/bin/remove-apt-repository \
|
__file /usr/local/bin/remove-apt-repository \
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
# run 'apt-get update' if anything in /etc/apt is newer then /var/lib/apt/lists
|
# run 'apt-get update' if anything in /etc/apt is newer then /var/lib/apt/lists
|
||||||
cat << DONE
|
cat << DONE
|
||||||
if find /etc/apt -cnewer /var/lib/apt/lists | grep . > /dev/null; then
|
if find /etc/apt -mindepth 1 -cnewer /var/lib/apt/lists | grep . > /dev/null; then
|
||||||
apt-get update || apt-get update
|
apt-get update || apt-get update
|
||||||
fi
|
fi
|
||||||
DONE
|
DONE
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
|
||||||
#
|
|
||||||
# This file is part of cdist.
|
|
||||||
#
|
|
||||||
# cdist is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# cdist is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
name="/$__object_id"
|
|
||||||
map="$(cat "$__object/parameter/map")"
|
|
||||||
|
|
||||||
if [ -f "$__object/parameter/type" ]; then
|
|
||||||
type="$(cat "$__object/parameter/type")"
|
|
||||||
else
|
|
||||||
type="file"
|
|
||||||
echo "$type" > "$__object/parameter/type"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Generate entry for use in auto.master
|
|
||||||
entry="${name} ${type}:${map}"
|
|
||||||
if [ -f "$__object/parameter/options" ]; then
|
|
||||||
entry="$entry $(cat "$__object/parameter/options")"
|
|
||||||
fi
|
|
||||||
if [ -f "$__object/parameter/comment" ]; then
|
|
||||||
echo "# $(cat "$__object/parameter/comment")" > "$__object/parameter/entry"
|
|
||||||
fi
|
|
||||||
echo "$entry" >> "$__object/parameter/entry"
|
|
||||||
|
|
||||||
require="$__object_name" __autofs_master
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Generated from cdist __autofs_master
|
|
||||||
# Do not change this file. Changes will be overwritten.
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
header
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -24,11 +24,11 @@
|
||||||
destination="/$__object_id"
|
destination="/$__object_id"
|
||||||
|
|
||||||
if [ -e "$destination" ]; then
|
if [ -e "$destination" ]; then
|
||||||
if [ -f "$destination" ]; then
|
if [ -f "$destination" ]; then
|
||||||
cksum < "$destination"
|
cksum < "$destination"
|
||||||
else
|
else
|
||||||
echo "NO REGULAR FILE"
|
echo "NO REGULAR FILE"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "NO FILE FOUND, NO CHECKSUM CALCULATED."
|
echo "NO FILE FOUND, NO CHECKSUM CALCULATED."
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
destination="/$__object_id"
|
destination="/$__object_id"
|
||||||
|
|
||||||
if [ -e "$destination" ]; then
|
if [ -e "$destination" ]; then
|
||||||
echo yes
|
echo yes
|
||||||
else
|
else
|
||||||
echo no
|
echo no
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -22,12 +22,13 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
destination="/$__object_id"
|
destination="/$__object_id"
|
||||||
state_should="$(cat "$__object/parameter/state")"
|
state_should=present
|
||||||
|
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
|
||||||
exists="$(cat "$__object/explorer/exists")"
|
exists="$(cat "$__object/explorer/exists")"
|
||||||
|
|
||||||
[ "$state_should" = "exists" -a "$exists" = "yes" ] && exit 0 # nothing to do
|
[ "$state_should" = "exists" -a "$exists" = "yes" ] && exit 0 # nothing to do
|
||||||
|
|
||||||
if [ "$state_should" = "present" ]; then
|
if [ "$state_should" = "present" -o "$state_should" = "exists" ]; then
|
||||||
if [ -f "$__object/parameter/source" ]; then
|
if [ -f "$__object/parameter/source" ]; then
|
||||||
source="$(cat "$__object/parameter/source")"
|
source="$(cat "$__object/parameter/source")"
|
||||||
if [ "$source" = "-" ]; then
|
if [ "$source" = "-" ]; then
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -22,11 +22,12 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
destination="/$__object_id"
|
destination="/$__object_id"
|
||||||
state_should="$(cat "$__object/parameter/state")"
|
state_should=present
|
||||||
|
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
|
||||||
exists="$(cat "$__object/explorer/exists")"
|
exists="$(cat "$__object/explorer/exists")"
|
||||||
|
|
||||||
case "$state_should" in
|
case "$state_should" in
|
||||||
present)
|
present|exists)
|
||||||
# No source? Create empty file
|
# No source? Create empty file
|
||||||
if [ ! -f "$__object/parameter/source" ]; then
|
if [ ! -f "$__object/parameter/source" ]; then
|
||||||
if [ "$exists" = "no" ]; then
|
if [ "$exists" = "no" ]; then
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -24,17 +24,16 @@ destination=/etc/issue
|
||||||
os="$(cat "$__global/explorer/os")"
|
os="$(cat "$__global/explorer/os")"
|
||||||
|
|
||||||
if [ -f "$__object/parameter/source" ]; then
|
if [ -f "$__object/parameter/source" ]; then
|
||||||
source="$(cat "$__object/parameter/source")"
|
source="$(cat "$__object/parameter/source")"
|
||||||
echo using $source
|
|
||||||
else
|
else
|
||||||
case "$os" in
|
case "$os" in
|
||||||
archlinux|redhat)
|
archlinux|redhat)
|
||||||
source="$__type/files/$os"
|
source="$__type/files/$os"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
source="$__type/files/default"
|
source="$__type/files/default"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
__file "$destination" --source "$source"
|
__file "$destination" --source "$source"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -18,42 +19,42 @@
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
key="$(cat "$__object/parameter/key")"
|
key="$__object_id"
|
||||||
|
[ -f "$__object/parameter/key" ] && key="$(cat "$__object/parameter/key")"
|
||||||
|
state_should=present
|
||||||
|
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
|
||||||
|
|
||||||
file="$(cat "$__object/parameter/file")"
|
file="$(cat "$__object/parameter/file")"
|
||||||
delimiter="$(cat "$__object/parameter/delimiter")"
|
delimiter="$(cat "$__object/parameter/delimiter")"
|
||||||
value="$(cat "$__object/parameter/value")"
|
value="$(cat "$__object/parameter/value")"
|
||||||
|
|
||||||
state_is="$(cat "$__object/explorer/state")"
|
state_is="$(cat "$__object/explorer/state")"
|
||||||
state_should="$(cat "$__object/parameter/state")"
|
|
||||||
|
|
||||||
if [ "$state_is" = "$state_should" ]; then
|
[ "$state_is" = "$state_should" ] && exit 0
|
||||||
# nothing to do
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$state_should" in
|
case "$state_should" in
|
||||||
absent)
|
absent)
|
||||||
# remove lines starting with key
|
# remove lines starting with key
|
||||||
echo "sed '/^$key\($delimiter\+\)/d' \"$file\" > \"$file.cdist-tmp\""
|
echo "sed '/^$key\($delimiter\+\)/d' \"$file\" > \"$file.cdist-tmp\""
|
||||||
echo "mv \"$file.cdist-tmp\" \"$file\""
|
echo "mv \"$file.cdist-tmp\" \"$file\""
|
||||||
;;
|
;;
|
||||||
present)
|
present)
|
||||||
case "$state_is" in
|
case "$state_is" in
|
||||||
absent)
|
absent)
|
||||||
# add new key and value
|
# add new key and value
|
||||||
echo "echo \"${key}${delimiter}${value}\" >> \"$file\""
|
echo "echo \"${key}${delimiter}${value}\" >> \"$file\""
|
||||||
;;
|
;;
|
||||||
wrongvalue)
|
wrongvalue)
|
||||||
# change exisiting value
|
# change exisiting value
|
||||||
echo "sed \"s|^$key\($delimiter\+\).*|$key\1$value|\" \"$file\" > \"$file.cdist-tmp\""
|
echo "sed \"s|^$key\($delimiter\+\).*|$key\1$value|\" \"$file\" > \"$file.cdist-tmp\""
|
||||||
echo "mv \"$file.cdist-tmp\" \"$file\""
|
echo "mv \"$file.cdist-tmp\" \"$file\""
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown explorer state: $state_is" >&2
|
echo "Unknown explorer state: $state_is" >&2
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown state: $state_should" >&2
|
echo "Unknown state: $state_should" >&2
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -18,13 +19,10 @@
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
# set defaults
|
state_should=present
|
||||||
key="$(cat "$__object/parameter/key" 2>/dev/null \
|
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
|
||||||
|| echo "$__object_id" | tee "$__object/parameter/key")"
|
|
||||||
state="$(cat "$__object/parameter/state" 2>/dev/null \
|
|
||||||
|| echo "present" | tee "$__object/parameter/state")"
|
|
||||||
|
|
||||||
if [ "$state" = "present" -a ! -f "$__object/parameter/value" ]; then
|
if [ "$state_should" = "present" -a ! -f "$__object/parameter/value" ]; then
|
||||||
echo "Missing required parameter 'value'" >&2
|
echo "Missing required parameter 'value'" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -27,35 +27,33 @@ type="$(cat "$__object/parameter/type")"
|
||||||
source="$(cat "$__object/parameter/source")"
|
source="$(cat "$__object/parameter/source")"
|
||||||
|
|
||||||
case "$type" in
|
case "$type" in
|
||||||
symbolic)
|
symbolic)
|
||||||
lnopt="-s"
|
lnopt="-s"
|
||||||
;;
|
;;
|
||||||
hard)
|
hard)
|
||||||
lnopt=""
|
lnopt=""
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown type: $type" >&2
|
echo "Unknown link type: $type" >&2
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
state_is="$(cat "$__object/explorer/state")"
|
state_is="$(cat "$__object/explorer/state")"
|
||||||
state_should="$(cat "$__object/parameter/state")"
|
state_should=present
|
||||||
|
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
|
||||||
|
|
||||||
if [ "$state_should" = "$state_is" ]; then
|
[ "$state_should" = "$state_is" ] && exit 0
|
||||||
# nothing to do
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$state_should" in
|
case "$state_should" in
|
||||||
present)
|
present)
|
||||||
echo ln ${lnopt} -f \"$source\" \"$destination\"
|
echo ln ${lnopt} -f \"$source\" \"$destination\"
|
||||||
;;
|
;;
|
||||||
absent)
|
absent)
|
||||||
echo rm -f \"$destination\"
|
echo rm -f \"$destination\"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown state: $state_should" >&2
|
echo "Unknown state: $state_should" >&2
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -1,38 +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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
device="$(cat "$__object/parameter/device")"
|
|
||||||
type="$(cat "$__object/parameter/type")"
|
|
||||||
|
|
||||||
if [ "$type" = "swap" ]; then
|
|
||||||
echo "mkswap $device"
|
|
||||||
else
|
|
||||||
command="mkfs -t $type -q"
|
|
||||||
if [ -f "$__object/parameter/options" ]; then
|
|
||||||
options="$(cat "$__object/parameter/options")"
|
|
||||||
command="$command $options"
|
|
||||||
fi
|
|
||||||
command="$command $device"
|
|
||||||
if [ -f "$__object/parameter/blocks" ]; then
|
|
||||||
blocks="$(cat "$__object/parameter/blocks")"
|
|
||||||
command="$command $blocks"
|
|
||||||
fi
|
|
||||||
echo "$command"
|
|
||||||
fi
|
|
|
@ -1,57 +0,0 @@
|
||||||
cdist-type__mkfs(7)
|
|
||||||
===================
|
|
||||||
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
|
||||||
|
|
||||||
|
|
||||||
NAME
|
|
||||||
----
|
|
||||||
cdist-type__mkfs - build a linux file system
|
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
|
||||||
-----------
|
|
||||||
This cdist type is a wrapper for the mkfs command.
|
|
||||||
|
|
||||||
|
|
||||||
REQUIRED PARAMETERS
|
|
||||||
-------------------
|
|
||||||
type::
|
|
||||||
The filesystem type to use. Same as mkfs -t.
|
|
||||||
|
|
||||||
|
|
||||||
OPTIONAL PARAMETERS
|
|
||||||
-------------------
|
|
||||||
device::
|
|
||||||
defaults to object_id
|
|
||||||
|
|
||||||
options::
|
|
||||||
file system-specific options to be passed to the mkfs command
|
|
||||||
|
|
||||||
blocks::
|
|
||||||
the number of blocks to be used for the file system
|
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
|
||||||
--------
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
# reiserfs /dev/sda5
|
|
||||||
__mkfs /dev/sda5 --type reiserfs
|
|
||||||
# same thing with explicit device
|
|
||||||
__mkfs whatever --device /dev/sda5 --type reiserfs
|
|
||||||
|
|
||||||
# jfs with journal on /dev/sda2
|
|
||||||
__mkfs /dev/sda1 --type jfs --options "-j /dev/sda2"
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
|
||||||
--------
|
|
||||||
- cdist-type(7)
|
|
||||||
- mkfs(8)
|
|
||||||
|
|
||||||
|
|
||||||
COPYING
|
|
||||||
-------
|
|
||||||
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
|
|
||||||
granted under the terms of the GNU General Public License version 3 (GPLv3).
|
|
|
@ -1,3 +0,0 @@
|
||||||
device
|
|
||||||
options
|
|
||||||
blocks
|
|
|
@ -1 +0,0 @@
|
||||||
type
|
|
|
@ -34,7 +34,7 @@ type::
|
||||||
__package_emerge for Gentoo
|
__package_emerge for Gentoo
|
||||||
|
|
||||||
state::
|
state::
|
||||||
The state the package should be in, either "present" or "absent"
|
Either "present" or "absent", defaults to "present"
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -25,7 +25,7 @@ name::
|
||||||
If supplied, use the name and not the object id as the package name.
|
If supplied, use the name and not the object id as the package name.
|
||||||
|
|
||||||
state::
|
state::
|
||||||
The state the package should be in, either "present" or "absent"
|
Either "present" or "absent", defaults to "present"
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -24,7 +24,7 @@ name::
|
||||||
If supplied, use the name and not the object id as the package name.
|
If supplied, use the name and not the object id as the package name.
|
||||||
|
|
||||||
state::
|
state::
|
||||||
The state the package should be in, either "present" or "absent"
|
Either "present" or "absent", defaults to "present"
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -24,7 +24,7 @@ name::
|
||||||
If supplied, use the name and not the object id as the package name.
|
If supplied, use the name and not the object id as the package name.
|
||||||
|
|
||||||
state::
|
state::
|
||||||
The state the package should be in, either "present" or "absent"
|
Either "present" or "absent", defaults to "present"
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -10,8 +10,7 @@ cdist-type__package_pacman - Manage packages with pacman
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
Pacman is usually used on the Archlinux distribution to manage
|
Pacman is usually used on the Archlinux distribution to manage packages.
|
||||||
packages.
|
|
||||||
|
|
||||||
|
|
||||||
REQUIRED PARAMETERS
|
REQUIRED PARAMETERS
|
||||||
|
@ -25,7 +24,7 @@ name::
|
||||||
If supplied, use the name and not the object id as the package name.
|
If supplied, use the name and not the object id as the package name.
|
||||||
|
|
||||||
state::
|
state::
|
||||||
The state the package should be in, either "present" or "absent"
|
Either "present" or "absent", defaults to "present"
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -28,7 +28,7 @@ pip::
|
||||||
Instead of using pip from PATH, use the specific pip path.
|
Instead of using pip from PATH, use the specific pip path.
|
||||||
|
|
||||||
state::
|
state::
|
||||||
Either "present" or "absent".
|
Either "present" or "absent", defaults to "present"
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -21,19 +21,19 @@ None
|
||||||
OPTIONAL PARAMETERS
|
OPTIONAL PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
name::
|
name::
|
||||||
If supplied, use the name and not the object id as the package name.
|
If supplied, use the name and not the object id as the package name.
|
||||||
|
|
||||||
flavor::
|
flavor::
|
||||||
If supplied, use to avoid ambiguity.
|
If supplied, use to avoid ambiguity.
|
||||||
|
|
||||||
version::
|
version::
|
||||||
If supplied, use to install a specific version of the package named.
|
If supplied, use to install a specific version of the package named.
|
||||||
|
|
||||||
pkgsite::
|
pkgsite::
|
||||||
If supplied, use to install from a specific package repository.
|
If supplied, use to install from a specific package repository.
|
||||||
|
|
||||||
state::
|
state::
|
||||||
Either "present" or "absent".
|
Either "present" or "absent", defaults to "present"
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -27,7 +27,7 @@ flavor::
|
||||||
If supplied, use to avoid ambiguity.
|
If supplied, use to avoid ambiguity.
|
||||||
|
|
||||||
state::
|
state::
|
||||||
The state the package should be in, either "present" or "absent"
|
Either "present" or "absent", defaults to "present"
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -24,7 +24,7 @@ name::
|
||||||
If supplied, use the name and not the object id as the package name.
|
If supplied, use the name and not the object id as the package name.
|
||||||
|
|
||||||
state::
|
state::
|
||||||
The state the package should be in, either "present" or "absent"
|
Either "present" or "absent", defaults to "present"
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -26,8 +26,7 @@ name::
|
||||||
If supplied, use the name and not the object id as the package name.
|
If supplied, use the name and not the object id as the package name.
|
||||||
|
|
||||||
state::
|
state::
|
||||||
The state the package should be in, either "present" or "absent"
|
Either "present" or "absent", defaults to "present"
|
||||||
(the old values "installed" or "removed" will be removed in cdist 2.1).
|
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -24,7 +24,7 @@ name::
|
||||||
If supplied, use the name and not the object id as the package name.
|
If supplied, use the name and not the object id as the package name.
|
||||||
|
|
||||||
state::
|
state::
|
||||||
The state the package should be in, either "present" or "absent"
|
Either "present" or "absent", defaults to "present"
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
cdist-type__partition_msdos(7)
|
|
||||||
==============================
|
|
||||||
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
|
||||||
|
|
||||||
|
|
||||||
NAME
|
|
||||||
----
|
|
||||||
cdist-type__partition_msdos - creates msdos partitions
|
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
|
||||||
-----------
|
|
||||||
This cdist type allows you to create msdos paritions.
|
|
||||||
|
|
||||||
|
|
||||||
REQUIRED PARAMETERS
|
|
||||||
-------------------
|
|
||||||
type::
|
|
||||||
the partition type used in fdisk (such as 82 or 83) or "extended"
|
|
||||||
|
|
||||||
|
|
||||||
OPTIONAL PARAMETERS
|
|
||||||
-------------------
|
|
||||||
partition::
|
|
||||||
defaults to object_id
|
|
||||||
bootable::
|
|
||||||
mark partition as bootable, true or false, defaults to false
|
|
||||||
size::
|
|
||||||
the size of the partition (such as 32M or 15G, whole numbers
|
|
||||||
only), '+' for remaining space, or 'n%' for percentage of remaining
|
|
||||||
(these should only be used after all specific partition sizes are
|
|
||||||
specified). Defaults to +.
|
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
|
||||||
--------
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
# 128MB, linux, bootable
|
|
||||||
__partition_msdos /dev/sda1 --type 83 --size 128M --bootable true
|
|
||||||
# 512MB, swap
|
|
||||||
__partition_msdos /dev/sda2 --type 82 --size 512M
|
|
||||||
# 100GB, extended
|
|
||||||
__partition_msdos /dev/sda3 --type extended --size 100G
|
|
||||||
# 10GB, linux
|
|
||||||
__partition_msdos /dev/sda5 --type 83 --size 10G
|
|
||||||
# 50% of the free space of the extended partition, linux
|
|
||||||
__partition_msdos /dev/sda6 --type 83 --size 50%
|
|
||||||
# rest of the extended partition, linux
|
|
||||||
__partition_msdos /dev/sda7 --type 83 --size +
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
|
||||||
--------
|
|
||||||
- cdist-type(7)
|
|
||||||
|
|
||||||
|
|
||||||
COPYING
|
|
||||||
-------
|
|
||||||
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
|
|
||||||
granted under the terms of the GNU General Public License version 3 (GPLv3).
|
|
|
@ -1,41 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
|
||||||
#
|
|
||||||
# This file is part of cdist.
|
|
||||||
#
|
|
||||||
# cdist is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# cdist is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
# set defaults
|
|
||||||
if [ -f "$__object/parameter/partition" ]; then
|
|
||||||
partition="(cat "$__object/parameter/partition")"
|
|
||||||
else
|
|
||||||
partition="/$__object_id"
|
|
||||||
echo "$partition" > "$__object/parameter/partition"
|
|
||||||
fi
|
|
||||||
device="$(echo "$partition" | sed 's/[0-9]//g')"
|
|
||||||
echo "$device" > "$__object/parameter/device"
|
|
||||||
minor="$(echo "$partition" | sed 's/[^0-9]//g')"
|
|
||||||
echo "$minor" > "$__object/parameter/minor"
|
|
||||||
|
|
||||||
if [ ! -f "$__object/parameter/bootable" ]; then
|
|
||||||
echo "false" > "$__object/parameter/bootable"
|
|
||||||
fi
|
|
||||||
if [ ! -f "$__object/parameter/size" ]; then
|
|
||||||
echo "+" > "$__object/parameter/size"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# pull in the type that actually does something with the above parameters
|
|
||||||
require="$__object_name" __partition_msdos_apply
|
|
|
@ -1,3 +0,0 @@
|
||||||
partition
|
|
||||||
bootable
|
|
||||||
size
|
|
|
@ -1 +0,0 @@
|
||||||
type
|
|
|
@ -1,3 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
cat /proc/partitions
|
|
|
@ -1,61 +0,0 @@
|
||||||
die() {
|
|
||||||
echo "[__partition_msdos_apply] $@" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
debug() {
|
|
||||||
#echo "[__partition_msdos_apply] $@" >&2
|
|
||||||
:
|
|
||||||
}
|
|
||||||
|
|
||||||
fdisk_command() {
|
|
||||||
local device="$1"
|
|
||||||
local cmd="$2"
|
|
||||||
|
|
||||||
debug fdisk_command "running fdisk command '${cmd}' on device ${device}"
|
|
||||||
printf "${cmd}\nw\n" | fdisk -c -u "$device"
|
|
||||||
# give disk some time
|
|
||||||
sleep 1
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
||||||
create_disklabel() {
|
|
||||||
local device=$1
|
|
||||||
|
|
||||||
debug create_disklabel "creating new msdos disklabel"
|
|
||||||
fdisk_command ${device} "o"
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
||||||
create_partition() {
|
|
||||||
local device="$1"
|
|
||||||
local minor="$2"
|
|
||||||
local size="$3"
|
|
||||||
local type="$4"
|
|
||||||
local primary_count="$5"
|
|
||||||
|
|
||||||
if [ "$type" = "extended" -o "$type" = "5" ]; then
|
|
||||||
# Extended partition
|
|
||||||
primary_extended="e\n"
|
|
||||||
first_minor="${minor}\n"
|
|
||||||
[ "${minor}" = "4" ] && first_minor=""
|
|
||||||
type_minor="${minor}\n"
|
|
||||||
[ "${minor}" = "1" ] && type_minor=""
|
|
||||||
type="5"
|
|
||||||
elif [ "${minor}" -lt "5" ]; then
|
|
||||||
primary_extended="p\n"
|
|
||||||
first_minor="${minor}\n"
|
|
||||||
[ "${minor}" = "4" ] && first_minor=""
|
|
||||||
type_minor="${minor}\n"
|
|
||||||
[ "${minor}" = "1" ] && type_minor=""
|
|
||||||
else
|
|
||||||
# Logical partitions
|
|
||||||
first_minor="${minor}\n"
|
|
||||||
type_minor="${minor}\n"
|
|
||||||
primary_extended="l\n"
|
|
||||||
[ "$primary_count" -gt "3" ] && primary_extended=""
|
|
||||||
fi
|
|
||||||
[ -n "${size}" ] && size="+${size}M"
|
|
||||||
fdisk_command ${device} "n\n${primary_extended}${first_minor}\n${size}\nt\n${type_minor}${type}\n"
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,138 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
|
||||||
#
|
|
||||||
# This file is part of cdist.
|
|
||||||
#
|
|
||||||
# cdist is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# cdist is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
die() {
|
|
||||||
echo "[__partition_msdos_apply] $@" >&2
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
debug() {
|
|
||||||
#echo "[__partition_msdos_apply] $@" >&2
|
|
||||||
:
|
|
||||||
}
|
|
||||||
|
|
||||||
# Convert a size specifier 1G 100M or 50% into the corresponding numeric MB.
|
|
||||||
size_to_mb() {
|
|
||||||
local size=$1
|
|
||||||
local available_size="$2"
|
|
||||||
|
|
||||||
local number_suffix="$(echo ${size} | sed -e 's:\.[0-9]\+::' -e 's:\([0-9]\+\)\([MmGg%]\)[Bb]\?:\1|\2:')"
|
|
||||||
local number="$(echo ${number_suffix} | cut -d '|' -f1)"
|
|
||||||
local suffix="$(echo ${number_suffix} | cut -d '|' -f2)"
|
|
||||||
|
|
||||||
case "$suffix" in
|
|
||||||
M|m)
|
|
||||||
size="$number"
|
|
||||||
;;
|
|
||||||
G|g)
|
|
||||||
size="$(( $number * 1024 ))"
|
|
||||||
;;
|
|
||||||
%)
|
|
||||||
size="$(( $available_size * $number / 100 ))"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
size="-1"
|
|
||||||
esac
|
|
||||||
echo "$size"
|
|
||||||
}
|
|
||||||
|
|
||||||
# include function library for use on target
|
|
||||||
cat "$__type/files/lib.sh"
|
|
||||||
|
|
||||||
partitions="$__object/explorer/partitions"
|
|
||||||
objects=$(find "$__global/object/__partition_msdos" -path "*.cdist")
|
|
||||||
current_device=""
|
|
||||||
available_device_size=
|
|
||||||
available_extended_size=
|
|
||||||
available_size=
|
|
||||||
primary_count=0
|
|
||||||
for object in $objects; do
|
|
||||||
device="$(cat "$object/parameter/device")"
|
|
||||||
if [ "$current_device" != "$device" ]; then
|
|
||||||
echo "create_disklabel \"$device\" || die 'Failed to create disklabel for $device'"
|
|
||||||
current_device="$device"
|
|
||||||
device_name=$(echo ${device} | sed -e 's:^/dev/::;s:/:\\/:g')
|
|
||||||
available_device_size=$(( $(awk "/${device_name}\$/ { print \$3; }" "$partitions") / 1024))
|
|
||||||
# make sure we don't go past the end of the drive
|
|
||||||
available_device_size=$((available_device_size - 2))
|
|
||||||
available_extended_size=0
|
|
||||||
primary_count=0
|
|
||||||
debug "----- $device"
|
|
||||||
debug "current_device=$current_device"
|
|
||||||
debug "available_device_size=$available_device_size"
|
|
||||||
fi
|
|
||||||
|
|
||||||
type="$(cat "$object/parameter/type")"
|
|
||||||
partition="$(cat "$object/parameter/partition")"
|
|
||||||
minor="$(cat "$object/parameter/minor")"
|
|
||||||
|
|
||||||
bootable="$(cat "$object/parameter/bootable")"
|
|
||||||
size="$(cat "$object/parameter/size")"
|
|
||||||
|
|
||||||
|
|
||||||
if [ "${minor}" -lt "5" ]; then
|
|
||||||
# Primary partitions
|
|
||||||
primary_count=$(( $primary_count + 1 ))
|
|
||||||
available_size=$available_device_size
|
|
||||||
else
|
|
||||||
# Logical partitions
|
|
||||||
available_size=$available_extended_size
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$size" = "+" ]; then
|
|
||||||
# use rest of device
|
|
||||||
partition_size=""
|
|
||||||
available_size=0
|
|
||||||
else
|
|
||||||
partition_size=$(size_to_mb "$size" "$available_size")
|
|
||||||
available_size="$(( $available_size - $partition_size ))"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${minor}" -lt "5" ]; then
|
|
||||||
# Primary partitions
|
|
||||||
available_device_size=$available_size
|
|
||||||
if [ "$type" = "extended" -o "$type" = "5" ]; then
|
|
||||||
# Extended partition
|
|
||||||
available_extended_size=$partition_size
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Logical paritions
|
|
||||||
available_extended_size=$available_size
|
|
||||||
fi
|
|
||||||
|
|
||||||
[ "$partition_size" = "-1" ] && die "could not translate size '$size' to a usable value"
|
|
||||||
debug "----- $partition"
|
|
||||||
debug "primary_count=$primary_count"
|
|
||||||
debug "current_device=$current_device"
|
|
||||||
debug "device=$device"
|
|
||||||
debug "type=$type"
|
|
||||||
debug "partition=$partition"
|
|
||||||
debug "minor=$minor"
|
|
||||||
debug "bootable=$bootable"
|
|
||||||
debug "size=$size"
|
|
||||||
debug "partition_size=$partition_size"
|
|
||||||
debug "available_size=$available_size"
|
|
||||||
debug "available_device_size=$available_device_size"
|
|
||||||
debug "available_extended_size=$available_extended_size"
|
|
||||||
debug "----------"
|
|
||||||
|
|
||||||
echo "create_partition '$device' '$minor' '$partition_size' '$type' '$primary_count' \
|
|
||||||
|| die 'Failed to create partition: $partition'"
|
|
||||||
done
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ source::
|
||||||
Note that this type is almost useless without a ruleset defined, but it's technically not
|
Note that this type is almost useless without a ruleset defined, but it's technically not
|
||||||
needed, e.g. for the case of disabling the firewall temporarily.
|
needed, e.g. for the case of disabling the firewall temporarily.
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ __postgres_database mydbname --state present --owner mydbusername
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
- cdist-type(7)
|
- cdist-type(7)
|
||||||
|
- cdist-type__postgres_role(7)
|
||||||
|
|
||||||
|
|
||||||
COPYING
|
COPYING
|
||||||
|
|
|
@ -22,33 +22,28 @@ name="$__object_id"
|
||||||
state_is="$(cat "$__object/explorer/state")"
|
state_is="$(cat "$__object/explorer/state")"
|
||||||
state_should="$(cat "$__object/parameter/state")"
|
state_should="$(cat "$__object/parameter/state")"
|
||||||
|
|
||||||
if [ "$state_is" != "$state_should" ]; then
|
[ "$state_is" = "$state_should" ] && exit 0
|
||||||
case "$state_should" in
|
|
||||||
present)
|
case "$state_should" in
|
||||||
optional="password
|
present)
|
||||||
login
|
if [ -f "$__object/parameter/password" ]; then
|
||||||
createdb
|
password="$(cat "$__object/parameter/$parameter")"
|
||||||
createrole
|
fi
|
||||||
superuser"
|
booleans=""
|
||||||
for parameter in $optional; do
|
for boolean in login createdb createrole superuser; do
|
||||||
if [ -f "$__object/parameter/$parameter" ]; then
|
if [ ! -f "$__object/parameter/$boolean" ]; then
|
||||||
value="$(cat "$__object/parameter/$parameter")"
|
boolean="no${boolean}"
|
||||||
eval $parameter=$value
|
|
||||||
fi
|
fi
|
||||||
done
|
upper=$(echo $boolean | tr '[a-z]' '[A-Z]')
|
||||||
|
booleans="$booleans $upper"
|
||||||
|
done
|
||||||
|
|
||||||
[ -n "$password" ] && password="PASSWORD '$password'"
|
[ -n "$password" ] && password="PASSWORD '$password'"
|
||||||
[ "$login" = "true" ] && login="LOGIN" || login="NOLOGIN"
|
|
||||||
[ "$createdb" = "true" ] && createdb="CREATEDB" || createdb="NOCREATEDB"
|
|
||||||
[ "$createrole" = "true" ] && createrole="CREATEROLE" || createrole="NOCREATEROLE"
|
|
||||||
[ "$superuser" = "true" ] && superuser="SUPERUSER" || superuser="NOSUPERUSER"
|
|
||||||
[ "$inherit" = "true" ] && inherit="INHERIT" || inherit="NOINHERIT"
|
|
||||||
|
|
||||||
cmd="CREATE ROLE $name WITH $password $login $createdb $createrole $superuser $inherit"
|
cmd="CREATE ROLE $name WITH $password $booleans"
|
||||||
echo "su - postgres -c \"psql -c \\\"$cmd\\\"\""
|
echo "su - postgres -c \"psql -c \\\"$cmd\\\"\""
|
||||||
;;
|
;;
|
||||||
absent)
|
absent)
|
||||||
echo "su - postgres -c \"dropuser \\\"$name\\\"\""
|
echo "su - postgres -c \"dropuser \\\"$name\\\"\""
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
|
||||||
|
|
|
@ -16,22 +16,27 @@ This cdist type allows you to create or drop postgres roles.
|
||||||
REQUIRED PARAMETERS
|
REQUIRED PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
state::
|
state::
|
||||||
either 'present' or 'absent'
|
Either "present" or "absent", defaults to "present"
|
||||||
|
|
||||||
|
|
||||||
OPTIONAL PARAMETERS
|
OPTIONAL PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
All optional parameter map directly to the corresponding postgres createrole
|
All parameter map directly to the corresponding postgres createrole
|
||||||
parameters.
|
parameters.
|
||||||
|
|
||||||
password::
|
password::
|
||||||
|
|
||||||
|
BOOLEAN PARAMETERS
|
||||||
|
------------------
|
||||||
|
All parameter map directly to the corresponding postgres createrole
|
||||||
|
parameters.
|
||||||
|
|
||||||
login::
|
login::
|
||||||
createdb::
|
createdb::
|
||||||
createrole::
|
createrole::
|
||||||
superuser::
|
superuser::
|
||||||
inherit::
|
inherit::
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -40,15 +45,16 @@ __postgres_role myrole --state present
|
||||||
|
|
||||||
__postgres_role myrole --state present --password 'secret'
|
__postgres_role myrole --state present --password 'secret'
|
||||||
|
|
||||||
__postgres_role admin --state present --password 'very-secret' --superuser true
|
__postgres_role admin --state present --password 'very-secret' --superuser
|
||||||
|
|
||||||
__postgres_role dbcustomer --state present --password 'bla' --createdb true
|
__postgres_role dbcustomer --state present --password 'bla' --createdb
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
- cdist-type(7)
|
- cdist-type(7)
|
||||||
|
- cdist-type__postgres_database(7)
|
||||||
- http://www.postgresql.org/docs/current/static/sql-createrole.html
|
- http://www.postgresql.org/docs/current/static/sql-createrole.html
|
||||||
|
|
||||||
|
|
||||||
|
|
5
cdist/conf/type/__postgres_role/parameter/boolean
Normal file
5
cdist/conf/type/__postgres_role/parameter/boolean
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
login
|
||||||
|
createdb
|
||||||
|
createrole
|
||||||
|
superuser
|
||||||
|
inherit
|
|
@ -1,6 +1 @@
|
||||||
password
|
password
|
||||||
login
|
|
||||||
createdb
|
|
||||||
createrole
|
|
||||||
superuser
|
|
||||||
inherit
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -22,9 +22,9 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
if [ -f "$__object/parameter/name" ]; then
|
if [ -f "$__object/parameter/name" ]; then
|
||||||
name="$(cat "$__object/parameter/name")"
|
name="$(cat "$__object/parameter/name")"
|
||||||
else
|
else
|
||||||
name="$__object_id"
|
name="$__object_id"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pgrep -x -f "$name" || true
|
pgrep -x -f "$name" || true
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
if [ -f "$__object/parameter/name" ]; then
|
if [ -f "$__object/parameter/name" ]; then
|
||||||
name="$(cat "$__object/parameter/name")"
|
name="$(cat "$__object/parameter/name")"
|
||||||
else
|
else
|
||||||
name="$__object_id"
|
name="$__object_id"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
state_should="$(cat "$__object/parameter/state")"
|
state_should="$(cat "$__object/parameter/state")"
|
||||||
|
|
|
@ -16,25 +16,23 @@ This cdist type allows you to define the state of a process.
|
||||||
REQUIRED PARAMETERS
|
REQUIRED PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
state::
|
state::
|
||||||
State of the process: Either present or absent
|
Either "present" or "absent", defaults to "present"
|
||||||
(old values "stopped" and "running" are deprecated and will be removed in
|
|
||||||
cdist 2.1).
|
|
||||||
|
|
||||||
|
|
||||||
OPTIONAL PARAMETERS
|
OPTIONAL PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
name::
|
name::
|
||||||
Process name to match on when using pgrep -f -x.
|
Process name to match on when using pgrep -f -x.
|
||||||
|
|
||||||
This is useful, if the name starts with a "/",
|
This is useful, if the name starts with a "/",
|
||||||
because the leading slash is stripped away from
|
because the leading slash is stripped away from
|
||||||
the object id by cdist.
|
the object id by cdist.
|
||||||
|
|
||||||
stop::
|
stop::
|
||||||
Executable to use for stopping the process.
|
Executable to use for stopping the process.
|
||||||
|
|
||||||
start::
|
start::
|
||||||
Executable to use for starting the process.
|
Executable to use for starting the process.
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
@ -66,6 +64,7 @@ __process rpcstatd --state present --start "/etc/init.d/statd start" \
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
- cdist-type(7)
|
- cdist-type(7)
|
||||||
|
- cdist-type__start_on_boot(7)
|
||||||
|
|
||||||
|
|
||||||
COPYING
|
COPYING
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
# State: absent is handled by manifest - we need only to do stuff if image is
|
# State: absent is handled by manifest - we need only to do stuff if image is
|
||||||
# not existing and state != absent
|
# not existing and state != absent
|
||||||
#
|
#
|
||||||
[ -f "$__object/parameter/state" ] && state="$(cat "$__object/parameter/state")"
|
state="present"
|
||||||
|
[ -f "$__object/parameter/state" ] state="$(cat "$__object/parameter/state")"
|
||||||
[ "$state" = "absent" ] && exit 0
|
[ "$state" = "absent" ] && exit 0
|
||||||
|
|
||||||
exists="$(cat "$__object/explorer/exists")"
|
exists="$(cat "$__object/explorer/exists")"
|
||||||
|
@ -15,6 +16,6 @@ exists="$(cat "$__object/explorer/exists")"
|
||||||
format=qcow2
|
format=qcow2
|
||||||
[ -f "$__object/parameter/format" ] && format="$(cat "$__object/parameter/format")"
|
[ -f "$__object/parameter/format" ] && format="$(cat "$__object/parameter/format")"
|
||||||
size="$(cat "$__object/parameter/size")"
|
size="$(cat "$__object/parameter/size")"
|
||||||
vm="/$__object_id"
|
diskimage="/$__object_id"
|
||||||
|
|
||||||
echo qemu-img create -f \"$format\" \"$vm\" \"$size\"
|
echo qemu-img create -f \"$format\" \"$diskimage\" \"$size\"
|
||||||
|
|
|
@ -24,8 +24,7 @@ size::
|
||||||
OPTIONAL PARAMETERS
|
OPTIONAL PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
state::
|
state::
|
||||||
The state of the image file: either "present" or "absent".
|
Either "present" or "absent", defaults to "present"
|
||||||
Defaults to "present".
|
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -3,12 +3,13 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
format=qcow2
|
format=qcow2
|
||||||
|
state=present
|
||||||
[ -f "$__object/parameter/format" ] && format="$(cat "$__object/parameter/format")"
|
[ -f "$__object/parameter/format" ] && format="$(cat "$__object/parameter/format")"
|
||||||
[ -f "$__object/parameter/state" ] && state="$(cat "$__object/parameter/state")"
|
[ -f "$__object/parameter/state" ] && state="$(cat "$__object/parameter/state")"
|
||||||
|
|
||||||
vm="/$__object_id"
|
diskimage="/$__object_id"
|
||||||
|
|
||||||
# Absent is ensured by __file, present by gencode-remote
|
# Absent is ensured by __file, present by gencode-remote
|
||||||
if [ "$state" = "absent" ]; then
|
if [ "$state" = "absent" ]; then
|
||||||
__file "$vm" --state absent
|
__file "$diskimage" --state absent
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2012 Evax Software <contact@evax.fr>
|
# 2012 Evax Software <contact@evax.fr>
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -21,20 +22,20 @@
|
||||||
user="$__object_id"
|
user="$__object_id"
|
||||||
state_is="$(cat "$__object/explorer/state")"
|
state_is="$(cat "$__object/explorer/state")"
|
||||||
state_should="$(cat "$__object/parameter/state")"
|
state_should="$(cat "$__object/parameter/state")"
|
||||||
if [ "$state_is" != "$state_should" ]; then
|
|
||||||
case "$state_should" in
|
[ "$state_is" = "$state_should" ] && exit 0
|
||||||
present)
|
|
||||||
cat << DONE
|
case "$state_should" in
|
||||||
|
present)
|
||||||
|
cat << DONE
|
||||||
su - $user -c "unset rvm_path; unset rvm_bin_path; unset rvm_prefix; unset rvm_version; curl -L get.rvm.io | bash -s stable"
|
su - $user -c "unset rvm_path; unset rvm_bin_path; unset rvm_prefix; unset rvm_version; curl -L get.rvm.io | bash -s stable"
|
||||||
DONE
|
DONE
|
||||||
;;
|
;;
|
||||||
absent)
|
absent)
|
||||||
cat << DONE
|
cat << DONE
|
||||||
su - $user -c "rm -Rf \"\\\$HOME/.rvm\";
|
su - $user -c "rm -Rf \"\\\$HOME/.rvm\";
|
||||||
sed '/rvm\/scripts\/rvm/d' \"\\\$HOME/.bashrc\" > \"\\\$HOME/.bashrc.cdist-tmp\"
|
sed '/rvm\/scripts\/rvm/d' \"\\\$HOME/.bashrc\" > \"\\\$HOME/.bashrc.cdist-tmp\"
|
||||||
mv \"\\\$HOME/.bashrc.cdist-tmp\" \"\\\$HOME/.bashrc\""
|
mv \"\\\$HOME/.bashrc.cdist-tmp\" \"\\\$HOME/.bashrc\""
|
||||||
|
|
||||||
DONE
|
DONE
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ RVM is the Ruby enVironment Manager for the Ruby programming language.
|
||||||
REQUIRED PARAMETERS
|
REQUIRED PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
state::
|
state::
|
||||||
Either "present" or "absent".
|
Either "present" or "absent".
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2012 Evax Software <contact@evax.fr>
|
# 2012 Evax Software <contact@evax.fr>
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -30,8 +31,8 @@ fi
|
||||||
if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\"
|
if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\"
|
||||||
rvm list | grep -q $ruby"; then
|
rvm list | grep -q $ruby"; then
|
||||||
if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\"
|
if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\"
|
||||||
rvm use $ruby > /dev/null; rvm gemset list | grep -q $gemsetname &&
|
rvm use $ruby > /dev/null 2>&1; rvm gemset list | grep -q $gemsetname &&
|
||||||
rvm use $gemset > /dev/null && gem list | grep -q $gem"; then
|
rvm use $gemset > /dev/null 2>&1 && gem list | grep -q $gem"; then
|
||||||
echo "present"
|
echo "present"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh #
|
||||||
#
|
|
||||||
# 2012 Evax Software <contact@evax.fr>
|
# 2012 Evax Software <contact@evax.fr>
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -25,19 +25,18 @@ gemsetname="$(echo "$gemset" | cut -d '@' -f 2)"
|
||||||
state_is="$(cat "$__object/explorer/state")"
|
state_is="$(cat "$__object/explorer/state")"
|
||||||
user="$(cat "$__object/parameter/user")"
|
user="$(cat "$__object/parameter/user")"
|
||||||
state_should="$(cat "$__object/parameter/state")"
|
state_should="$(cat "$__object/parameter/state")"
|
||||||
if [ "$state_is" != "$state_should" ]; then
|
|
||||||
case "$state_should" in
|
[ "$state_is" = "$state_should" ] && exit 0
|
||||||
present)
|
|
||||||
cat << DONE
|
case "$state_should" in
|
||||||
su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\"
|
present)
|
||||||
rvm use $gemset; gem install $gem"
|
cat << DONE
|
||||||
|
su - "$user" -c 'source ~/.rvm/scripts/rvm; rvm use "$gemset"; gem install "$gem"'
|
||||||
DONE
|
DONE
|
||||||
;;
|
;;
|
||||||
absent)
|
absent)
|
||||||
cat << DONE
|
cat << DONE
|
||||||
su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\"
|
su - "$user" -c 'source ~/.rvm/scripts/rvm; rvm use "$gemset"; gem uninstall "$gem"'
|
||||||
rvm use $gemset; gem uninstall $gem"
|
|
||||||
DONE
|
DONE
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
|
||||||
|
|
|
@ -16,16 +16,16 @@ RVM is the Ruby enVironment Manager for the Ruby programming language.
|
||||||
REQUIRED PARAMETERS
|
REQUIRED PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
user::
|
user::
|
||||||
The remote user account to use
|
The remote user account to use
|
||||||
gemset::
|
gemset::
|
||||||
The gemset to use
|
The gemset to use
|
||||||
state::
|
state::
|
||||||
Either "present" or "absent".
|
Either "present" or "absent"
|
||||||
|
|
||||||
OPTIONAL PARAMETERS
|
OPTIONAL PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
default::
|
default::
|
||||||
Make the selected gemset the default
|
Make the selected gemset the default
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
--------
|
--------
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
# 2012 Evax Software <contact@evax.fr>
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
gem="$__object_id"
|
|
||||||
gemset="$(cat "$__object/parameter/gemset")"
|
|
||||||
ruby="$(echo "$gemset" | cut -d '@' -f 1)"
|
|
||||||
gemsetname="$(echo "$gemset" | cut -d '@' -f 2)"
|
|
||||||
user="$(cat "$__object/parameter/user")"
|
|
||||||
state="$(cat "$__object/explorer/state")"
|
|
||||||
if [ -f "$__object/parameter/default" ]; then
|
|
||||||
default="$(cat "$__object/parameter/default")"
|
|
||||||
else
|
|
||||||
default="no"
|
|
||||||
echo $default > "$__object/parameter/default"
|
|
||||||
fi
|
|
||||||
|
|
||||||
__rvm "$user" --state present
|
|
||||||
require="__rvm/$user" \
|
|
||||||
__rvm_ruby $ruby --user "$user" --state present --default $default
|
|
||||||
require="__rvm_ruby/$ruby" \
|
|
||||||
__rvm_gemset $gemset --user "$user" --state present --default $default
|
|
|
@ -22,14 +22,14 @@ gemset="$__object_id"
|
||||||
ruby="$(echo "$gemset" | cut -d '@' -f 1)"
|
ruby="$(echo "$gemset" | cut -d '@' -f 1)"
|
||||||
gemsetname="$(echo "$gemset" | cut -d '@' -f2)"
|
gemsetname="$(echo "$gemset" | cut -d '@' -f2)"
|
||||||
user="$(cat "$__object/parameter/user")"
|
user="$(cat "$__object/parameter/user")"
|
||||||
if su - "$user" -c "[ ! -d \"\$HOME/.rvm\" ]" ; then
|
|
||||||
|
if [ ! -e "~$user/.rvm/scripts/rvm" ] ; then
|
||||||
echo "absent"
|
echo "absent"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\"
|
|
||||||
rvm list | grep -q $ruby"; then
|
if su - "$user" -c 'source ~/.rvm/scripts/rvm; rvm list strings | grep -q "^$ruby\$"'; then
|
||||||
if su - "$user" -c "source \"\$HOME/.rvm/scripts/rvm\"
|
if su - "$user" -c 'source ~/.rvm/scripts/rvm; rvm use "$ruby" > /dev/null; rvm gemset list strings | cut -f 1 -d " " | grep -q "^$gemsetname\$"'; then
|
||||||
rvm use $ruby > /dev/null; rvm gemset list | grep -q $gemsetname"; then
|
|
||||||
echo "present"
|
echo "present"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2012 Evax Software <contact@evax.fr>
|
# 2012 Evax Software <contact@evax.fr>
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -25,29 +26,27 @@ state_is="$(cat "$__object/explorer/state")"
|
||||||
user="$(cat "$__object/parameter/user")"
|
user="$(cat "$__object/parameter/user")"
|
||||||
default="$(cat "$__object/parameter/default" 2>/dev/null || true)"
|
default="$(cat "$__object/parameter/default" 2>/dev/null || true)"
|
||||||
state_should="$(cat "$__object/parameter/state")"
|
state_should="$(cat "$__object/parameter/state")"
|
||||||
if [ "$state_is" != "$state_should" ]; then
|
|
||||||
case "$state_should" in
|
[ "$state_is" = "$state_should" ] && exit 0
|
||||||
present)
|
|
||||||
cat << DONE
|
case "$state_should" in
|
||||||
su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\"
|
present)
|
||||||
rvm $gemset --create"
|
cat << DONE
|
||||||
|
su - "$user" -c "source ~/.rvm/scripts/rvm; rvm $gemset --create"
|
||||||
DONE
|
DONE
|
||||||
case "$default" in
|
case "$default" in
|
||||||
no)
|
no)
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
cat << DONE
|
cat << DONE
|
||||||
su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\"
|
su - "$user" -c "source ~/.rvm/scripts/rvm; rvm use --default $gemset"
|
||||||
rvm use --default $gemset"
|
|
||||||
DONE
|
DONE
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
absent)
|
absent)
|
||||||
cat << DONE
|
cat << DONE
|
||||||
su - "$user" -c "source \"\\\$HOME/.rvm/scripts/rvm\"
|
su - "$user" -c "source ~/.rvm/scripts/rvm; rvm use $ruby; rvm --force gemset delete $gemsetname"
|
||||||
rvm use $ruby; rvm --force gemset delete $gemsetname"
|
|
||||||
DONE
|
DONE
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
|
||||||
|
|
|
@ -16,14 +16,14 @@ RVM is the Ruby enVironment Manager for the Ruby programming language.
|
||||||
REQUIRED PARAMETERS
|
REQUIRED PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
user::
|
user::
|
||||||
The remote user account to use
|
The remote user account to use
|
||||||
state::
|
state::
|
||||||
Either "present" or "absent".
|
Either "present" or "absent".
|
||||||
|
|
||||||
OPTIONAL PARAMETERS
|
OPTIONAL PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
default::
|
default::
|
||||||
If set to anything but "no" (the default), set the given gemset as default.
|
If set to anything but "no" (the default), set the given gemset as default.
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
--------
|
--------
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
# 2012 Evax Software <contact@evax.fr>
|
|
||||||
#
|
|
||||||
# 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/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
gemset="$__object_id"
|
|
||||||
ruby="$(echo "$gemset" | cut -d '@' -f 1)"
|
|
||||||
gemsetname="$(echo "$gemset" | cut -d '@' -f 2)"
|
|
||||||
user="$(cat "$__object/parameter/user")"
|
|
||||||
state="$(cat "$__object/explorer/state")"
|
|
||||||
if [ -f "$__object/parameter/default" ]; then
|
|
||||||
default="$(cat "$__object/parameter/default")"
|
|
||||||
else
|
|
||||||
default="no"
|
|
||||||
echo $default > "$__object/parameter/default"
|
|
||||||
fi
|
|
||||||
|
|
||||||
__rvm "$user" --state present
|
|
||||||
require="__rvm/$user" \
|
|
||||||
__rvm_ruby $ruby --user "$user" --state present --default $default
|
|
||||||
|
|
|
@ -24,23 +24,24 @@ user="$(cat "$__object/parameter/user")"
|
||||||
default="$(cat "$__object/parameter/default" 2>/dev/null || true)"
|
default="$(cat "$__object/parameter/default" 2>/dev/null || true)"
|
||||||
state_should="$(cat "$__object/parameter/state")"
|
state_should="$(cat "$__object/parameter/state")"
|
||||||
|
|
||||||
if [ "$state_is" != "$state_should" ]; then
|
[ "$state_is" = "$state_should" ] && exit 0
|
||||||
case "$state_should" in
|
|
||||||
present)
|
case "$state_should" in
|
||||||
echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\
|
present)
|
||||||
"rvm install $ruby\""
|
echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\
|
||||||
case "$default" in
|
"rvm install $ruby\""
|
||||||
no)
|
if [ -f "$__object/parameter/default" ]; then
|
||||||
;;
|
echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\
|
||||||
*)
|
"rvm use --default $ruby\""
|
||||||
echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\
|
fi
|
||||||
"rvm use --default $ruby\""
|
;;
|
||||||
;;
|
absent)
|
||||||
esac
|
echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\
|
||||||
;;
|
"rvm remove $ruby\""
|
||||||
absent)
|
;;
|
||||||
echo "su - \"$user\" -c \"source \\\$HOME/.rvm/scripts/rvm;"\
|
|
||||||
"rvm remove $ruby\""
|
*)
|
||||||
;;
|
echo "Unknown state $state_should" >&2
|
||||||
esac
|
exit 1
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
|
|
|
@ -16,14 +16,14 @@ RVM is the Ruby enVironment Manager for the Ruby programming language.
|
||||||
REQUIRED PARAMETERS
|
REQUIRED PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
user::
|
user::
|
||||||
The remote user account to use
|
The remote user account to use
|
||||||
state::
|
state::
|
||||||
Either "present" or "absent".
|
Either "present" or "absent".
|
||||||
|
|
||||||
OPTIONAL PARAMETERS
|
BOOLEAN PARAMETERS
|
||||||
-------------------
|
------------------
|
||||||
default:
|
default:
|
||||||
If set to anything but "no" (the default), set the given version as default
|
Set the given version as default
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
--------
|
--------
|
||||||
|
@ -33,7 +33,7 @@ EXAMPLES
|
||||||
__rvm_ruby ruby-1.9.3-p0 --user thelonious --state present
|
__rvm_ruby ruby-1.9.3-p0 --user thelonious --state present
|
||||||
|
|
||||||
# Install ruby 1.9.3 through rvm for user ornette and make it the default
|
# Install ruby 1.9.3 through rvm for user ornette and make it the default
|
||||||
__rvm_ruby ruby-1.9.3-p0 --user ornette --state present --default yes
|
__rvm_ruby ruby-1.9.3-p0 --user ornette --state present --default
|
||||||
|
|
||||||
# Remove ruby 1.9.3 for user john
|
# Remove ruby 1.9.3 for user john
|
||||||
__rvm_ruby ruby-1.9.3-p0 --user john --state absent
|
__rvm_ruby ruby-1.9.3-p0 --user john --state absent
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2012 Evax Software <contact@evax.fr>
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -17,67 +17,9 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
#
|
||||||
|
|
||||||
if [ -f "$__object/parameter/default" ]; then
|
# Required packages for building ruby
|
||||||
default="$(cat "$__object/parameter/default")"
|
for package in bzip2 gcc make; do
|
||||||
else
|
__package "$package" --state present
|
||||||
default="no"
|
done
|
||||||
echo "$default" > "$__object/parameter/default"
|
|
||||||
fi
|
|
||||||
|
|
||||||
ruby="$__object_id"
|
|
||||||
user="$(cat "$__object/parameter/user")"
|
|
||||||
state="$(cat "$__object/explorer/state")"
|
|
||||||
|
|
||||||
apt_ruby="build-essential openssl libreadline6 libreadline6-dev curl git-core
|
|
||||||
zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3
|
|
||||||
libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison
|
|
||||||
subversion"
|
|
||||||
apt_jruby="curl g++ openjdk-6-jre-headless"
|
|
||||||
apt_jruby_head="ant openjdk-6-jdk"
|
|
||||||
apt_ironruby="curl mono-2.0-devel"
|
|
||||||
|
|
||||||
emerge_ruby="libiconv readline zlib openssl curl git libyaml sqlite libxslt
|
|
||||||
libtool gcc autoconf automake bison m4"
|
|
||||||
emerge_jruby="dev-java/sun-jdk dev-java/sun-jre-bin"
|
|
||||||
emerge_ironruby="dev-lang/mono"
|
|
||||||
|
|
||||||
pacman_ruby="gcc patch curl zlib readline libxml2 libxslt git autoconf
|
|
||||||
diffutils make libtool bison subversion"
|
|
||||||
pacman_jruby="jdk jre curl"
|
|
||||||
pacman_ironruby="mono"
|
|
||||||
|
|
||||||
yum_ruby="gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel
|
|
||||||
libffi-devel openssl-devel make bzip2 autoconf automake libtool bison
|
|
||||||
iconv-devel"
|
|
||||||
yum_jruby="java"
|
|
||||||
|
|
||||||
os="$(cat "$__global/explorer/os")"
|
|
||||||
case "$os" in
|
|
||||||
archlinux) type="pacman" ;;
|
|
||||||
debian|ubuntu) type="apt" ;;
|
|
||||||
gentoo) type="emerge" ;;
|
|
||||||
fedora|redhat|centos) type="yum" ;;
|
|
||||||
*);;
|
|
||||||
esac
|
|
||||||
case "$ruby" in
|
|
||||||
ruby-head*)
|
|
||||||
deps_list="${type}_ruby_head"
|
|
||||||
;;
|
|
||||||
ruby*)
|
|
||||||
deps_list="${type}_ruby"
|
|
||||||
;;
|
|
||||||
jruby-head*)
|
|
||||||
deps_list="${type}_jruby_head"
|
|
||||||
;;
|
|
||||||
jruby*)
|
|
||||||
deps_list="${type}_jruby"
|
|
||||||
;;
|
|
||||||
ironruby*)
|
|
||||||
deps_list="${type}_ironruby"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
deps=$(eval echo \$$deps_list)
|
|
||||||
for p in $deps; do __package_${type} $p --state present; done
|
|
||||||
|
|
||||||
__rvm "$user" --state present
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
# This type allows to send a public ssh key from a user to the
|
# This type allows to send a public ssh key from a user to the
|
||||||
# authorized_keys of another
|
# authorized_keys of another
|
||||||
#
|
#
|
||||||
#require="__package openssh-server --state installed"
|
#require="__package openssh-server --state present"
|
||||||
# Get option srcuser if defined
|
# Get option srcuser if defined
|
||||||
if [ -f "$__object/parameter/srcuser" ]; then
|
if [ -f "$__object/parameter/srcuser" ]; then
|
||||||
srcuser=`cat "$__object/parameter/srcuser"`
|
srcuser=`cat "$__object/parameter/srcuser"`
|
||||||
|
@ -64,4 +64,3 @@ require="__directory${sshpath}" \
|
||||||
# the line added depends on authorized_keys existence
|
# the line added depends on authorized_keys existence
|
||||||
require="__file${sshpath}/authorized_keys" __addifnosuchline sshkey --file \
|
require="__file${sshpath}/authorized_keys" __addifnosuchline sshkey --file \
|
||||||
"$sshpath/authorized_keys" --line "$rsa"
|
"$sshpath/authorized_keys" --line "$rsa"
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ None.
|
||||||
OPTIONAL PARAMETERS
|
OPTIONAL PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
state::
|
state::
|
||||||
'present' or 'absent', defaults to 'present'
|
Either "present" or "absent", defaults to "present"
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
@ -45,6 +45,7 @@ __start_on_boot puppet --state absent
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
- cdist-type(7)
|
- cdist-type(7)
|
||||||
|
- cdist-type__process(7)
|
||||||
|
|
||||||
|
|
||||||
COPYING
|
COPYING
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -18,9 +18,13 @@
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Generate auto.master config based on all defined __autofs_map ojbects.
|
# This type allows to configure the desired localtime timezone.
|
||||||
#
|
|
||||||
|
|
||||||
auto_master="$__object/files/auto.master"
|
timezone="$__object_id"
|
||||||
cat "$(cat "$__object/parameter/header")" > "$auto_master"
|
os=$(cat "$__global/explorer/os")
|
||||||
find "$__global/object/__autofs_map" -path "*.cdist/parameter/entry" | xargs cat >> "$auto_master"
|
|
||||||
|
case "$os" in
|
||||||
|
ubuntu|debian)
|
||||||
|
echo "echo \"$timezone\" > /etc/timezone"
|
||||||
|
;;
|
||||||
|
esac
|
|
@ -1,6 +1,8 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2011 Ramon Salvadó (rsalvado at gnuine dot com)
|
# 2011 Ramon Salvadó (rsalvado at gnuine dot com)
|
||||||
|
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -21,8 +23,17 @@
|
||||||
# This type allows to configure the desired localtime timezone.
|
# This type allows to configure the desired localtime timezone.
|
||||||
|
|
||||||
timezone="$__object_id"
|
timezone="$__object_id"
|
||||||
|
os=$(cat "$__global/explorer/os")
|
||||||
|
|
||||||
__package tzdata --state installed
|
case "$os" in
|
||||||
require="__package/tzdata" __link /etc/localtime \
|
archlinux|debian|ubuntu)
|
||||||
--source "/usr/share/zoneinfo/${timezone}" \
|
__package tzdata --state present
|
||||||
--type symbolic
|
require="__package/tzdata" __link /etc/localtime \
|
||||||
|
--source "/usr/share/zoneinfo/${timezone}" \
|
||||||
|
--type symbolic
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unsupported OS $os" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
|
@ -54,6 +54,7 @@ __user foobar --uid 1001 --shell /bin/zsh --home /home/foobar
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
- cdist-type(7)
|
- cdist-type(7)
|
||||||
|
- usermod(8) or pw(8)
|
||||||
|
|
||||||
|
|
||||||
COPYING
|
COPYING
|
||||||
|
|
|
@ -79,7 +79,6 @@ class ConfigInstall(object):
|
||||||
|
|
||||||
def stage_prepare(self):
|
def stage_prepare(self):
|
||||||
"""Do everything for a deploy, minus the actual code stage"""
|
"""Do everything for a deploy, minus the actual code stage"""
|
||||||
self.local.link_emulator(self.context.exec_path)
|
|
||||||
self.explorer.run_global_explorers(self.local.global_explorer_out_path)
|
self.explorer.run_global_explorers(self.local.global_explorer_out_path)
|
||||||
self.manifest.run_initial_manifest(self.context.initial_manifest)
|
self.manifest.run_initial_manifest(self.context.initial_manifest)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2010-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -38,7 +38,7 @@ class Context(object):
|
||||||
remote_copy,
|
remote_copy,
|
||||||
remote_exec,
|
remote_exec,
|
||||||
initial_manifest=False,
|
initial_manifest=False,
|
||||||
conf_dirs=[],
|
add_conf_dirs=[],
|
||||||
exec_path=sys.argv[0],
|
exec_path=sys.argv[0],
|
||||||
debug=False):
|
debug=False):
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class Context(object):
|
||||||
self.temp_dir = tempfile.mkdtemp()
|
self.temp_dir = tempfile.mkdtemp()
|
||||||
self.out_path = os.path.join(self.temp_dir, "out")
|
self.out_path = os.path.join(self.temp_dir, "out")
|
||||||
|
|
||||||
self.local = local.Local(self.target_host, conf_dirs, self.out_path)
|
self.local = local.Local(self.target_host, self.out_path, self.exec_path, add_conf_dirs=add_conf_dirs)
|
||||||
|
|
||||||
self.initial_manifest = (initial_manifest or
|
self.initial_manifest = (initial_manifest or
|
||||||
os.path.join(self.local.manifest_path, "init"))
|
os.path.join(self.local.manifest_path, "init"))
|
||||||
|
@ -87,6 +87,6 @@ class Context(object):
|
||||||
def filter(self, record):
|
def filter(self, record):
|
||||||
"""Add hostname to logs via logging Filter"""
|
"""Add hostname to logs via logging Filter"""
|
||||||
|
|
||||||
record.msg = self.target_host + ": " + record.msg
|
record.msg = self.target_host + ": " + str(record.msg)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -24,7 +24,6 @@ import os
|
||||||
|
|
||||||
import cdist
|
import cdist
|
||||||
|
|
||||||
|
|
||||||
class NoSuchTypeError(cdist.Error):
|
class NoSuchTypeError(cdist.Error):
|
||||||
def __init__(self, type_path, type_absolute_path):
|
def __init__(self, type_path, type_absolute_path):
|
||||||
self.type_path = type_path
|
self.type_path = type_path
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -57,6 +57,29 @@ type manifeste is:
|
||||||
creates: new objects through type emulator
|
creates: new objects through type emulator
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
class NoInitialManifestError(cdist.Error):
|
||||||
|
"""
|
||||||
|
Display missing initial manifest:
|
||||||
|
- Display path if user given
|
||||||
|
- try to resolve link if it is a link
|
||||||
|
- Omit path if default (is a linked path in temp directory without
|
||||||
|
much help)
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, manifest_path, user_supplied):
|
||||||
|
msg_header = "Initial manifest missing"
|
||||||
|
|
||||||
|
if user_supplied:
|
||||||
|
if os.path.islink(manifest_path):
|
||||||
|
self.message = "%s: %s -> %s" % (msg_header, manifest_path, os.path.realpath(manifest_path))
|
||||||
|
else:
|
||||||
|
self.message = "%s: %s" % (msg_header, manifest_path)
|
||||||
|
else:
|
||||||
|
self.message = "%s" % (msg_header)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return repr(self.message)
|
||||||
|
|
||||||
|
|
||||||
class Manifest(object):
|
class Manifest(object):
|
||||||
"""Executes cdist manifests.
|
"""Executes cdist manifests.
|
||||||
|
@ -70,33 +93,52 @@ class Manifest(object):
|
||||||
|
|
||||||
self.env = {
|
self.env = {
|
||||||
'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']),
|
'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']),
|
||||||
'__target_host': self.target_host,
|
|
||||||
'__global': self.local.out_path,
|
|
||||||
'__cdist_type_base_path': self.local.type_path, # for use in type emulator
|
'__cdist_type_base_path': self.local.type_path, # for use in type emulator
|
||||||
|
'__global': self.local.out_path,
|
||||||
|
'__target_host': self.target_host,
|
||||||
}
|
}
|
||||||
if self.log.getEffectiveLevel() == logging.DEBUG:
|
if self.log.getEffectiveLevel() == logging.DEBUG:
|
||||||
self.env.update({'__cdist_debug': "yes" })
|
self.env.update({'__cdist_debug': "yes" })
|
||||||
|
|
||||||
|
|
||||||
def run_initial_manifest(self, script):
|
def env_initial_manifest(self, initial_manifest):
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env.update(self.env)
|
env.update(self.env)
|
||||||
|
env['__cdist_manifest'] = initial_manifest
|
||||||
env['__manifest'] = self.local.manifest_path
|
env['__manifest'] = self.local.manifest_path
|
||||||
env['__cdist_manifest'] = script
|
|
||||||
self.log.info("Running initial manifest " + self.local.manifest_path)
|
return env
|
||||||
self.local.run_script(script, env=env)
|
|
||||||
|
def run_initial_manifest(self, initial_manifest=None):
|
||||||
|
if not initial_manifest:
|
||||||
|
initial_manifest = self.local.initial_manifest
|
||||||
|
user_supplied = False
|
||||||
|
else:
|
||||||
|
user_supplied = True
|
||||||
|
|
||||||
|
self.log.info("Running initial manifest " + initial_manifest)
|
||||||
|
|
||||||
|
if not os.path.isfile(initial_manifest):
|
||||||
|
raise NoInitialManifestError(initial_manifest, user_supplied)
|
||||||
|
|
||||||
|
self.local.run_script(initial_manifest, env=self.env_initial_manifest(initial_manifest))
|
||||||
|
|
||||||
|
def env_type_manifest(self, cdist_object):
|
||||||
|
type_manifest = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path)
|
||||||
|
env = os.environ.copy()
|
||||||
|
env.update(self.env)
|
||||||
|
env.update({
|
||||||
|
'__cdist_manifest': type_manifest,
|
||||||
|
'__manifest': self.local.manifest_path,
|
||||||
|
'__object': cdist_object.absolute_path,
|
||||||
|
'__object_id': cdist_object.object_id,
|
||||||
|
'__object_name': cdist_object.name,
|
||||||
|
'__type': cdist_object.cdist_type.absolute_path,
|
||||||
|
})
|
||||||
|
|
||||||
|
return env
|
||||||
|
|
||||||
def run_type_manifest(self, cdist_object):
|
def run_type_manifest(self, cdist_object):
|
||||||
script = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path)
|
type_manifest = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path)
|
||||||
if os.path.isfile(script):
|
if os.path.isfile(type_manifest):
|
||||||
env = os.environ.copy()
|
self.local.run_script(type_manifest, env=self.env_type_manifest(cdist_object))
|
||||||
env.update(self.env)
|
|
||||||
env.update({
|
|
||||||
'__manifest': self.local.manifest_path,
|
|
||||||
'__object': cdist_object.absolute_path,
|
|
||||||
'__object_id': cdist_object.object_id,
|
|
||||||
'__object_name': cdist_object.name,
|
|
||||||
'__type': cdist_object.cdist_type.absolute_path,
|
|
||||||
'__cdist_manifest': script,
|
|
||||||
})
|
|
||||||
self.local.run_script(script, env=env)
|
|
||||||
|
|
|
@ -29,16 +29,19 @@ import cdist
|
||||||
from cdist import core
|
from cdist import core
|
||||||
|
|
||||||
class Emulator(object):
|
class Emulator(object):
|
||||||
def __init__(self, argv):
|
def __init__(self, argv, stdin=sys.stdin, env=os.environ):
|
||||||
self.argv = argv
|
self.argv = argv
|
||||||
|
self.stdin = stdin
|
||||||
|
self.env = env
|
||||||
|
|
||||||
self.object_id = False
|
self.object_id = False
|
||||||
|
|
||||||
self.global_path = os.environ['__global']
|
self.global_path = self.env['__global']
|
||||||
self.target_host = os.environ['__target_host']
|
self.target_host = self.env['__target_host']
|
||||||
|
|
||||||
# Internally only
|
# Internally only
|
||||||
self.object_source = os.environ['__cdist_manifest']
|
self.object_source = self.env['__cdist_manifest']
|
||||||
self.type_base_path = os.environ['__cdist_type_base_path']
|
self.type_base_path = self.env['__cdist_type_base_path']
|
||||||
|
|
||||||
self.object_base_path = os.path.join(self.global_path, "object")
|
self.object_base_path = os.path.join(self.global_path, "object")
|
||||||
|
|
||||||
|
@ -62,7 +65,7 @@ class Emulator(object):
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Emulate type commands (i.e. __file and co)"""
|
"""Emulate type commands (i.e. __file and co)"""
|
||||||
|
|
||||||
if '__install' in os.environ:
|
if '__install' in self.env:
|
||||||
if not self.cdist_type.is_install:
|
if not self.cdist_type.is_install:
|
||||||
self.log.debug("Running in install mode, ignoring non install type")
|
self.log.debug("Running in install mode, ignoring non install type")
|
||||||
return True
|
return True
|
||||||
|
@ -79,7 +82,7 @@ class Emulator(object):
|
||||||
logformat = '%(levelname)s: %(message)s'
|
logformat = '%(levelname)s: %(message)s'
|
||||||
logging.basicConfig(format=logformat)
|
logging.basicConfig(format=logformat)
|
||||||
|
|
||||||
if '__cdist_debug' in os.environ:
|
if '__cdist_debug' in self.env:
|
||||||
logging.root.setLevel(logging.DEBUG)
|
logging.root.setLevel(logging.DEBUG)
|
||||||
else:
|
else:
|
||||||
logging.root.setLevel(logging.INFO)
|
logging.root.setLevel(logging.INFO)
|
||||||
|
@ -146,32 +149,27 @@ class Emulator(object):
|
||||||
# Record / Append source
|
# Record / Append source
|
||||||
self.cdist_object.source.append(self.object_source)
|
self.cdist_object.source.append(self.object_source)
|
||||||
|
|
||||||
chunk_size = 8192
|
|
||||||
def _read_stdin(self):
|
|
||||||
return sys.stdin.buffer.read(self.chunk_size)
|
|
||||||
def save_stdin(self):
|
def save_stdin(self):
|
||||||
"""If something is written to stdin, save it in the object as
|
"""If something is written to stdin, save it in the object as
|
||||||
$__object/stdin so it can be accessed in manifest and gencode-*
|
$__object/stdin so it can be accessed in manifest and gencode-*
|
||||||
scripts.
|
scripts.
|
||||||
"""
|
"""
|
||||||
if not sys.stdin.isatty():
|
if not self.stdin.isatty():
|
||||||
try:
|
try:
|
||||||
# go directly to file instead of using CdistObject's api
|
# go directly to file instead of using CdistObject's api
|
||||||
# as that does not support streaming
|
# as that does not support streaming
|
||||||
|
# FIXME: no streaming needed anymore - use a raw file (not yet there?)
|
||||||
path = os.path.join(self.cdist_object.absolute_path, 'stdin')
|
path = os.path.join(self.cdist_object.absolute_path, 'stdin')
|
||||||
with open(path, 'wb') as fd:
|
with open(path, 'w') as fd:
|
||||||
chunk = self._read_stdin()
|
fd.write(self.stdin.read())
|
||||||
while chunk:
|
|
||||||
fd.write(chunk)
|
|
||||||
chunk = self._read_stdin()
|
|
||||||
except EnvironmentError as e:
|
except EnvironmentError as e:
|
||||||
raise cdist.Error('Failed to read from stdin: %s' % e)
|
raise cdist.Error('Failed to read from stdin: %s' % e)
|
||||||
|
|
||||||
def record_requirements(self):
|
def record_requirements(self):
|
||||||
"""record requirements"""
|
"""record requirements"""
|
||||||
|
|
||||||
if "require" in os.environ:
|
if "require" in self.env:
|
||||||
requirements = os.environ['require']
|
requirements = self.env['require']
|
||||||
self.log.debug("reqs = " + requirements)
|
self.log.debug("reqs = " + requirements)
|
||||||
for requirement in requirements.split(" "):
|
for requirement in requirements.split(" "):
|
||||||
# Ignore empty fields - probably the only field anyway
|
# Ignore empty fields - probably the only field anyway
|
||||||
|
@ -191,7 +189,7 @@ class Emulator(object):
|
||||||
"""An object shall automatically depend on all objects that it defined in it's type manifest.
|
"""An object shall automatically depend on all objects that it defined in it's type manifest.
|
||||||
"""
|
"""
|
||||||
# __object_name is the name of the object whose type manifest is currently executed
|
# __object_name is the name of the object whose type manifest is currently executed
|
||||||
__object_name = os.environ.get('__object_name', None)
|
__object_name = self.env.get('__object_name', None)
|
||||||
if __object_name:
|
if __object_name:
|
||||||
# The object whose type manifest is currently run
|
# The object whose type manifest is currently run
|
||||||
parent = self.cdist_object.object_from_name(__object_name)
|
parent = self.cdist_object.object_from_name(__object_name)
|
||||||
|
|
|
@ -37,24 +37,30 @@ class Local(object):
|
||||||
Directly accessing the local side from python code is a bug.
|
Directly accessing the local side from python code is a bug.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, target_host, conf_dirs, out_path, cache_dir=None):
|
def __init__(self, target_host, out_path, exec_path, add_conf_dirs=[], cache_dir=None):
|
||||||
|
|
||||||
self.target_host = target_host
|
self.target_host = target_host
|
||||||
self.add_conf_dirs = conf_dirs
|
|
||||||
self.out_path = out_path
|
self.out_path = out_path
|
||||||
|
self.exec_path = exec_path
|
||||||
|
|
||||||
|
self._add_conf_dirs = add_conf_dirs
|
||||||
|
|
||||||
self._init_log()
|
self._init_log()
|
||||||
self._init_permissions()
|
self._init_permissions()
|
||||||
self._init_home_dir()
|
|
||||||
self._init_paths()
|
self._init_paths()
|
||||||
self._init_cache_dir(cache_dir)
|
self._init_cache_dir(cache_dir)
|
||||||
self._init_conf_dirs()
|
self._init_conf_dirs()
|
||||||
|
|
||||||
def _init_home_dir(self):
|
@property
|
||||||
|
def dist_conf_dir(self):
|
||||||
|
return os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf"))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def home_dir(self):
|
||||||
if 'HOME' in os.environ:
|
if 'HOME' in os.environ:
|
||||||
self.home_dir = os.environ['HOME']
|
return os.path.join(os.environ['HOME'], ".cdist")
|
||||||
else:
|
else:
|
||||||
self.home_dir = None
|
return None
|
||||||
|
|
||||||
def _init_log(self):
|
def _init_log(self):
|
||||||
self.log = logging.getLogger(self.target_host)
|
self.log = logging.getLogger(self.target_host)
|
||||||
|
@ -79,17 +85,16 @@ class Local(object):
|
||||||
self.conf_dirs = []
|
self.conf_dirs = []
|
||||||
|
|
||||||
# Comes with the distribution
|
# Comes with the distribution
|
||||||
system_conf_dir = os.path.join(os.path.dirname(cdist.__file__), "conf")
|
system_conf_dir = os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf"))
|
||||||
self.conf_dirs.append(system_conf_dir)
|
self.conf_dirs.append(system_conf_dir)
|
||||||
|
|
||||||
# Is the default place for user created explorer, type and manifest
|
# Is the default place for user created explorer, type and manifest
|
||||||
if self.home_dir:
|
if self.home_dir:
|
||||||
user_conf_dir = os.path.join(self.home_dir, ".cdist")
|
self.conf_dirs.append(self.home_dir)
|
||||||
self.conf_dirs.append(user_conf_dir)
|
|
||||||
|
|
||||||
# Add user supplied directories
|
# Add user supplied directories
|
||||||
if self.add_conf_dirs:
|
if self._add_conf_dirs:
|
||||||
self.conf_dirs.extend(self.add_conf_dirs)
|
self.conf_dirs.extend(self._add_conf_dirs)
|
||||||
|
|
||||||
def _init_cache_dir(self, cache_dir):
|
def _init_cache_dir(self, cache_dir):
|
||||||
if cache_dir:
|
if cache_dir:
|
||||||
|
@ -146,16 +151,16 @@ class Local(object):
|
||||||
def create_files_dirs(self):
|
def create_files_dirs(self):
|
||||||
self._create_context_dirs()
|
self._create_context_dirs()
|
||||||
self._create_conf_path_and_link_conf_dirs()
|
self._create_conf_path_and_link_conf_dirs()
|
||||||
|
self._link_types_for_emulator()
|
||||||
|
|
||||||
def _create_context_dirs(self):
|
def _create_context_dirs(self):
|
||||||
self.mkdir(self.out_path)
|
self.mkdir(self.out_path)
|
||||||
|
|
||||||
self.mkdir(self.conf_path)
|
self.mkdir(self.conf_path)
|
||||||
self.mkdir(self.global_explorer_out_path)
|
self.mkdir(self.global_explorer_out_path)
|
||||||
self.mkdir(self.bin_path)
|
self.mkdir(self.bin_path)
|
||||||
|
|
||||||
def _create_conf_path_and_link_conf_dirs(self):
|
def _create_conf_path_and_link_conf_dirs(self):
|
||||||
self.mkdir(self.conf_path)
|
|
||||||
|
|
||||||
# Link destination directories
|
# Link destination directories
|
||||||
for sub_dir in [ "explorer", "manifest", "type" ]:
|
for sub_dir in [ "explorer", "manifest", "type" ]:
|
||||||
self.mkdir(os.path.join(self.conf_path, sub_dir))
|
self.mkdir(os.path.join(self.conf_path, sub_dir))
|
||||||
|
@ -185,9 +190,9 @@ class Local(object):
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise cdist.Error("Linking %s %s to %s failed: %s" % (sub_dir, src, dst, e.__str__()))
|
raise cdist.Error("Linking %s %s to %s failed: %s" % (sub_dir, src, dst, e.__str__()))
|
||||||
|
|
||||||
def link_emulator(self, exec_path):
|
def _link_types_for_emulator(self):
|
||||||
"""Link emulator to types"""
|
"""Link emulator to types"""
|
||||||
src = os.path.abspath(exec_path)
|
src = os.path.abspath(self.exec_path)
|
||||||
for cdist_type in core.CdistType.list_types(self.type_path):
|
for cdist_type in core.CdistType.list_types(self.type_path):
|
||||||
dst = os.path.join(self.bin_path, cdist_type.name)
|
dst = os.path.join(self.bin_path, cdist_type.name)
|
||||||
self.log.debug("Linking emulator: %s to %s", src, dst)
|
self.log.debug("Linking emulator: %s to %s", src, dst)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -24,13 +24,19 @@ import unittest
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
cdist_base_path = os.path.abspath(
|
cdist_base_path = os.path.abspath(
|
||||||
os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../../"))
|
os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../"))
|
||||||
|
|
||||||
cdist_exec_path = os.path.join(cdist_base_path, "bin/cdist")
|
cdist_exec_path = os.path.join(cdist_base_path, "scripts/cdist")
|
||||||
|
|
||||||
|
global_fixtures_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "fixtures"))
|
||||||
|
|
||||||
class CdistTestCase(unittest.TestCase):
|
class CdistTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
remote_exec = os.path.join(global_fixtures_dir, "remote", "exec")
|
||||||
|
remote_copy = os.path.join(global_fixtures_dir, "remote", "copy")
|
||||||
|
|
||||||
|
target_host = 'cdisttesthost'
|
||||||
|
|
||||||
def mkdtemp(self, **kwargs):
|
def mkdtemp(self, **kwargs):
|
||||||
return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs)
|
return tempfile.mkdtemp(prefix='tmp.cdist.test.', **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -34,23 +35,29 @@ import cdist.context
|
||||||
import os.path as op
|
import os.path as op
|
||||||
my_dir = op.abspath(op.dirname(__file__))
|
my_dir = op.abspath(op.dirname(__file__))
|
||||||
fixtures = op.join(my_dir, 'fixtures')
|
fixtures = op.join(my_dir, 'fixtures')
|
||||||
local_base_path = fixtures
|
add_conf_dir = op.join(fixtures, 'conf')
|
||||||
|
|
||||||
|
|
||||||
class AutorequireTestCase(test.CdistTestCase):
|
class AutorequireTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.orig_environ = os.environ
|
self.orig_environ = os.environ
|
||||||
os.environ = os.environ.copy()
|
os.environ = os.environ.copy()
|
||||||
self.target_host = 'localhost'
|
|
||||||
self.temp_dir = self.mkdtemp()
|
self.temp_dir = self.mkdtemp()
|
||||||
os.environ['__cdist_out_dir'] = self.temp_dir
|
|
||||||
|
self.out_dir = os.path.join(self.temp_dir, "out")
|
||||||
|
self.remote_out_dir = os.path.join(self.temp_dir, "remote")
|
||||||
|
|
||||||
|
os.environ['__cdist_out_dir'] = self.out_dir
|
||||||
|
os.environ['__cdist_remote_out_dir'] = self.remote_out_dir
|
||||||
|
|
||||||
self.context = cdist.context.Context(
|
self.context = cdist.context.Context(
|
||||||
target_host=self.target_host,
|
target_host=self.target_host,
|
||||||
base_path=local_base_path,
|
remote_copy=self.remote_copy,
|
||||||
|
remote_exec=self.remote_exec,
|
||||||
|
add_conf_dirs=[add_conf_dir],
|
||||||
exec_path=test.cdist_exec_path,
|
exec_path=test.cdist_exec_path,
|
||||||
debug=False)
|
debug=False)
|
||||||
|
|
||||||
self.config = config.Config(self.context)
|
self.config = config.Config(self.context)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -19,10 +20,9 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import getpass
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import getpass
|
|
||||||
import logging
|
|
||||||
|
|
||||||
import cdist
|
import cdist
|
||||||
from cdist import core
|
from cdist import core
|
||||||
|
@ -34,23 +34,27 @@ from cdist.core import code
|
||||||
import os.path as op
|
import os.path as op
|
||||||
my_dir = op.abspath(op.dirname(__file__))
|
my_dir = op.abspath(op.dirname(__file__))
|
||||||
fixtures = op.join(my_dir, 'fixtures')
|
fixtures = op.join(my_dir, 'fixtures')
|
||||||
local_base_path = fixtures
|
conf_dir = op.join(fixtures, 'conf')
|
||||||
|
|
||||||
class CodeTestCase(test.CdistTestCase):
|
class CodeTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.target_host = 'localhost'
|
self.target_host = 'localhost'
|
||||||
|
|
||||||
self.local_base_path = local_base_path
|
|
||||||
self.out_path = self.mkdtemp()
|
self.out_path = self.mkdtemp()
|
||||||
self.local = local.Local(self.target_host, self.local_base_path, self.out_path)
|
|
||||||
self.local.create_directories()
|
self.local = local.Local(
|
||||||
|
target_host=self.target_host,
|
||||||
|
out_path = self.out_path,
|
||||||
|
exec_path = cdist.test.cdist_exec_path,
|
||||||
|
add_conf_dirs=[conf_dir])
|
||||||
|
self.local.create_files_dirs()
|
||||||
|
|
||||||
self.remote_base_path = self.mkdtemp()
|
self.remote_base_path = self.mkdtemp()
|
||||||
self.user = getpass.getuser()
|
remote_exec = self.remote_exec
|
||||||
remote_exec = "ssh -o User=%s -q" % self.user
|
remote_copy = self.remote_copy
|
||||||
remote_copy = "scp -o User=%s -q" % self.user
|
|
||||||
self.remote = remote.Remote(self.target_host, self.remote_base_path, remote_exec, remote_copy)
|
self.remote = remote.Remote(self.target_host, self.remote_base_path, remote_exec, remote_copy)
|
||||||
|
self.remote.create_files_dirs()
|
||||||
|
|
||||||
self.code = code.Code(self.target_host, self.local, self.remote)
|
self.code = code.Code(self.target_host, self.local, self.remote)
|
||||||
|
|
||||||
|
@ -58,8 +62,6 @@ class CodeTestCase(test.CdistTestCase):
|
||||||
self.cdist_object = core.CdistObject(self.cdist_type, self.local.object_path, 'whatever')
|
self.cdist_object = core.CdistObject(self.cdist_type, self.local.object_path, 'whatever')
|
||||||
self.cdist_object.create()
|
self.cdist_object.create()
|
||||||
|
|
||||||
self.log = logging.getLogger("cdist")
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.out_path)
|
shutil.rmtree(self.out_path)
|
||||||
shutil.rmtree(self.remote_base_path)
|
shutil.rmtree(self.remote_base_path)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import string
|
import string
|
||||||
|
@ -33,89 +35,80 @@ from cdist import core
|
||||||
from cdist import config
|
from cdist import config
|
||||||
import cdist.context
|
import cdist.context
|
||||||
|
|
||||||
local_base_path = test.cdist_base_path
|
import os.path as op
|
||||||
|
my_dir = op.abspath(op.dirname(__file__))
|
||||||
|
fixtures = op.join(my_dir, 'fixtures')
|
||||||
|
conf_dir = op.join(fixtures, 'conf')
|
||||||
|
|
||||||
class EmulatorTestCase(test.CdistTestCase):
|
class EmulatorTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.orig_environ = os.environ
|
|
||||||
os.environ = os.environ.copy()
|
|
||||||
self.temp_dir = self.mkdtemp()
|
self.temp_dir = self.mkdtemp()
|
||||||
handle, self.script = self.mkstemp(dir=self.temp_dir)
|
handle, self.script = self.mkstemp(dir=self.temp_dir)
|
||||||
os.close(handle)
|
os.close(handle)
|
||||||
self.target_host = 'localhost'
|
|
||||||
out_path = self.temp_dir
|
out_path = self.temp_dir
|
||||||
self.local = local.Local(self.target_host, local_base_path, out_path)
|
|
||||||
self.local.create_directories()
|
self.local = local.Local(
|
||||||
self.env = {
|
target_host=self.target_host,
|
||||||
'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']),
|
out_path=out_path,
|
||||||
'__target_host': self.target_host,
|
exec_path=test.cdist_exec_path,
|
||||||
'__global': self.local.out_path,
|
add_conf_dirs=[conf_dir])
|
||||||
'__cdist_type_base_path': self.local.type_path, # for use in type emulator
|
self.local.create_files_dirs()
|
||||||
'__manifest': self.local.manifest_path,
|
|
||||||
'__cdist_manifest': self.script,
|
self.manifest = core.Manifest(self.target_host, self.local)
|
||||||
}
|
self.env = self.manifest.env_initial_manifest(self.script)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
os.environ = self.orig_environ
|
|
||||||
shutil.rmtree(self.temp_dir)
|
shutil.rmtree(self.temp_dir)
|
||||||
|
|
||||||
def test_nonexistent_type_exec(self):
|
def test_nonexistent_type_exec(self):
|
||||||
argv = ['__does-not-exist']
|
argv = ['__does-not-exist']
|
||||||
os.environ.update(self.env)
|
self.assertRaises(core.NoSuchTypeError, emulator.Emulator, argv, env=self.env)
|
||||||
self.assertRaises(core.NoSuchTypeError, emulator.Emulator, argv)
|
|
||||||
|
|
||||||
def test_nonexistent_type_requirement(self):
|
def test_nonexistent_type_requirement(self):
|
||||||
argv = ['__file', '/tmp/foobar']
|
argv = ['__file', '/tmp/foobar']
|
||||||
os.environ.update(self.env)
|
self.env['require'] = '__does-not-exist/some-id'
|
||||||
os.environ['require'] = '__does-not-exist/some-id'
|
emu = emulator.Emulator(argv, env=self.env)
|
||||||
emu = emulator.Emulator(argv)
|
|
||||||
self.assertRaises(core.NoSuchTypeError, emu.run)
|
self.assertRaises(core.NoSuchTypeError, emu.run)
|
||||||
|
|
||||||
def test_illegal_object_id_requirement(self):
|
def test_illegal_object_id_requirement(self):
|
||||||
argv = ['__file', '/tmp/foobar']
|
argv = ['__file', '/tmp/foobar']
|
||||||
os.environ.update(self.env)
|
self.env['require'] = '__file/bad/id/with/.cdist/inside'
|
||||||
os.environ['require'] = '__file/bad/id/with/.cdist/inside'
|
emu = emulator.Emulator(argv, env=self.env)
|
||||||
emu = emulator.Emulator(argv)
|
|
||||||
self.assertRaises(core.IllegalObjectIdError, emu.run)
|
self.assertRaises(core.IllegalObjectIdError, emu.run)
|
||||||
|
|
||||||
def test_missing_object_id_requirement(self):
|
def test_missing_object_id_requirement(self):
|
||||||
argv = ['__file', '/tmp/foobar']
|
argv = ['__file', '/tmp/foobar']
|
||||||
os.environ.update(self.env)
|
self.env['require'] = '__file'
|
||||||
os.environ['require'] = '__file'
|
emu = emulator.Emulator(argv, env=self.env)
|
||||||
emu = emulator.Emulator(argv)
|
|
||||||
self.assertRaises(core.IllegalObjectIdError, emu.run)
|
self.assertRaises(core.IllegalObjectIdError, emu.run)
|
||||||
|
|
||||||
def test_singleton_object_requirement(self):
|
def test_singleton_object_requirement(self):
|
||||||
argv = ['__file', '/tmp/foobar']
|
argv = ['__file', '/tmp/foobar']
|
||||||
os.environ.update(self.env)
|
self.env['require'] = '__issue'
|
||||||
os.environ['require'] = '__issue'
|
emu = emulator.Emulator(argv, env=self.env)
|
||||||
emu = emulator.Emulator(argv)
|
|
||||||
emu.run()
|
emu.run()
|
||||||
# if we get here all is fine
|
# if we get here all is fine
|
||||||
|
|
||||||
def test_requirement_pattern(self):
|
def test_requirement_pattern(self):
|
||||||
argv = ['__file', '/tmp/foobar']
|
argv = ['__file', '/tmp/foobar']
|
||||||
os.environ.update(self.env)
|
self.env['require'] = '__file/etc/*'
|
||||||
os.environ['require'] = '__file/etc/*'
|
emu = emulator.Emulator(argv, env=self.env)
|
||||||
emu = emulator.Emulator(argv)
|
|
||||||
# if we get here all is fine
|
# if we get here all is fine
|
||||||
|
|
||||||
|
|
||||||
import os.path as op
|
|
||||||
my_dir = op.abspath(op.dirname(__file__))
|
|
||||||
fixtures = op.join(my_dir, 'fixtures')
|
|
||||||
|
|
||||||
class AutoRequireEmulatorTestCase(test.CdistTestCase):
|
class AutoRequireEmulatorTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.temp_dir = self.mkdtemp()
|
self.temp_dir = self.mkdtemp()
|
||||||
self.target_host = 'localhost'
|
out_path = os.path.join(self.temp_dir, "out")
|
||||||
out_path = self.temp_dir
|
|
||||||
_local_base_path = fixtures
|
self.local = local.Local(
|
||||||
self.local = local.Local(self.target_host, _local_base_path, out_path)
|
target_host=self.target_host,
|
||||||
self.local.create_directories()
|
out_path=out_path,
|
||||||
self.local.link_emulator(cdist.test.cdist_exec_path)
|
exec_path=test.cdist_exec_path,
|
||||||
|
add_conf_dirs=[conf_dir])
|
||||||
|
self.local.create_files_dirs()
|
||||||
self.manifest = core.Manifest(self.target_host, self.local)
|
self.manifest = core.Manifest(self.target_host, self.local)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
@ -135,22 +128,19 @@ class ArgumentsTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.temp_dir = self.mkdtemp()
|
self.temp_dir = self.mkdtemp()
|
||||||
self.target_host = 'localhost'
|
|
||||||
out_path = self.temp_dir
|
out_path = self.temp_dir
|
||||||
handle, self.script = self.mkstemp(dir=self.temp_dir)
|
handle, self.script = self.mkstemp(dir=self.temp_dir)
|
||||||
os.close(handle)
|
os.close(handle)
|
||||||
_local_base_path = fixtures
|
|
||||||
self.local = local.Local(self.target_host, _local_base_path, out_path)
|
self.local = local.Local(
|
||||||
self.local.create_directories()
|
target_host=self.target_host,
|
||||||
self.local.link_emulator(test.cdist_exec_path)
|
out_path=out_path,
|
||||||
self.env = {
|
exec_path=test.cdist_exec_path,
|
||||||
'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']),
|
add_conf_dirs=[conf_dir])
|
||||||
'__target_host': self.target_host,
|
self.local.create_files_dirs()
|
||||||
'__global': self.local.out_path,
|
|
||||||
'__cdist_type_base_path': self.local.type_path, # for use in type emulator
|
self.manifest = core.Manifest(self.target_host, self.local)
|
||||||
'__manifest': self.local.manifest_path,
|
self.env = self.manifest.env_initial_manifest(self.script)
|
||||||
'__cdist_manifest': self.script,
|
|
||||||
}
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.temp_dir)
|
shutil.rmtree(self.temp_dir)
|
||||||
|
@ -227,40 +217,59 @@ class StdinTestCase(test.CdistTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.orig_environ = os.environ
|
self.orig_environ = os.environ
|
||||||
os.environ = os.environ.copy()
|
os.environ = os.environ.copy()
|
||||||
self.target_host = 'localhost'
|
|
||||||
self.temp_dir = self.mkdtemp()
|
|
||||||
os.environ['__cdist_out_dir'] = self.temp_dir
|
|
||||||
local_base_path = fixtures
|
|
||||||
|
|
||||||
self.context = cdist.context.Context(
|
self.temp_dir = self.mkdtemp()
|
||||||
|
out_path = os.path.join(self.temp_dir, "out")
|
||||||
|
|
||||||
|
self.local = local.Local(
|
||||||
target_host=self.target_host,
|
target_host=self.target_host,
|
||||||
remote_copy='scp -o User=root -q',
|
out_path=out_path,
|
||||||
remote_exec='ssh -o User=root -q',
|
|
||||||
base_path=local_base_path,
|
|
||||||
exec_path=test.cdist_exec_path,
|
exec_path=test.cdist_exec_path,
|
||||||
debug=False)
|
add_conf_dirs=[conf_dir])
|
||||||
self.config = config.Config(self.context)
|
|
||||||
|
self.local.create_files_dirs()
|
||||||
|
|
||||||
|
self.manifest = core.Manifest(
|
||||||
|
target_host=self.target_host,
|
||||||
|
local = self.local)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
os.environ = self.orig_environ
|
os.environ = self.orig_environ
|
||||||
shutil.rmtree(self.temp_dir)
|
shutil.rmtree(self.temp_dir)
|
||||||
|
|
||||||
def test_file_from_stdin(self):
|
def test_file_from_stdin(self):
|
||||||
handle, destination = self.mkstemp(dir=self.temp_dir)
|
"""
|
||||||
os.close(handle)
|
Test whether reading from stdin works
|
||||||
source_handle, source = self.mkstemp(dir=self.temp_dir)
|
"""
|
||||||
candidates = string.ascii_letters+string.digits
|
|
||||||
with os.fdopen(source_handle, 'w') as fd:
|
|
||||||
for x in range(100):
|
|
||||||
fd.write(''.join(random.sample(candidates, len(candidates))))
|
|
||||||
|
|
||||||
handle, initial_manifest = self.mkstemp(dir=self.temp_dir)
|
######################################################################
|
||||||
with os.fdopen(handle, 'w') as fd:
|
# Create string with random content
|
||||||
fd.write('__file_from_stdin %s --source %s\n' % (destination, source))
|
random_string = str(random.sample(range(1000), 800))
|
||||||
self.context.initial_manifest = initial_manifest
|
random_buffer = io.BytesIO(bytes(random_string, 'utf-8'))
|
||||||
self.config.stage_prepare()
|
|
||||||
|
|
||||||
cdist_type = core.CdistType(self.config.local.type_path, '__file')
|
######################################################################
|
||||||
cdist_object = core.CdistObject(cdist_type, self.config.local.object_path, destination)
|
# Prepare required args and environment for emulator
|
||||||
# Test weither stdin has been stored correctly
|
type_name = '__file'
|
||||||
self.assertTrue(filecmp.cmp(source, os.path.join(cdist_object.absolute_path, 'stdin')))
|
object_id = "cdist-test-id"
|
||||||
|
argv = [type_name, object_id]
|
||||||
|
|
||||||
|
initial_manifest_path = "/cdist-test/path/that/does/not/exist"
|
||||||
|
env = self.manifest.env_initial_manifest(initial_manifest_path)
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
# Create path where stdin should reside at
|
||||||
|
cdist_type = core.CdistType(self.local.type_path, type_name)
|
||||||
|
cdist_object = core.CdistObject(cdist_type, self.local.object_path, object_id)
|
||||||
|
stdin_out_path = os.path.join(cdist_object.absolute_path, 'stdin')
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
# Run emulator
|
||||||
|
emu = emulator.Emulator(argv, stdin=random_buffer, env=env)
|
||||||
|
emu.run()
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
# Read where emulator should have placed stdin
|
||||||
|
with open(stdin_out_path, 'r') as fd:
|
||||||
|
stdin_saved_by_emulator = fd.read()
|
||||||
|
|
||||||
|
self.assertEqual(random_string, stdin_saved_by_emulator)
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
../../../../../conf/type/__file
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -25,9 +26,6 @@ import shutil
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
|
|
||||||
#import logging
|
|
||||||
#logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s')
|
|
||||||
|
|
||||||
import cdist
|
import cdist
|
||||||
from cdist import test
|
from cdist import test
|
||||||
from cdist.exec import local
|
from cdist.exec import local
|
||||||
|
@ -35,17 +33,23 @@ from cdist.exec import local
|
||||||
import os.path as op
|
import os.path as op
|
||||||
my_dir = op.abspath(op.dirname(__file__))
|
my_dir = op.abspath(op.dirname(__file__))
|
||||||
fixtures = op.join(my_dir, 'fixtures')
|
fixtures = op.join(my_dir, 'fixtures')
|
||||||
local_base_path = fixtures
|
conf_dir = op.join(fixtures, "conf")
|
||||||
|
|
||||||
|
|
||||||
class LocalTestCase(test.CdistTestCase):
|
class LocalTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.temp_dir = self.mkdtemp()
|
|
||||||
target_host = 'localhost'
|
target_host = 'localhost'
|
||||||
|
self.temp_dir = self.mkdtemp()
|
||||||
self.out_path = self.temp_dir
|
self.out_path = self.temp_dir
|
||||||
self.base_path = local_base_path
|
|
||||||
self.local = local.Local(target_host, self.base_path, self.out_path)
|
self.local = local.Local(
|
||||||
|
target_host=target_host,
|
||||||
|
out_path=self.out_path,
|
||||||
|
exec_path=test.cdist_exec_path
|
||||||
|
)
|
||||||
|
|
||||||
|
self.home_dir = os.path.join(os.environ['HOME'], ".cdist")
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.temp_dir)
|
shutil.rmtree(self.temp_dir)
|
||||||
|
@ -53,19 +57,10 @@ class LocalTestCase(test.CdistTestCase):
|
||||||
### test api
|
### test api
|
||||||
|
|
||||||
def test_cache_path(self):
|
def test_cache_path(self):
|
||||||
self.assertEqual(self.local.cache_path, os.path.join(self.base_path, "cache"))
|
self.assertEqual(self.local.cache_path, os.path.join(self.home_dir, "cache"))
|
||||||
|
|
||||||
def test_conf_path(self):
|
def test_conf_path(self):
|
||||||
self.assertEqual(self.local.conf_path, os.path.join(self.base_path, "conf"))
|
self.assertEqual(self.local.conf_path, os.path.join(self.out_path, "conf"))
|
||||||
|
|
||||||
def test_global_explorer_path(self):
|
|
||||||
self.assertEqual(self.local.global_explorer_path, os.path.join(self.base_path, "conf", "explorer"))
|
|
||||||
|
|
||||||
def test_manifest_path(self):
|
|
||||||
self.assertEqual(self.local.manifest_path, os.path.join(self.base_path, "conf", "manifest"))
|
|
||||||
|
|
||||||
def test_type_path(self):
|
|
||||||
self.assertEqual(self.local.type_path, os.path.join(self.base_path, "conf", "type"))
|
|
||||||
|
|
||||||
def test_out_path(self):
|
def test_out_path(self):
|
||||||
self.assertEqual(self.local.out_path, self.out_path)
|
self.assertEqual(self.local.out_path, self.out_path)
|
||||||
|
@ -81,6 +76,53 @@ class LocalTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
### /test api
|
### /test api
|
||||||
|
|
||||||
|
### test internal implementation
|
||||||
|
|
||||||
|
def test_global_explorer_path(self):
|
||||||
|
self.assertEqual(self.local.global_explorer_path, os.path.join(self.out_path, "conf", "explorer"))
|
||||||
|
|
||||||
|
def test_manifest_path(self):
|
||||||
|
self.assertEqual(self.local.manifest_path, os.path.join(self.out_path, "conf", "manifest"))
|
||||||
|
|
||||||
|
def test_type_path(self):
|
||||||
|
self.assertEqual(self.local.type_path, os.path.join(self.out_path, "conf", "type"))
|
||||||
|
|
||||||
|
def test_dist_conf_dir_linking(self):
|
||||||
|
"""Ensure that links are correctly created for types included in distribution"""
|
||||||
|
|
||||||
|
test_type="__file"
|
||||||
|
|
||||||
|
link_test_local = local.Local(
|
||||||
|
target_host='localhost',
|
||||||
|
out_path=self.out_path,
|
||||||
|
exec_path=test.cdist_exec_path,
|
||||||
|
)
|
||||||
|
|
||||||
|
link_test_local._create_conf_path_and_link_conf_dirs()
|
||||||
|
|
||||||
|
our_type_dir = os.path.join(link_test_local.type_path, test_type)
|
||||||
|
|
||||||
|
self.assertTrue(os.path.isdir(our_type_dir))
|
||||||
|
|
||||||
|
def test_added_conf_dir_linking(self):
|
||||||
|
"""Ensure that links are correctly created for types in added conf directories"""
|
||||||
|
|
||||||
|
test_type="__cdist_test_type"
|
||||||
|
|
||||||
|
link_test_local = local.Local(
|
||||||
|
target_host='localhost',
|
||||||
|
out_path=self.out_path,
|
||||||
|
exec_path=test.cdist_exec_path,
|
||||||
|
add_conf_dirs=[conf_dir]
|
||||||
|
)
|
||||||
|
|
||||||
|
link_test_local._create_conf_path_and_link_conf_dirs()
|
||||||
|
|
||||||
|
our_type_dir = os.path.join(link_test_local.type_path, test_type)
|
||||||
|
|
||||||
|
self.assertTrue(os.path.isdir(our_type_dir))
|
||||||
|
|
||||||
|
### other tests
|
||||||
|
|
||||||
def test_run_success(self):
|
def test_run_success(self):
|
||||||
self.local.run(['/bin/true'])
|
self.local.run(['/bin/true'])
|
||||||
|
@ -98,7 +140,7 @@ class LocalTestCase(test.CdistTestCase):
|
||||||
handle, script = self.mkstemp(dir=self.temp_dir)
|
handle, script = self.mkstemp(dir=self.temp_dir)
|
||||||
with os.fdopen(handle, "w") as fd:
|
with os.fdopen(handle, "w") as fd:
|
||||||
fd.writelines(["#!/bin/sh\n", "/bin/false"])
|
fd.writelines(["#!/bin/sh\n", "/bin/false"])
|
||||||
self.assertRaises(local.LocalScriptError, self.local.run_script, script)
|
self.assertRaises(cdist.Error, self.local.run_script, script)
|
||||||
|
|
||||||
def test_run_script_get_output(self):
|
def test_run_script_get_output(self):
|
||||||
handle, script = self.mkstemp(dir=self.temp_dir)
|
handle, script = self.mkstemp(dir=self.temp_dir)
|
||||||
|
@ -117,7 +159,8 @@ class LocalTestCase(test.CdistTestCase):
|
||||||
self.local.rmdir(temp_dir)
|
self.local.rmdir(temp_dir)
|
||||||
self.assertFalse(os.path.isdir(temp_dir))
|
self.assertFalse(os.path.isdir(temp_dir))
|
||||||
|
|
||||||
def test_create_directories(self):
|
def test_create_files_dirs(self):
|
||||||
self.local.create_directories()
|
self.local.create_files_dirs()
|
||||||
self.assertTrue(os.path.isdir(self.local.out_path))
|
self.assertTrue(os.path.isdir(self.local.out_path))
|
||||||
self.assertTrue(os.path.isdir(self.local.bin_path))
|
self.assertTrue(os.path.isdir(self.local.bin_path))
|
||||||
|
self.assertTrue(os.path.isdir(self.local.conf_path))
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -23,7 +23,6 @@
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import getpass
|
import getpass
|
||||||
import logging
|
|
||||||
|
|
||||||
import cdist
|
import cdist
|
||||||
from cdist import core
|
from cdist import core
|
||||||
|
@ -35,35 +34,45 @@ from cdist.core import explorer
|
||||||
import os.path as op
|
import os.path as op
|
||||||
my_dir = op.abspath(op.dirname(__file__))
|
my_dir = op.abspath(op.dirname(__file__))
|
||||||
fixtures = op.join(my_dir, 'fixtures')
|
fixtures = op.join(my_dir, 'fixtures')
|
||||||
local_base_path = fixtures
|
conf_dir = op.join(fixtures, "conf")
|
||||||
|
|
||||||
class ExplorerClassTestCase(test.CdistTestCase):
|
class ExplorerClassTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.target_host = 'localhost'
|
self.target_host = 'localhost'
|
||||||
|
|
||||||
self.local_base_path = local_base_path
|
self.temp_dir = self.mkdtemp()
|
||||||
self.out_path = self.mkdtemp()
|
self.out_path = os.path.join(self.temp_dir, "out")
|
||||||
self.local = local.Local(self.target_host, self.local_base_path, self.out_path)
|
self.remote_base_path = os.path.join(self.temp_dir, "remote")
|
||||||
self.local.create_directories()
|
os.makedirs(self.remote_base_path)
|
||||||
|
|
||||||
self.remote_base_path = self.mkdtemp()
|
self.local = local.Local(
|
||||||
self.user = getpass.getuser()
|
target_host=self.target_host,
|
||||||
remote_exec = "ssh -o User=%s -q" % self.user
|
out_path=self.out_path,
|
||||||
remote_copy = "scp -o User=%s -q" % self.user
|
exec_path=test.cdist_exec_path,
|
||||||
self.remote = remote.Remote(self.target_host, self.remote_base_path, remote_exec, remote_copy)
|
add_conf_dirs=[conf_dir])
|
||||||
|
|
||||||
self.explorer = explorer.Explorer(self.target_host, self.local, self.remote)
|
self.local.create_files_dirs()
|
||||||
|
|
||||||
self.log = logging.getLogger(self.target_host)
|
self.remote = remote.Remote(
|
||||||
|
self.target_host,
|
||||||
|
self.remote_base_path,
|
||||||
|
self.remote_exec,
|
||||||
|
self.remote_copy)
|
||||||
|
self.remote.create_files_dirs()
|
||||||
|
|
||||||
|
self.explorer = explorer.Explorer(
|
||||||
|
self.target_host,
|
||||||
|
self.local,
|
||||||
|
self.remote)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.out_path)
|
shutil.rmtree(self.temp_dir)
|
||||||
shutil.rmtree(self.remote_base_path)
|
|
||||||
|
|
||||||
def test_list_global_explorer_names(self):
|
def test_list_global_explorer_names(self):
|
||||||
expected = ['foobar', 'global']
|
names = self.explorer.list_global_explorer_names()
|
||||||
self.assertEqual(self.explorer.list_global_explorer_names(), expected)
|
self.assertIn("foobar", names)
|
||||||
|
self.assertIn("global", names)
|
||||||
|
|
||||||
def test_transfer_global_explorers(self):
|
def test_transfer_global_explorers(self):
|
||||||
self.explorer.transfer_global_explorers()
|
self.explorer.transfer_global_explorers()
|
||||||
|
@ -72,14 +81,20 @@ class ExplorerClassTestCase(test.CdistTestCase):
|
||||||
self.assertEqual(sorted(os.listdir(source)), sorted(os.listdir(destination)))
|
self.assertEqual(sorted(os.listdir(source)), sorted(os.listdir(destination)))
|
||||||
|
|
||||||
def test_run_global_explorer(self):
|
def test_run_global_explorer(self):
|
||||||
|
"""Checkt that running ONE global explorer works"""
|
||||||
self.explorer.transfer_global_explorers()
|
self.explorer.transfer_global_explorers()
|
||||||
output = self.explorer.run_global_explorer('global')
|
output = self.explorer.run_global_explorer('global')
|
||||||
self.assertEqual(output, 'global\n')
|
self.assertEqual(output, 'global\n')
|
||||||
|
|
||||||
def test_run_global_explorers(self):
|
def test_run_global_explorers(self):
|
||||||
|
"""Ensure output is created for every global explorer"""
|
||||||
out_path = self.mkdtemp()
|
out_path = self.mkdtemp()
|
||||||
|
|
||||||
self.explorer.run_global_explorers(out_path)
|
self.explorer.run_global_explorers(out_path)
|
||||||
self.assertEqual(sorted(os.listdir(out_path)), sorted(['foobar', 'global']))
|
names = sorted(self.explorer.list_global_explorer_names())
|
||||||
|
output = sorted(os.listdir(out_path))
|
||||||
|
|
||||||
|
self.assertEqual(names, output)
|
||||||
shutil.rmtree(out_path)
|
shutil.rmtree(out_path)
|
||||||
|
|
||||||
def test_list_type_explorer_names(self):
|
def test_list_type_explorer_names(self):
|
||||||
|
|
1
cdist/test/fixtures/remote
vendored
Symbolic link
1
cdist/test/fixtures/remote
vendored
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../../other/examples/remote/local
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -37,8 +38,7 @@ from cdist.core import manifest
|
||||||
import os.path as op
|
import os.path as op
|
||||||
my_dir = op.abspath(op.dirname(__file__))
|
my_dir = op.abspath(op.dirname(__file__))
|
||||||
fixtures = op.join(my_dir, 'fixtures')
|
fixtures = op.join(my_dir, 'fixtures')
|
||||||
local_base_path = fixtures
|
conf_dir = op.join(fixtures, 'conf')
|
||||||
|
|
||||||
|
|
||||||
class ManifestTestCase(test.CdistTestCase):
|
class ManifestTestCase(test.CdistTestCase):
|
||||||
|
|
||||||
|
@ -48,9 +48,13 @@ class ManifestTestCase(test.CdistTestCase):
|
||||||
self.temp_dir = self.mkdtemp()
|
self.temp_dir = self.mkdtemp()
|
||||||
self.target_host = 'localhost'
|
self.target_host = 'localhost'
|
||||||
out_path = self.temp_dir
|
out_path = self.temp_dir
|
||||||
self.local = local.Local(self.target_host, local_base_path, out_path)
|
self.local = local.Local(
|
||||||
self.local.create_directories()
|
target_host=self.target_host,
|
||||||
self.local.link_emulator(cdist.test.cdist_exec_path)
|
out_path=out_path,
|
||||||
|
exec_path = cdist.test.cdist_exec_path,
|
||||||
|
add_conf_dirs=[conf_dir])
|
||||||
|
self.local.create_files_dirs()
|
||||||
|
|
||||||
self.manifest = manifest.Manifest(self.target_host, self.local)
|
self.manifest = manifest.Manifest(self.target_host, self.local)
|
||||||
self.log = logging.getLogger(self.target_host)
|
self.log = logging.getLogger(self.target_host)
|
||||||
|
|
||||||
|
@ -103,6 +107,8 @@ class ManifestTestCase(test.CdistTestCase):
|
||||||
self.assertEqual(output_dict['__object_name'], cdist_object.name)
|
self.assertEqual(output_dict['__object_name'], cdist_object.name)
|
||||||
|
|
||||||
def test_debug_env_setup(self):
|
def test_debug_env_setup(self):
|
||||||
|
current_level = self.log.getEffectiveLevel()
|
||||||
self.log.setLevel(logging.DEBUG)
|
self.log.setLevel(logging.DEBUG)
|
||||||
manifest = cdist.core.manifest.Manifest(self.target_host, self.local)
|
manifest = cdist.core.manifest.Manifest(self.target_host, self.local)
|
||||||
self.assertTrue("__cdist_debug" in manifest.env)
|
self.assertTrue("__cdist_debug" in manifest.env)
|
||||||
|
self.log.setLevel(current_level)
|
||||||
|
|
|
@ -4,6 +4,30 @@ Changelog
|
||||||
* Changes are always commented with their author in (braces)
|
* Changes are always commented with their author in (braces)
|
||||||
* Exception: No braces means author == Nico Schottelius
|
* Exception: No braces means author == Nico Schottelius
|
||||||
|
|
||||||
|
2.1.0pre8:
|
||||||
|
* Type cleanup: __apt_ppa, __apt_ppa_update_index, __file,
|
||||||
|
__ssh_authorized_key, __timezone, all install types (Steven Armstrong)
|
||||||
|
* Types: Remove all parameter changing code
|
||||||
|
* Type __rvm_ruby: Change parameter "default" to be boolean
|
||||||
|
|
||||||
|
2.1.0pre7: 2012-11-07
|
||||||
|
* Core: All unit tests restored back to working
|
||||||
|
* Core: Print error message on missing initial manifest
|
||||||
|
|
||||||
|
2.1.0pre6: 2012-11-05
|
||||||
|
* New Example: Turn remote calls into local calls (used for unittesting)
|
||||||
|
* Core: Export PYTHONPATH, it's also needed by emulator
|
||||||
|
* Bugfix Type __rvm_ruby: Add clean package dependencies
|
||||||
|
* Bugfix Type __rvm_gem: Run rvm as user, not as root
|
||||||
|
* Cleanup Type __rvm, __rvm_gemset: Use shortcut version
|
||||||
|
* Bugfix __rvm_gemset: Correctly check for gemsets
|
||||||
|
* Cleanup Type __postgres_database, __postgres_role: Reference each other
|
||||||
|
in documentation
|
||||||
|
* Cleanp Type __postgres_role: Use boolean parameters where appropriate
|
||||||
|
* Cleanp Type __postgres_role: Use shortcut version
|
||||||
|
|
||||||
|
2.1.0pre5: 2012-11-01
|
||||||
|
* Core: First round of tests updated to work with multiple configuration directories
|
||||||
|
|
||||||
2.1.0pre4: 2012-10-31
|
2.1.0pre4: 2012-10-31
|
||||||
* Dist: PyPi: Moved cdist.py to script/cdist to avoid double import
|
* Dist: PyPi: Moved cdist.py to script/cdist to avoid double import
|
||||||
|
@ -27,7 +51,7 @@ Changelog
|
||||||
Parameter state accepts only "present" and "absent"
|
Parameter state accepts only "present" and "absent"
|
||||||
* Dist: Initial support for pypi packaging
|
* Dist: Initial support for pypi packaging
|
||||||
|
|
||||||
2.0.15:
|
2.0.15: 2012-11-02
|
||||||
* Core: Make variable __object_name available in type explorers (Steven Armtrong)
|
* Core: Make variable __object_name available in type explorers (Steven Armtrong)
|
||||||
* New Type: __qemu_img
|
* New Type: __qemu_img
|
||||||
* New Type: __line
|
* New Type: __line
|
||||||
|
|
5
docs/dev/logs/2012-05-23.urls
Normal file
5
docs/dev/logs/2012-05-23.urls
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
http://nu-ex.com/cv.html
|
||||||
|
|
||||||
|
https://lists.metalab.at/pipermail/devops/2012-January/000089.html
|
||||||
|
|
||||||
|
http://www.ir0nik.com/wordpress/?p=121
|
47
docs/dev/logs/2012-11-02.migration_to_2.1
Normal file
47
docs/dev/logs/2012-11-02.migration_to_2.1
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
create a new branch to ensure nothing breaks
|
||||||
|
|
||||||
|
% git checkout -b 2.1_merge
|
||||||
|
|
||||||
|
fetch latest upstream changes (change origin if you use another
|
||||||
|
remote name for upstream cdist)
|
||||||
|
|
||||||
|
% git fetch -v origin
|
||||||
|
|
||||||
|
Now try to merge upstream into the new branch.
|
||||||
|
|
||||||
|
|
||||||
|
% git merge origin/2.1
|
||||||
|
|
||||||
|
fix any conflicts that may have been occurred due to local changes
|
||||||
|
and then **git add** and *git commit** those changes.
|
||||||
|
|
||||||
|
As the types have a new location, **cdist/conf/** now, you have to move
|
||||||
|
your own types there as well:
|
||||||
|
|
||||||
|
% git mv conf/type/* cdist/conf/
|
||||||
|
|
||||||
|
The manifest location also changed, so move this one as well:
|
||||||
|
|
||||||
|
% git mv conf/manifest/* cdist/conf/manifest/
|
||||||
|
|
||||||
|
Use **git status** to review the changes and ensure they
|
||||||
|
are in the git database:
|
||||||
|
|
||||||
|
% git commit -m "Move types and manifests for 2.1 migration"
|
||||||
|
|
||||||
|
This should be everything necessary for a 2.1 migration. Test the result
|
||||||
|
by running cdist on one of your staging hosts:
|
||||||
|
|
||||||
|
% ./bin/cdist config -v staging-host
|
||||||
|
|
||||||
|
|
||||||
|
You can now cleanup the empty conf/ directory:
|
||||||
|
|
||||||
|
% rmdir conf/* && rmdir conf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Boolean parameter introduced:
|
||||||
|
__directory /path/to --parents yes => __directory /path/to --parents
|
|
@ -77,7 +77,7 @@ git clone git://git.schottelius.org/cdist
|
||||||
|
|
||||||
# Create manifest (maps configuration to host(s)
|
# Create manifest (maps configuration to host(s)
|
||||||
cd cdist
|
cd cdist
|
||||||
echo '__file /etc/cdist-configured' > conf/manifest/init
|
echo '__file /etc/cdist-configured' > cdist/conf/manifest/init
|
||||||
|
|
||||||
# Configure localhost in verbose mode
|
# Configure localhost in verbose mode
|
||||||
./bin/cdist config -v localhost
|
./bin/cdist config -v localhost
|
||||||
|
|
1
other/archived_types/.README.unmaintained
Normal file
1
other/archived_types/.README.unmaintained
Normal file
|
@ -0,0 +1 @@
|
||||||
|
This type is not maintained by anymore and has thus been removed from cdist.
|
3
other/archived_types/README
Normal file
3
other/archived_types/README
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
This directory contains types that used to be included with
|
||||||
|
cdist, but are not in use anymore. Have a look at the README
|
||||||
|
file in each type, to find out why it was removed.
|
1
other/archived_types/__autofs/README
Symbolic link
1
other/archived_types/__autofs/README
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../.README.unmaintained
|
|
@ -1,21 +1,21 @@
|
||||||
cdist-type__partition_msdos_apply(7)
|
cdist-type__autofs(7)
|
||||||
====================================
|
=====================
|
||||||
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
Steven Armstrong <steven-cdist--@--armstrong.cc>
|
||||||
|
|
||||||
|
|
||||||
NAME
|
NAME
|
||||||
----
|
----
|
||||||
cdist-type__partition_msdos_apply - Apply dos partition settings
|
cdist-type__autofs - install and start autofs
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
Create the partitions defined with __partition_msdos
|
This space intentionally left blank.
|
||||||
|
|
||||||
|
|
||||||
REQUIRED PARAMETERS
|
REQUIRED PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
None
|
None.
|
||||||
|
|
||||||
|
|
||||||
OPTIONAL PARAMETERS
|
OPTIONAL PARAMETERS
|
||||||
|
@ -27,16 +27,16 @@ EXAMPLES
|
||||||
--------
|
--------
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
__partition_msdos_apply
|
__autofs
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
- cdist-type(7)
|
- cdist-type(7)
|
||||||
- cdist-type__partition_msdos_apply(7)
|
|
||||||
|
|
||||||
COPYING
|
COPYING
|
||||||
-------
|
-------
|
||||||
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
|
Copyright \(C) 2012 Steven Armstrong. Free use of this software is
|
||||||
granted under the terms of the GNU General Public License version 3 (GPLv3).
|
granted under the terms of the GNU General Public License version 3 (GPLv3).
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
|
# 2012 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -18,14 +19,16 @@
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
# set defaults
|
|
||||||
if [ -f "$__object/parameter/device" ]; then
|
|
||||||
device="(cat "$__object/parameter/device")"
|
|
||||||
else
|
|
||||||
device="/$__object_id"
|
|
||||||
echo "$device" > "$__object/parameter/device"
|
|
||||||
fi
|
|
||||||
|
|
||||||
type="(cat "$__object/parameter/type")"
|
os=$(cat "$__global/explorer/os")
|
||||||
|
|
||||||
options="(cat "$__object/parameter/options")"
|
case "$os" in
|
||||||
|
ubuntu|debian|archlinux)
|
||||||
|
__package autofs --state present
|
||||||
|
__start_on_boot autofs --state present
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unsupported OS: $os" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
1
other/archived_types/__autofs_map/README
Symbolic link
1
other/archived_types/__autofs_map/README
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../.README.unmaintained
|
50
other/archived_types/__autofs_map/explorer/entry
Executable file
50
other/archived_types/__autofs_map/explorer/entry
Executable file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# 2011 - 2012 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
|
#
|
||||||
|
# This file is part of cdist.
|
||||||
|
#
|
||||||
|
# cdist is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# cdist is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
candidates="/etc/auto.master /etc/autofs/auto.master"
|
||||||
|
find_auto_master() {
|
||||||
|
# get the path of the auto.master file
|
||||||
|
for candidate in $candidates; do
|
||||||
|
if [ -f "$candidate" ]; then
|
||||||
|
echo "$candidate"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
auto_master="$(find_auto_master)"
|
||||||
|
|
||||||
|
# no auto.master, nothing we could do
|
||||||
|
[ -f "$auto_master" ] || exit 0
|
||||||
|
|
||||||
|
# NOTE: keep variables in sync in manifest/explorer/gencode-*
|
||||||
|
prefix="#cdist:$__object_name"
|
||||||
|
suffix="#/cdist:$__object_name"
|
||||||
|
awk -v prefix="$prefix" -v suffix="$suffix" '{
|
||||||
|
if (index($0,prefix)) {
|
||||||
|
triggered=1
|
||||||
|
}
|
||||||
|
if (triggered) {
|
||||||
|
if (index($0,suffix)) {
|
||||||
|
triggered=0
|
||||||
|
}
|
||||||
|
print
|
||||||
|
}
|
||||||
|
}' "$auto_master"
|
93
other/archived_types/__autofs_map/gencode-remote
Executable file
93
other/archived_types/__autofs_map/gencode-remote
Executable file
|
@ -0,0 +1,93 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# 2011 - 2012 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
|
#
|
||||||
|
# This file is part of cdist.
|
||||||
|
#
|
||||||
|
# cdist is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# cdist is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
entry="$__object/files/entry"
|
||||||
|
state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo present)"
|
||||||
|
if [ ! -s "$__object/explorer/entry" ]; then
|
||||||
|
state_is='absent'
|
||||||
|
else
|
||||||
|
state_is=$(diff -q "$entry" "$__object/explorer/entry" >/dev/null \
|
||||||
|
&& echo present \
|
||||||
|
|| echo changed
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$state_should" = "$state_is" ]; then
|
||||||
|
# Nothing to do, move along
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat << DONE
|
||||||
|
candidates="/etc/auto.master /etc/autofs/auto.master"
|
||||||
|
find_auto_master() {
|
||||||
|
# get the path of the auto.master file
|
||||||
|
for candidate in \$candidates; do
|
||||||
|
if [ -f "\$candidate" ]; then
|
||||||
|
echo "\$candidate"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
auto_master="\$(find_auto_master)"
|
||||||
|
|
||||||
|
if [ ! -f "\$auto_master" ]; then
|
||||||
|
echo "Could not determine auto.master location, tried: \$candidates" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
DONE
|
||||||
|
|
||||||
|
remove_entry() {
|
||||||
|
# NOTE: keep variables in sync in manifest/explorer/gencode-*
|
||||||
|
prefix="#cdist:$__object_name"
|
||||||
|
suffix="#/cdist:$__object_name"
|
||||||
|
cat << DONE
|
||||||
|
awk -v prefix="$prefix" -v suffix="$suffix" '
|
||||||
|
{
|
||||||
|
if (index(\$0,prefix)) {
|
||||||
|
triggered=1
|
||||||
|
}
|
||||||
|
if (triggered) {
|
||||||
|
if (index(\$0,suffix)) {
|
||||||
|
triggered=0
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print
|
||||||
|
}
|
||||||
|
}' "\$auto_master" > "\$auto_master"+
|
||||||
|
mv -f "\$auto_master"+ "\$auto_master"
|
||||||
|
DONE
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$state_should" in
|
||||||
|
present)
|
||||||
|
if [ "$state_is" = "changed" ]; then
|
||||||
|
remove_entry
|
||||||
|
fi
|
||||||
|
cat << DONE
|
||||||
|
cat >> "\$auto_master" << EOC
|
||||||
|
$(cat "$entry")
|
||||||
|
EOC
|
||||||
|
DONE
|
||||||
|
;;
|
||||||
|
absent)
|
||||||
|
remove_entry
|
||||||
|
;;
|
||||||
|
esac
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue