}
## 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
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