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

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