]> git.nbdom.net Git - nb.git/commitdiff
nb-update:cron
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 10 Mar 2015 23:23:30 +0000 (23:23 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 10 Mar 2015 23:23:30 +0000 (23:23 +0000)
bin/nb-install

index 363c35f52c0c2fc10c9aee89bd09e12e8e7d0cad..a95d2cc3a8e04081da75db564e50e93e3a037613 100755 (executable)
@@ -7,14 +7,14 @@
 . "${BASH_SOURCE%/*}/../etc/profile.sh" || exit
 declare -r NAME="$(basename "${0}")"
 declare TMP=/tmp/$NAME.$$
-declare install="rsync -au --force"
+declare INSTALL="rsync -au --force"
 
 #
 # Args
 #
 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
+case "$@" in *-v*) INSTALL="$INSTALL -v";; esac
+case "$@" in *-n*) INSTALL="$INSTALL -n";; esac
 
 #
 # Functions
@@ -23,10 +23,6 @@ function verbose() {
   printf '> %s\n' "$@"
 }
 
-function crond2tab() {
-  local src="$1"
-}
-
 function fdiff() {
   [ -e "$1" ] || return 0
   [ -e "$2" ] || return 0
@@ -41,16 +37,17 @@ if [ -d /etc/cron.d ]; then
 
   if fdiff "$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
+    $INSTALL "$NB_ROOT/etc/cron/nb" /etc/cron.d/nb
   fi
 
 else
 
   crontab -l > $TMP.crontab.orig.orig
   (
-    crontab -l | grep -vE 'nb-update|^PATH'
     # Delete user
-    perl -ane '/^PATH/ and print; /^[\*\d]/ or next; print join(" ",@F[0..4,6..$#F])."\n"' $NB_ROOT/etc/cron/nb
+    perl -ane '/^(NB_LOG|SHELL|PATH)/ and print; /^[\*\d]/ or next; print join(" ",@F[0..4,6..$#F])."\n"' $NB_ROOT/etc/cron/nb
+    #perl -ane '/^\s*(#|$)/ and next; print ( scalar(@F>7) ? $_ : join(" ",@F[0..4,6..$#F])."\n" ); BEGIN{print "#>NB\n"} ;END {print "#<NB\n"}' $src
+    crontab -l | grep -vE 'nb-update|^(PATH|NB_LOG|SHELL|#[<>]nb)'
   ) > $TMP.crontab.orig.new
 
   if fdiff $TMP.crontab.orig.orig $TMP.crontab.orig.new; then
@@ -68,7 +65,7 @@ if [ -d /etc/profile.d ]; then
 
   if fdiff $TMP.profile /etc/profile.d/nb-profile.sh; then
     verbose "Install /etc/profile.d/nb-profile.sh"
-    $install -c $TMP.profile /etc/profile.d/nb-profile.sh
+    $INSTALL -c $TMP.profile /etc/profile.d/nb-profile.sh
     chmod 755 /etc/profile.d/nb-profile.sh
   fi