[25493] in Source-Commits
/svn/athena r25023 - trunk/debathena/config/recovery-mode-config/debian
daemon@ATHENA.MIT.EDU (Jonathan D Reed)
Fri Mar 11 22:35:50 2011
Date: Fri, 11 Mar 2011 22:35:44 -0500
From: Jonathan D Reed <jdreed@MIT.EDU>
Message-Id: <201103120335.p2C3ZiZ2000745@drugstore.mit.edu>
To: source-commits@mit.edu
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Author: jdreed
Date: 2011-03-11 22:35:44 -0500 (Fri, 11 Mar 2011)
New Revision: 25023
Added:
trunk/debathena/config/recovery-mode-config/debian/netparams
trunk/debathena/config/recovery-mode-config/debian/require_network.sh
Modified:
trunk/debathena/config/recovery-mode-config/debian/athena-renumber
trunk/debathena/config/recovery-mode-config/debian/athena-update
trunk/debathena/config/recovery-mode-config/debian/changelog
trunk/debathena/config/recovery-mode-config/debian/debathena-recovery-mode-config.install
Log:
In recovery-mode-config:
* Don't poweroff, reboot, since kexec is nolonger an issue (Trac #759)
* Make athena-update functional by requiring network (Trac #759)
* Make athena-renumber less stupid
Modified: trunk/debathena/config/recovery-mode-config/debian/athena-renumber
===================================================================
--- trunk/debathena/config/recovery-mode-config/debian/athena-renumber 2011-03-12 00:11:39 UTC (rev 25022)
+++ trunk/debathena/config/recovery-mode-config/debian/athena-renumber 2011-03-12 03:35:44 UTC (rev 25023)
@@ -1,147 +1,128 @@
-#!/usr/bin/perl -w
+#!/bin/sh
#
-# A script to change the IP/hostname on a cluster machine
-# jdreed@mit.edu
+# Change the IP/hostname on cluster machines
+#
-use strict;
-use Socket;
-use File::Copy;
-use Getopt::Std;
+# Required for recovery-mode scripts
+if [ "$1" = "test" ]; then
+ echo "Change IP address or hostname"
+ exit 0
+fi
-# sulogin gets upset if it gets a ^C
-$SIG{'INT'} = 'bail';
+if [ "$(id -u)" != "0" ]; then
+ echo "This script must be run as root."
+ exit 0
+fi
-my $MASKS="/usr/share/debathena-recovery-mode-config/masks";
-if (defined($ARGV[0]) && ($ARGV[0] eq 'test')) {
- print "Change IP address or hostname\n";
- exit 0;
+# Blatantly stolen from the installer
+ask() {
+ answer=''
+ while [ y != "$answer" -a n != "$answer" ]; do
+ echo -n "$1"
+ read answer
+ [ Y = answer ] && answer=y
+ [ N = answer ] && answer=n
+ [ -z "$answer" ] && answer=$2
+ done
}
-sub confirm {
- my $question = shift || "Continue?";
- print "${question} (y/n) ";
- my $ans = <STDIN>;
- return ($ans =~ m/^y$/i);
-}
-
-sub bail {
- if ($_[0] eq 'INT') {
- print "\nCancelled.";
- } else {
- print shift;
- }
- print "\n\n(press ENTER to return to the recovery mode menu)\n";
- my $dummy = <STDIN>;
+bail() {
+ echo
+ echo "Cancelled. Press Enter to the menu."
+ read dummy
exit 0;
}
-sub mask {
- my $ip = shift;
- my $mask = shift;
- my $mbits = pack("B*", (1 x $mask) . (0 x (32 - $mask)));
- my $ibits = pack("CCCC", split(/\./, $ip));
- my $net = $ibits & $mbits;
- return join('.', unpack("CCCC", $net));
-}
+# sulogin gets upset if it gets a ^C
+trap bail INT
-sub cidr2ip {
- my $cidr = shift;
- return join('.', unpack("CCCC", pack("B*", (1 x $cidr) . (0 x (32 - $cidr)))));
-}
+PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
-sub validIP {
- my $ip = shift;
- if ($ip =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) {
- if (scalar(grep { ($_ <= 255) && ($_ >= 0) } ($1, $2, $3, $4)) == 4) {
- return 1;
- }
- }
- return 0;
-}
+if [ "$DEBATHENA_DEBUG" = "1" ]; then
+ echo "**********\nDEBUG MODE\n**********"
+ MASKS="$(pwd)/masks";
+ NETPARAMS="$(pwd)/netparams";
+ . "$(pwd)/require_network.sh"
+else
+ MASKS="/usr/share/debathena-recovery-mode-config/masks";
+ NETPARAMS="/usr/share/debathena-recovery-mode-config/netparams";
+ . /usr/share/debathena-recovery-mode-config/require_network.sh
+fi
-# main
+if [ "$DEBATHENA_DEBUG" != "1" ] && \
+ [ "$(machtype -L)" != "debathena-cluster" ]; then
+ echo "WARNING: This script is designed for debathena-cluster machines"
+ echo "but this machine is running $(machtype -L).\n";
+ ask "Are you SURE you want to continue? (y/N) " n
+ if [ "$answer" = "n" ]; then
+ exit 0
+ fi
+fi
-# Sanity checks
-foreach (qw(/etc/network/interfaces /etc/hosts /etc/hostname)) {
- (-w $_) || bail("Cannot write to $_. (Are you root?)");
-}
+echo "Testing networking, please wait..."
+if ! require_network; then
+ echo "Can't verify that networking is available. If you continue,"
+ ask "errors may occur. Continue? (y/N) " n
+ if [ "$answer" = "n" ]; then
+ exit 0
+ fi
+fi
-(-r $MASKS) || bail("Cannot read $MASKS");
+while true; do
+ while [ -z "$IPADDR" ] ; do
+ echo -n "Enter IP address: "
+ read IPADDR
+ done
-my $machtype = `machtype -L`;
-chomp($machtype);
-if ($machtype ne 'debathena-cluster') {
- print "WARNING: This script is designed for debathena-cluster machines but\n";
- print "this machine is running $machtype.\n";
- confirm("Are you SURE you want to continue?") || bail("OK, cancelled.");
-}
+ NETMASK=`$NETPARAMS -f $MASKS $IPADDR|cut -d\ -f 1`
+ GATEWAY=`$NETPARAMS -f $MASKS $IPADDR|cut -d\ -f 4`
-my $ip = '';
-until (validIP($ip)) {
- if ($ip) {
- print "Invalid IP address ($ip). Try again.\n";
- }
- print "Enter the new IP address: ";
- ($ip = <STDIN>) =~ s/\s//g;
-}
-print "Looking up hostname...";
-my $fqdn = gethostbyaddr(inet_aton($ip), AF_INET);
-if ($fqdn) {
- print " found.\n";
-} else {
- $fqdn = '';
- print " not found.\n";
- until ($fqdn =~ /^[a-z][\w\-\.]*/i) {
- print "Please enter the machine's new hostname: ";
- ($fqdn = <STDIN>) =~ s/\s//g;
- }
-}
-$fqdn = lc($fqdn);
-my $hostname = $fqdn;
-if ($fqdn =~ /\./) {
- $hostname = (split(/\./, $fqdn))[0];
-} else {
- print "NOTE: No domain specified, assuming 'mit.edu'";
- $fqdn = "${hostname}.mit.edu";
-}
+ echo "Address: $IPADDR"
+ echo
+ echo "Autoconfigured settings:"
+ echo " Netmask: $NETMASK"
+ echo " Gateway: $GATEWAY"
+ echo
+ ask "Is this correct? (Y/n) " y
+ [ "$answer" = "y" ] || continue
+ echo "Looking up hostname...";
+ FQDN="$(dig +short -x $IPADDR 2>/dev/null | sed -e 's/.$//')"
+ if [ $? != 0 ]; then
+ echo "Unable to look up hostname. You may enter it below"
+ echo "but beware that typos may render your machine unusable."
+ FQDN=
+ while [ -z "$FQDN" ] ; do
+ echo -n "Enter hostname: "
+ read FQDN
+ FQDN="$(echo $FQDN | tr -d ' ')"
+ if echo "$FQDN" | egrep -qi "[^a-z0-9_-\.]"; then
+ echo "Invalid characters in hostname, try again."
+ FQDN=
+ fi
+ done
+ fi
+ if ! echo "$FQDN" | grep -qi "MIT.EDU$"; then
+ FQDN="$FQDN.MIT.EDU"
+ fi
+ echo "Hostname: $FQDN"
+ ask "Is this correct? (Y/n) " y
+ if [ "$answer" = "y" ]; then
+ break
+ fi
+done
+HOSTNAME="$(echo "$FQDN" | cut -d. -f 1)"
+DOMAIN="$(echo "$FQDN" | sed 's/[^\.]*\.//')"
+if [ "$DEBATHENA_DEBUG" = "1" ]; then
+ echo "$IPADDR $NETMASK $GATEWAY $HOSTNAME $DOMAIN $FQDN"
+ echo "Done!"
+ exit 0
+fi
+echo "Updating /etc/network/interfaces..."
+mv -f "/etc/network/interfaces" "/etc/network/interfaces.old"
+cat <<EOF >/etc/network/interfaces
+# This file was created by athena-renumber
-my ($subnetmask, $gateway);
-print "Looking up netmask information...\n";
-open(MASKS, $MASKS) || bail("Cannot read $MASKS: $!");
-while (<MASKS>) {
- next if (/^#/);
- next unless (/\d/);
- my ($addr, $sbits, $mbits, $gw) = split(' '); #the ' ' pattern emulates awk
- if (mask($ip, $sbits) eq $addr) {
- $subnetmask = cidr2ip($mbits);
- if (! $gw) {
- my @octets = split(/\./, mask($ip, $mbits));
- my $trailing = pop(@octets) + 1;
- $gateway = join('.', @octets, $trailing);
- } else {
- $gateway = $gw;
- }
- last;
- }
-}
-(defined($subnetmask) && defined($gateway)) || bail("Could not find a matching line in masks file for $ip.\nIf you are sure you typed the IP address correctly, please report\nthis error to IS&T, along with the IP address you were trying to use.");
-
-close(MASKS);
-print "IP address: $ip\n";
-print "Subnet Mask: $subnetmask\n";
-print "Gateway: $gateway\n";
-print "Hostname: $hostname\n";
-print "FQDN: $fqdn\n\n";
-
-confirm("Does that look correct?") || bail("OK, cancelled.");
-
-print "Updating /etc/network/interfaces...\n";
-copy("/etc/network/interfaces", "/etc/network/interfaces.old") || bail("Could not copy /etc/network/interfaces");
-open(INTERFACES, ">/etc/network/interfaces") || bail ("Could not overwrite /etc/network/interfaces: $!");
-print INTERFACES <<"ENDINTERFACES";
-# This file was created by $0
-
# The loopback interface
auto lo
iface lo inet loopback
@@ -149,19 +130,15 @@
# The primary network interface
auto eth0
iface eth0 inet static
- address $ip
- netmask $subnetmask
- gateway $gateway
+ address $IPADDR
+ netmask $NETMASK
+ gateway $GATEWAY
dns-nameservers 18.70.0.160 18.71.0.151 18.72.0.3
-ENDINTERFACES
-close(INTERFACES);
-
-print "Updating /etc/hosts...\n";
-
-copy("/etc/hosts", "/etc/hosts.old") || bail("Could not copy /etc/hosts");
-open(HOSTS, ">/etc/hosts") || bail ("Could not overwrite /etc/hosts: $!");
-print HOSTS <<"ENDHOSTS";
-# This file was created by $0
+EOF
+echo "Updating /etc/hosts..."
+mv -f "/etc/hosts" "/etc/hosts.old"
+cat <<EOF >/etc/hosts
+# This file was created by athena-renumber
127.0.0.1 localhost
127.0.1.1 $fqdn $hostname
@@ -172,23 +149,18 @@
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
-ENDHOSTS
-close(HOSTS);
-
-print "Updating /etc/hostname...\n";
-copy("/etc/hostname", "/etc/hostname.old") || bail("Could not copy /etc/hostname");
-open(HOSTNAME, ">/etc/hostname") || bail ("Could not overwrite /etc/hostname: $!");
-print HOSTNAME "$hostname\n";
-close(HOSTNAME);
-
-print "Setting hostname...\n";
-system("/bin/hostname", $hostname);
-print "\nDone! You will need to reboot the workstation for the\n";
-print "changes to take effect.\n";
-confirm("Would you like to reboot now?") || bail("Please perform a full shutdown and reboot as soon as possible.");
-print "The workstation will now power down completely.\n";
-print "When you turn it back on, it will use the new IP address.\n\n";
-print "(press ENTER to power down the workstation)";
-getc(STDIN);
-system("/sbin/poweroff");
-exit 0;
+EOF
+echo "Updating /etc/hostname..."
+mv -f /etc/hostname /etc/hostname.old
+echo $HOSTNAME > /etc/hostname
+echo "Setting hostname...";
+hostname $HOSTNAME
+echo
+echo "Done! You will need to reboot the workstation for the changes to take effect."
+ask "Would you like to reboot now? (Y/n) " y
+if [ "$answer" = "n" ]; then
+ echo "Please perform a full shutdown and reboot as soon as possible."
+ echo "(Press Enter to return to the menu)"
+ exit 0
+fi
+reboot
Modified: trunk/debathena/config/recovery-mode-config/debian/athena-update
===================================================================
--- trunk/debathena/config/recovery-mode-config/debian/athena-update 2011-03-12 00:11:39 UTC (rev 25022)
+++ trunk/debathena/config/recovery-mode-config/debian/athena-update 2011-03-12 03:35:44 UTC (rev 25023)
@@ -17,8 +17,17 @@
exit 0
fi
-# Unloading kexec doesn't work, awesome. Use new -n option to prevent
-# auto-update from rebooting
+. /usr/share/debathena-recovery-mode-config/require_network.sh
+
+echo "Testing networking, please wait..."
+if ! require_network; then
+ echo "Can't verify that networking is available. If you continue,"
+ ask "errors may occur. Continue? (y/N) " n
+ if [ "$answer" = "n" ]; then
+ exit 0
+ fi
+fi
+
echo "Running auto-updater, please wait..."
/usr/sbin/athena-auto-update -n
if [ $? != 0 ]; then
@@ -26,12 +35,11 @@
read dummy
exit 0
fi
-ask "The workstation needs to be shut down and rebooted. Do that now? (y/n) " y
+# We can just return to the menu and resume boot once LP:436936 gets fixed
+ask "The workstation needs to be rebooted. Do that now? (Y/n) " y
if [ "$answer" = "y" ]; then
- echo "The workstation will now shut down. You can then turn it back on."
- echo "(Press Enter to continue)"
- read dummy
- /sbin/poweroff
+ /sbin/reboot
fi
-echo "Please shut down as soon as possible. Press Enter to return to the menu."
+echo "Please reboot as soon as possible. Press Enter to return to the menu."
read dummy
+exit 0
Modified: trunk/debathena/config/recovery-mode-config/debian/changelog
===================================================================
--- trunk/debathena/config/recovery-mode-config/debian/changelog 2011-03-12 00:11:39 UTC (rev 25022)
+++ trunk/debathena/config/recovery-mode-config/debian/changelog 2011-03-12 03:35:44 UTC (rev 25023)
@@ -1,10 +1,10 @@
debathena-recovery-mode-config (1.3) unstable; urgency=low
- * Divert /usr/share/recovery-mode/options/netroot so that it actually
- works rather than just running dhclient and hoping for the best
- * Fix typo in athena-update
+ * Don't poweroff, reboot, since kexec is nolonger an issue (Trac #759)
+ * Make athena-update functional by requiring network (Trac #759)
+ * Make athena-renumber less stupid
- -- Jonathan Reed <jdreed@mit.edu> Thu, 17 Feb 2011 10:39:47 -0500
+ -- Jonathan Reed <jdreed@mit.edu> Fri, 11 Mar 2011 22:32:36 -0500
debathena-recovery-mode-config (1.2.1) unstable; urgency=low
Modified: trunk/debathena/config/recovery-mode-config/debian/debathena-recovery-mode-config.install
===================================================================
--- trunk/debathena/config/recovery-mode-config/debian/debathena-recovery-mode-config.install 2011-03-12 00:11:39 UTC (rev 25022)
+++ trunk/debathena/config/recovery-mode-config/debian/debathena-recovery-mode-config.install 2011-03-12 03:35:44 UTC (rev 25023)
@@ -1,3 +1,5 @@
debian/athena-update usr/share/recovery-mode/options
debian/athena-renumber usr/share/recovery-mode/options
debian/masks usr/share/debathena-recovery-mode-config
+debian/netparams usr/share/debathena-recovery-mode-config
+debian/require_network.sh usr/share/debathena-recovery-mode-config
Added: trunk/debathena/config/recovery-mode-config/debian/netparams
===================================================================
--- trunk/debathena/config/recovery-mode-config/debian/netparams (rev 0)
+++ trunk/debathena/config/recovery-mode-config/debian/netparams 2011-03-12 03:35:44 UTC (rev 25023)
@@ -0,0 +1,261 @@
+#!/bin/sh
+# $Id: netparams.sh,v 1.2 1998/05/17 03:25:03 ghudson Exp $
+
+# Usage: netparams [-d defaultbits] [-e] [-f file] address ...
+#
+# Computes the netmask for each address and outputs the netmask,
+# network, broadcast address, and gateway address. Options are:
+#
+# -d defaultbits Give the default number of bits to use if an
+# IP address is not located on the file. The
+# default is 24.
+#
+# -e Error if an IP address is not located in the
+# file.
+#
+# -f file Give the masks filename to use. The default
+# is the concatenation of /etc/athena/masks.local
+# (if it exists) and /etc/athena/masks.
+#
+# The format of each line of the masks file is:
+#
+# address significant-bits mask-bits [gateway]
+#
+# The first <significant-bits> of <address> are compared against the
+# given IP address. If they match, <mask-bits> is the number of bits
+# in the netmask, and <gateway> is the gateway address if given. (If
+# gateway is not given, it is assumed to be one greater than the
+# network address.) The first match in the file is taken. Blank lines
+# and lines beginning with a '#' are ignored.
+
+# This script may want to run before /usr is mounted on BSD-ish
+# systems, so it uses a very limited set of external commands (expr,
+# test, echo). If you want to use a command not in that set, make
+# sure it lives in /bin or /sbin in BSD 4.4.
+
+# Regular expression to match things that looklike IP addresss.
+ipreg='[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$'
+
+# Usage message
+usage="$0 [-f file] [-d defaultbits] [-e] address ..."
+
+# octet <ip address> sets o1..o4 to the octets of the address.
+octets() {
+ OLDIFS="$IFS"
+ IFS=.
+ set -- $1
+ o1=$1 o2=$2 o3=$3 o4=$4
+ IFS="$OLDIFS"
+}
+
+# octetbits <n> splits <n> up into four values b1..b4 each between 0
+# and 8. If you want the first n bits of a 32-bit value, then you
+# want the first b1..b4 bits of the corresponding octets.
+octetbits() {
+ case "$1" in
+ 0) b1=0; b2=0; b3=0; b4=0 ;;
+ 1) b1=1; b2=0; b3=0; b4=0 ;;
+ 2) b1=2; b2=0; b3=0; b4=0 ;;
+ 3) b1=3; b2=0; b3=0; b4=0 ;;
+ 4) b1=4; b2=0; b3=0; b4=0 ;;
+ 5) b1=5; b2=0; b3=0; b4=0 ;;
+ 6) b1=6; b2=0; b3=0; b4=0 ;;
+ 7) b1=7; b2=0; b3=0; b4=0 ;;
+ 8) b1=8; b2=0; b3=0; b4=0 ;;
+ 9) b1=8; b2=1; b3=0; b4=0 ;;
+ 10) b1=8; b2=2; b3=0; b4=0 ;;
+ 11) b1=8; b2=3; b3=0; b4=0 ;;
+ 12) b1=8; b2=4; b3=0; b4=0 ;;
+ 13) b1=8; b2=5; b3=0; b4=0 ;;
+ 14) b1=8; b2=6; b3=0; b4=0 ;;
+ 15) b1=8; b2=7; b3=0; b4=0 ;;
+ 16) b1=8; b2=8; b3=0; b4=0 ;;
+ 17) b1=8; b2=8; b3=1; b4=0 ;;
+ 18) b1=8; b2=8; b3=2; b4=0 ;;
+ 19) b1=8; b2=8; b3=3; b4=0 ;;
+ 20) b1=8; b2=8; b3=4; b4=0 ;;
+ 21) b1=8; b2=8; b3=5; b4=0 ;;
+ 22) b1=8; b2=8; b3=6; b4=0 ;;
+ 23) b1=8; b2=8; b3=7; b4=0 ;;
+ 24) b1=8; b2=8; b3=8; b4=0 ;;
+ 25) b1=8; b2=8; b3=8; b4=1 ;;
+ 26) b1=8; b2=8; b3=8; b4=2 ;;
+ 27) b1=8; b2=8; b3=8; b4=3 ;;
+ 28) b1=8; b2=8; b3=8; b4=4 ;;
+ 29) b1=8; b2=8; b3=8; b4=5 ;;
+ 30) b1=8; b2=8; b3=8; b4=6 ;;
+ 31) b1=8; b2=8; b3=8; b4=7 ;;
+ 32) b1=8; b2=8; b3=8; b4=8 ;;
+ esac
+}
+
+# mask8 <o> <b> sets a8 to the first <b> bits of <o>.
+mask8() {
+ case "$2" in
+ 0) a8=0 ;;
+ 1) a8=`expr "$1" - "$1" % 128` ;;
+ 2) a8=`expr "$1" - "$1" % 64` ;;
+ 3) a8=`expr "$1" - "$1" % 32` ;;
+ 4) a8=`expr "$1" - "$1" % 16` ;;
+ 5) a8=`expr "$1" - "$1" % 8` ;;
+ 6) a8=`expr "$1" - "$1" % 4` ;;
+ 7) a8=`expr "$1" - "$1" % 2` ;;
+ 8) a8=$1 ;;
+ esac
+}
+
+# fill8 <o> <b> sets a8 to <o> with the last 8-<b> bits set to 1.
+fill8() {
+ case "$2" in
+ 0) a8=255 ;;
+ 1) a8=`expr "$1" - "$1" % 128 + 127` ;;
+ 2) a8=`expr "$1" - "$1" % 64 + 63` ;;
+ 3) a8=`expr "$1" - "$1" % 32 + 31` ;;
+ 4) a8=`expr "$1" - "$1" % 16 + 15` ;;
+ 5) a8=`expr "$1" - "$1" % 8 + 7` ;;
+ 6) a8=`expr "$1" - "$1" % 4 + 3` ;;
+ 7) a8=`expr "$1" - "$1" % 2 + 1` ;;
+ 8) a8=$1 ;;
+ esac
+}
+
+# mask <ip address> <n> sets a to the first <n> bits of <ip address>.
+# If a third parameter is given, add 1 to the last octet (to get the
+# gateway address).
+mask() {
+ a=""
+ octets "$1"
+ octetbits "$2"
+ mask8 "$o1" "$b1"
+ a=$a8
+ mask8 "$o2" "$b2"
+ a=$a.$a8
+ mask8 "$o3" "$b3"
+ a=$a.$a8
+ mask8 "$o4" "$b4"
+ if [ -n "$3" ]; then
+ a8=`expr "$a8" + 1`
+ fi
+ a=$a.$a8
+}
+
+# fill <ip address> <n> sets a to <ip address> with the last 32-<n> bits
+# set to 1.
+fill() {
+ a=""
+ octets "$1"
+ octetbits "$2"
+ fill8 "$o1" "$b1"
+ a=$a8
+ fill8 "$o2" "$b2"
+ a=$a.$a8
+ fill8 "$o3" "$b3"
+ a=$a.$a8
+ fill8 "$o4" "$b4"
+ a=$a.$a8
+}
+
+# getnetmask <ip address> <file> sets maskbits to the number of netmask
+# bits for <ip address> according to <file>. Also sets gateway to the
+# gateway field on the matching line, if one was specified.
+getnetmask() {
+ exec < $2
+ maskbits=""
+ while read addr sigbits mbits gw; do
+ # Ignore blank lines and comments.
+ if [ -z "$addr" -o `expr "$addr" : '#'` -ne 0 ]; then
+ continue
+ fi
+
+ # Make sure the line is in the proper form.
+ if [ `expr "$addr" : "$ipreg"` -eq 0 \
+ -o `expr "$sigbits" : '[0-9][0-9]*$'` -eq 0 \
+ -o `expr "$mbits" : '[0-9][0-9]*$'` -eq 0 ]; then
+ echo "Bad line in $2: $addr $sigbits $mbits $gw" 1>&2
+ exit 1
+ fi
+ if [ -n "$gw" -a `expr "$gw" : "$ipreg"` -eq 0 ]; then
+ echo "Bad gateway in $2: $gw" 1>&2
+ exit 1
+ fi
+
+ mask "$1" "$sigbits"
+ if [ "$a" = "$addr" ]; then
+ maskbits=$mbits
+ gateway=$gw
+ break
+ fi
+ done
+}
+
+# Process arguments.
+defaultbits=24
+errornf=false
+maskfile=""
+while getopts d:ef: opt; do
+ case "$opt" in
+ d)
+ defaultbits=$OPTARG
+ ;;
+ e)
+ errornf=true
+ ;;
+ f)
+ maskfile=$OPTARG
+ ;;
+ \?)
+ echo "$usage"
+ exit 1
+ ;;
+ esac
+done
+shift `expr $OPTIND - 1`
+
+# Make sure we have some addresses.
+if [ $# -eq 0 ]; then
+ echo "Usage: $0 ip-address ..." 1>&2
+ exit 1
+fi
+
+# Make sure our addresses are in something like the proper format.
+for ip in "$@"; do
+ if [ `expr "$ip" : "$ipreg"` -eq 0 ]; then
+ echo "Bad address: $ip" 1>&2
+ echo "Usage: $0 ip-address ..." 1>&2
+ exit 1
+ fi
+done
+
+for ip in "$@"; do
+ if [ -n "$maskfile" ]; then
+ getnetmask "$ip" "$maskfile"
+ elif [ -f /etc/athena/masks.local ]; then
+ getnetmask "$ip" /etc/athena/masks.local
+ if [ -z "$maskbits" ]; then
+ getnetmask "$ip" /etc/athena/masks
+ fi
+ else
+ getnetmask "$ip" /etc/athena/masks
+ fi
+ if [ -z "$maskbits" ]; then
+ # Error out if we were told to, or guess.
+ if [ "$errornf" = true ]; then
+ echo "$ip not matched." 1>&2
+ exit 1
+ fi
+ maskbits=$defaultbits
+ fi
+
+ mask 255.255.255.255 "$maskbits"
+ netmask=$a
+ mask "$ip" "$maskbits"
+ network=$a
+ fill "$ip" "$maskbits"
+ broadcast=$a
+ if [ -z "$gateway" ]; then
+ mask "$ip" "$maskbits" 1
+ gateway=$a
+ fi
+
+ echo "$netmask $network $broadcast $gateway $maskbits"
+done
Property changes on: trunk/debathena/config/recovery-mode-config/debian/netparams
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/debathena/config/recovery-mode-config/debian/require_network.sh
===================================================================
--- trunk/debathena/config/recovery-mode-config/debian/require_network.sh (rev 0)
+++ trunk/debathena/config/recovery-mode-config/debian/require_network.sh 2011-03-12 03:35:44 UTC (rev 25023)
@@ -0,0 +1,28 @@
+# This is sourced by sh, not executed
+#
+# Ensure that networking is up
+
+require_network() {
+ # Ensure that eth0 is up
+ ifup eth0 2>/dev/null
+ gw=$(route -n | grep ^0.0.0.0\ | awk '{print $2}')
+ if [ -z "$gw" ]; then
+ echo "Something is wrong with the networking config (no default route)"
+ return 1
+ fi
+ # Re-verify connection to gateway... one ping only.
+ ping -w 5 -c 1 $gw >/dev/null 2>&1
+ if [ $? != 0 ]; then
+ echo "Could not ping gateway after trying for 5 seconds"
+ return 1
+ fi
+ if ! grep nameserver /etc/resolv.conf | grep -qv 127.0.0.1$; then
+ echo "Trying to start bind..."
+ service bind9 start
+ fi
+ host web.mit.edu >/dev/null 2>&1
+ if [ $? != 0 ]; then
+ echo "Couldn't look up web.mit.edu - DNS may be broken"
+ return 1
+ fi
+}