source: trunk/debathena/config/recovery-mode-config/debian/athena-renumber @ 25023

Revision 25023, 4.2 KB checked in by jdreed, 13 years ago (diff)
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
  • Property svn:executable set to *
Line 
1#!/bin/sh
2#
3# Change the IP/hostname on cluster machines
4#
5
6# Required for recovery-mode scripts
7if [ "$1" = "test" ]; then
8  echo "Change IP address or hostname"
9  exit 0
10fi
11
12if [ "$(id -u)" != "0" ]; then
13    echo "This script must be run as root."
14    exit 0
15fi
16
17
18# Blatantly stolen from the installer
19ask() {
20  answer=''
21  while [ y != "$answer" -a n != "$answer" ]; do
22    echo -n "$1"
23    read answer
24    [ Y = answer ] && answer=y
25    [ N = answer ] && answer=n
26    [ -z "$answer" ] && answer=$2
27  done
28}
29
30bail() {
31    echo
32    echo "Cancelled.  Press Enter to the menu."
33    read dummy
34    exit 0;
35}
36
37# sulogin gets upset if it gets a ^C
38trap bail INT
39
40PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
41
42if [ "$DEBATHENA_DEBUG" = "1" ]; then
43    echo "**********\nDEBUG MODE\n**********"
44    MASKS="$(pwd)/masks";
45    NETPARAMS="$(pwd)/netparams";
46    . "$(pwd)/require_network.sh"
47else
48    MASKS="/usr/share/debathena-recovery-mode-config/masks";
49    NETPARAMS="/usr/share/debathena-recovery-mode-config/netparams";
50    . /usr/share/debathena-recovery-mode-config/require_network.sh
51fi
52
53if [ "$DEBATHENA_DEBUG" != "1" ] && \
54   [ "$(machtype -L)" != "debathena-cluster" ]; then
55    echo "WARNING: This script is designed for debathena-cluster machines"
56    echo "but this machine is running $(machtype -L).\n";
57    ask "Are you SURE you want to continue? (y/N) " n
58    if [ "$answer" = "n" ]; then
59        exit 0
60    fi
61fi
62
63echo "Testing networking, please wait..."
64if ! require_network; then
65    echo "Can't verify that networking is available.  If you continue,"
66    ask "errors may occur.  Continue? (y/N) " n
67    if [ "$answer" = "n" ]; then
68        exit 0
69    fi
70fi
71
72while true; do
73    while [ -z "$IPADDR" ] ; do
74        echo -n "Enter IP address: "
75        read IPADDR
76    done
77
78    NETMASK=`$NETPARAMS -f $MASKS $IPADDR|cut -d\  -f 1`
79    GATEWAY=`$NETPARAMS -f $MASKS $IPADDR|cut -d\  -f 4`
80
81    echo "Address: $IPADDR"
82    echo
83    echo "Autoconfigured settings:"
84    echo "  Netmask: $NETMASK"
85    echo "  Gateway: $GATEWAY"
86    echo
87    ask "Is this correct? (Y/n) " y
88    [ "$answer" = "y" ] || continue
89    echo "Looking up hostname...";
90    FQDN="$(dig +short -x $IPADDR 2>/dev/null | sed -e 's/.$//')"
91    if [ $? != 0 ]; then
92        echo "Unable to look up hostname.  You may enter it below"
93        echo "but beware that typos may render your machine unusable."
94        FQDN=
95        while [ -z "$FQDN" ] ; do
96            echo -n "Enter hostname: "
97            read FQDN
98            FQDN="$(echo $FQDN | tr -d ' ')"
99            if echo "$FQDN" | egrep -qi "[^a-z0-9_-\.]"; then
100                echo "Invalid characters in hostname, try again."
101                FQDN=
102            fi
103        done
104    fi 
105    if ! echo "$FQDN" | grep -qi "MIT.EDU$"; then
106        FQDN="$FQDN.MIT.EDU"
107    fi
108    echo "Hostname: $FQDN"
109    ask "Is this correct? (Y/n) " y
110    if [ "$answer" = "y" ]; then
111        break
112    fi
113done
114HOSTNAME="$(echo "$FQDN" | cut -d. -f 1)"
115DOMAIN="$(echo "$FQDN" | sed 's/[^\.]*\.//')"
116if [ "$DEBATHENA_DEBUG" = "1" ]; then
117    echo "$IPADDR $NETMASK $GATEWAY $HOSTNAME $DOMAIN $FQDN"
118    echo "Done!"
119    exit 0
120fi
121echo "Updating /etc/network/interfaces..."
122mv -f "/etc/network/interfaces" "/etc/network/interfaces.old"
123cat <<EOF >/etc/network/interfaces
124# This file was created by athena-renumber
125
126# The loopback interface
127auto lo
128iface lo inet loopback
129
130# The primary network interface
131auto eth0
132iface eth0 inet static
133        address $IPADDR
134        netmask $NETMASK
135        gateway $GATEWAY
136        dns-nameservers 18.70.0.160 18.71.0.151 18.72.0.3
137EOF
138echo "Updating /etc/hosts..."
139mv -f "/etc/hosts" "/etc/hosts.old"
140cat <<EOF >/etc/hosts
141# This file was created by athena-renumber
142127.0.0.1       localhost
143127.0.1.1       $fqdn $hostname
144
145# The following lines are desirable for IPv6 capable hosts
146::1     localhost ip6-localhost ip6-loopback
147fe00::0 ip6-localnet
148ff00::0 ip6-mcastprefix
149ff02::1 ip6-allnodes
150ff02::2 ip6-allrouters
151ff02::3 ip6-allhosts
152EOF
153echo "Updating /etc/hostname..."
154mv -f /etc/hostname /etc/hostname.old
155echo $HOSTNAME > /etc/hostname
156echo "Setting hostname...";
157hostname $HOSTNAME
158echo
159echo "Done!  You will need to reboot the workstation for the changes to take effect."
160ask "Would you like to reboot now? (Y/n) " y
161if [ "$answer" = "n" ]; then
162    echo "Please perform a full shutdown and reboot as soon as possible."
163    echo "(Press Enter to return to the menu)"
164    exit 0
165fi
166reboot
Note: See TracBrowser for help on using the repository browser.