declare -r NAME="$(basename "${0}")"
declare install="rsync -au --force"
+
case "$@" in *-h*|*-help*) exec echo "Usage: $NAME [-v] [-n]";; esac
case "$@" in *-v*) install="$install -v";; esac
case "$@" in *-n*) install="$install -n";; esac
printf '> %s\n' "$@"
}
+function crond2tab() {
+ local src="$1"
+}
+
#
# Cron
#
if [ -d /etc/cron.d ]; then
- verbose "Install /etc/cron.d/nb"
- $install "$NB_ROOT/etc/cron/nb" /etc/cron.d/nb
+ if [ -n "$(diff -q $NB_ROOT/etc/cron/nb /etc/cron.d/nb)" ]; then
+ verbose "Install /etc/cron.d/nb"
+ $install "$NB_ROOT/etc/cron/nb" /etc/cron.d/nb
+ fi
+
+else
+
+ crontab -l > /tmp/nb-crontab.orig
+ (
+ crontab -l | grep -v nb-update
+ # Delete user
+ perl -ane '/^PATH/ and print; /^[\*\d]/ or next; print join(" ",@F[0..4,6..$#F])."\n"' $NB_ROOT/etc/cron/nb
+ ) > /tmp/nb-crontab.new
+
+ if [ -n "$(diff -q /tmp/nb-crontab.orig /tmp/nb-crontab.new)" ]; then
+ verbose "Install /etc/cron.d/nb"
+ crontab /tmp/nb-crontab.new
+ fi
+ rm -f /tmp/nb-crontab.*
+
fi
#