From 0416d89d9e2eed3b57df54b48269717a7ecdaf10 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 7 Jul 2015 01:24:27 +0100 Subject: [PATCH] nb-update, profile.d --- bin/nb-install | 3 +-- bin/nb-update | 17 +++++++++++++---- etc/bashrc.function | 12 ++++++------ etc/profile | 2 +- lib/php/cache.php | 1 + lib/php/test.php | 12 ++++++++---- 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/bin/nb-install b/bin/nb-install index c8bf12f1..1efe8fe7 100755 --- a/bin/nb-install +++ b/bin/nb-install @@ -46,9 +46,8 @@ else crontab -l > $TMP.crontab.orig.orig ( # Delete user - 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)' + perl -ane '/^(NB_LOG|SHELL|PATH)/ and print; /^[\*\d]/ or next; print join(" ",@F[0..4,6..$#F])."\n"' $NB_ROOT/etc/cron/nb ) > $TMP.crontab.orig.new if fdiff $TMP.crontab.orig.orig $TMP.crontab.orig.new; then diff --git a/bin/nb-update b/bin/nb-update index 4a9dc3b8..144f3edc 100755 --- a/bin/nb-update +++ b/bin/nb-update @@ -15,15 +15,21 @@ for repo in \ $NB_ROOT \ /opt/backup_servers \ /{opt,home/www}/rent \ - /etc/puppet \ + root:/etc/puppet \ /etc/puppet/data \ /etc/puppet/modules \ /home/www/izideal \ ; do + + case "$repo" in + *:*) user=${repo%%:*}; repo=${repo#*:} ;; + *) user="" ;; + esac + [ -d "$repo/.git" ] || continue cd "$repo" || continue - user=`ls -dl "$repo" |awk '{print $3}'` + [ -z "$user" ] && user=`ls -dl "$repo" |awk '{print $3}'` echo ">git pull $repo (user=$user)" if [ "$USER" == "$user" ]; then @@ -31,8 +37,11 @@ for repo in \ else su $user -c "cd \"$repo\" && git pull" fi + ret=$? - [ "$ret" != "0" ] && ex=$ret + [ "$ret" != "0" ] && ex=$ret && echo ">err $ret" + + echo done @@ -45,5 +54,5 @@ nb-install ##################################################################### # End # -[ "$ex" == "0" ] && echo ">OK" +[ "$ex" == "0" ] && printf "\n>OK\n" exit $ex diff --git a/etc/bashrc.function b/etc/bashrc.function index 3f26d4c0..7ac86ac3 100644 --- a/etc/bashrc.function +++ b/etc/bashrc.function @@ -364,11 +364,12 @@ Choose one > \ # NB 06.07.15 } replace_tag_content() { - local tag="$1" content="$@" + declare tag="$1"; shift + declare content="$@" perl -ne 'BEGIN { -$tag = shift @ARGV; -$t1 = "# > $tag"; -$t2 = "# < $tag"; +$tag = shift(@ARGV)." - replace_tag_content"; +$t1 = "# >>> $tag"; +$t2 = "# <<< $tag"; $content = shift @ARGV; $content = "$t1\n$content\n$t2\n" } @@ -376,8 +377,7 @@ $content = "$t1\n$content\n$t2\n" if (/^$t1$/ .. /^$t2$/) { print "$content" and $content="" if /^$t1$/; } else { - #$_ = "OUT $_"; - print "OUT $_"; + print "$_"; } END { print "$content" if $content; } diff --git a/etc/profile b/etc/profile index 3883f93d..371345a0 100644 --- a/etc/profile +++ b/etc/profile @@ -2,7 +2,7 @@ [ -r "${BASH_SOURCE%/*}/bashrc" ] && . "${BASH_SOURCE%/*}/bashrc" [ -r "${BASH_SOURCE%/*}/aliases" ] && . "${BASH_SOURCE%/*}/aliases" -for i in $NB_ROOT/etc/*.sh; do +for i in ${BASH_SOURCE%/*}/profile.d/*.sh; do [ -r "$i" ] && . "$i" done unset i diff --git a/lib/php/cache.php b/lib/php/cache.php index 64a727b4..90f1bbaa 100644 --- a/lib/php/cache.php +++ b/lib/php/cache.php @@ -8,6 +8,7 @@ function cache_get_file($id,$expires) { if (!file_exists($file)) return null; $content = file_get_contents($file); + if ( filectime($file) < (time()-$expires) ) @unlink($file); return $content; diff --git a/lib/php/test.php b/lib/php/test.php index 68c0fb41..2fff54c0 100644 --- a/lib/php/test.php +++ b/lib/php/test.php @@ -18,21 +18,25 @@ exit; */ function _f1() { - $var = ''; is_null($var); + $_REQUEST['zaza'] === null; } benchmark('_f1'); function _f2() { - $var = ''; empty($var); + $_REQUEST['zaza'] == null; } benchmark('_f2'); function _f3() { - $var = ''; isset($var); + @$_REQUEST['zaza']; } benchmark('_f3'); function _f4() { - stripos('zaza', 'z') == ( strlen('zaza')-strlen('z') ); + isset($_REQUEST['zaza']); } benchmark('_f4'); +function _f5() { + !empty($_REQUEST['zaza']); +} benchmark('_f5'); + benchmark(); exit; -- 2.47.3