dont change parameters; dont use tmpfile; update copyright

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2013-05-10 12:35:22 +02:00
parent d8630dc6d4
commit d72afd3903
4 changed files with 18 additions and 27 deletions

View file

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

View file

@ -18,38 +18,29 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
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" '
{

View file

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

View file

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