Merge branch '__cron' of https://github.com/asteven/cdist into ssh_callback

This commit is contained in:
Nico Schottelius 2013-05-10 13:02:53 +02:00
commit 516244c7cb
4 changed files with 18 additions and 27 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# 2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc)
# #
# This file is part of cdist. # This file is part of cdist.
# #

View File

@ -18,38 +18,29 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>. # along with cdist. If not, see <http://www.gnu.org/licenses/>.
# #
os="$(cat "$__global/explorer/os")"
user="$(cat "$__object/parameter/user")" user="$(cat "$__object/parameter/user")"
state_should="$(cat "$__object/parameter/state")" state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")"
state_is=$(diff -q "$__object/parameter/entry" "$__object/explorer/entry" \ state_is=$(diff -q "$__object/parameter/entry" "$__object/explorer/entry" \
&& echo present \ && echo present \
|| echo absent || echo absent
) )
# FreeBSD mktemp doesn't allow execution without at least one param
if [ "$os" = "freebsd" ]; then
mktemp="mktemp -t tmp"
else
mktemp="mktemp"
fi
if [ "$state_is" != "$state_should" ]; then if [ "$state_is" != "$state_should" ]; then
case "$state_should" in case "$state_should" in
present) present)
cat << DONE cat << DONE
tmp=\$($mktemp) (
crontab -u $user -l > \$tmp || true crontab -u $user -l || true
cat >> \$tmp << EOC cat << EOC
$(cat "$__object/parameter/entry") $(cat "$__object/parameter/entry")
EOC EOC
crontab -u $user \$tmp ) | crontab -u $user -
rm \$tmp
DONE DONE
;; ;;
absent) absent)
# defined in type manifest # NOTE: keep variables in sync in manifest/explorer/gencode-*
prefix="$(cat "$__object/parameter/prefix")" prefix="#cdist:__cron/$name"
suffix="$(cat "$__object/parameter/suffix")" suffix="#/cdist:__cron/$name"
cat << DONE cat << DONE
crontab -u $user -l | awk -v prefix="$prefix" -v suffix="$suffix" ' crontab -u $user -l | awk -v prefix="$prefix" -v suffix="$suffix" '
{ {

View File

@ -68,5 +68,5 @@ SEE ALSO
COPYING COPYING
------- -------
Copyright \(C) 2011 Steven Armstrong. Free use of this software is Copyright \(C) 2011-2013 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3). granted under the terms of the GNU General Public License version 3 (GPLv3).

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# 2011 Steven Armstrong (steven-cdist at armstrong.cc) # 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -21,9 +21,7 @@
name="$__object_id" name="$__object_id"
user="$(cat "$__object/parameter/user")" user="$(cat "$__object/parameter/user")"
command="$(cat "$__object/parameter/command")" command="$(cat "$__object/parameter/command")"
state="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")"
# set defaults
test -f "$__object/parameter/state" || echo "present" > "$__object/parameter/state"
if [ -f "$__object/parameter/raw" ]; then if [ -f "$__object/parameter/raw" ]; then
raw="$(cat "$__object/parameter/raw")" raw="$(cat "$__object/parameter/raw")"
@ -37,9 +35,11 @@ else
entry="$minute $hour $day_of_month $month $day_of_week $command" entry="$minute $hour $day_of_month $month $day_of_week $command"
fi fi
# NOTE: if changed, also change in explorers # NOTE: keep variables in sync in manifest/explorer/gencode-*
prefix="#cdist:__cron/$name" prefix="#cdist:__cron/$name"
suffix="#/cdist:__cron/$name" suffix="#/cdist:__cron/$name"
echo "$prefix" | tee "$__object/parameter/prefix" > "$__object/parameter/entry" cat >> "$__object/parameter/entry" << DONE
echo "$entry" >> "$__object/parameter/entry" "$prefix"
echo "$suffix" | tee "$__object/parameter/suffix" >> "$__object/parameter/entry" "$entry"
"$suffix"
DONE