#!/sbin/sh # UberJS Version 3.05.0-Solaris8Mini ### ... stripped of: ### - DHCP, as we will not be using it. ### - ROUTED, same as for DHCP. ### - WGET, FTP/HTTP(S) access is not (yet) available. (WAN-boot may require this at some point in time). ### ### Enhancements added: ### - Use only primary interfaces (eg eri0) to simulate the net boot, not reversed from hme2 back to 0. ### ### Bug-fixes: ### - 'gw' is not part of 'route add default' on Solaris (it is on GNU/Linux). ### - Several shellcoding & style issues fixed (clean-up), for easy reading. ### ### VERSION: ### $Id: uberjs-exec,v 1.18 2004/02/26 14:21:45 g7143m55 Exp $ ### Author: Classified ### # -- Globals SCRIPT="`basename $0`" TMPNFS="/tmp/nfs" # -- Functions warn() { echo "$@" >&2 return 0 } die() { warn "$@. Aborted" # Below *MAY* be a security-issue /sbin/sh -i exit 1 } stop_on_user_request() { # $@ = any answer case "$@" in [Qq]|[Qq][Uu][Ii][Tt]|[Xx]|[Ee][Xx][Ii][Tt]|[Hh][Aa][Ll][Tt]|[Ss][Tt][Oo][Pp]) die "Stopped at user request" ;; *) ;; esac return 0 } ask_and_set() { # $1 = question (required) # $2 = variable containing answer (required) # $3 = default value (optional) if [ "$#" -lt 2 ]; then die "ask_and_set: missing parameter. Internal error" fi correct=0 answer="" question="$1" variable="$2" default="$3" while [ "$correct" -ne 1 ] do echo "$question" if [ "x$default" != "x" ]; then echo "Press ENTER to use [$default]" fi read answer if [ "x$answer" = "x" ]; then answer="$default" fi stop_on_user_request $answer echo "You entered: ${answer}" echo "Is this correct? [y/n]" read response stop_on_user_request $response case "$response" in [Yy]|[Yy][Ee][Ss]) correct=1 ;; *) ;; esac done eval ${variable}="${answer}" return 0 } ####################################################################### # -- MAIN cat <<_EOF Mini-UberJS based on: UberJS Standard v3.05.0 with NetInit v3.04.10 Booting $SCRIPT \$Id: uberjs-exec,v 1.18 2004/02/26 14:21:45 g7143m55 Exp $ _EOF # -- Interface PRI_IF="`ifconfig -a | grep '^[a-z]*[0-9]:' | sed 's/^\([a-z]*[0-9]\):.*/\1/' | grep -v '^lo[0-9]' | head -1`" IP_FROM_ETHERS="" MY_NETMASK="" ask_and_set "Please enter IP address for $PRI_IF:" \ IP_FROM_ETHERS ask_and_set "Please input netmask for $PRI_IF (dotted decimal):" \ MY_NETMASK \ "255.255.240.0" echo "Configuring ${PRI_IF}..." ifconfig $PRI_IF up $IP_FROM_ETHERS netmask $MY_NETMASK >/dev/null 2>&1 if [ "$?" -ne 0 ]; then die "Failed to configure $PRI_IF" fi # Wait for the 'configured' message sleep 5 # -- Routing DEFROUTER="" ask_and_set "Please enter gateway address:" \ DEFROUTER echo "Using default router ${DEFROUTER}" route add default $DEFROUTER echo "Putting default route in /tmp/root/etc/defaultrouter" echo "${DEFROUTER}" > /tmp/root/etc/defaultrouter # -- Hostname ask_and_set "Please type the hostname of this system:" HOSTNAME bootcd uname -S ${HOSTNAME:-localhost} # -- NFS/Jumpstart NFS_SRV="" NFS_BASE="" INSTALL_FS="" PROFILE_FS="" SYSID_FS="" ask_and_set "Please type the IP-address of the Jumpstart/NFS server" \ NFS_SRV \ "10.102.194.175" ask_and_set "Please type the Jumpstart/NFS mount-point:" \ NFS_BASE \ "/export/jumpstart" ask_and_set "Please type the NFS path to the rules.ok directory:" \ PROFILE_FS \ "." ask_and_set "Please type the NFS path to the Media directory:" \ INSTALL_FS \ "OS/Solaris_8.0_2003-05" ask_and_set "Please type the NFS path to the Sysid Config directory (Sysidcfg/uXYZ):" \ SYSID_FS \ "Sysidcfg/${HOSTNAME}" # -- Handle mount-points & Jumpstart set-up if [ ! -d "${TMPNFS}" ]; then # If it already existed mkdir might fail on a readonly fs mkdir -p "${TMPNFS}" >/dev/null 2>&1 || \ die "Failed to create ${TMPNFS}" fi cd / umount /cdrom >/dev/null 2>&1 echo "Mounting the Jumpstart(tm) directory from ${NFS_SRV}:${NFS_BASE} on $TMPNFS" mount -F nfs -o ro "${NFS_SRV}:${NFS_BASE}" $TMPNFS 2>&1 || \ die "Mount failed, spawning a shell" echo "Mounting the install media from ${NFS_SRV}:${NFS_BASE}/${INSTALL_FS} on /cdrom" mount -F nfs -o ro "${NFS_SRV}:${NFS_BASE}/${INSTALL_FS}" /cdrom 2>&1 || \ die "Mount failed, spawning a shell" # did it this way in case sun changes where SI_CONFIG_DIR is. # This usually is /tmp/install_config SI_CONFIG_DIR="`grep SI_CONFIG_DIR= /usr/sbin/install.d/profind | awk -F= '{print $2}'`" SI_CONFIG_DIR_PATH="`dirname $SI_CONFIG_DIR`" # should be /tmp (could be /tmp/bla/bla) SI_CONFIG_DIR_BASE="`basename $SI_CONFIG_DIR`" # should be install_config mkdir -p "$SI_CONFIG_DIR_PATH" ln -s "${TMPNFS}/${PROFILE_FS}" "$SI_CONFIG_DIR" if [ -d /tmp/sysidfs ]; then rm -rf /tmp/sysidfs fi ln -s "${TMPNFS}/${SYSID_FS}" /tmp/sysidfs if [ -f /tmp/sysidfs/sysidcfg ]; then echo "Copying sysidcfg file into /tmp/root/etc" cp /tmp/sysidfs/sysidcfg /tmp/root/etc else # JVB: For debugging die "No sysidcfg file was found" fi echo "$SCRIPT done."