X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=crontab.d%2Fupdate.sh;h=2b174c165a5437040044ff544b9034620e336dbd;hb=3742d8b34552762cc3627dde22975b5c94d33b22;hp=173142ec214db7ddb29eed6ec690704ced1a97ed;hpb=556fcce13fb08df53b84f2878fdff27464aacf6b;p=config%2Fdotfiles.git diff --git a/crontab.d/update.sh b/crontab.d/update.sh index 173142e..2b174c1 100755 --- a/crontab.d/update.sh +++ b/crontab.d/update.sh @@ -29,10 +29,10 @@ HEADER_WARNING="# WARNING! DO NOT EDIT THIS FILE! #" # Don't overwrite existing crontab entries. Not race condition free but that # can't be helped. if crontab -l >/dev/null 2>&1; then - if crontab -l | head -n3 | grep "^$HEADER_WARNING$" >/dev/null; then + if crontab -l | head -n3 | grep -F -x "$HEADER_WARNING" >/dev/null; then : else - echo "Existing crontab entry found, please remove it manually." + echo 'Existing crontab entry found, please remove it manually.' exit 2 fi fi @@ -46,11 +46,12 @@ fi # `set -e` aborts when `mktemp` fails. CRONTAB=`mktemp --tmpdir="$DIRECTORY" update-crontab.XXXXXXXXXXXX` -echo "###################################" > "$CRONTAB" -echo "$HEADER_WARNING" >> "$CRONTAB" -echo "###################################" >> "$CRONTAB" -echo >> "$CRONTAB" -echo "# It was generated from '$DIRECTORY/*' on `date -R`." >> "$CRONTAB" +echo '###################################' >"$CRONTAB" +echo "$HEADER_WARNING" >>"$CRONTAB" +echo '###################################' >>"$CRONTAB" +echo >>"$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 @@ -63,23 +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" \ + <"$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" + >>"$CRONTAB" done # Update crontab with the crontab.* files.