]> git.nbdom.net Git - nb.git/commitdiff
cron for osx
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 18 Nov 2014 00:41:37 +0000 (00:41 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 18 Nov 2014 00:41:37 +0000 (00:41 +0000)
bin/nb-install

index 1fc3835734fdc1e9e240be6a3c2c5274c5b8ed8c..c3131d57b4add14adae9349ec4e72f2f79b1b772 100755 (executable)
@@ -3,6 +3,7 @@
 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
@@ -11,12 +12,34 @@ function verbose() {
   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
 
 #