3 # the name of the floppy based network configuration
4 # files (checked first). the name planet.cnf is kept
5 # for backward compatibility with old nodes, and only
6 # the floppy disk is searched for files with this name.
7 # new files are named plnode.txt and can be located on
8 # a floppy or usb device or on the cdrom
9 OLD_NODE_CONF_NAME=planet.cnf
10 NEW_NODE_CONF_NAME=plnode.txt
12 # one location of cd-based network configuration file
13 # (checked if floppy conf file missing and usb
14 # configuration file is missing)
15 CD_NET_CONF_BOOT=/usr/boot/$NEW_NODE_CONF_NAME
17 # the other location of cd-based network configuration file
18 CD_NET_CONF_ROOT=/usr/$NEW_NODE_CONF_NAME
20 # if all other network configuration file sources
21 # don't exist, fall back to this one (always on the cd)
22 FALLBACK_NET_CONF=/usr/boot/default-node.txt
24 # a temporary place to hold the old configuration file
25 # off of the floppy disk if we find it (so we don't have
26 # to remount the floppy later)
27 TMP_OLD_FLOPPY_CONF_FILE=/tmp/oldfloppy_planet.cnf
29 # once a configuration file is found, save it in /tmp
30 # (may be used later by boot scripts)
31 USED_NET_CONF=/tmp/planet.cnf
33 # default device to use for contacting PLC if not specified
34 # in the configuration file
37 # where to store the temporary dhclient conf file
38 DHCLIENT_CONF_FILE=/tmp/dhclient.conf
40 # which fs types we support finding node configuration files on
41 # (will be based as a -t parameter to mount)
42 NODE_CONF_DEVICE_FS_TYPES="msdos,ext2"
44 # a temporary place to mount devices that might contain configuration
46 CONF_DEVICE_MOUNT_POINT=/mnt/confdevice
47 /bin/mkdir -p $CONF_DEVICE_MOUNT_POINT
49 # for some backwards compatibility, save the ifconfig <device>
50 # output to this file after everything is online
51 IFCONFIG_OUTPUT=/tmp/ifconfig
53 # set to 1 if the default network configuration was loaded off the cd
54 # (no other configuration file found)
61 echo $(date "+%H:%M:%S") " pl_netinit: network initialization failed,"
62 echo $(date "+%H:%M:%S") " pl_netinit: shutting down machine in two hours"
68 # Function for checking the IP address to see if its sensible.
72 "" | *[!0-9.]* | *[!0-9]) return 1 ;;
77 [ ${1:-666} -le 255 ] && [ ${2:-666} -le 255 ] &&
78 [ ${3:-666} -le 255 ] && [ ${4:-666} -le 255 ]
81 # find and parse a node network configuration file. return 0 if not found,
82 # return 1 if found and parsed. if this is the case, DEFAULT_NET_CONF will
83 # be set to 1. For any found configuration file, $USED_NET_CONF will
84 # contain the validated contents
87 /bin/rm -f $TMP_OLD_FLOPPY_CONF_FILE 2>&1 > /dev/null
89 echo $(date "+%H:%M:%S") " pl_netinit: looking for node configuration file on floppy"
91 /bin/mount -o ro -t $NODE_CONF_DEVICE_FS_TYPES /dev/fd0 \
92 $CONF_DEVICE_MOUNT_POINT 2>&1 > /dev/null
93 if [[ $? -eq 0 ]]; then
95 # 1. check for new named file first on the floppy disk
96 if [ -r "$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME" ]; then
97 conf_file="$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME"
98 echo $(date "+%H:%M:%S") " pl_netinit: found node configuration file $conf_file"
99 /etc/init.d/pl_validateconf < $conf_file > $USED_NET_CONF
100 /bin/umount $CONF_DEVICE_MOUNT_POINT
103 # since we have the floppy mounted already, see if an old file
104 # exists there so we don't have to remount the floppy when we need
105 # to check for an old file on it (later in the order). if it does
106 # just copy it off to a special location
107 elif [ -r "$CONF_DEVICE_MOUNT_POINT/$OLD_NODE_CONF_NAME" ]; then
108 conf_file="$CONF_DEVICE_MOUNT_POINT/$OLD_NODE_CONF_NAME"
109 /bin/cp -f $conf_file $TMP_OLD_FLOPPY_CONF_FILE
110 echo $(date "+%H:%M:%S") " pl_netinit: found old named configuration file, checking later."
112 echo $(date "+%H:%M:%S") " pl_netinit: floppy mounted, but no configuration file."
115 /bin/umount $CONF_DEVICE_MOUNT_POINT
117 echo $(date "+%H:%M:%S") " pl_netinit: no floppy could be mounted, continuing search."
120 # 2. check for a new named file on removable flash devices (those
121 # that start with sd*, because usb_storage emulates scsi devices).
122 # to prevent checking normal scsi disks, also make sure
123 # /sys/block/<dev>/removable is set to 1
125 echo $(date "+%H:%M:%S") " pl_netinit: looking for node configuration file on flash based devices"
127 # make the sd* hd* expansion fail to an empty string if there are no sd
131 for device in /sys/block/[hs]d*; do
132 removable=`cat $device/removable`
133 if [[ $removable -ne 1 ]]; then
137 partitions=$(/bin/awk "\$4 ~ /`basename $device`[0-9]*/ { print \$4 }" /proc/partitions)
138 for partition in $partitions ; do
139 check_dev=/dev/$partition
141 echo $(date "+%H:%M:%S") " pl_netinit: looking for node configuration file on device $check_dev"
142 /bin/mount -o ro -t $NODE_CONF_DEVICE_FS_TYPES $check_dev \
143 $CONF_DEVICE_MOUNT_POINT 2>&1 > /dev/null
144 if [[ $? -eq 0 ]]; then
145 if [ -r "$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME" ]; then
146 conf_file="$CONF_DEVICE_MOUNT_POINT/$NEW_NODE_CONF_NAME"
147 echo $(date "+%H:%M:%S") " pl_netinit: found node configuration file $conf_file"
148 /etc/init.d/pl_validateconf < $conf_file > $USED_NET_CONF
149 echo $(date "+%H:%M:%S") " pl_netinit: found configuration"
150 /bin/umount $CONF_DEVICE_MOUNT_POINT
154 echo $(date "+%H:%M:%S") " pl_netinit: not found"
156 /bin/umount $CONF_DEVICE_MOUNT_POINT
161 # normal filename expansion setting
164 # 3. see if there is an old file on the floppy disk. if there was,
165 # the file $TMP_OLD_FLOPPY_CONF_FILE will be readable.
166 if [ -r "$TMP_OLD_FLOPPY_CONF_FILE" ]; then
167 conf_file=$TMP_OLD_FLOPPY_CONF_FILE
168 echo $(date "+%H:%M:%S") " pl_netinit: found node configuration file $conf_file"
169 /etc/init.d/pl_validateconf < $conf_file > $USED_NET_CONF
174 # 4. check for plnode.txt on the cd at /usr/boot
175 echo $(date "+%H:%M:%S") " pl_netinit: looking for network configuration on cd in /usr/boot"
176 if [ -r "$CD_NET_CONF_BOOT" ]; then
178 echo $(date "+%H:%M:%S") " pl_netinit: found cd configuration file $CD_NET_BOOT_CONF"
179 /etc/init.d/pl_validateconf < $CD_NET_CONF_BOOT > $USED_NET_CONF
184 # 5. check for plnode.txt on the cd at /usr
185 echo $(date "+%H:%M:%S") " pl_netinit: looking for network configuration on cd in /usr"
186 if [ -r "$CD_NET_CONF_ROOT" ]; then
188 echo $(date "+%H:%M:%S") " pl_netinit: found cd configuration file $CD_NET_CONF_ROOT"
189 /etc/init.d/pl_validateconf < $CD_NET_CONF_ROOT > $USED_NET_CONF
194 # 6. no node configuration file could be found, fall back to
195 # builtin default. this can't be used to install a machine, but
196 # will at least let it download and run the boot manager, which
197 # can inform the users appropriately.
198 echo $(date "+%H:%M:%S") " pl_netinit: using default network configuration"
199 if [ -r "$FALLBACK_NET_CONF" ]; then
200 echo $(date "+%H:%M:%S") " pl_netinit: found cd default configuration file $FALLBACK_NET_CONF"
201 /etc/init.d/pl_validateconf < $FALLBACK_NET_CONF > $USED_NET_CONF
210 echo $(date "+%H:%M:%S") " pl_netinit: bringing loopback network device up"
211 /sbin/ifconfig lo 127.0.0.1 up
214 if [ $? -eq 0 ]; then
215 # no network configuration file found. this should not happen as the
216 # default cd image has a backup one. halt.
217 echo $(date "+%H:%M:%S") " pl_netinit: unable to find even a default network configuration"
218 echo $(date "+%H:%M:%S") " pl_netinit: file, this cd may be corrupt."
222 # load the configuration file. if it was a default one (not user specified),
223 # then remove the saved copy from /tmp, but continue on. since a network
224 # configuration file is required and boot scripts only know about this location
225 # they will fail (as they should) - but the network will be up if dhcp is
228 echo $(date "+%H:%M:%S") " pl_netinit: loading network configuration"
231 if [[ $DEFAULT_NET_CONF -eq 1 ]]; then
232 /bin/rm -f $USED_NET_CONF
235 # initialize IPMI device
236 if [[ -n "$IPMI_ADDRESS" ]] ; then
237 echo -n "pl_netinit: initializing IPMI: "
238 cmd="ipnmac -i $IPMI_ADDRESS"
239 if [[ -n "$IPMI_MAC" ]] ; then
240 cmd="$cmd -m $IPMI_MAC"
246 # now, we need to find which device to use (ie, eth0 or eth1). start out
247 # by defaulting to eth0, then see if the network configuration file specified
248 # either a mac address (in which case we will need to find the device), or
251 if [[ -n "$NET_DEVICE" ]]; then
252 # the user specified a mac address we should use. find the network
254 NET_DEVICE=$(tr A-Z a-z <<<$NET_DEVICE)
258 dev_address=`cat $device/address | tr A-Z a-z`
259 if [ "$device" == "$NET_DEVICE" -o "$dev_address" == "$NET_DEVICE" ]; then
261 echo $(date "+%H:%M:%S") " pl_netinit: found device $ETH_DEVICE with mac address $dev_address"
267 ETH_DEVICE=$DEFAULT_NET_DEV
268 echo $(date "+%H:%M:%S") " pl_netinit: using default device $ETH_DEVICE"
273 # if we couldn't find a device (would happen if NET_DEVICE was specified
274 # but we couldn't find a device for that addresS), then abort the rest
277 if [[ -z "$ETH_DEVICE" ]]; then
278 echo $(date "+%H:%M:%S") " pl_netinit: unable to find a usable device, check to make sure"
279 echo $(date "+%H:%M:%S") " pl_netinit: the NET_DEVICE field in the configuration file"
280 echo $(date "+%H:%M:%S") " pl_netinit: cooresponds with a network adapter on this system"
285 # actually check to make sure ifconfig <device> succeeds
286 /sbin/ifconfig $ETH_DEVICE up 2>&1 > /dev/null
287 if [[ $? -ne 0 ]]; then
288 echo $(date "+%H:%M:%S") " pl_netinit: device $ETH_DEVICE does not exist, most likely"
289 echo $(date "+%H:%M:%S") " pl_netinit: this cd does not have hardware support for your"
290 echo $(date "+%H:%M:%S") " pl_netinit: network adapter. please send the following lines"
291 echo $(date "+%H:%M:%S") " pl_netinit: to PlanetLab Support: support@planet-lab.org"
292 echo $(date "+%H:%M:%S") " pl_netinit: for further assistance"
294 /sbin/lspci -n | /bin/grep "Class 0200"
300 ifcfg=/etc/sysconfig/network-scripts/ifcfg-$ETH_DEVICE
301 echo "DEVICE=$ETH_DEVICE" > $ifcfg
302 [ -n "$NET_DEVICE" ] && \
303 echo "HWADDR=$NET_DEVICE" >> $ifcfg
304 echo "BOOTPROTO=$IP_METHOD" >> $ifcfg
305 echo "DHCP_HOSTNAME=$HOST_NAME.$DOMAIN_NAME" >> $ifcfg
307 if [ -n "$WLAN_SSID$WLAN_IWCONFIG$WLAN_MODE" ]; then
308 [ -n "$WLAN_SSID" ] && \
309 echo "ESSID=$WLAN_SSID" >> $ifcfg
310 [ -n "$WLAN_IWCONFIG" ] && \
311 echo "IWCONFIG=$WLAN_IWCONFIG" >> $ifcfg
312 [ -n "$WLAN_MODE" ] && \
313 echo "MODE=$WLAN_MODE" >> $ifcfg
316 if [ "$IP_METHOD" = "static" ]; then
317 echo "IPADDR=$IP_ADDRESS" >> $ifcfg
318 echo "NETMASK=$IP_NETMASK" >> $ifcfg
319 echo "GATEWAY=$IP_GATEWAY" >> $ifcfg
321 /bin/hostname "$HOST_NAME.$DOMAIN_NAME"
323 if [[ -z "$IP_DNS1" ]]; then
324 echo $(date "+%H:%M:%S") " pl_netinit: no dns server specified, cannot continue."
328 echo "nameserver $IP_DNS1" > /etc/resolv.conf
329 if [[ -n "$IP_DNS2" ]]; then
330 echo "nameserver $IP_DNS2" >> /etc/resolv.conf
335 echo $(date "+%H:%M:%S") " pl_netinit: attempting to bring up device $ETH_DEVICE"
336 /sbin/ifup $ETH_DEVICE
338 # for backwards compatibility
339 /sbin/ifconfig $ETH_DEVICE > $IFCONFIG_OUTPUT
341 echo $(date "+%H:%M:%S") " pl_netinit: network online"