For a recent project we really needed a way to interactively prompt the user when they were installing an image using a boot CD. Normally we could do this with local.cfg on a floppy, but the machines did not have floppy drives and truthfully it gets to be pretty annoying to edit a file on a floppy disk between each install.

So what we did was added code to the "read_local_cfg" method in the init.d functions that prompts the user for overrides.

An example execution may look like:

----------------------------------------------------------
Do you want to override local settings? y,[n] y

Overriding local settings manually.
Any settings entered here will over ride the settings from DHCP and from
local.cfg files on the hard drive or floppy drive. Any setting left blank will
use the default or current setting.


Name to assign to target machine. (www1) HOSTNAME=[myhost.example.com] clusternode4
DNS domain name: (systemimager.org) DOMAINNAME=[] example.com
IP address of the image server: (10.0.0.3) IMAGESERVER=[] 192.168.1.1
Name of the image you want installed on this machine. system_image_1.0 IMAGENAME=[] clusternode_image
Do you want to specify static network information? y,[n] y
Network device that you want to use for the install. (eth0) DEVICE=[] eth0
IP Address to assign to DEVICE. (10.0.0.99) IPADDR=[] 192.168.1.2.4
Netmask to assign to DEVICE. (255.255.255.0) NETMASK=[] 255.255.255.0
Network address for DEVICE (not the host address, but the network address) (10.0.0.0) NETWORK=[] 192.168.1.2.0
Broadcast address for DEVICE. (10.0.0.255) BROADCAST=[] 192.168.1.255
IP address of the default router. (10.0.0.1) GATEWAY=[] 192.168.1.2.1
Device that should be used to reach the default router. (eth0) GATEWAYDEV=[] eth0
Current settings are:
 HOSTNAME=clusternode4
 DOMAINNAME=example.com

 IMAGESERVER=192.168.1.1
 IMAGENAME=clusternode_image

 DEVICE=eth0
 IPADDR=192.168.1.2.4
 NETMASK=255.255.255.0
 NETWORK=192.168.1.2.0
 BROADCAST=192.168.1.255

 GATEWAY=192.168.1.2.1
 GATEWAYDEV=eth0
------------------------------------------

The patched worked out very well except for one problem. With the shell used on the autoinstall CD there is no way we could find to prompt for input with a timeout.

For example in bash you can normally use:

"read -p "Do you want to do something? y,[n] " -t 5 answer"

This will timeout after 5 seconds and continue. Unfortunately since we could not do this the patch makes the CD autoinstall stop and wait for user input. Obviously this is not a good thing but we couldn't find a way around it. Does anyone have another idea.

It is worth noting that this patch could be extended to allow overriding of other options and settings during installation. It basically just provides an interactive hook into the variables that are set and used during initial imaging.

Please let me know what you think of the patch. I don't have any more time to work on it but I would be interested to hear feedback from other users especially if they have another idea for how to enable this type of overriding.

Thanks,
Allen
Index: initrd_source/skel/etc/init.d/functions
===================================================================
--- initrd_source/skel/etc/init.d/functions	(revision 3495)
+++ initrd_source/skel/etc/init.d/functions	(working copy)
@@ -743,6 +743,70 @@
         logmsg "Reading configuration from /tmp/local.cfg"
         . /tmp/local.cfg || shellout
     fi
+    
+    # Allow manual override of settings
+    # I wish busybox supported the -t option so we could have a timeout
+    #read -p "Do you want to override local settings? y,[n] " -t 5 answer <&1
+    read -p "Do you want to override local settings? y,[n] " answer
+    echo
+
+    if [ "$answer" = "y" ] ; then
+       logmsg "Overriding local settings manually."
+
+       logmsg "Any settings entered here will over ride the settings from DHCP and from"
+       logmsg "local.cfg files on the hard drive or floppy drive.  Any setting left blank will"
+       logmsg "use the default or current setting."
+       logmsg
+       logmsg
+
+       read -p "Name to assign to target machine. (www1) HOSTNAME=[$HOSTNAME] " REPLY
+       HOSTNAME=${REPLY:-$HOSTNAME}
+       read -p "DNS domain name: (systemimager.org) DOMAINNAME=[$DOMAINNAME] " REPLY
+       DOMAINNAME=${REPLY:-$DOMAINNAME}
+       read -p "IP address of the image server: (10.0.0.3) IMAGESERVER=[$IMAGESERVER] "  REPLY
+       IMAGESERVER=${REPLY:-$IMAGESERVER}
+       read -p "Name of the image you want installed on this machine. system_image_1.0 IMAGENAME=[$IMAGENAME] " REPLY
+       IMAGENAME=${REPLY:-$IMAGENAME}
+
+       answer=""
+       read -p "Do you want to specify static network information? y,[n] " answer REPLY
+
+       if [ "$answer" = "y" ] ; then
+
+       read -p "Network device that you want to use for the install. (eth0) DEVICE=[$DEVICE] " REPLY
+       DEVICE=${REPLY:-$DEVICE}
+       read -p "IP Address to assign to DEVICE. (10.0.0.99) IPADDR=[$IPADDR] " REPLY
+       IPADDR=${REPLY:-$IPADDR}
+       read -p "Netmask to assign to DEVICE. (255.255.255.0) NETMASK=[$NETMASK] " REPLY
+       NETMASK=${REPLY:-$NETMASK}
+       read -p "Network address for DEVICE (not the host address, but the network address) (10.0.0.0) NETWORK=[$NETWORK] " REPLY
+       NETWORK=${REPLY:-$NETWORK}
+       read -p "Broadcast address for DEVICE. (10.0.0.255) BROADCAST=[$BROADCAST] " REPLY
+       BROADCAST=${REPLY:-$BROADCAST}
+       read -p "IP address of the default router. (10.0.0.1) GATEWAY=[$GATEWAY] " REPLY
+       GATEWAY=${REPLY:-$GATEWAY}
+       read -p "Device that should be used to reach the default router. (eth0) GATEWAYDEV=[$GATEWAYDEV] " REPLY
+       GATEWAYDEV=${REPLY:-$GATEWAYDEV}
+
+       fi
+
+       logmsg "Current settings are:"
+       logmsg "  HOSTNAME=$HOSTNAME"
+       logmsg "  DOMAINNAME=$DOMAINNAME"
+       logmsg
+       logmsg "  IMAGESERVER=$IMAGESERVER"
+       logmsg "  IMAGENAME=$IMAGENAME"
+       logmsg
+       logmsg "  DEVICE=$DEVICE"
+       logmsg "  IPADDR=$IPADDR"
+       logmsg "  NETMASK=$NETMASK"
+       logmsg "  NETWORK=$NETWORK"
+       logmsg "  BROADCAST=$BROADCAST"
+       logmsg
+       logmsg "  GATEWAY=$GATEWAY"
+       logmsg "  GATEWAYDEV=$GATEWAYDEV"
+       logmsg
+    fi
 }
 #
 ################################################################################

Reply via email to