Fix a bug that was exposed by the SXEmacs configure script.
[pkgusr] / usr / lib / pkgusr / install
index bca9010..fec2973 100755 (executable)
@@ -100,7 +100,7 @@ if [ ! -n "$DAISY_CHAIN" ]; then
 fi
 
 ## root has no business installing things here!!
-if [ $UID -eq 0 ]; then
+if [ $(id -u) -eq 0 ]; then
     echo 1>&2 '***' $(dirname $0) should not be in root\'s \$PATH
     echo 1>&2 '***' call '"'$DAISY_CHAIN ${pristinecmd[*]}'"' directly
     exit 1
@@ -156,7 +156,7 @@ _group()
     local GRP_LIST
 
     # GID or name?
-    printf '%d' $group &>/dev/null
+    printf '%d' "$group" &>/dev/null
     if [ $? -eq 0 ]; then
        GRP_LIST=$(id -G)
     else
@@ -186,7 +186,7 @@ _owner()
     local MYNAME
 
     # UID or name?
-    printf '%d' $owner &>/dev/null
+    printf '%d' "$owner" &>/dev/null
     if [ $? -eq 0 ]; then
        MYNAME=$(id -u)
     else
@@ -207,26 +207,24 @@ _owner()
 #  are symbolic, convert them to numerical first.
 _perms()
 {
-    local p
+    local testfile
     ### HACK-O-MATIC:
     # Convert symbolic permissions to numerical.
-    printf '%d' $perm &>/dev/null
-    if [ $? -eq 0 ]; then
-       p=$perm
-    else
-       touch /tmp/hack-o-matic-9000
+    printf '%d' "$perm" &>/dev/null
+    if [ $? -ne 0 ]; then
+       testfile=$(mktemp hack-o-matic-install.XXXXX --tmpdir)
        # A tiny risk hard-coding /bin/chmod here, but I don't won't
        # the chmod wrapper in play for this.
-       /bin/chmod $perm /tmp/hack-o-matic-9000
-       p=$(stat --printf "%a" /tmp/hack-o-matic-9000)
-       rm -f /tmp/hack-o-matic-9000
+       exec /bin/chmod ${perm} ${testfile}
+       perm=$(stat --printf "%a" ${testfile})
+       rm -f ${testfile}
     fi
     # Catch the funky shit
-    if [ $p -gt 999 ]; then
+    if [ $perm -gt 999 ]; then
        report
-       cmdopts="$cmdopts -m${p/?/}"
+       cmdopts="$cmdopts -m${perm/?/}"
     else
-       cmdopts="$cmdopts -m$p"
+       cmdopts="$cmdopts -m$perm"
     fi
     return
 }
@@ -284,7 +282,7 @@ done
 shift $(( $OPTIND - 1 ))
 
 # We've done all we can, now lets run install
-$DAISY_CHAIN ${cmdopts} $@ || exit $?
+exec $DAISY_CHAIN ${cmdopts} $@ || exit $?
 exit 0
 
 ### End install