Alexander, good day. Thu, Feb 03, 2011 at 07:43:06PM +0000, Alexander Best wrote: > it seems the -d flag breaks the semantics of tools/install.sh entirely and > using the script in such a case simply passes all args over to install(1). > > simply adding the -d flag to the first switch statement won't work, since we > need to tell install(1) that it should only expect a single directory as > argument. so the -d flag needs to be passed over to install(1), while options > such as -o X, -g X, etc. need to be stripped away.
The attached patch should fix this: {{{ $ sh install.sh.orig -d -m 700 `pwd`/a-test $ ls -ld a-test drwx------ 2 rea rea 512 4 Feb 10:03 a-test $ sh install.sh -d -m 700 `pwd`/a-test $ ls -ld a-test drwxr-xr-x 2 rea rea 512 4 Feb 10:03 a-test }}} It also adds some proper quoting for the remaining arguments (plain $* vs quoted "$@") to the install.sh (this is a pathological case, but it is better to fix this too, while we're on topic): {{{ $ rm -rf 1; mkdir 1; cd 1; sh -x ../install.sh.orig -d -m 512 "this is a test"; ls -l; cd .. + [ 4 -gt 0 ] + break + exec install -p -d -m 512 this is a test total 8 dr-x--x-w- 2 rea rea 512 Feb 4 10:10 a dr-x--x-w- 2 rea rea 512 Feb 4 10:10 is dr-x--x-w- 2 rea rea 512 Feb 4 10:10 test dr-x--x-w- 2 rea rea 512 Feb 4 10:10 this $ rm -rf 1; mkdir 1; cd 1; sh -x ../install.sh -d -m 512 "this is a test"; ls -l; cd .. + dirmode='' + [ 4 -gt 0 ] + dirmode=YES + shift + [ 3 -gt 0 ] + shift + shift + [ 1 -gt 0 ] + break + [ 1 -eq 0 ] + [ -z YES ] + install -d 'this is a test' total 2 drwxr-xr-x 2 rea rea 512 Feb 4 10:10 this is a test }}} -- Eygene Ryabinkin ,,,^..^,,, [ Life's unfair - but root password helps! | codelabs.ru ] [ 82FE 06BC D497 C0DE 49EC 4FF0 16AF 9EAE 8152 ECFB | freebsd.org ]
--- install.sh.orig 2011-02-04 09:57:39.000000000 +0300 +++ install.sh 2011-02-04 10:03:05.000000000 +0300 @@ -29,8 +29,10 @@ # $FreeBSD$ # parse install's options and ignore them completely. +dirmode="" while [ $# -gt 0 ]; do case $1 in + -d) dirmode="YES"; shift;; -[bCcMpSs]) shift;; -[Bfgmo]) shift; shift;; -[Bfgmo]*) shift;; @@ -38,5 +40,16 @@ esac done +if [ "$#" -eq 0 ]; then + echo "Nothing to do: no files/dirs specified" >&2 + exit 1 +fi + # the remaining arguments are assumed to be files/dirs only. -exec install -p $* +if [ -z "$dirmode" ]; then + exec install -p "$@" +else + for d in "$@"; do + install -d "$d" + done +fi
pgpzyMbPsPOSI.pgp
Description: PGP signature