Date: Fri, 4 Feb 2011 10:13:45 +0300 From: Eygene Ryabinkin <rea@freebsd.org> To: Alexander Best <arundel@freebsd.org> Cc: freebsd-hackers@freebsd.org Subject: Re: insufficient flag handling in tools/install.sh Message-ID: <tO0VRfG8IHdubUqZgtUh/v4OTF0@QsmfhJNucgI88DfvPJdT1/nyboE> In-Reply-To: <20110203194306.GA55376@freebsd.org> References: <20110203194306.GA55376@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--hxkXGo8AKqTJ+9QI Content-Type: multipart/mixed; boundary="Bu8it7iiRSEf40bY" Content-Disposition: inline --Bu8it7iiRSEf40bY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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). >=20 > 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 opt= ions > 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 te= st"; 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=3D'' + [ 4 -gt 0 ] + dirmode=3DYES + 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 }}} --=20 Eygene Ryabinkin ,,,^..^,,, [ Life's unfair - but root password helps! | codelabs.ru ] [ 82FE 06BC D497 C0DE 49EC 4FF0 16AF 9EAE 8152 ECFB | freebsd.org ] --Bu8it7iiRSEf40bY Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="9.x-install.sh-process-d.diff" Content-Transfer-Encoding: quoted-printable --- 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$ =20 # parse install's options and ignore them completely. +dirmode=3D"" while [ $# -gt 0 ]; do case $1 in + -d) dirmode=3D"YES"; shift;; -[bCcMpSs]) shift;; -[Bfgmo]) shift; shift;; -[Bfgmo]*) shift;; @@ -38,5 +40,16 @@ esac done =20 +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 --Bu8it7iiRSEf40bY-- --hxkXGo8AKqTJ+9QI Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (FreeBSD) iF4EAREIAAYFAk1LpykACgkQFq+eroFS7PvocAD/UP7/1NAIiDUPyxar0C6EXXD0 b96psw+lazyoUCp8Zr4BAIV/9tTiBO29tFH9mzTh7xOKIWIBJrUiMJ5VibIDJMdj =xt/9 -----END PGP SIGNATURE----- --hxkXGo8AKqTJ+9QI--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?tO0VRfG8IHdubUqZgtUh/v4OTF0>