Commit 81956bb4 authored by David Johnson's avatar David Johnson

Update ifcfg-eth99 to handle the widearea static IP case, and add a couple

osconfig scripts.
  * fixserial: fixes securetty, inittab, grub.conf according to args
  * cpwa.sh: simply copies widearea files from boot medium to disk
(the scripts can be run without osconfig, but then you need to set some
env vars that osconfig sets before it runs them.)
parent 521bca25
#!/bin/sh
#
# Simple script to "fix" serial config for a Fedora image.
#
# Args: [-s <speed> -p <parity> -a <portaddr> -d <databits>] <device>
# (device can be COMX, ttySX ;
# portaddr is something like 0x2f8 (physical port addr) ;
# speed is baud rate (some number);
# parity is (no|odd|even) ;
# databits is the number of data bits .
#
#
# Need to fix up
# * /boot/grub/grub.conf (or /boot/grub/menu.lst)
# * /etc/securetty (make sure we require a passwd for login)
# * /etc/inittab (fix where we start a getty)
#
# little util function
checkAndMount() {
if [ "$ELAB_UPD_MNT" != "" ]; then
mount | grep -q "on ${ELAB_UPD_MNT}"
if [ "$?" = "0" ]; then
return 0
elif [ "$ELAB_UPD_DEV" != "" -a "$ELAB_UPD_MNTARGS" != "" ]; then
/bin/sh -c "mount ${ELAB_UPD_MNTARGS} ${ELAB_UPD_DEV} ${ELAB_UPD_MNT}"
if [ "$?" != "0" ]; then
echo "mount of ${ELAB_UPD_DEV} at ${ELAB_UPD_MNT} failed!";
return 1;
fi
return 0;
else
echo "not enough info to mount ${ELAB_UPD_MNT}!";
return 1;
fi
elif [ "$ELAB_UPD_DEV" != "" -a "$ELAB_UPD_MNTARGS" != "" ]; then
/bin/sh -c "/sbin/mount ${ELAB_UPD_MNTARGS} ${ELAB_UPD_DEV} ${ELAB_UPD_MNT}"
if [ "$?" != "0" ]; then
echo "mount of ${ELAB_UPD_DEV} at ${ELAB_UPD_MNT} failed!";
return 1;
fi
return 0;
fi
echo "total failure to mount a slice to work on!";
return 1;
}
# defaults: we must have non-null for speed, parity, and data bits
speed="115200"
parity="no"
bits="8"
addr=""
# they must give us a device
device=""
while [ $# -gt 1 ]; do
# shift
# arg=$1
case $1 in
"-s") shift
speed=$1
echo "$speed" | grep -q '^[0-9][0-9]*$'
if [ $? != 0 ]; then
echo "Speed must be a number!"
exit 1
fi
;;
"-p") shift
parity=$1
if [ "$parity" != "even" -a "$parity" != "odd" \
-a "$parity" != "no" ]; then
echo "Parity must be one of (even|odd|no)!"
exit 1
fi
;;
"-a") shift
addr=$1
echo "$addr" | grep -q '^0x[0-9a-fA-F][0-9a-fA-F]*$'
if [ $? != 0 ]; then
echo "Port address must be a hex number starting with 0x!"
exit 1
fi
;;
"-d") shift
bits=$1
echo "$bits" | grep -q '^[0-9][0-9]*$'
if [ $? != 0 ]; then
echo "Data bits must be a decimal number!"
exit 1
fi
;;
*) echo "Bad argument ${1}!"
exit 1
;;
esac
# do this last to pick up the first arg...
shift
done
echo "after arg parsing, '$@'"
#shift
device=$1
echo "$device" | grep -q '^ttyS[0-9][0-9]*$'
if [ "$?" != "0" ]; then
comdevnum=`echo "$device" | grep '^COM[0-9][0-9]*' | sed -e 's/^COM\([0-9][0-9]*\)$/\1/'`
if [ "$comdevnum" != "" ]; then
comdevnum=`expr $comdevnum - 1`
device="ttyS${comdevnum}"
else
echo "Incorrect device name ${device}!"
exit 2
fi
fi
# ok, we're good, let's move on..
echo "Fixing serial configuration for Fedora..."
checkAndMount()
if [ "$?" != 0 ]; then
exit 4
fi
mnt="$ELAB_UPD_MNT"
#
# /etc/securetty: just append our device if it's not there.
#
grep -q "^[ \t]*${device}" $mnt/etc/securetty
if [ "$?" != "0" ]; then
cp -p $mnt/etc/securetty $mnt/etc/securetty.pre.fixserial
echo "" >> $mnt/etc/securetty
echo "${device}" >> $mnt/etc/securetty
fi
#
# /etc/inittab: just make sure there's an agetty entry for our device; don't
# remove anything
#
# XXX don't hardcode these agetty args, crib off what's there instead
agetty_args="-L ${speed} $device vt100"
grep -q "^[^#].*agetty.*-L[ \t]*${speed}[ \t]*${device}.*$" $mnt/etc/inittab
if [ "$?" != "0" ]; then
snum=`echo "$device" | sed -e 's/tty\(S[0-9][0-9]*\)/\1/'`
if [ "$snum" != "$device" ]; then
cp -p $mnt/etc/inittab $mnt/etc/inittab.pre.fixserial
# if it has an uncommented line about this serial device, we comment
# it out first
grep -q "^[^#].*${device}.*$" $mnt/etc/inittab
if [ "$?" = "0" ]; then
echo "commenting out old line in inittab for ${device}!"
sed -e "s/^\([^#].*${device}.*\)$/#\1/" $mnt/etc/inittab \
> $mnt/etc/inittab.sed
mv $mnt/etc/inittab.sed $mnt/etc/inittab
fi
# now make our addition
echo "" >> $mnt/etc/inittab
echo "# Emulab updater addition" >> $mnt/etc/inittab
echo "${snum}:2345:respawn:/sbin/agetty ${agetty_args}" \
>> $mnt/etc/inittab
else
echo "error: could not grok device name ${device}; inittab not updated!"
fi
fi
#
# /boot/grub/(grub.conf|menu.lst): make sure that serial, terminal, and kernel
# commands are fixed up properly.
#
grubconf=$mnt/boot/grub/grub.conf
if [ ! -e $grubconf ]; then
grubconf=$mnt/boot/grub/menu.lst
if [ ! -e $grubconf ]; then
echo "could not find grub.conf, not updating!"
exit 6
fi
fi
cp -p $grubconf ${grubconf}.pre.fixserial
# replace whatever kernel console=ttySX[,<speed>] line was there with the
# specified device and speed.
repstr="${device},${speed}"
if [ "$parity" != "" ]; then
case $parity in
odd) repstr="${repstr}o"
;;
even) repstr="${repstr}e"
;;
no) repstr="${repstr}n"
;;
*) ;;
esac
fi
if [ "$bits" != "" ]; then
repstr="${repstr}${bits}"
fi
#if [ "$hwflowctl" != "" ]; then
# repstr="r"
#fi
sed -e "s/^\([ \t]*kernel.*console=\)\(ttyS[0-9][0-9]*[,0-9]*\)\(.*\)$/\1${repstr}\3/" \
$grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
# replace serial command unit number
snum=`echo "$device" | sed -e 's/ttyS\([0-9][0-9]*\)/\1/'`
grep -q "^[ \t]*serial.*--unit.*$" $grubconf
if [ "$?" = 0 ]; then
sed -e "s/^\([ \t]*serial.*\)\(--unit=\)\([^ \t]*\)\(.*\)$/\1\2${snum}\4/" $grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
else
sed -e "s/^\([ \t]*serial[ \t]*\)\(.*\)$/\1 --unit=${snum} \2/" $grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
fi
# replace serial command with correct port address
if [ "$addr" != "" ]; then
grep -q "^[ \t]*serial.*--port.*$" $grubconf
if [ "$?" = "0" ]; then
sed -e "s/^\([ \t]*serial.*\)\(--port=\)\([^ \t]*\)\(.*\)$/\1\2${addr}\4/" $grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
else
sed -e "s/^\([ \t]*serial[ \t]*\)\(.*\)$/\1 --port=${addr} \2/" $grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
fi
fi
# replace serial command parity
if [ "$parity" != "" ]; then
grep -q "^[ \t]*serial.*--parity.*$" $grubconf
if [ "$?" = "0" ]; then
sed -e "s/^\([ \t]*serial.*\)\(--parity=\)\([^ \t]*\)\(.*\)$/\1\2${parity}\4/" $grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
else
sed -e "s/^\([ \t]*serial[ \t]*\)\(.*\)$/\1 --parity=${parity} \2/" $grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
fi
fi
# replace serial command speed
if [ "$speed" != "" ]; then
grep -q "^[ \t]*serial.*--speed.*$" $grubconf
if [ "$?" = "0" ]; then
sed -e "s/^\([ \t]*serial.*\)\(--speed=\)\([^ \t]*\)\(.*\)$/\1\2${speed}\4/" $grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
else
sed -e "s/^\([ \t]*serial[ \t]*\)\(.*\)$/\1 --speed=${speed} \2/" $grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
fi
fi
# replace serial command data bits
if [ "$bits" != "" ]; then
grep -q "^[ \t]*serial.*--data.*$" $grubconf
if [ "$?" = "0" ]; then
sed -e "s/^\([ \t]*serial.*\)\(--data=\)\([^ \t]*\)\(.*\)$/\1\2${bits}\4/" $grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
else
sed -e "s/^\([ \t]*serial[ \t]*\)\(.*\)$/\1 --data=${bits} \2/" $grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
fi
fi
# rearrange terminal command to ensure serial has precedence, add --dumb
sed -e 's/^\([ \t]*terminal.*\)\(console\)\(.*\)\(serial\)\(.*\)/\1 serial \3 console \5/' \
$grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
grep -q "^[ \t]*terminal.*--dumb.*$" $grubconf
if [ "$?" != "0" ]; then
# add "--dumb" -- no curses please
sed -e "s/^\([ \t]*terminal[ \t]*\)\(.*\)$/\1 --dumb \2/" $grubconf > ${grubconf}.tmp
mv ${grubconf}.tmp $grubconf
fi
# whewph!
exit 0
......@@ -7,6 +7,7 @@
#
# HACK: run dhclient on all interfaces, and do nothing else
# (well, now also bring up a widearea node control net statically if asked)
#
# Note that this file's name (eth99) cannot overlap with an actual
# existing interface or dhclient will loop. dhclient-script invokes
......@@ -19,13 +20,100 @@
. /etc/emulab/paths.sh
DEVICE="eth99"
IFACETYPES="3c59x e100 e1000 tulip"
IFACETYPES="3c59x e100 e1000 tulip e1000e tg3"
#
# First, probe for all our supported ethernet types
#
modprobe -qa $IFACETYPES
#
# Check: are we a remote node? If so, possibly try static config in pref
# to dhcp.
#
if [ -e /etc/emulab/isrem -a -e /etc/emulab/waconfig ]; then
. /etc/emulab/waconfig
echo "Found Emulab widearea config info..."
_ifs=`ifconfig -s -a | awk '{ print $1 }' | grep -v 'Iface' | grep -v '^lo$'`
if [ "$WA_BOOTMETHOD" = "static" -a "$WA_MAC" != "" ]; then
# try to find an iface matching WA_MAC
cnetif=""
for _if in $_ifs; do
ifconfig $_if | grep HWaddr | sed -e 's/.*HWaddr\s*\(.*\)/\1/' \
| grep -q -i "$WA_MAC"
if [ "$?" = "0" ]; then
cnetif="$_if"
break
fi
done
if [ x"$cnetif" = x"" ]; then
echo "Could not find iface with MAC $WA_MAC; trying DHCP!"
WA_BOOTMETHOD="dhcp"
elif [ x"WA_HOSTNAME" = "x" \
-o x"WA_DOMAIN" = "x" \
-o x"WA_IP_ADRR" = "x" \
-o x"WA_IP_NETMASK" = "x" \
-o x"WA_IP_GATEWAY" = "x" \
-o x"WA_IP_DNS1" = "x" ]; then
echo "Missing static IP config vars; trying DHCP!"
WA_BOOTMETHOD="dhcp"
fi
fi
fi
#
# Try static config if all its constraints above are met...
#
if [ "$WA_BOOTMETHOD" = "static" ]; then
echo "Statically configuring control net on $cnetif ..."
ifconfig "$cnetif" inet "$WA_IP_ADDR" netmask "$WA_IP_NETMASK" up
route add default gateway "$WA_IP_GATEWAY"
# bring up lo too just to make sure it's up
ifconfig lo0 inet 127.0.0.1 up
route add -net 127.0.0.0/8 dev lo
# setup resolv.conf
echo "search $WA_DOMAIN" > /etc/resolv.conf
echo "nameserver $WA_IP_DNS1" >> /etc/resolv.conf
if [ x"$WA_IP_DNS2" != x ]; then
echo "nameserver $WA_IP_DNS2" >> /etc/resolv.conf
fi
# set hostname
hosts_str="$WA_HOSTNAME"
echo "$WA_HOSTNAME" | grep -q \\.
if [ $? = 0 ]; then
hostname "$WA_HOSTNAME"
else
hostname "${WA_HOSTNAME}.${WA_DOMAIN}"
hosts_str="${WA_HOSTNAME}.${WA_DOMAIN} ${hosts_str}"
fi
# setup hosts file
echo "$WA_IP_ADDR ${hosts_str}" >> /etc/hosts
# setup a few necessary emulab files...
echo "$cnetif" > $BOOTDIR/controlif
if [ -e "/etc/emulab/bossnode" ]; then
bossnode=`cat /etc/emulab/bossnode`
echo `host -t A "$bossnode" | sed -e 's/.*has address\s*\(.*\)/\1/'` \
> $BOOTDIR/bossip
fi
echo "$WA_HOSTNAME" > $BOOTDIR/realname
echo "$WA_IP_GATEWAY" > $BOOTDIR/routerip
echo "$WA_IP_ADDR" > $BOOTDIR/myip
echo "$WA_IP_NETMASK" > $BOOTDIR/mynetmask
exit 0
fi
#
# else default to dhclient...
#
#
# If dhclient returns success, then it has configured the first interface
# and gone into background mode. At that point we don't care about it any
......@@ -33,6 +121,7 @@ modprobe -qa $IFACETYPES
# dhclient will leave "up") and set ONBOOT=no to prevent ifup (our caller)
# from doing any further configuration on this fake interface.
#
echo "Discovering control net via dhcp ..."
if [ -x /sbin/dhclient ] && /sbin/dhclient -q ; then
killall dhclient
......
#!/bin/sh
#
# Simple script to copy widearea settings from the boot medium, or, if these
# settings are not present, remove them from the slice we're working on.
#
# little util function
checkAndMount() {
if [ "$ELAB_UPD_MNT" != "" ]; then
mount | grep -q "on ${ELAB_UPD_MNT}"
if [ "$?" = "0" ]; then
return 0
elif [ "$ELAB_UPD_DEV" != "" -a "$ELAB_UPD_MNTARGS" != "" ]; then
/bin/sh -c "mount ${ELAB_UPD_MNTARGS} ${ELAB_UPD_DEV} ${ELAB_UPD_MNT}"
if [ "$?" != "0" ]; then
echo "mount of ${ELAB_UPD_DEV} at ${ELAB_UPD_MNT} failed!";
return 1;
fi
return 0;
else
echo "not enough info to mount ${ELAB_UPD_MNT}!";
return 1;
fi
elif [ "$ELAB_UPD_DEV" != "" -a "$ELAB_UPD_MNTARGS" != "" ]; then
/bin/sh -c "/sbin/mount ${ELAB_UPD_MNTARGS} ${ELAB_UPD_DEV} ${ELAB_UPD_MNT}"
if [ "$?" != "0" ]; then
echo "mount of ${ELAB_UPD_DEV} at ${ELAB_UPD_MNT} failed!";
return 1;
fi
return 0;
fi
echo "total failure to mount a slice to work on!";
return 1;
}
ETCDIR=/etc/emulab
mnt="$ELAB_UPD_MNT"
METCDIR="${mnt}${ETCDIR}"
if [ -e $ETCDIR/isrem ]; then
checkAndMount
if [ "$?" != "0" ]; then
exit 5
fi
cp -p $ETCDIR/isrem $METCDIR/isrem
cp -p $ETCDIR/bossnode $METCDIR/bossnode
cp -p $ETCDIR/emulab-privkey $METCDIR/emulab-privkey
cp -p $ETCDIR/waconfig $METCDIR/waconfig
fi
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment