X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=usr_bin%2Fgrml-exec-wrapper;h=cd51cae50d5135bc1987de93fa70c0f2c4f09703;hb=d03a386825bd12fb95cf4b87572038102a7ee514;hp=a826be1fdd9ece15151596e3121a0379bb216137;hpb=37bccb45ba7b9351a2fcc9f6c3a1f19f6b58ec99;p=grml-scripts.git diff --git a/usr_bin/grml-exec-wrapper b/usr_bin/grml-exec-wrapper index a826be1..cd51cae 100755 --- a/usr_bin/grml-exec-wrapper +++ b/usr_bin/grml-exec-wrapper @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Filename: grml-exec-wrapper # Purpose: simple but smart program execution wrapper # Authors: grml-team (grml.org), (c) Michael Prokop @@ -6,9 +6,26 @@ # License: This file is licensed under the GPL v2 or any later version. ################################################################################ +is_installed() { + prog="$1" + [ -z "$prog" ] && return 1 + + ret=1 + oifs="$IFS" + IFS=: + for dir in $PATH; do + [ -z "$dir" ] && continue + [ -x "$dir/$prog" ] && ret=0 && break + done + + IFS="$oifs" + unset oifs + return "$ret" +} + # use Xdisplay only if present and running under X: display_info() { -if type -a Xdialog 1>/dev/null 2>&1 && test -n "$DISPLAY" ; then +if is_installed Xdialog && test -n "$DISPLAY" ; then Xdialog --title "grml-exec-wrapper" --msgbox "$1" 0 0 0 else print "$1">&2 @@ -28,8 +45,8 @@ case $PROG in *sudo*) PROG="$2" ;; esac -if type -a "$PROG" 1>/dev/null 2>&1 ; then - exec $@ +if is_installed "$PROG" ; then + exec "$@" else RC=1 display_info "Sorry: ${PROG} not available.