]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 25 Aug 2016 23:57:05 +0000 (00:57 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 25 Aug 2016 23:57:05 +0000 (00:57 +0100)
bin/nb-repo-dirs
bin/nb-update
etc/profile
etc/profile.d/envs
etc/profile.d/functions

index cc13dbfce573b07cacbc68c42f915322021a8a9d..660f9fdb7de2763e4b7b4c614c480471aee5b85e 100755 (executable)
@@ -40,8 +40,8 @@ print
                #my $dir = /\/\Q$FILE_EXISTS\E$/ ? dirname($_) : $_;
                my $dir = !-d  $_ ? dirname($_) : $_;
 
-               if (-d $dir and -d "$dir/.git") {
-      warn "DEBUG: MISSING: $dir\n" if $debug and !-r "$dir/FILE_EXISTS";
+               if (-d "$dir/.git") {
+      warn "DEBUG: MISSING: $dir/$FILE_EXISTS\n" if $debug and !-r "$dir/$FILE_EXISTS";
       add_args($dir);
                        #$dir;
                } else {
@@ -54,14 +54,22 @@ print
 ;
 
 sub add_args {
-  # Concat each args (ex: $0 proie etc/profile ...)
+  # Concat each args and return existing (ex: $0 proie etc/profile ...)
   my @new;
-  foreach my $d (@_) {
-    foreach my $a (@ARGV) {
+
+  for my $d (@_) {
+       #for my $d (glob join(' ',@_)) {
+  #for my $d (map { glob $_ } @_) {
+      #warn ".. $d" if $debug;
+    for my $a (@ARGV) {
       #warn "$d/$a";
-      push @new, "$d/$a";
+      #warn ".. $d/$a" if $debug;
+      push @new, glob "$d/$a";
     }
   }
-  return @new if @new;
+
+  #warn @new;
+  @_ = grep { -e $_} @new if @new;
+  #return grep {-e $_} @_;
   return @_;
 }
index ba04e1c56a66fe355e7e214d7e7910b246e81891..870225f986c5131f9f9ca967a364fe7e70a2b03f 100755 (executable)
@@ -16,14 +16,32 @@ declare CLEANUP=0
 #####################################################################
 # Git Connection check
 #
+url2nc() {
+  perl -e '
+for (@ARGV) {
+@_ = m,://([^/:]+)(?::(\d+))?, and print join(" ",$_[0],$_[1] ? $_[1] : (/^https/?443:80))."\n", and next;
+@_ = m,^(?:[^@]+@)?([^:/]+):[^/].*?(?:\.git)?$, and print "$1 22\n" and next;
+@_ = m,([^@:/]+):[^/].*?(?:\.git)?$, and print "$1 22\n" and next;
+}
+' $@
+  return 0
+}
+#[ "$1" = "TEST" ] && url2nc nico@zaza.com:re.git && exit
+#[ "$1" = "TEST" ] && url2nc zaza.com:re.git && exit
+#[ "$1" = "TEST" ] && url2nc https://zaza.com/re.git && exit
 _git_conn_check=" "
 git_conn_check() {
-  local dest=$(git config --local --get remote.origin.url | sed -e 's/:.*$//' -e 's/^.*@//')
+  #local dest=$(git config --local --get remote.origin.url | sed -e 's/:.*$//' -e 's/^.*@//')
+  local dest=$(git config --local --get remote.origin.url)
+  local port=''
 
   if [ -z "$dest" ]; then
-    logger -t $NAME -s "Can't get \`git config --het remote.origin.url\` from `pwd`"
+    logger -t $NAME -s "Can't get url from \`git config --het remote.origin.url\` in `pwd`"
     return 1
   fi
+  #[ "$1" = "TEST" ] &&
+  dest=$(url2nc "$dest")
+  #dest="$dest 22"
 
   local ok
   case "$_git_conn_check" in
@@ -33,8 +51,9 @@ git_conn_check() {
       ok=0
       case "$dest" in
         *"@"*) timeout 5 ssh -o BatchMode=yes -o ConnectTimeout=5 $dest true && ok=1 ;;
-        *) nc -z -w 5 $dest 22 && ok=1 ;;
+        *) nc -z -w 5 $dest && ok=1 ;;
       esac
+#echo "$ok: git=$(git config --local --get remote.origin.url) | dest=$dest | url2nc="$(url2nc $(git config --local --get remote.origin.url))
       _git_conn_check="${_git_conn_check}$dest=$ok "
     ;;
   esac
@@ -77,13 +96,14 @@ for repo in $(nb-repo-dirs); do
   [ "$CLEANUP" = "1" ] && cmd="$cmd && git gc"
 
   if [ 1 = 1 ] && ! git_conn_check; then
-     [ 1 = 1 ]
+    echo
   elif [ "$USER" = "$user" ]; then
     bash -c "$cmd"
   elif [ "$USER" = "root" ]; then
     su $user -c "$cmd"
   else
-    echo "Ignore $repo: current user=$USER repo user=$user"
+    echo "Wrong user current user=$USER repo user=$user"
+    echo
     continue
   fi
   ret=$?
index 6c04a36f544a8014ae81505567bea22667fe20dc..fdf0d9a3c5a0e1be3a83d7ee7a0080ed97185193 100644 (file)
@@ -1,11 +1,17 @@
 #
 # Avoid infinit loop. Eg: profile -> .bashrc -> profile
 #
-[ -n "$NB_LOOP" ] && return; export NB_LOOP=1
-[ "$1" = "--debug" ] && NB_DEBUG='eval echo 1>&2 "$(basename $BASH_SOURCE): "' && shift
+#[ "$1" = "--debug" ] && NB_DEBUG='eval echo 1>&2 "$(basename $BASH_SOURCE): "' && shift
+[ "$1" = "--debug" ] && NB_DEBUG='echo NB_DEBUG:' && shift
+if [ -n "$NB_LOOP" ]; then
+  [ -n "$NB_DEBUG" ] && $NB_DEBUG "NB_LOOP=$NB_LOOP: BASH_SOURCE=$BASH_SOURCE \$0=$0"
+  NB_LOOP=$(($NB_LOOP+1))
+  return
+fi
+export NB_LOOP=1
 
 #
-# ROOT PATH
+# SEARCH ROOT
 #
 dir='.'
 case "$BASH_SOURCE" in
@@ -17,23 +23,26 @@ case "$BASH_SOURCE" in
     fi
   ;;
 esac
-[ -e "$dir/profile.d/functions" ] && source "$dir/profile.d/functions"
+
+[ -e "$dir/profile.d/functions" ] && . "$dir/profile.d/functions"
 NB_ROOT=$(realpath ${dir}/.. 2>/dev/null)
+
+#echo "$NB_ROOT: `pwd`"
 unset dir
 
 #
 # Profiles
 #
 if [ -n "$NB_ROOT" ]; then
+  [ -e "$NB_ROOT/etc/profile.d/envs" ] && . "$NB_ROOT/etc/profile.d/envs"
 
   for i in \
-    ${NB_ROOT}/etc/profile.d/envs \
     ${NB_ROOT}/etc/profile.d/aliases \
     ${NB_ROOT}/etc/profile.d/*.sh \
-    ${HOME}/.${SHELL_NAME}rc \
+    $(nb-repo-dirs "etc/profile" "etc/profile.d/*.sh") \
   ;do
-    [ -n "$NB_DEBUG" ] && $NB_DEBUG "$i"
-    [ -r "$i" ] && source "$i"
+    [ -n "$NB_DEBUG" ] && $NB_DEBUG "$i"
+    [ -r "$i" -a -f "$i" ] && . "$i"
   done
 
 fi
index f251393190bf3e94e507420c5ba8412b5a565c7c..0e076cad6f48778c6863917cb828192310e76552 100644 (file)
 [ -z "$UID" ] && UID=`id -u`
 [ -z "$USER" ] && USER=`whoami`
 [ -z "$OSTYPE" ] && OSTYPE=`uname|tr [:upper:] [:lower:]`
-[ -z "PWD" ] && PWD=`pwd`
+# NB 25.08.16 [ -z "PWD" ] && PWD=`pwd`
+
+# We don't want to destroyed variables
+if true || env_add_path &>/dev/null; then
 
 #
-# PATHS
+# PATH
 #
-env_add_path &>/dev/null && PATH=`env_add_path "$PATH" \
+[ -n "$NB_ROOT" ] && PATH=$(env_add_path "$PATH" "$NB_ROOT/bin") # to find nb-repo-dirs
+  #$($NB_ROOT/bin/nb-repo-dirs bin sbin)
+PATH=$(env_add_path "$PATH" \
   /bin \
   /sbin \
   /usr/sbin \
@@ -26,24 +31,35 @@ env_add_path &>/dev/null && PATH=`env_add_path "$PATH" \
   /opt/local/sbin \
   /usr/local/bin \
   /usr/local/sbin \
+  /usr/share/awstats/tools \
+  $(nb-repo-dirs bin sbin) \
+  /home/bin \
   $HOME/bin \
-  $HOME/sbin \
-       /usr/share/awstats/tools \
-       /home/bin \
-       /home/www/wp/bin \
-  $($NB_ROOT/bin/nb-repo-dirs | xargs -n1 -IZ printf '%s\n%s\n' "Z/bin" "Z/sbin" 2>/dev/null)
-`
+)
 export PATH
 
+#
+# MANPATH
+#
+MANPATH=$(env_add_path "$MANPATH" \
+  /usr/share/man\
+  /usr/local/man\
+  /usr/local/memcached/share/man \
+  $(nb-repo-dirs | xargs -n1 -IZ echo "Z/man" 2>/dev/null) \
+)
+export MANPATH
+
+fi # < env_add_path
+
 #
 # OTHERS
 #
 
 export IGNOREEOF=0
+case "$OSTYPE" in darwin*) export DARWIN=1;; esac
 export LESS="-iMR"
 export PAGER="less $LESS"
 export EDITOR=vim
-case "$OSTYPE" in darwin*) export DARWIN=1;; esac
 
 #
 # SHELL
index 4ec9d6f4a8d98e1d142010bb9795c3a8ac197b39..83019078415ac76c137a6ff76d3025e21b315ee1 100644 (file)
@@ -84,7 +84,7 @@ ips() {
 env_add_path() {
   # Add paths to a variables
   # Usage PATH=`env_add_path "$PATH" "/blbabla"`
-  declare env_value; env_value=$1; shift
+  declare env_value=$1; shift
 
   for p in $@; do
     [ -e "$p" ] || continue