diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2002-04-26 02:14:24 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2002-04-26 02:14:24 +0000 |
commit | 6f95c3ff05069313ccb22b5535bcf401a23b17eb (patch) | |
tree | db0f4f2af5419b345c827f9f05d3991470cfae81 /distrib/miniroot | |
parent | 12a262bc38ab5e0ff93561f9faca3d2216898e53 (diff) |
Improve use of sed in various places, eliminating unnecessary
calls to grep and file redirections.
Eliminate function firstchar(). Rework of partition gathering
code removes the only use.
Remove the usual extraneous 'X's and {}'s in the code being
worked on.
From espie@ with slight modifications. ok espie@ millert@
Diffstat (limited to 'distrib/miniroot')
-rw-r--r-- | distrib/miniroot/install.sh | 35 | ||||
-rw-r--r-- | distrib/miniroot/install.sub | 32 |
2 files changed, 32 insertions, 35 deletions
diff --git a/distrib/miniroot/install.sh b/distrib/miniroot/install.sh index 57a22686660..007d02468e8 100644 --- a/distrib/miniroot/install.sh +++ b/distrib/miniroot/install.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: install.sh,v 1.96 2002/04/20 13:42:52 krw Exp $ +# $OpenBSD: install.sh,v 1.97 2002/04/26 02:14:23 krw Exp $ # $NetBSD: install.sh,v 1.5.2.8 1996/08/27 18:15:05 gwr Exp $ # # Copyright (c) 1997-2002 Todd Miller, Theo de Raadt, Ken Westerback @@ -137,26 +137,33 @@ __EOT # also allow a way to enter non-BSD partitions (but don't newfs!) # Get the list of BSD partitions and store sizes _npartitions=0 - for _p in `disklabel ${DISK} 2>&1 | grep '^ *[a-p]:.*BSD' | sed 's/^ *\([a-p]\): *\([0-9][0-9]*\) .*/\1\2/'`; do - _pp=`firstchar ${_p}` - if [ "${DISK}" = "${ROOTDISK}" -a "$_pp" = "a" ]; then - continue - fi - _ps=`echo ${_p} | sed 's/^.//'` - _partitions[${_npartitions}]=${_pp} - _psizes[${_npartitions}]=${_ps} + + # XXX - It would be nice to just pipe the output of sed to a + # 'while read _pp _ps' loop, but our 'sh' runs the last + # element of a pipeline in a subshell and the required side + # effects to _partitions, _npartitions, etc. would be lost. + for _p in $(disklabel ${DISK} 2>&1 | sed -ne '/^ *\([a-p]\): *\([0-9][0-9]*\).*BSD.*/s//\1\2/p'); do + # All characters after the initial [a-p] are the partition size + _ps=${_p#?} + # Removing the partition size leaves us with the partition name + _pp=${_p%${_ps}} + + [ "$DISK" = "$ROOTDISK" -a "$_pp" = "a" ] && continue + + _partitions[$_npartitions]=$_pp + _psizes[$_npartitions]=$_ps # If the user assigned a mount point, use it. - if [ -f /tmp/fstab.${DISK} ]; then - _mount_points[${_npartitions}]=`sed -n "s:^/dev/$DISK$_pp[ ]*\([^ ]*\).*:\1:p" < /tmp/fstab.${DISK}` + if [ -f /tmp/fstab.$DISK ]; then + _mount_points[$_npartitions]=`sed -n "s:^/dev/${DISK}${_pp}[ ]*\([^ ]*\).*:\1:p" < /tmp/fstab.${DISK}` fi - _npartitions=$(( ${_npartitions} + 1 )) + : $(( _npartitions += 1 )) done # Now prompt the user for the mount points. Loop until "done" echo _i=0 - resp=X - while [ $_npartitions -gt 0 -a X${resp} != X"done" ]; do + resp= + while [ $_npartitions -gt 0 -a "$resp" != "done" ]; do _pp=${_partitions[${_i}]} _ps=$(( ${_psizes[${_i}]} / 2 )) _mp=${_mount_points[${_i}]} diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index 063e9a6102f..13d10712f04 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: install.sub,v 1.206 2002/04/20 13:42:52 krw Exp $ +# $OpenBSD: install.sub,v 1.207 2002/04/26 02:14:23 krw Exp $ # $NetBSD: install.sub,v 1.5.2.8 1996/09/02 23:25:02 pk Exp $ # # Copyright (c) 1997-2002 Todd Miller, Theo de Raadt, Ken Westerback @@ -196,16 +196,6 @@ cutlast () { eval echo \$$# } -# return first character of argument -firstchar () { - local _a=$1 - - while [ ${#_a} != 1 ]; do - _a=${_a%?} - done - echo $_a -} - basename () { local _oifs @@ -418,7 +408,7 @@ __EOT # $1 - IP address # $2 - symbolic name addhostent() { - sed "/ $2\$/d" < /tmp/hosts > /tmp/hosts.new + sed "/ $2\$/d" /tmp/hosts > /tmp/hosts.new mv /tmp/hosts.new /tmp/hosts echo "$1 $2" >> /tmp/hosts @@ -1182,14 +1172,13 @@ __EOT -a ${resp:-0} -ge 1 \ -a -f /tmp/ftplist ] then - maxlines=`grep "^${_url_type}:" /tmp/ftplist | cat -n | - sed -n -e '$p' | cutword 1` + maxlines=`grep "^${_url_type}:" /tmp/ftplist | sed -ne '$='` if [ $maxlines -lt $resp ]; then echo "There is no ${resp}th line in the list." resp= continue fi - tline=`grep "^${_url_type}:" /tmp/ftplist | sed -n -e "${resp}p"` + tline=`grep "^${_url_type}:" /tmp/ftplist | sed -ne "${resp}p"` url=`echo $tline | sed -e "s/^${_url_type}:\/\///" | cutword -t' ' 1 | cutword -t' ' 1` host=`echo $url | cutword -t/ 1` @@ -2031,7 +2020,7 @@ get_fqdn() { # 1.2.3.4 hostname # to # 1.2.3.4 hostname.$FQDN hostname - sed "s/\\(.*\\)[[:space:]]\\(.*\\)\$/\\1 \\2.$FQDN \\2/" < $2 > $2.new + sed "s/\\(.*\\)[[:space:]]\\(.*\\)\$/\\1 \\2.$FQDN \\2/" $2 > $2.new mv $2.new $2 else echo -n "Enter DNS domain name (e.g. 'bar.com'): [$FQDN] " @@ -2101,9 +2090,11 @@ __EOT # override a user supplied (or previous DHCP supplied) FQDN. get_fqdn /tmp/resolv.conf /tmp/hosts - resp=`route -n show | - grep '^default' | - sed -e 's/^default *//' -e 's/ .*//'` + resp=`route -n show | sed -ne '/^default */{ + s/// + s/ .*// + p + }'` if [ -z "$resp" ] ; then resp=none if [ -f /tmp/mygate ]; then @@ -2125,8 +2116,7 @@ __EOT resp=none if [ -f /tmp/resolv.conf ]; then resp= - for n in `grep '^nameserver ' /tmp/resolv.conf | \ - sed -e 's/^nameserver //'` + for n in `sed -ne '/^nameserver /s///p' /tmp/resolv.conf` do if [ -z "$resp" ] ; then resp=$n |