From c0da6fcc897c38efe1514be65218200aaaeba87a Mon Sep 17 00:00:00 2001
From: Daniel Heule <hda@sfs.biz>
Date: Mon, 9 Dec 2013 09:44:40 +0100
Subject: [PATCH] =?UTF-8?q?Verbesserungen=20am=20=5F=5Fcron=20type=201.=20?=
 =?UTF-8?q?Filter=20messages=20from=20crontab=20-l=20welche=20das=20ganze?=
 =?UTF-8?q?=20file=20f=C3=BCllen=202.=20neuer=20parameter=20raw=5Fcommand,?=
 =?UTF-8?q?=20um=20globale=20variablen=20zu=20setzen=20...?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 cdist/conf/type/__cron/explorer/entry    | 0
 cdist/conf/type/__cron/gencode-remote    | 9 ++++++---
 cdist/conf/type/__cron/man.text          | 8 ++++++++
 cdist/conf/type/__cron/parameter/boolean | 1 +
 4 files changed, 15 insertions(+), 3 deletions(-)
 mode change 100755 => 100644 cdist/conf/type/__cron/explorer/entry
 mode change 100755 => 100644 cdist/conf/type/__cron/gencode-remote
 create mode 100644 cdist/conf/type/__cron/parameter/boolean

diff --git a/cdist/conf/type/__cron/explorer/entry b/cdist/conf/type/__cron/explorer/entry
old mode 100755
new mode 100644
diff --git a/cdist/conf/type/__cron/gencode-remote b/cdist/conf/type/__cron/gencode-remote
old mode 100755
new mode 100644
index c04a7245..6f1feb90
--- a/cdist/conf/type/__cron/gencode-remote
+++ b/cdist/conf/type/__cron/gencode-remote
@@ -26,6 +26,8 @@ command="$(cat "$__object/parameter/command")"
 if [ -f "$__object/parameter/raw" ]; then
    raw="$(cat "$__object/parameter/raw")"
    entry="$raw $command"
+elif [ -f "$__object/parameter/raw_command" ]; then
+   entry="$command"
 else
    minute="$(cat "$__object/parameter/minute" 2>/dev/null || echo "*")"
    hour="$(cat "$__object/parameter/hour" 2>/dev/null || echo "*")"
@@ -55,8 +57,9 @@ state_should="$(cat "$__object/parameter/state" 2>/dev/null || echo "present")"
 # These are the old markers
 prefix="#cdist:__cron/$__object_id"
 suffix="#/cdist:__cron/$__object_id"
+filter="^# DO NOT EDIT THIS FILE|^# \(.* installed on |^# \(Cron version V"
 cat << DONE
-crontab -u $user -l | awk -v prefix="$prefix" -v suffix="$suffix" '
+crontab -u $user -l | grep -v -E "$filter" | awk -v prefix="$prefix" -v suffix="$suffix" '
 {
    if (index(\$0,prefix)) {
       triggered=1
@@ -75,12 +78,12 @@ DONE
 case "$state_should" in
     present)
         echo "("
-        echo "crontab -u $user -l 2>/dev/null || true"
+        echo "crontab -u $user -l | grep -v -E "$filter" 2>/dev/null || true"
         echo "echo '$entry'"
         echo ") | crontab -u $user -"
     ;;
     absent)
-        echo "( crontab -u $user -l 2>/dev/null || true ) | \\"
+        echo "( crontab -u $user -l | grep -v -E "$filter" 2>/dev/null || true ) | \\"
         echo "grep -v \"# $name\\$\" | crontab -u $user -"
     ;;
 esac
diff --git a/cdist/conf/type/__cron/man.text b/cdist/conf/type/__cron/man.text
index 22627234..f4e80a08 100644
--- a/cdist/conf/type/__cron/man.text
+++ b/cdist/conf/type/__cron/man.text
@@ -41,6 +41,10 @@ raw::
    Can for example be used to specify cron EXTENSIONS like reboot, yearly etc.
    See crontab(5) for the extensions if any that your cron implementation
    implements.
+raw_command::
+   Take whatever the user has given in the commmand and ignore everything else.
+   If given, the command will be added to crontab.
+   Can for example be used to define variables like SHELL or MAILTO.
 
 
 EXAMPLES
@@ -57,6 +61,10 @@ __cron some-id --user root --command "/path/to/script" \
 
 # remove cronjob
 __cron some-id --user root --command "/path/to/script" --state absent
+
+# define default shell
+__cron some-id --user root --raw_command --command "SHELL=/bin/bash" \
+   --state present
 --------------------------------------------------------------------------------
 
 
diff --git a/cdist/conf/type/__cron/parameter/boolean b/cdist/conf/type/__cron/parameter/boolean
new file mode 100644
index 00000000..54cfb0b3
--- /dev/null
+++ b/cdist/conf/type/__cron/parameter/boolean
@@ -0,0 +1 @@
+raw_command