diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2002-05-04 22:21:22 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2002-05-04 22:21:22 +0000 |
commit | e83997051c103aa7d5596b705118923addaea95e (patch) | |
tree | 9fbe82cce6ebf9582e373ae70113671eeb80e16e /distrib/miniroot | |
parent | a1fb4e4b7740e6d4b48d151b9a0c73f41e408cbf (diff) |
Clean up the logic in install_url():
a) Eliminate extraneous cat invocations that are piped to
grep by simply calling grep with the file name.
b) Eliminate the only use of isnumeric() by using a ksh'ism
left exposed in sh: '+([0-9])'. Eliminate isnumeric().
c) Test for a http/ftp list index of '0' and treat as an out
of range error rather than an IP address.
d) Reorganize to make smaller and more clear.
Add documentation to sh(1) for ksh patterns that are available.
ok millert@, miod@
Diffstat (limited to 'distrib/miniroot')
-rw-r--r-- | distrib/miniroot/install.sub | 75 |
1 files changed, 33 insertions, 42 deletions
diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index 0e968d4eda1..c8850473e96 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,4 +1,4 @@ -# $OpenBSD: install.sub,v 1.217 2002/04/30 23:26:27 krw Exp $ +# $OpenBSD: install.sub,v 1.218 2002/05/04 22:21:21 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 @@ -187,19 +187,6 @@ cutlast () { eval echo \$\{$#\} } -isnumeric() { - local _a=$1 - - while [ ${#_a} != 0 ]; do - case $_a in - [0-9]*) ;; - *) echo 0; return;; - esac - _a=${_a#?} - done - echo 1; return -} - # return available network devices get_ifdevs() { /sbin/ifconfig -a | egrep -v '^([[:space:]]|(lo|enc|gre|ppp|sl|tun|bridge)[[:digit:]])' | cutword -t: 1 @@ -1069,48 +1056,52 @@ __EOT # ftp.openbsd.org == 129.128.5.191 and will remain at # that address for the forseeable future. ftp ${_ftp_active} -V -a -o /tmp/ftplist ftp://129.128.5.191/pub/OpenBSD/${VERSION_MAJOR}.${VERSION_MINOR}/ftplist > /dev/null - cat /tmp/ftplist | grep "^${_url_type}:" | cat -n | less -XE + grep "^${_url_type}:" /tmp/ftplist | cat -n | less -XE ;; esac - # Get server IP address + # Get server IP address or hostname resp= while [ -z "$resp" ] ; do - if [ -f /tmp/ftplist ]; then - eval ask \"Server IP address, hostname, or list#?\" \"\$_${_url_type}_server_ip\" - else + if [ ! -f /tmp/ftplist ]; then eval ask \"Server IP address, or hostname?\" \"\$_${_url_type}_server_ip\" + continue; fi - if [ "$resp" = "?" -a -f /tmp/ftplist ]; then - cat /tmp/ftplist | grep "^${_url_type}:" | cat -n | less -XE + + eval ask \"Server IP address, hostname, or list#?\" \"\$_${_url_type}_server_ip\" + + case $resp in + "?") + grep "^${_url_type}:" /tmp/ftplist | cat -n | less -XE resp= - elif [ -n "$resp" \ - -a `isnumeric $resp` -eq 1 \ - -a ${resp:-0} -ge 1 \ - -a -f /tmp/ftplist ] - then + ;; + +([0-9])) maxlines=`grep "^${_url_type}:" /tmp/ftplist | sed -ne '$='` - if [ $maxlines -lt $resp ]; then + + if [ $maxlines -lt $resp -o $resp -lt 1 ]; then echo "There is no ${resp}th line in the list." - resp= - continue + else + 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` + path=`echo $url | sed -e "s/^${host}\///"` + path=${path}/${VERSION_MAJOR}.${VERSION_MINOR}/${ARCH} + eval _${_url_type}_server_ip=$host + eval _${_url_type}_server_dir=$path + echo "Using $tline" fi - 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` - path=`echo $url | sed -e "s/^${host}\///"` - path=${path}/${VERSION_MAJOR}.${VERSION_MINOR}/${ARCH} - eval _${_url_type}_server_ip=$host - eval _${_url_type}_server_dir=$path - # do it again, just to double check + + # Always do it again, just to double check resp= - echo "Using $tline" - else - eval _${_url_type}_server_ip=$resp - fi + ;; + *) + ;; + esac done + eval _${_url_type}_server_ip=$resp + # Get server directory if [ "$_url_type" = "ftp" -a -z "$_ftp_server_dir" ] ; then # Default ftp dir |