# UberJS Version 1.2.2-Server echo "" echo "UberJS Server v1.2.2 with NetInit v4.0.1a Booting" echo "" MOUNTVIACD=`mount | grep "^/ " | grep cdrom` # check for / being mounted from cdrom MOUNTVIASCSI=`mount | grep "^/ " | grep scsi` # check for / being mounted from scsi (some blade machines doe not have a devalias for scsi) if [ "${MOUNTVIACD}" = "" -a "${MOUNTVIASCSI}" = "" ]; then # if this is a net boot, we should boot UberJS Standard not UberJS Server echo "Detected a network boot via an UberJS Server" echo "Redirecting to the SBC Booter" /sbin/sh /tmp/uberjs/uberjs-SBC-exec exit fi #################################################################################################################################### # UberJS Mechanism ( http://clue.eng.iastate.edu/uberjs - uberjs@iastate.edu ) #################################################################################################################################### # Method: # 1. Check /tmp/uberjs/ipethers # If mac address is not there or is listed with DHCP the system will try DHCP first. # If mac address is listed with an IP, the system will skip DHCP attempts. # 2. Bring up interfaces # If /tmp/uberjs/nodhcp exists, DHCP will not be attempted # If DHCP was specified, IP, netmask, and default routes will be configured by DHCP and brought up # If DHCP fails, the user will be prompted for an IP and the interface will be brought up # If DHCP gives an invalid address, or undesirable address, the user is given the option to be prompted instead # If /tmp/uberjs/useonly or /tmp/uberjs/ignore files exist, only certain interfaces will be included or excluded # If no IP was given in ipethers, the builder will be prompted for IP then the interface will be brought up # If an IP was given in ipethers, the ip address specified will be user and the interface will be brought up # 3. Netmask # If /tmp/uberjs/netmask exists, that netmask (dotted decimal) will be used # If that file does not exist, the builder will be prompted # 4. Automatic route detection # If /tmp/uberjs/noautoroute exists, automatic route detection will not be attempted. # If DHCP was specified, default route is already established # If DHCP was not used, in.routed is used to determine a route # If in.routed cannot find a router after 120 seconds, the user is prompted to enter one # 5. Hostname determination # nslookup is used to determine hostname, then set with hostname -s # If no hostname is found, hostname defaults to localhost # 6. WGET # Wget is run and downloads a directory structure from ftp or www as specified in /tmp/uberjs/wget_servers # Wget will try each server down the line, but will stop trying when a server succeeds (expects mirrors) # Wget copies any downloaded files to /tmp (straight into/over the ramdisk filesystem, allows for some last minute tweaks) # 7. NFS Mounting # If bootparams was downloaded by wget or already on the CD, it is parsed and the filesystem locations are determined # If bootparams does not have our hostname in it, /tmp/uberjs/nfs_servers will be checked and a menu will be presented # the user can then select any of the servers specified # If no nfs_servers file exists, or any of the filesystem locations are blank, the user will be prompted for the blank entries. # Finally, filesystems are mounted and things are put in place so that the jumpstart can proceed # Note that all the scripts think we're doing a cd install because of the prom command boot cdrom - install # so the media is mounted on /cdrom, and the $SI_CONFIG_DIR becomes a mountpoint instead of a hardcoded file # 8. Sysidcfg Copy/Tweak # If the mounts were successful, sysidcfg is copied from the nfs mount that contains the sysidcfg file to /tmp/root/etc # If the sysidcfg file exists and contains the line 'network_interface=', no tweaks are made at this point # If the file doesnt contain that line, UberJS adds it with some intelligence about whether the system was booted with # DHCP or was configured manually to an IP. # If the sysidcfg file exists and contains the line 'name_service=', no tweaks are made at this point # If the file doesnt contain that line, and resolv.conf exists, UberJS adds it with the information in /tmp/root/etc/resolv.conf # 9. Sun Install # At this point, the standard jumpstart mechanism takes over # #################################################################################################################################### # # NOTE: Reading this document requires a basic knowledge of SH scripting, but the comments should help you see what is going on. # To be successful in modifications, a more in-depth knowledge may be necessary. # Also, some awk scripting is used (note awk, not gnu awk), and admittedly, some may be able to be replaced with other code. # # A couple coding hints follow # The most common errors occur when: # String variables in if statements when quotation marks are not around the $variable and the variable is empty # ie # if [ $MYVAR = "" ]; then should be if [ "$MYVAR" = "" ]; then # # sun also often does if [ "x$MYVAR" = "x" ]; then # # # The brackets [] in an if statement are not separated from the if conditions by a space on either side # ie # if ["$MYVAR" = "" ]; then or if [ $MYVAR -eq 2]; then or if [ "$MYVAR" = "TEST"]; then # #################################################################################################################################### # NOTE: Don't redirect outputs to /dev/null! In rcS script, it says to redirect all output to /tmp/somefile because of # an nfs bug of some kind #################################################################################################################################### echo "" echo "UberJS v4.0.1a Network Initialization Code Beginning" echo "" #################################################################################################################################### # NETWORK INITIALIZATION SECTION # Find and mount the image from nfs #################################################################################################################################### ############################ # MAC ADDRESS DETECTION ############################ echo "Detecting mac address" CURRENT_ETHER=`ifconfig -a | grep "ether" | awk '{ if (NR==1) { print $2 } }'` # use first interface only echo "My mac address is ${CURRENT_ETHER}" ############################ # IP ETHERS MATCHING # Check /tmp/uberjs/ipethers ############################ echo "Checking /tmp/uberjs/ipethers for matching mac address" if [ -f /tmp/uberjs/ipethers ]; then IP_FROM_ETHERS=`cat /tmp/uberjs/ipethers | grep "${CURRENT_ETHER}" | awk '{ print $2 }'` # get the IP address for that mac address in ipethers if [ "${IP_FROM_ETHERS}" != "" ]; then echo "Matched entry for ${CURRENT_ETHER} in ipethers is ${IP_FROM_ETHERS}" else echo "No match found, will try DHCP for this host" fi else echo "No /tmp/uberjs/ipethers file, will try DHCP for this host" fi ############################ # INTERFACE CONFIGURATION ############################ # the below is a new feature, create /tmp/uberjs/useonly-primary or /tmp/uberjs/useonly-fcip0 or /tmp/uberjs/useonly-hme0 # to use only that interface. # works by only placing the desired devices in net_device_list echo "Iterating interfaces on this machine" net_device_list="" USEONLY_TEST=`ls /tmp/uberjs/useonly-*` # note whether we have useonly specifiers so we only use those interfaces if [ "${USEONLY_TEST}" = "" ]; then USEONLY_EXISTS="no" else echo "Useonly specifiers exist in /tmp/uberjs, will only use those interfaces" USEONLY_EXISTS="yes" fi # check if a useonly-primary directive exists if [ -f /tmp/uberjs/useonly-primary ]; then PRI_IF="`ifconfig -a | grep '^[a-z]*[0-9]:' | sed 's/^\([a-z]*[0-9]\):.*/\1/' | grep -v '^lo[0-9]' | head -1`" echo "Found useonly specifier for the primary interface." echo "Primary interface on this system is ${PRI_IF}." if [ "${PRI_IF}" = "" ]; then echo "No primary interface discovered!" /sbin/sh -i exit 1 fi net_device_list="${PRI_IF}:${net_device_list}" fi # The following little section is a Sun devised way to enumerate the interfaces and loop through them # # Get the complete list of network devices # so that we can ifconfig them individually # for i in `ifconfig -a |grep "^[a-z0-9]*:" | awk -F':' '{print $1}'`; do if [ "${USEONLY_EXISTS}" = "yes" ]; then if [ -f /tmp/uberjs/useonly-primary -a "${i}" = "${PRI_IF}" ]; then echo "Found useonly specifier for interface ${i}, already added with useonly-primary" # don't relist primary continue fi if [ -f /tmp/uberjs/useonly-${i} ]; then echo "Found useonly specifier for interface ${i}." net_device_list="${i}:${net_device_list}" fi else net_device_list="${i}:${net_device_list}" fi done # # net_device_list contains a ":" delimited list # of network devices # old_ifs=$IFS IFS=":" set -- $net_device_list for i do if [ "$i" = "lo0" ]; then continue fi if [ -f /tmp/uberjs/ignore-${i} ]; then echo "Found ignore specifier for interface ${i}. Skipping." continue #skip this interface if ignore designated fi ############################ # DHCP METHOD ############################ if [ "${IP_FROM_ETHERS}" = "" -a -f /tmp/uberjs/nodhcp ]; then echo "/tmp/uberjs/nodhcp file present, Not attempting DHCP configuration." else IP_FROM_ETHERS="DHCP" fi if [ "${IP_FROM_ETHERS}" = "DHCP" ]; then # if we dont have an ipethers specified address or it says to do DHCP, do DHCP! echo "Trying DHCP on $i (timeout is 60 seconds)" /sbin/ifconfig $i dhcp primary start wait 60 # attempt dhcp configuration if [ $? -eq 0 ] ; then echo "Network initialized via DHCP" IP_FROM_ETHERS=`/sbin/ifconfig $i | grep inet | awk '{ print $2 }'` #set ip so we dont try and override it DEFROUTER=`netstat -rn | grep default | awk '{print $2}'` #needed below echo "Getting hostname from DNS" NS_OF_IP=`nslookup ${IP_FROM_ETHERS} | grep "Name:" | awk '{print $2}' 2> /tmp/uberjs.out` #look up hostname # the following awk mess translates hex formatted netmask to dotted decimal MY_NETMASK=`ifconfig $i | grep netmask | awk '{ for(i=0;i<4;i++) { bytes1[i]=substr($4,((i*2)+1),1); bytes2[i]=substr($4,((i*2)+2),1); if (bytes1[i]=="a") { bytes1[i]=10 } else if (bytes1[i]=="b") { bytes1[i]=11 } else if (bytes1[i]=="c") { bytes1[i]=12 } else if (bytes1[i]=="d") { bytes1[i]=13 } else if (bytes1[i]=="e") { bytes1[i]=14 } else if (bytes1[i]=="f") { bytes1[i]=15 }; if (bytes2[i]=="a") { bytes2[i]=10 } else if (bytes2[i]=="b") { bytes2[i]=11 } else if (bytes2[i]=="c") { bytes2[i]=12 } else if (bytes2[i]=="d") { bytes2[i]=13 } else if (bytes2[i]=="e") { bytes2[i]=14 } else if (bytes2[i]=="f") { bytes2[i]=15 }; bytes[i]=((bytes1[i]*16)+bytes2[i]) } print bytes[0]"."bytes[1]"."bytes[2]"."bytes[3] }'` CORRECT=0 while [ $CORRECT != 1 ]; # allow user to refuse the DHCP'd address do echo "" echo "IP: ${IP_FROM_ETHERS}" echo "Hostname: ${NS_OF_IP}" echo "Gateway: ${DEFROUTER}" echo "Netmask: ${MY_NETMASK}" echo "" echo "Is this acceptable? [y/n]" read DHCPOK if [ "${DHCPOK}" = "n" -o "${DHCPOK}" = "no" ]; then # wipe out variables IP_FROM_ETHERS="" DEFROUTER="" MY_NETMASK="" /usr/sbin/route -f >/tmp/uberjs.out 2>&1 # flush routes /sbin/ifconfig $i down unplumb # unplumb it /sbin/ifconfig $i plumb # then replumb it to get back to 0.0.0.0 on the interface CORRECT=1 elif [ "${DHCPOK}" = "y" -o "${DHCPOK}" = "yes" ]; then DHCP_IFACE=$i uname -S ${NS_OF_IP} # set DHCP hostname from DNS CORRECT=1 fi done else # No luck, give up on this interface /sbin/ifconfig $i dhcp drop # wipe out variables IP_FROM_ETHERS="" DEFROUTER="" MY_NETMASK="" /usr/sbin/route -f >/tmp/uberjs.out 2>&1 # flush routes /sbin/ifconfig $i down unplumb # unplumb it /sbin/ifconfig $i plumb # then replumb it to get back to 0.0.0.0 on the interface fi fi ############################ # MANUAL METHOD, prompting ############################ ipaddr=`/sbin/ifconfig $i | grep inet | awk '{ print $2 }'` # check to see if we didnt configure above, or didnt like the dhcp'd info if [ "X$ipaddr" = "X0.0.0.0" -a "${IP_FROM_ETHERS}" = "" ]; then # ip address is unset and none was found by the files CORRECT=0 while [ $CORRECT != 1 ]; # loop until they enter an ip address they're happy with do echo "Please enter IP address for $i:" echo "If you wish to skip this interface, simply leave blank" read IP_FROM_ETHERS if [ "${IP_FROM_ETHERS}" = "" ]; then echo "Skip this interface? [y/n]" IP_FROM_ETHERS="SKIP" else echo "You entered: ${IP_FROM_ETHERS}" echo "Is this correct? [y/n]" fi read YESNO if [ "${YESNO}" = "y" -o "${YESNO}" = "yes" ]; then CORRECT=1 fi if [ "${YESNO}" = "n" -o "${YESNO}" = "no" ]; then if [ "${IP_FROM_ETHERS}" = "SKIP" ]; then CORRECT=1 fi fi done # so now $IP_FROM_ETHERS has a new, user entered and verified IP address and the code below will be happy. fi if [ "${IP_FROM_ETHERS}" = "SKIP" ]; then echo "Skipping this interface" IP_FROM_ETHERS="" continue fi ############################ # MANUAL METHOD, activation ############################ if [ "X$ipaddr" = "X0.0.0.0" ]; then # we have a plumbed, but unconfigured interface /sbin/ifconfig $i $IP_FROM_ETHERS 2>&1 ipaddr=`/sbin/ifconfig $i | grep inet | awk '{ print $2 }'` if [ "X$ipaddr" != "X0.0.0.0" ]; then # The interface configured itself correctly echo "Configured interface $i" /sbin/ifconfig $i up ############################ # NETMASK SETUP ############################ if [ -f /tmp/uberjs/netmask ]; then # check to see if the file exists MY_NETMASK=`cat /tmp/uberjs/netmask 2>/tmp/uberjs.out` if [ "${MY_NETMASK}" != "" ]; then echo "Found netmask ${MY_NETMASK} in /tmp/uberjs/netmask" else echo "No netmask found in /tmp/uberjs/netmask" MY_NETMASK="" # set to empty fi else echo "No /tmp/uberjs/netmask file present" MY_NETMASK="" # set to empty fi if [ "${MY_NETMASK}" = "" ]; then # if no netmask from /tmp/uberjs/netmask, default then confirm CORRECT=0 while [ $CORRECT != 1 ]; do echo "Assuming netmask of 255.255.0.0, is this acceptable? [y/n]" read YESNO if [ "${YESNO}" = "y" -o "${YESNO}" = "yes" ]; then MY_NETMASK="255.255.0.0" # set the netmask CORRECT=1 fi if [ "${YESNO}" = "n" -o "${YESNO}" = "no" ]; then MY_NETMASK="" # allow a prompt CORRECT=1 fi done fi if [ "${MY_NETMASK}" = "" ]; then # if default not acceptable (mask still blank), prompt CORRECT=0 while [ $CORRECT != 1 ]; do echo "Please input netmask for $i (dotted decimal):" read MY_NETMASK echo "You entered: ${MY_NETMASK}" echo "Is this correct? [y/n]" read YESNO if [ "${YESNO}" = "y" -o "${YESNO}" = "yes" ]; then CORRECT=1 fi done fi echo "Configuring interface $i to use the new netmask" /sbin/ifconfig $i netmask ${MY_NETMASK} >/tmp/uberjs.out 2>&1 ############################ # ROUTE DISCOVERY ############################ if [ -f /tmp/uberjs/noautoroute ]; then echo "/tmp/uberjs/noautoroute present: Not attempting automatic route discovery" else /usr/sbin/route -f >/tmp/uberjs.out 2>&1 # flush routes echo "Starting in.routed to find default routers" echo "Routed will run for a max of 60 seconds" # The start time current time, and elapsed time variables are time converted to seconds from midnight and it takes # the difference from the start time to the current time to determine how long the process has been running. # the process loops until a default route pops into the routing table or the allotted time has expired STARTTIME=`date '+%H:%M:%S' | awk -F":" 'BEGIN {totseconds=0} { totseconds+=($3+($2*60)+($1*60*60)) } END { print totseconds }'` CURTIME=${STARTTIME} ELAPSEDTIME=0 DEFROUTER="" /usr/sbin/in.routed # start the discovery daemon ROUTEDPID=`ps -ef | grep routed | grep -v grep | awk '{ print $2 }'` # get its pid so we can kill it later while [ "$DEFROUTER" = "" -a $ELAPSEDTIME -lt 60 ]; do # run for 30 seconds or until we get a route DEFROUTER=`/usr/bin/netstat -rn | grep default | awk '{print $2}'` # check for default routes CURTIME=`date '+%H:%M:%S' | awk -F":" 'BEGIN {totseconds=0} { totseconds+=($3+($2*60)+($1*60*60)) } END { print totseconds }'` ELAPSEDTIME=`echo "$STARTTIME $CURTIME" | awk '{ print abs($2-$1) }'` done if [ "$DEFROUTER" = "" ]; then echo "No default router found after 60 seconds." fi echo "Killing in.routed on PID ${ROUTEDPID}" kill -9 $ROUTEDPID fi if [ "$DEFROUTER" = "" ]; then CORRECT=0 while [ $CORRECT != 1 ]; do echo "Please enter gateway address:" read DEFROUTER echo "You entered: ${DEFROUTER}" echo "Is this correct? [y/n]" read RESPONSE if [ "${RESPONSE}" = "y" -o "${RESPONSE}" = "yes" ]; then CORRECT=1 fi done /usr/sbin/route add default $DEFROUTER # add the default route fi echo "Using default router ${DEFROUTER}" echo "Putting default route in /tmp/root/etc/defaultrouter" echo "${DEFROUTER}" > /tmp/root/etc/defaultrouter else echo "Skipping manual configuration of interface $i" fi fi ############################ # HOSTNAME SETUP ############################ echo "Determining my hostname from nslookup" NS_OF_IP=`nslookup ${IP_FROM_ETHERS} | grep Name | awk '{ print $2}'` if [ "${NS_OF_IP}" != "" ]; then echo "Nslookup returns my hostname is ${NS_OF_IP}" echo "Setting hostname with uname -S" uname -S ${NS_OF_IP} else echo "Nslookup failed, or ip has no dns name." echo "setting hostname to localhost with uname -S" uname -S localhost fi done IFS=$old_ifs #echo "${Rootfs} - / ${Roottype} - no ro" >> /etc/vfstab #################################################################################################################################### # WGET Routine, downloads from a location and puts files in the /tmp/uberjs directory # tries one server at a time until one succeeds (assumes mirroed configuration) # Good files to wget: bootparams, nfs_servers, possibly resolv.conf #################################################################################################################################### if [ -f /tmp/uberjs/wget_servers ]; then NUMWGETSERVERS=`/usr/bin/wc -l /tmp/uberjs/wget_servers | awk '{ print $1 }'` echo "List contains ${NUMWGETSERVERS} servers for wget configuration" if [ ! -d /tmp/wget ]; then mkdir /tmp/wget else rm -rf /tmp/wget mkdir /tmp/wget fi SERVERNO=1 DONEWGET=0 # loop through the file until we are successful while [ $DONEWGET = 0 ] do export SERVERNO CURSERVER=`cat /tmp/uberjs/wget_servers | tail +${SERVERNO} | awk '{ if ( NR==1) { print $0 }}'` # print the record we want echo "Trying Server #${SERVERNO} : ${CURSERVER}" /tmp/uberjs/wget -qr -nH -P /tmp/wget ${CURSERVER} if [ $? = 0 ]; then DONEWGET=1 SUCCESS=1 echo "Success" else if [ $SERVERNO = $NUMWGETSERVERS ]; then DONEWGET=1 SUCCESS=0 else SERVERNO=`echo $SERVERNO | awk '{ tmp = $1; print ($1+1) }'` fi fi done if [ $SUCCESS = 1 ]; then #NOTE: Because of how wget works, if your files are in ftp://foobar.org/uberftpget #/tmp/uberftpget will be created. Using the -nd argument creates a flat filesystem unfortunately #and we cannot use it. Instead, the below method will work for ANY TOP-LEVEL DIRECTORY on your ftp server #so whatever toplevel directory you create should have the uberjs directory and perhaps root/etc directory #as well echo "Copying the wget'd configs from $CURSERVER into /tmp" cp -r /tmp/wget/*/* /tmp rm -rf /tmp/wget else echo "Wget failed, proceeding normally." fi fi echo "" echo "Network Initialization Section Completed." #################################################################################################################################### # UberJS Server Portion #################################################################################################################################### echo "" echo "UberJS Server Portion Beginning" echo "" echo "Starting inetd with the -s option" inetd -s echo "Starting rpcbind" rpcbind echo "Initializing /clientinfo" mount -F tmpfs swap /clientinfo MYHOSTIP=`ifconfig -a | grep inet | grep broadcast | awk '{ print $2 }'` MYHOSTDNS=`nslookup ${MYHOSTIP} | grep "Name:" | awk '{ print $2 }'` MYHOSTLHS=`echo ${MYHOSTDNS} | awk -F"." '{ print $1 }'` echo "${MYHOSTIP} ${MYHOSTDNS} ${MYHOSTLHS}" >> /etc/hosts echo "Added: ${MYHOSTIP} ${MYHOSTDNS} ${MYHOSTLHS} to /etc/hosts" echo "" echo "Server Initialization Complete" echo "" echo "Responding no to the following question will bring up a command prompt." echo "From there you may run /InstallTools/uber-aic or /InstallTools/assisted-aic" echo "to configure your server." echo "" echo "Start the Assisted Add Install Client setup? [y/n]" read YESNO if [ "${YESNO}" = "n" -o "${YESNO}" = "no" ]; then echo "" echo "Starting up a shell" elif [ "${YESNO}" = "y" -o "${YESNO}" = "yes" ]; then echo "" echo "Beginning assisted setup" /InstallTools/assisted-aic else echo "" echo "You did not select a valid option" echo "Returning you to a shell" echo "" fi while [ 1 ]; do /sbin/sh echo "" echo "Exiting the shell would return you to the sun-installer." echo "Starting a new shell" echo "" done