#. "${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
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
# 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
#--------------------------------------------------------------------------------
# vim
#
-which vim &>/dev/null && alias vi=vim
+which vim 1>/dev/null && alias vi=vim
# > 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
[ -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)
[ -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
#
# 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
return 0
;;
esac
- shift
+ shift 2>/dev/null || break
done
return 1
#
# 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"
}
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"
(
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
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
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/;
}
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
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
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 "
#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
#--------------------------------------------------------------------------------
# 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)'
#--------------------------------------------------------------------------------
#
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'"