X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=usr_bin%2Fgrml-exec-wrapper;h=d3ff8eeec350613c0a38ddfaca2f608fdf3bef49;hb=5b0c6b200fe0a76b7a78c984733defdb3120ea6a;hp=f20ffd4aeb549636064019901f0056e9fc66832a;hpb=7760a197c555cc8fa6e72653dca0a53b0e950dff;p=grml-scripts.git diff --git a/usr_bin/grml-exec-wrapper b/usr_bin/grml-exec-wrapper index f20ffd4..d3ff8ee 100755 --- a/usr_bin/grml-exec-wrapper +++ b/usr_bin/grml-exec-wrapper @@ -6,32 +6,27 @@ # License: This file is licensed under the GPL v2 or any later version. ################################################################################ -# use Xdisplay only if present and running under X: -display_info() { -if type -a Xdialog 1>/dev/null 2>&1 && test -n "$DISPLAY" ; then - Xdialog --title "grml-exec-wrapper" --msgbox "$1" 0 0 0 -else - print "$1">&2 -fi -} - -if [ -z "$1" ] ; then - display_info "Usage: $0 []" - exit 1 -fi +usage() { + printf "Usage: $0 [] -RC='0' -PROG="$1" +Available options: -# make sure to support 'grml-exec-wrapper sudo wireshark' as well: -case $PROG in - *sudo*) PROG="$2" ;; -esac + -h | --help display this usage information + -p check specified argument instead of default args, like: + $(basename $0) -p aumix xterm -T aumix -e aumix +" +} 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=: @@ -45,20 +40,49 @@ is_installed() { return "$ret" } -if is_installed "$PROG" 1>/dev/null 2>&1 ; then - exec $@ +# use Xdisplay only if present and running under X: +display_info() { +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" -o "$1" = '-h' -o "$1" = '--help' ] ; then + usage + exit 1 +fi + +if [ "$1" = '-p' ] ; then + if [ -z "$2" ] ; then + usage + exit 1 + else + PROG="$2" + shift ; shift + fi else - RC=1 - display_info "Sorry: ${PROG} not available. + 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 "$@" +fi + +display_info "Sorry: ${PROG} not available. 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}) " -fi -exit $RC +exit 1 ## END OF FILE #################################################################