X-Git-Url: http://git.grml.org/?p=grml-scripts.git;a=blobdiff_plain;f=usr_bin%2Fgrml-exec-wrapper;h=d3ff8eeec350613c0a38ddfaca2f608fdf3bef49;hp=81592460dd9e5e934db505e290a8438a15b46880;hb=HEAD;hpb=78cd3bc89d1e9e7a670b2eb529d1791f6b43f551 diff --git a/usr_bin/grml-exec-wrapper b/usr_bin/grml-exec-wrapper index 8159246..4e5a3cc 100755 --- a/usr_bin/grml-exec-wrapper +++ b/usr_bin/grml-exec-wrapper @@ -6,10 +6,28 @@ # License: This file is licensed under the GPL v2 or any later version. ################################################################################ +PN=$(basename "$0") + +usage() { + printf "Usage: %s [] + +Available options: + + -h | --help display this usage information + -p check specified argument instead of default args, like: + %s -p aumix xterm -T aumix -e aumix\n" "${PN}" "${PN}" +} + is_installed() { prog="$1" [ -z "$prog" ] && return 1 + case "${prog}" in + /*) # deal with absolute-path programs + [ -x "${prog}" ] && return 0 + return 1 ;; + esac + ret=1 oifs="$IFS" IFS=: @@ -25,24 +43,33 @@ is_installed() { # use Xdisplay only if present and running under X: display_info() { -if is_installed Xdialog && test -n "$DISPLAY" ; then - Xdialog --title "grml-exec-wrapper" --msgbox "$1" 0 0 0 +if is_installed xterm && test -n "$DISPLAY" ; then + xterm -T 'Sorry :(' -e "dialog --msgbox \"$1\" 0 0" else printf '%s\n' "$1">&2 fi } -if [ -z "$1" ] ; then - display_info "Usage: $0 []" +if [ -z "$1" ] || [ "$1" = '-h' ] || [ "$1" = '--help' ] ; then + usage exit 1 fi -PROG="$1" - -# make sure to support 'grml-exec-wrapper sudo wireshark' as well: -case $PROG in - *sudo*) PROG="$2" ;; -esac +if [ "$1" = '-p' ] ; then + if [ -z "$2" ] ; then + usage + exit 1 + else + PROG="$2" + shift ; shift + fi +else + PROG="$1" + # make sure to support 'grml-exec-wrapper sudo wireshark' as well: + case $PROG in + *sudo*) PROG="$2" ;; + esac +fi if is_installed "$PROG" ; then exec "$@" @@ -54,7 +81,7 @@ Looks like the grml flavour you are using does not ship ${PROG}. :( You can search for ${PROG} executing: -apt-get update && apt-cache search ${PROG} +apt-get update && apt-cache search $(basename "${PROG}") " exit 1