# UberJS Version 1.0.3-SBC echo "UberJS Server Booted Client (SBC) v1.0.3 Booting" echo "" #################################################################################################################################### # UberJS Server Booted Client (SBC) Portion #################################################################################################################################### MY_IP=`ifconfig -a | grep inet | grep broadcast | awk '{ print $2 }'` MY_NM=`nslookup ${MY_IP} | grep "Name:" | awk '{ print $2 }'` if [ "${MY_NM}" = "" ]; then echo "Setting hostname: localhost" uname -S localhost else echo "Setting hostname: ${MY_NM}" uname -S ${MY_NM} fi Slashpath=`mount | awk '{ if ($1=="/") { print $3 }}'` Clientfs=`echo ${Slashpath} | awk -F":" '{ print $1":/clientinfo" }'` Installfs=`bpgetfile install | awk '{ print $1":"$3 }'` Profilefs=`bpgetfile install_config | awk '{ print $1":"$3 }'` Sysidfs=`bpgetfile sysid_config | awk '{ print $1":"$3 }'` echo "This machine will be installing from the following paths:" echo "Install: ${Installfs}" echo "Install Config: ${Profilefs}" echo "Sysid Config: ${Sysidfs}" echo "" echo "UberJS Boot Server Paths:" echo "Root: ${Slashpath}" echo "UberDHCP info: ${Clientfs}" echo "" # ideally, here we would run UberJS-Standard, without the NetInit stuff. But for now the code is too different for that to work. # hopefully I can put in some tweaks to merge the code echo "Proceeding to mount NFS paths." #----------------------------------------------------------------------- echo "Mounting Install Media from ${Installfs} on /cdrom" /sbin/mount -F nfs -o ro ${Installfs} /cdrom >/tmp/uberjs.out 2>&1 if [ $? != 0 ]; then echo "Mount failed, bringing up a shell" exec /bin/sh fi #----------------------------------------------------------------------- echo "Unmounting any previous install_config mounts" for CURMOUNT in `mount | grep install_config | awk '{ print $1 }'`; do echo "Unmounting ${CURMOUNT}" umount $CURMOUNT done # did it this way in case sun changes where SI_CONFIG_DIR is. SI_CONFIG_DIR=`cat /usr/sbin/install.d/profind | grep "SI_CONFIG_DIR=" | awk -F"=" '{ print $2 }'` echo "Creating mountpoint for profind (SI_CONFIG_DIR)" if [ -d ${SI_CONFIG_DIR} ]; then rm -rf ${SI_CONFIG_DIR} fi mkdir ${SI_CONFIG_DIR} echo "Mounting Profile Info from ${Profilefs} on ${SI_CONFIG_DIR}" /sbin/mount -F nfs -o ro ${Profilefs} ${SI_CONFIG_DIR} >/tmp/uberjs.out 2>&1 if [ $? != 0 ]; then echo "Mount failed, bringing up a shell" exec /bin/sh fi #----------------------------------------------------------------------- echo "Creating mountpoint for sysid info" mkdir /tmp/sysidfs echo "Mounting Sysid Info from ${Sysidfs} on /tmp/sysidfs" /sbin/mount -F nfs -o ro ${Sysidfs} /tmp/sysidfs >/tmp/uberjs.out 2>&1 if [ $? != 0 ]; then echo "Mount failed, bringing up a shell" exec /bin/sh else if [ -f /tmp/sysidfs/sysidcfg ]; then echo "Copying sysidcfg file into /tmp/root/etc" cp /tmp/sysidfs/sysidcfg /tmp/root/etc else echo "No sysidcfg file was found on this mount" fi echo "Un-mounting /tmp/sysidfs" umount /tmp/sysidfs fi #----------------------------------------------------------------------- echo "Mounting client info from our boot server" mount -F nfs -o ro ${Clientfs} /clientinfo UberJSDHCP=`cat /clientinfo/uberdhcp | grep ${MY_NM} | awk '{ print $2 }'` if [ "${UberJSDHCP}" = "yes" -o "${UberJSDHCP}" = "y" ]; then UberJSDHCP="yes" else UberJSDHCP="no" fi #----------------------------------------------------------------------- echo "Mounting completed" ############################################################## # SYSIDCFG Modification ############################################################## if [ -f /tmp/root/etc/sysidcfg ]; then # Default Router Tweak (avoids having to enter the already discovered/entered default router in the sun install phase) # Also is DHCP Tweak NETIFACELINE=`cat /tmp/root/etc/sysidcfg | grep "^network_interface="` if [ "${NETIFACELINE}" = "" ]; then # only write out if line doesnt already exist if [ "${UberJSDHCP}" = "no" ]; then # add netmask and default router since not DHCP DEFROUTER=`netstat -rn | grep default | awk '{ print $2 }'` # try get default router if [ "${DEFROUTER}" = "" ]; then /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 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}" fi UPIFACE=`ifconfig -a | grep -v "lo0:" | grep "UP" | awk -F":" '{ print $1 }'` # get the name of the non loopback interface thats up MY_NETMASK=`ifconfig ${UPIFACE} | 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] }'` # turn the netmask to a dotted decimal echo "Adding network_interface line to sysidcfg with ipv6=no, netmask=${MY_NETMASK}, and default_route=${DEFROUTER}" echo "network_interface=PRIMARY { protocol_ipv6=no netmask=$MY_NETMASK default_route=$DEFROUTER }" >> /tmp/root/etc/sysidcfg else # dont add netmask or default router, just add DHCP since we booted with DHCP echo "Adding network_interface line to sysidcfg with ipv6=no and DHCP tag" echo "network_interface=PRIMARY { protocol_ipv6=no dhcp }" >> /tmp/root/etc/sysidcfg fi else # make no changes because the network_interface line exists. This may not be optimal. echo "network_interface already specified in sysidcfg, this may not be optimal. No changes will be made at this point." fi # Name Service Tweak (avoids having to enter the information from resolv.conf) NAMESERVICELINE=`cat /tmp/root/etc/sysidcfg | grep "^name_service="` if [ -f /tmp/root/etc/resolv.conf -a "${NAMESERVICELINE}" = "" ]; then # only write if resolv.conf exists and the line doesnt already exist RESOLVDOMAIN=`cat /tmp/root/etc/resolv.conf | grep domain | awk '{ if (NR==1) { print $2 }}'` # return only first record in case of bad file RESOLVNS=`cat /tmp/root/etc/resolv.conf | grep nameserver | awk 'BEGIN { nslist="" } { if (NR==1) { nslist=$2 } else if (NR<=3) { nslist=nslist","$2 }} END { print nslist }'` # get comma separated list of nameservers, up to max of 3 RESOLVSEARCH=`cat /tmp/root/etc/resolv.conf | grep search | awk '{ srchlist=$2 ; for (i=3;i<=NF;i++) { srchlist=srchlist","$i } ; print srchlist }'` if [ "$RESOLVDOMAIN" != "" -a "$RESOLVNS" != "" -a "$RESOLVSEARCH" != "" ]; then echo "Adding name_service line to sysidcfg from resolv.conf information" echo "name_service=DNS { domain_name=$RESOLVDOMAIN name_server=$RESOLVNS search=$RESOLVSEARCH }" >> /tmp/root/etc/sysidcfg else echo "Resolv.conf is not complete. No changes will be made to sysidcfg" fi else echo "Resolv.conf does not exist or name_service line already specified in sysidcfg. No changes will be made to sysidcfg." fi fi echo "Exiting to the sun installer"