various cleanups

This commit is contained in:
David Majnemer 2010-07-02 11:11:00 -07:00
parent 689cd43612
commit a9b7c68f98

View file

@ -4,41 +4,46 @@
unkey_host () unkey_host ()
{ {
[ ${#} -ne 1 ] && return 1 [ $# -ne 1 ] && return 1
sed -i -e "/$1/d" $HOME/.ssh/known_hosts sed -i -e "/$1/d" $HOME/.ssh/known_hosts
} }
err () err ()
{ {
case $@ in case $1 in
E*) E*)
errconst=$1
unset errno unset errno
if [ "${errno}" = "" ] && ( command -v python > /dev/null 2>&1 ); then if [ "${errno}" = "" ] && ( command -v python > /dev/null 2>&1 ); then
errno=`python -c "import errno;print(errno.$@)" 2>/dev/null` errno=`python -c "import errno;print(errno.${errconst})" 2>/dev/null`
fi
if [ "${errno}" = "" ] && ( command -v perl > /dev/null 2>&1 ); then
errno=`perl -MErrno -e "print &Errno::${errconst}.\"\n\";" 2>/dev/null`
fi fi
if [ "${errno}" = "" ] && ( command -v ruby > /dev/null 2>&1 ); then if [ "${errno}" = "" ] && ( command -v ruby > /dev/null 2>&1 ); then
errno=`ruby -e "puts Errno::$@::Errno if (Errno::$@)" 2>/dev/null` errno=`ruby -e "puts Errno::${errconst}::Errno" 2>/dev/null`
fi fi
if [ "${errno}" = "" ] && [ -e /usr/include/errno.h ] ; then if [ "${errno}" = "" ] && [ -e /usr/include/errno.h ] ; then
errno=`cpp -dM /usr/include/errno.h | grep -w "$@" | grep -oE '[0-9]+' 2>/dev/null` errno=`cpp -dM /usr/include/errno.h | grep -E "${errconst}[[:space:]]+[0-9]+$" | grep -oE '[0-9]+' 2>/dev/null`
fi fi
if [ "${errno}" ] ; then if [ "${errno}" ] ; then
echo "$@ = $errno" echo "${errconst} = ${errno}"
else else
return 1 return 1
fi fi
;; ;;
*) *)
errno=$1
unset errconst unset errconst
if [ "${errconst}" = "" ] && ( command -v python > /dev/null 2>&1 ); then
errconst=`python -c "import errno;print(errno.errorcode[$@])" 2>/dev/null`
fi
if [ "${errconst}" = "" ] && ( command -v ruby > /dev/null 2>&1 ); then if [ "${errconst}" = "" ] && ( command -v ruby > /dev/null 2>&1 ); then
errconst=`ruby -e "puts Errno.constants.find_all{|err| eval('Errno::' + err + '::Errno') == $@ }"` errconst=`ruby -e "puts Errno.constants.find_all{|err| eval('Errno::' + err + '::Errno') == ${errno} }, ' = ${errno}'" 2>/dev/null`
fi
if [ "${errconst}" = "" ] && ( command -v python > /dev/null 2>&1 ); then
errconst=`python -c "import errno;print(errno.errorcode[${errno}] + ' = ${errno}')" 2>/dev/null`
fi fi
if [ "${errconst}" = "" ] && [ -e /usr/include/errno.h ] ; then if [ "${errconst}" = "" ] && [ -e /usr/include/errno.h ] ; then
errconst=`cpp -dM /usr/include/errno.h | grep -w "E.* $@"` errconst=`cpp -dM /usr/include/errno.h | grep -E "E[[:alnum:]]+[[:space:]]+${errno}$"`
fi fi
if [ "${errconst}" ] ; then if [ "${errconst}" ] ; then
@ -46,15 +51,21 @@ err ()
else else
return 1 return 1
fi fi
errno=$@
;; ;;
esac esac
if ( command -v perl > /dev/null 2>&1 ) ; then unset errstr
perl -MPOSIX -e 'print strerror($ARGV[0])."\n";' $errno if [ "${errstr}" = "" ] && ( command -v perl > /dev/null 2>&1 ) ; then
elif ( command -v python > /dev/null 2>&1 ) ; then errstr=`perl -MPOSIX -e 'print strerror($ARGV[0])."\n";' $errno`
python -c "import os;print(os.strerror($errno))" fi
if [ "${errstr}" = "" ] && ( command -v python > /dev/null 2>&1 ) ; then
errstr=`python -c "import os;print(os.strerror($errno))" 2>/dev/null`
fi
if [ "${errstr}" ] ; then
echo $errstr
else
return 2
fi fi
} }
@ -70,13 +81,13 @@ mkcd ()
extract () extract ()
{ {
if ( command -v aunpack > /dev/null 2>&1 ) ; then if [ ! -f "$1" ] ; then
aunpack "${1}" echo "The file ("$1") does not exist!"
return return
fi fi
if [ ! -f "$1" ] ; then if ( command -v aunpack > /dev/null 2>&1 ) ; then
echo "The file ("$1") does not exist!" aunpack "${1}"
return return
fi fi