]> git.nbdom.net Git - nb.git/commitdiff
bin/iwtop
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 13 Jul 2016 13:12:21 +0000 (14:12 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 13 Jul 2016 13:12:21 +0000 (14:12 +0100)
bin/iwtop [new file with mode: 0755]
bin/nb-update

diff --git a/bin/iwtop b/bin/iwtop
new file mode 100755 (executable)
index 0000000..9de3531
--- /dev/null
+++ b/bin/iwtop
@@ -0,0 +1,62 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Data::Dumper;
+
+$_ = @ARGV ? ' '.join(' ',@ARGV) : '';
+@ARGV = ("iwlist$_ scan 2>/dev/null |");
+
+#open(STDOUT,"| sort -t'|' -k 5 -n -r");
+my (
+  $int,
+  $cell,
+  %net
+);
+
+while (<>) {
+
+  /^([\w:_-]+)/ and $int = $1 and next;
+  /^\s*Cell (\d+)/ and $cell = $1;
+  my $k = "$int-$cell";
+  $net{$k}{int} = $int;
+  $net{$k}{cell} = $cell;
+
+  /ESSID: *"(.*)"/ and $net{$k}{name} = $1;
+  /Address: *(.*)/ and $net{$k}{addr} = $1;
+  if (/Frequency:(.*?) \(Channel (\d+)\)/) {
+    $net{$k}{frequency} = $1;
+    $net{$k}{channel} = $2;
+  }
+  /Bit Rates: *(.*)/ and $net{$k}{speed} = $1;
+  if (/Quality=(\d+).100\s+Signal level=(\d+).100/) {
+    $net{$k}{quality} = $1;
+    $net{$k}{signal} = $2;
+  }
+
+}
+
+#die Dumper \%net;
+my $fmt = "%5s | %17s | %9s | %2s | %8s | %3s | %3s | %s\n";
+printf $fmt,'INT','MAC','FREQ','CH','SPEED','SIG','QLT','NAME';
+for my $k (sort {
+  ($net{$b}{signal}||0) <=> ($net{$a}{signal}||0)
+  or
+  ($net{$b}{quality}||0) <=> ($net{$a}{quality}||0)
+} keys %net) {
+  printf $fmt
+    ,$net{$k}{int}||'?'
+    ,$net{$k}{addr}||'?'
+    ,$net{$k}{frequency}||'?'
+    ,$net{$k}{channel}||'?'
+    ,$net{$k}{speed}||'?'
+    ,$net{$k}{signal}||'?'
+    ,$net{$k}{quality}||'?'
+    ,$net{$k}{name}||'?'
+  ;
+}
+exit 0;
+
+sub out {
+my %h = @_;
+
+}
index 94d609dcb77bb780359bd9c1d4ed4e972d574a09..2481b1bf8c16e2f19384f35710b96cd1a84154d9 100755 (executable)
 declare -r NAME="$(basename "${0}")"
 declare -r TMP="/tmp/$NAME.tmp"
 
+#####################################################################
+# Git Connection check
+#
+_git_conn_check=" "
+git_conn_check() {
+  local dest=$(git config --local --get remote.origin.url | sed 's/:.*\?$//')
+
+  if [ -z "$dest" ]; then
+    logger -t $NAME -s "Can't get git repo from `cwd`"
+    return 1
+  fi
+
+  local ok
+  case "$_git_conn_check" in
+    *" $dest=0 "*) ok=0 ;;
+    *" $dest=1 "*) ok=1 ;;
+    *)
+      ok=0
+      timeout 5 ssh -o BatchMode=yes -o ConnectTimeout=5 $dest true && ok=1
+      _git_conn_check="${_git_conn_check}$dest=$ok "
+      echo "<$_git_conn_check>"
+    ;;
+  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
+
 #####################################################################
 # Gits pull
 #
@@ -32,10 +68,13 @@ for repo in $(nb-repo-dirs); do
 
   # Pull
   echo ">git pull $repo (user=$user)"
+  #git_conn_check || continue
 
-  cmd="GIT_SSH=$TMP cd \"$repo\" && git pull"
+  cmd="GIT_SSH=$GIT_SSH cd \"$repo\" && git pull"
 
-  if [ "$USER" == "$user" ]; then
+  if ! git_conn_check; then
+    true
+  elif [ "$USER" == "$user" ]; then
     bash -c "$cmd"
   elif [ "$USER" == "root" ]; then
     su $user -c "$cmd"
@@ -51,7 +90,6 @@ for repo in $(nb-repo-dirs); do
   else
     cmd_root="true"
     [ -x bin/$name-install ] && cmd_root="$cmd_root && echo '  >$name-install' && bin/$name-install|sed 's/^/    /'"
-    #[ "$cmd_root" == "true" ] || eval "$cmd_root" || echo ">err"
     if [ "$cmd_root" != "true" ]; then
       eval "$cmd_root"
       ex=$?