From d72afd390377890fa1a1ec10c212275c162838cb Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Fri, 10 May 2013 12:35:22 +0200 Subject: [PATCH] dont change parameters; dont use tmpfile; update copyright Signed-off-by: Steven Armstrong --- cdist/conf/type/__cron/explorer/entry | 2 +- cdist/conf/type/__cron/gencode-remote | 25 ++++++++----------------- cdist/conf/type/__cron/man.text | 2 +- cdist/conf/type/__cron/manifest | 16 ++++++++-------- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/cdist/conf/type/__cron/explorer/entry b/cdist/conf/type/__cron/explorer/entry index 1b4bec42..9b52d6e4 100755 --- a/cdist/conf/type/__cron/explorer/entry +++ b/cdist/conf/type/__cron/explorer/entry @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # diff --git a/cdist/conf/type/__cron/gencode-remote b/cdist/conf/type/__cron/gencode-remote index fac0170f..af06edb3 100755 --- a/cdist/conf/type/__cron/gencode-remote +++ b/cdist/conf/type/__cron/gencode-remote @@ -18,38 +18,29 @@ # along with cdist. If not, see . # -os="$(cat "$__global/explorer/os")" 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" \ && echo present \ || 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 case "$state_should" in present) cat << DONE -tmp=\$($mktemp) -crontab -u $user -l > \$tmp || true -cat >> \$tmp << EOC +( +crontab -u $user -l || true +cat << EOC $(cat "$__object/parameter/entry") EOC -crontab -u $user \$tmp -rm \$tmp +) | crontab -u $user - DONE ;; absent) - # defined in type manifest - prefix="$(cat "$__object/parameter/prefix")" - suffix="$(cat "$__object/parameter/suffix")" + # NOTE: keep variables in sync in manifest/explorer/gencode-* + prefix="#cdist:__cron/$name" + suffix="#/cdist:__cron/$name" cat << DONE crontab -u $user -l | awk -v prefix="$prefix" -v suffix="$suffix" ' { diff --git a/cdist/conf/type/__cron/man.text b/cdist/conf/type/__cron/man.text index 47f47456..22627234 100644 --- a/cdist/conf/type/__cron/man.text +++ b/cdist/conf/type/__cron/man.text @@ -68,5 +68,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2011 Steven Armstrong. Free use of this software is +Copyright \(C) 2011-2013 Steven Armstrong. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__cron/manifest b/cdist/conf/type/__cron/manifest index 7aca41ff..71910bf5 100755 --- a/cdist/conf/type/__cron/manifest +++ b/cdist/conf/type/__cron/manifest @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Steven Armstrong (steven-cdist at armstrong.cc) +# 2011-2013 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -21,9 +21,7 @@ name="$__object_id" user="$(cat "$__object/parameter/user")" command="$(cat "$__object/parameter/command")" - -# set defaults -test -f "$__object/parameter/state" || echo "present" > "$__object/parameter/state" +state="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")" if [ -f "$__object/parameter/raw" ]; then raw="$(cat "$__object/parameter/raw")" @@ -37,9 +35,11 @@ else entry="$minute $hour $day_of_month $month $day_of_week $command" fi -# NOTE: if changed, also change in explorers +# NOTE: keep variables in sync in manifest/explorer/gencode-* prefix="#cdist:__cron/$name" suffix="#/cdist:__cron/$name" -echo "$prefix" | tee "$__object/parameter/prefix" > "$__object/parameter/entry" -echo "$entry" >> "$__object/parameter/entry" -echo "$suffix" | tee "$__object/parameter/suffix" >> "$__object/parameter/entry" +cat >> "$__object/parameter/entry" << DONE +"$prefix" +"$entry" +"$suffix" +DONE