Fix nasty bug in chmod, plus minor fixes.
[pkgusr] / usr / lib / pkgusr / install
index fec2973..ab2986d 100755 (executable)
@@ -201,28 +201,23 @@ _owner()
 }
 
 ## Mode
-#  If the file perms are being set to a 4-digit number they are
-#  trying to do something funky like setuid.  In that case, truncate
-#  the 1st digit and set -m to what's left, and report it.  If perms
-#  are symbolic, convert them to numerical first.
+#  Remove any nasty bits like setuid, setgid, sticky.
 _perms()
 {
-    local testfile
-    ### HACK-O-MATIC:
-    # Convert symbolic permissions to numerical.
-    printf '%d' "$perm" &>/dev/null
+    local tperm=${perm}
+
+    printf '%o' "0${tperm}" &>/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.
-       exec /bin/chmod ${perm} ${testfile}
-       perm=$(stat --printf "%a" ${testfile})
-       rm -f ${testfile}
+       tperm=${tperm//[st]/}
+    else
+       if [ ${tperm} -gt 777 ]; then
+           tperm=${tperm/?/}
+       fi
     fi
-    # Catch the funky shit
-    if [ $perm -gt 999 ]; then
+    # Did we change anything?
+    if [ "${tperm}" != "${perm}" ]; then
        report
-       cmdopts="$cmdopts -m${perm/?/}"
+       cmdopts="$cmdopts -m$tperm"
     else
        cmdopts="$cmdopts -m$perm"
     fi
@@ -282,7 +277,7 @@ done
 shift $(( $OPTIND - 1 ))
 
 # We've done all we can, now lets run install
-exec $DAISY_CHAIN ${cmdopts} $@ || exit $?
+$DAISY_CHAIN ${cmdopts} $@ || exit $?
 exit 0
 
 ### End install