]> ruderich.org/simon Gitweb - config/dotfiles.git/blobdiff - crontab.d/update.sh
Don't use echo for data from the user.
[config/dotfiles.git] / crontab.d / update.sh
index ca08be1c080a5b18112fed33f602a6f6cd220280..72422fc90390e3c767eddfacd5fc676045eae484 100755 (executable)
@@ -50,8 +50,11 @@ echo "###################################"  > "$CRONTAB"
 echo "$HEADER_WARNING"                     >> "$CRONTAB"
 echo "###################################" >> "$CRONTAB"
 echo >> "$CRONTAB"
-echo "# It was generated from '$DIRECTORY/*' on `date -R`." >> "$CRONTAB"
+printf "# It was generated from '%s/*' on %s." \
+    "$DIRECTORY" "`LANG=C date '+%a, %d %b %Y %H:%M:%S %z'`" >>"$CRONTAB"
 
+# Enforce C sort order.
+LC_ALL=C
 
 NO_MATCHES=
 for file in "$DIRECTORY"/crontab.*; do
@@ -61,18 +64,20 @@ for file in "$DIRECTORY"/crontab.*; do
         break
     fi
 
-    echo "Found '$file'."
+    printf "Found '%s'.\n" "$file"
 
-    echo             >> "$CRONTAB"
-    echo             >> "$CRONTAB"
-    echo "## $file:" >> "$CRONTAB"
+    printf '\n\n## %s:\n' "$file" >>"$CRONTAB"
 
+    # Strip licenses, multiple empty lines and fix $HOME variables in PATH
+    # (cron doesn't expand variables).
     START_REGEX='^# This [a-zA-Z]* is free software: you can redistribute it'
     END_REGEX='^# along with this [a-zA-Z]*.  If not, see <[^>]*>\.'
     < "$file" sed -e "/$START_REGEX/,/$END_REGEX/ d" \
                   -e "/^#[ ]*$/ d" \
                   -e "/^# Copyright (C) [0-9][0-9]* / d" \
         | cat --squeeze-blank \
+        | sed "/^PATH/ s:\$HOME:$HOME:g" \
+        | sed 's/RAND_SLEEP \([0-9]*\)/sleep `perl -e "srand; print int rand \1;"`/' \
         >> "$CRONTAB"
 done