]> git.nbdom.net Git - nb.git/commitdiff
fix bug sh compatible
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 19 Dec 2016 14:40:58 +0000 (15:40 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 19 Dec 2016 14:40:58 +0000 (15:40 +0100)
bin/nb-update
etc/profile
etc/profile.d/aliases
etc/profile.d/envs
etc/profile.d/functions
etc/profile.d/git.sh
etc/profile.d/nico.sh

index 559c039f216a96b6d89ad1cfd557ef5fda0509f7..9847bd203ac7494d820b50a6c1d1a959f5fd55df 100755 (executable)
@@ -9,7 +9,8 @@
 #. "${BASH_SOURCE%/*}/../etc/profile" || exit
 #echo "$0 | $(dirname "$0")/.. | $PATH"
 . $(dirname "$0")/../etc/profile || exit 1; [ -z "$NB_ROOT" ] && exit
-#nb_repos exit;
+#exit;
+#nb_repos; exit;
 NAME="$(basename "${0}")"
 TMP="/tmp/$NAME.tmp"
 CLEANUP=0
index 152ab35c9ab2c945ddeb854384bf664eb208d4eb..41f7c00ef14e9a82f6d42d9bd9675ab2fd662f00 100755 (executable)
@@ -46,7 +46,7 @@ else
   tmp=$PWD
   for i in /*/*/etc/profile.d/functions /*/*/*/etc/profile.d/functions; do
 
-    cd "$(dirname "$i")"/.. &> /dev/null || continue
+    cd "$(dirname "$i")"/.. 1>/dev/null 2>&1 || continue
 
     # Check other files
     [ -e profile.d/envs ] || continue
index a522e17a38012fe6e7e6d787714bea64e5d4100e..273fea3dd0402aa5bd7e758baa2983a07a96cf32 100644 (file)
@@ -3,19 +3,19 @@
 # Aliases
 #
 #################################################################################
-[ -n "$MYVIMRC" ] && shopt -s expand_aliases
+[ -n "$MYVIMRC" -a -n "$BASH" ] && shopt -s expand_aliases
 
 #--------------------------------------------------------------------------------
 # Others
 #
-which blkid &>/dev/null && alias uuid-hds='blkid -o full -s UUID'
-which dpkg-query &>/dev/null && alias dpkg-sort-size="dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -k1,1nr"
-which apg &>/dev/null && alias password-gener='apg -m 12 -x 12 -a 0 -M L|head -1;'
-which mysql &>/dev/null && alias mysqlshow-view="mysql -e \"SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'VIEW'\""
-which nmap &>/dev/null && alias nmap-ping="nmap -sP -PE -PS443 -PA21,22,23,80,3389"
-which arp &>/dev/null && alias arp-list="arp -an"
-which gs &>/dev/null && alias pdf2jpegs='gs -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=5 -sOutputFile=pdf2jpegs%d.jpg -dJPEGQ=100 -r500 -c quit'
-which maildirmake &>/dev/null && alias nb-maildir-make="maildirmake -S Maildir; for d in Spam Trash Sent;do maildirmake -f $d Maildir; done"
+which blkid 1>/dev/null && alias uuid-hds='blkid -o full -s UUID'
+which dpkg-query 1>/dev/null && alias dpkg-sort-size="dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -k1,1nr"
+which apg 1>/dev/null && alias password-gener='apg -m 12 -x 12 -a 0 -M L|head -1;'
+which mysql 1>/dev/null && alias mysqlshow-view="mysql -e \"SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'VIEW'\""
+which nmap 1>/dev/null && alias nmap-ping="nmap -sP -PE -PS443 -PA21,22,23,80,3389"
+which arp 1>/dev/null && alias arp-list="arp -an"
+which gs 1>/dev/null && alias pdf2jpegs='gs -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=5 -sOutputFile=pdf2jpegs%d.jpg -dJPEGQ=100 -r500 -c quit'
+which maildirmake 1>/dev/null && alias nb-maildir-make="maildirmake -S Maildir; for d in Spam Trash Sent;do maildirmake -f $d Maildir; done"
 
 #--------------------------------------------------------------------------------
 # Beep
@@ -30,4 +30,4 @@ which bc 1>/dev/null && alias bc="bc -q"
 #--------------------------------------------------------------------------------
 # vim
 #
-which vim &>/dev/null && alias vi=vim
+which vim 1>/dev/null && alias vi=vim
index a2e66b0fad20fc4d534b0c75d3c145db24da1524..654a26b2cf24eeb1a3b2d565b97f47cb48ff53b7 100644 (file)
@@ -19,7 +19,7 @@
 
 # > env_add_path
 #We don't want to destroyed variables if function does not exists !
-if true || env_add_path &>/dev/null; then
+if true || env_add_path 1>/dev/null; then
 
 #
 # PATH
index 8252cc687a275be2879dcf6e2284dc1f35a706c0..efa1856b0a336c7b352e9533bea19ff258694590 100644 (file)
@@ -14,7 +14,9 @@ nb_repos() {
     [ -s "$conf" ] || conf="$NB_ROOT/etc/repos.conf"
 
     # Realpath
-    local IFS=$'\n'
+    #ls -d1 $(grep -v '^ *\(#\|$\)' "$conf") 2>/dev/null
+    local IFS="
+"
     for dir in $(ls -d1 $(grep -v '^ *\(#\|$\)' "$conf") 2>/dev/null); do
 
       # Accept directories or files (ex: use to tag a directory: .nb-install)
@@ -34,7 +36,9 @@ nb_repos_ls() {
   [ -z "$FUNCNAME" ] && local FUNCNAME='nb_repos_ls' # for busybox
 
   # Look for paths
-  local d f i repo IFS=$'\n'
+  local d f i repo
+  local IFS="
+"
   for d in `nb_repos`; do
 
     for f in "$@"; do
@@ -117,7 +121,11 @@ shell_help() {
   #
   # Print help message and return true if args contains -?-h(elp)?
   #
-  local msg="$1"; shift
+  local msg=""
+  if [ "$#" -gt 0 ]; then
+    msg="$1"
+    shift
+  fi
 
   local i
   #while [ $# -gt 0 ]; do
@@ -131,7 +139,7 @@ shell_help() {
         return 0
       ;;
     esac
-    shift
+    shift 2>/dev/null || break
   done
 
   return 1
@@ -141,9 +149,13 @@ shell_help_noarg() {
   #
   # Print help message and return true if args contains -?-h(elp)? or is empty
   #
-  local msg="$1"; shift
+  local msg=""
+  if [ "$#" -gt 0 ]; then
+    msg="$1"
+    shift
+  fi
 
-  local args=""; args="$@" # zsh compatible
+  local args="$*"
   [ -z "$args" ] && args="--help"
 
   shell_help "$msg" "$args"
@@ -156,7 +168,7 @@ shell_functions() {
 }
 
 shell_ssh() {
-  local ssh_opt; case "$1" in -*) ssh_opt="$1"; shift ;; esac
+  local ssh_opt; case "$1" in -*) ssh_opt="$1"; [ "$#" -gt 0 ] && shift ;; esac
   local server; server="$1"; shift
   local tmp; tmp="/tmp/$FUNCNAME.$USER"
   (
@@ -207,7 +219,7 @@ env_add_path() {
 
 if ! which realpath >/dev/null; then
 realpath() {
-  if which perl &> /dev/null; then
+  if which perl 1>/dev/null; then
     perl -MFile::Spec -MCwd -e 'print File::Spec->rel2abs( Cwd::abs_path($ARGV[0]) )."\n" if -e $ARGV[0]' "$1"
   else
     case "$OSTYPE" in
@@ -417,7 +429,9 @@ cron_d_install() {
   fi
 
   shell_help_noarg "$usage" "$@" && return 1
-  case "$1" in -t|--test) test=1; shift ;; esac
+  if [ "$#" -gt 0 ]; then
+    case "$1" in -t|--test) test=1; shift ;; esac
+  fi
 
   #echo "$#"; return
   if [ $# -gt 3 ]; then
@@ -734,8 +748,6 @@ file_user() {
   ls -dl "$1" | awk '{print $3}'
 }
 
-# NB 08.12.16: TODEL 
-unalias alias myip &> /dev/null
 myip() {
   local url='';
   for url in http://ipinfo.io/ip http://www.ipchicken.com http://icanhazip.com http://ident.me http://nicolas.boisselier.free.f/myip/;
@@ -747,13 +759,13 @@ myip() {
 }
 
 http_get() {
-  if which curl &>/dev/null; then
+  if which curl 1>/dev/null; then
     curl -sk $*
 
-  elif which wget &>/dev/null; then
+  elif which wget 1>/dev/null; then
     wget -O - --quiet --no-verbose --no-check-certificate --timeout 5 --tries 1 $*
 
-  elif which lynx &>/dev/null; then
+  elif which lynx 1>/dev/null; then
     lynx --source -dump $*
 
   else
@@ -763,13 +775,13 @@ http_get() {
 alias Get=http_get
 
 http_head() {
-  if which curl &>/dev/null; then
+  if which curl 1>/dev/null; then
     curl -sk --head $*
 
-  elif which wget &>/dev/null; then
+  elif which wget 1>/dev/null; then
     zGet --save-headers - $* | perl -ne '/^\s*$/ and last;print'
 
-  elif which lynx &>/dev/null; then
+  elif which lynx 1>/dev/null; then
     lynx --head -dump $*
 
   else
index de74b713edff9cd3f0c988819f47960aaa398452..22fcd79a85e66c682ddefc084a7953cea733704e 100644 (file)
@@ -148,7 +148,7 @@ 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 &>/dev/null && ok=1 ;;
+        *) nc -z -w 5 $dest >/dev/null 2>&1 && ok=1 ;;
       esac
       [ -z "$_git_conn_check" ] && _git_conn_check=" "
       _git_conn_check="${_git_conn_check}$dest=$ok "
index 1fd8d47c4d74f6622863744a0e3433691b19ba56..1664b22283f2e628670e2353c1c37c6725dd6bc8 100644 (file)
@@ -21,8 +21,8 @@
 #alias torrentdir="btlaunchmanycurses.py --max_download_rate 150 --max_files_open 0"
 
 # btdownloadcurses
-which btdownloadcurses &>/dev/null && alias torrent="btdownloadcurses --max_upload_rate 1 --minport 6881 --maxport 6999"
-which btlaunchmanycurses &>/dev/null && alias torrentdir="btlaunchmanycurses --max_upload_rate 1 --minport 6881 --maxport 6999"
+which btdownloadcurses 1>/dev/null && alias torrent="btdownloadcurses --max_upload_rate 1 --minport 6881 --maxport 6999"
+which btlaunchmanycurses 1>/dev/null && alias torrentdir="btlaunchmanycurses --max_upload_rate 1 --minport 6881 --maxport 6999"
 
 #--------------------------------------------------------------------------------
 # xterm
@@ -32,7 +32,7 @@ which btlaunchmanycurses &>/dev/null && alias torrentdir="btlaunchmanycurses --m
 #--------------------------------------------------------------------------------
 # debian upgrade
 #
-which server-package.pl &>/dev/null && alias servers-upgrade='server-package.pl update,upgrade $((printf "big.cascais.loc\n";mysql -h mysql izi -NBe "select host from server where not hidden") | sort -u)'
+which server-package.pl 1>/dev/null && alias servers-upgrade='server-package.pl update,upgrade $((printf "big.cascais.loc\n";mysql -h mysql izi -NBe "select host from server where not hidden") | sort -u)'
 
 #--------------------------------------------------------------------------------
 #
@@ -75,7 +75,7 @@ nb_alert() {
     local ip=`dig +short $host`
     [ -z "$ip" ] && echo "Can't resolve $host" 1>&2 && return 1
 
-    ping -qc1 "$host" &> /dev/null || ( echo "Can't ping $host" 1>&2; return 1 )
+    ping -qc1 "$host" >/dev/null 2>&1 || ( echo "Can't ping $host" 1>&2; return 1 )
 
     ips | grep -qxFm1 "$ip" || cmd="ssh -o BatchMode=yes $host -- '$cmd'"