A new function, check_cmd, relies on type -p's return value instead of a
string check.

And gettext was previously being tested with type -t, which was
inconsistent with the rest of the tests pertaining commands that aren't
expected to be functions nor builtins.

Signed-off-by: Andres P <[email protected]>
---

i don't think the inline comments i added are necessary, since the
function is pretty explicit

 scripts/makepkg.sh.in |   39 ++++++++++++++++++++++++++-------------
 1 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 8c0da8b..650358b 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -193,6 +193,19 @@ get_url() {
        echo "${1#*::}"
 }
 
+
+##
+# Checks to see if command is present in PATH
+#
+#  usage : check_cmd( $command )
+# return : 0 - found
+#          1 - not found
+##
+check_cmd() {
+       type -p -- "$1" >/dev/null
+}
+
+
 ##
 # Checks to see if options are present in makepkg.conf or PKGBUILD;
 # PKGBUILD options always take precedence.
@@ -345,7 +358,7 @@ download_file() {
 run_pacman() {
        local ret=0
        if (( ! ASROOT )) && [[ $1 != "-T" && $1 != "-Qq" ]]; then
-               if [ "$(type -p sudo)" ] && sudo -l $PACMAN &>/dev/null; then
+               if check_cmd sudo && sudo -l $PACMAN &>/dev/null; then
                        sudo $PACMAN $PACMAN_OPTS "$@" || ret=$?
                else
                        su -c "$PACMAN $PACMAN_OPTS $*" || ret=$?
@@ -519,7 +532,7 @@ generate_checksums() {
        msg "$(gettext "Generating checksums for source files...")"
        plain ""
 
-       if [ ! $(type -p openssl) ]; then
+       if ! check_cmd openssl; then
                error "$(gettext "Cannot find openssl.")"
                exit 1 # $E_MISSING_PROGRAM
        fi
@@ -580,7 +593,7 @@ generate_checksums() {
 check_checksums() {
        (( ! ${#sour...@]} )) && return 0
 
-       if [ ! $(type -p openssl) ]; then
+       if ! check_cmd openssl; then
                error "$(gettext "Cannot find openssl.")"
                exit 1 # $E_MISSING_PROGRAM
        fi
@@ -1333,27 +1346,27 @@ devel_check() {
                # Also do a brief check to make sure we have the VCS tool 
available.
                oldpkgver=$pkgver
                if [[ -n ${_darcstrunk} && -n ${_darcsmod} ]] ; then
-                       [ $(type -p darcs) ] || return 0
+                       check_cmd darcs || return 0
                        msg "$(gettext "Determining latest darcs revision...")"
                        newpkgver=$(date +%Y%m%d)
                elif [[ -n ${_cvsroot} && -n ${_cvsmod} ]] ; then
-                       [ $(type -p cvs) ] || return 0
+                       check_cmd cvs || return 0
                        msg "$(gettext "Determining latest cvs revision...")"
                        newpkgver=$(date +%Y%m%d)
                elif [[ -n ${_gitroot} && -n ${_gitname} ]] ; then
-                       [ $(type -p git) ] || return 0
+                       check_cmd git || return 0
                        msg "$(gettext "Determining latest git revision...")"
                        newpkgver=$(date +%Y%m%d)
                elif [[ -n ${_svntrunk} && -n ${_svnmod} ]] ; then
-                       [ $(type -p svn) ] || return 0
+                       check_cmd svn || return 0
                        msg "$(gettext "Determining latest svn revision...")"
                        newpkgver=$(LC_ALL=C svn info $_svntrunk | sed -n 
's/^Last Changed Rev: \([0-9]*\)$/\1/p')
                elif [[ -n ${_bzrtrunk} && -n ${_bzrmod} ]] ; then
-                       [ $(type -p bzr) ] || return 0
+                       check_cmd bzr || return 0
                        msg "$(gettext "Determining latest bzr revision...")"
                        newpkgver=$(bzr revno ${_bzrtrunk})
                elif [[ -n ${_hgroot} && -n ${_hgrepo} ]] ; then
-                       [ $(type -p hg) ] || return 0
+                       check_cmd hg || return 0
                        msg "$(gettext "Determining latest hg revision...")"
                        if [[ -d ./src/$_hgrepo ]] ; then
                                cd ./src/$_hgrepo
@@ -1555,7 +1568,7 @@ There is NO WARRANTY, to the extent permitted by law.\n")"
 # PROGRAM START
 
 # determine whether we have gettext; make it a no-op if we do not
-if [ ! $(type -t gettext) ]; then
+if ! check_cmd gettext; then
        gettext() {
                echo "$@"
        }
@@ -1729,7 +1742,7 @@ if (( ! INFAKEROOT )); then
                plain "$(gettext "Please rerun makepkg without the --asroot 
flag.")"
                exit 1 # $E_USER_ABORT
        elif [[ $(check_buildenv fakeroot) = "y" ]] && (( EUID > 0 )); then
-               if [ ! $(type -p fakeroot) ]; then
+               if ! check_cmd fakeroot; then
                        error "$(gettext "Fakeroot must be installed if using 
the 'fakeroot' option")"
                        plain "$(gettext "in the BUILDENV array in %s.")" 
"$MAKEPKG_CONF"
                        exit 1
@@ -1749,7 +1762,7 @@ fi
 
 # check for sudo if we will need it during makepkg execution
 if (( ! ( ASROOT || INFAKEROOT ) && ( DEP_BIN || RMDEPS || INSTALL ) )); then
-       if [ ! "$(type -p sudo)" ]; then
+       if ! check_cmd sudo; then
                warning "$(gettext "Sudo can not be found. Will use su to 
acquire root privileges.")"
        fi
 fi
@@ -1921,7 +1934,7 @@ if (( NODEPS || ( (NOBUILD || REPKG) && !DEP_BIN ) )); 
then
        if (( NODEPS || ( REPKG && PKGFUNC ) )); then
                warning "$(gettext "Skipping dependency checks.")"
        fi
-elif [ $(type -p "${PACMAN%% *}") ]; then
+elif check_cmd "${PACMAN%% *}"; then
        if (( RMDEPS )); then
                original_pkglist=($(run_pacman -Qq | sort))    # required by 
remove_dep
        fi
-- 
1.7.1


Reply via email to