[25749] in Source-Commits
Re: /svn/athena r25207 -
daemon@ATHENA.MIT.EDU (Benjamin Kaduk)
Sat Jul 2 19:56:12 2011
Date: Sat, 2 Jul 2011 19:56:04 -0400 (EDT)
From: Benjamin Kaduk <kaduk@MIT.EDU>
To: Jonathan D Reed <jdreed@MIT.EDU>
cc: source-commits@MIT.EDU
In-Reply-To: <201106301913.p5UJDOPJ004525@drugstore.mit.edu>
Message-ID: <alpine.GSO.1.10.1107021943590.6818@multics.mit.edu>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
On Thu, 30 Jun 2011, Jonathan D Reed wrote:
> Author: jdreed
> Date: 2011-06-30 15:13:24 -0400 (Thu, 30 Jun 2011)
> New Revision: 25207
>
> Modified:
> trunk/debathena/scripts/installer/pxe/stage1/debathena/installer.sh
> Log:
> Attempt to support DNS in the installer (Trac: #622 and #897)
>
> Modified: trunk/debathena/scripts/installer/pxe/stage1/debathena/installer.sh
> ===================================================================
> --- trunk/debathena/scripts/installer/pxe/stage1/debathena/installer.sh 2011-06-30 17:55:42 UTC (rev 25206)
> +++ trunk/debathena/scripts/installer/pxe/stage1/debathena/installer.sh 2011-06-30 19:13:24 UTC (rev 25207)
> @@ -1,5 +1,7 @@
> #!/bin/sh
>
> +dnscgi="http://18.9.60.73/website/dns.cgi"
> +
> test=
> if [ "$1" = "--test" ]; then
> test="test"
> @@ -16,13 +18,59 @@
> echo "Configuring network..."
> mp=/debathena
> if [ "$test" = "test" ]; then
> - mp="`dirname $0`/$mp"
> + mp="`dirname $0`"
> fi
> - export IPADDR NETMASK GATEWAY SYSTEM CONTROL
> + export IPADDR NETMASK GATEWAY SYSTEM CONTROL HOSTNAME
> + # This will fail if dhreg addresses ever stop being able to reach net 18
> + # First make sure we're talking to who we think we are
> + havedns=n
> + ipprompt="Enter IP address:"
> + if [ "$(wget -qO - $dnscgi"/q")" = "Debathena DNS-CGI" ]; then
We hardcode dnscgi, so I'll let the lack of quotes around it slide.
> + havedns=y
> + ipprompt="Enter IP address or hostname:"
> + fi
> +
> while [ -z "$IPADDR" ] ; do
> - echo -n "Enter IP address: "
> + HOSTNAME=
> + echo -n "$ipprompt "
> read IPADDR
> + # RFC1123 does permit hostnames to start with digits, moira doesn't
> + # If you do that, suck it up and type the IP
> + if echo "$IPADDR" | grep -q '[a-zA-Z]'; then
> + HOSTNAME="$IPADDR"
> + IPADDR=
> + if [ "$havedns" != "y" ]; then
> + echo "Enter a valid IP address. (DNS not available)".
> + continue
> + fi
> + echo "Looking up IP for $HOSTNAME..."
> + dig="$(wget -qO - $dnscgi"/a/$HOSTNAME")"
The dnscgi usage tells me that only 'A' and 'PTR' are acceptable!
(But this works, so.)
> + if echo $dig | grep -q '^OK:'; then
> + IPADDR="$(echo "$dig" | sed 's/^OK: //')"
> + echo "Found $IPADDR..."
> + else
> + echo $dig
This one should perhaps have quotes, though. (echo only takes one
argument, so injection isn't really an issue. But it is foreign input.
"For the whitespace-preservation, Montressor!")
> + echo "Could not look up IP address for $HOSTNAME. Try again."
> + fi
> + fi
> done
> +
> + if [ -z "$HOSTNAME" ] && [ "$havedns" = "y" ]; then
> + dig="$(wget -qO - $dnscgi"/ptr/$IPADDR")"
> + if echo $dig | grep -q '^OK:'; then
> + HOSTNAME="$(echo "$dig" | sed 's/^OK: //')"
> + echo "$IPADDR reverse-resolves to $HOSTNAME..."
> + else
> + echo $dig
And here.
> + echo "Could not look up hostname for $IPADDR. Oh well..."
> + fi
> + fi
> + if [ -z "$HOSTNAME" ]; then
> + HOSTNAME=install-target-host
> + fi
> +
> + HOSTNAME="$(echo $HOSTNAME | sed 's/\.MIT\.EDU$//i')"
> +
> NETMASK=`$mp/athena/netparams -f $mp/athena/masks $IPADDR|cut -d\ -f 1`
> net=`$mp/athena/netparams -f $mp/athena/masks $IPADDR|cut -d\ -f 2`
> bc=`$mp/athena/netparams -f $mp/athena/masks $IPADDR|cut -d\ -f 3`
> @@ -229,11 +277,12 @@
> fi
> dkargs="DEBCONF_DEBUG=5"
>
> -hname=install-target-host
> +hname="$HOSTNAME"
> if [ "$IPADDR" = dhcp ] ; then
> knetinfo="netcfg/get_hostname=$hname "
> else
> # There's no good way to get a hostname here, but the postinstall will deal.
> + # True, but thanks to wget, there's a bad way to get a hostname
Quite so. Thanks for making dns.cgi work!
ACKfully,
Ben
> knetinfo="netcfg/disable_dhcp=true \
> netcfg/get_domain=mit.edu \
> netcfg/get_hostname=$hname \
>
>