#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 {
;
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 @_;
}
#####################################################################
# 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
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
[ "$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=$?
#
# 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
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
[ -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 \
/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
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