#####################################################################
# 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)
- local port=''
-
- if [ -z "$dest" ]; then
- 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
- *" $dest=0 "*) ok=0 ;;
- *" $dest=1 "*) ok=1 ;;
- *)
- ok=0
- case "$dest" in
- *"@"*) timeout 5 ssh -o BatchMode=yes -o ConnectTimeout=5 $dest true && 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
-
- #if ! timeout 5 ssh BatchMode=yes -o ConnectTimeout=5 $dest true; then
- if [ "$ok" != "1" ]; then
- logger -t $NAME -s "Can't connect to $dest"
- return 1
- fi
-
- return 0
-}
#cd $NB_ROOT || exit
#git_conn_check || git_conn_check || exit
#exec echo BYE
[[ $- == *i* ]] && return 0
return 1
}
+
+url2nc() {
+ local in="cat";
+ [ -n "$@" ] && in="echo $@";
+ $in | perl -MURI::Split -ne 'BEGIN{%port=("ssh"=>22,"https"=>443,"http"=>80);}; chomp($_); m,^\w+://, or $_="ssh://$_"; s,:([a-zAZ]),/$1,; @_=URI::Split::uri_split($_) or next; $_=$_[1]; s/^[^@]+@//; s/:/ / or $_.=" ".$port{$_[0]||"ssh"}; print "$_\n"'
+}
#--------------------------------------------------------------------------------
# Git
#
-GIT_REPO='git@git.nbdom.net'
+[ -z "GIT_REPO" ] && GIT_REPO='git@git.nbdom.net'
alias git_grep="git grep --color=auto"
alias git_ls_tree="git ls-tree --full-tree -r HEAD"
local repo=$(echo "$GIT_REPO" | perl -pe 's,^\w+://,,; s,/.*$,,;')
ssh $repo list | perl -ne '/(\S+).git/ and print "$1\n"'
}
+
+_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)
+ local port=''
+
+ if [ -z "$dest" ]; then
+ 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
+ *" $dest=0 "*) ok=0 ;;
+ *" $dest=1 "*) ok=1 ;;
+ *)
+ ok=0
+ case "$dest" in
+ *"@"*) timeout 5 ssh -o BatchMode=yes -o ConnectTimeout=5 $dest true && 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
+
+ #if ! timeout 5 ssh BatchMode=yes -o ConnectTimeout=5 $dest true; then
+ if [ "$ok" != "1" ]; then
+ logger -t $NAME -s "Can't connect to $dest"
+ return 1
+ fi
+
+ return 0
+}