#! /usr/bin/sh # #pragma ident "@(#)profind.sh 1.39 06/01/31 SMI" # # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Search for a JumpStart directory. If one is found, leave # it mounted on SI_CONFIG_DIR directory. # # Exit values: # 1 - no profile directory found # 0 - profile directory with rules.ok file found # # NOTE: this script assumes that if there is a floppy in the # drive that it is not already mounted anywhere # NOTE: LOFS file system drivers must be loaded for this # script to work # NOTE: larger profind delay is because of bpgetfile delaying # Shell Variables # NETBOOTINFO=/usr/lib/inet/wanboot/netbootinfo SI_CONFIG_DIR=/tmp/install_config CD_CONFIG_DIR=/cdrom/.install_config SYSTEM_CONF=/etc/netboot/system.conf RULES=rules.ok PROFETCH=/usr/sbin/install.d/profetch MESSAGE=`gettext "not found"` ESTATUS=1 # Profile directory verification routine # Arguments: $1 - location for failure message # verify_config() { if [ -f ${SI_CONFIG_DIR}/${RULES} ]; then MESSAGE=`gettext "Using ${RULES} from $1."` ESTATUS=0 else # There is no rules.ok file. Report the status # and unmount the remote directory. # MESSAGE=`gettext "No ${RULES} found on $1."` ESTATUS=1 umount ${SI_CONFIG_DIR} >/dev/null 2>&1 fi } # Custom JumpStart profile search # Arguments: none # floppy () { MOUNT_CONFIG_DIR=/tmp/config.$$ # Check to see if there is a floppy in the drive (silently) # /usr/bin/eject -q floppy >/dev/null 2>&1 if [ $? -eq 0 ]; then # Make the mount point directory used in searching # for the profile # if [ ! -d ${MOUNT_CONFIG_DIR} ]; then mkdir ${MOUNT_CONFIG_DIR} 2>/dev/null fi # Try to mount the floppy first as PCFS, then as UFS # mount -o ro,foldcase -F pcfs /dev/diskette ${MOUNT_CONFIG_DIR} \ >/dev/null 2>&1 status=$? if [ ${status} -ne 0 ]; then mount -o ro -F ufs /dev/diskette ${MOUNT_CONFIG_DIR} \ >/dev/null 2>&1 status=$? fi if [ ${status} -eq 0 ]; then if [ -f ${MOUNT_CONFIG_DIR}/${RULES} ]; then echo `gettext "${RULES} found on floppy."` echo `gettext "Copying information to disk..."` old_dir=`pwd` cd ${MOUNT_CONFIG_DIR} find . -depth -print | \ cpio -pdmu ${SI_CONFIG_DIR} >/dev/null 2>&1 status=$? cd $old_dir fi umount ${MOUNT_CONFIG_DIR} fi rmdir ${MOUNT_CONFIG_DIR} if [ ${status} -eq 0 ]; then verify_config "floppy" fi fi } # Custom JumpStart profile search using bootparams # Arguments: none # bootparams() { # Check for an 'install_config' bootparams entry # set -- `/sbin/bpgetfile -retries 1 install_config` if [ $1"X" != "X" ]; then mount -o ro,retry=2 -F nfs $2:$3 ${SI_CONFIG_DIR} >/dev/null 2>&1 if [ $? -eq 0 ]; then verify_config "$2:$3" fi fi } # Custom JumpStart profile search using DHCP or manual # Arguments: none # dhcp_or_manual() { # Check for a SjumpsCF entry in system.conf. If system.conf is # not present, check for an 'SjumpsCF' DHCP entry # if [ -f ${SYSTEM_CONF} ] ; then . ${SYSTEM_CONF} else SjumpsCF=`/sbin/dhcpinfo SjumpsCF` fi if [ -n "${SjumpsCF}" ] ; then case ${SjumpsCF} in *://*) # It's a URL PROXY=`${NETBOOTINFO} SHTTPproxy 2> /dev/null` if [ -n "$PROXY" -a "$PROXY" != "none" ] ; then PROFETCH_ARGS="-p ${PROXY}" fi ${PROFETCH} ${PROFETCH_ARGS} ${SjumpsCF}/${RULES} > /tmp/${RULES}.$$ 2> /dev/null if [ $? -eq 0 ] ; then cat /tmp/${RULES}.$$ > ${SI_CONFIG_DIR}/${RULES} 2> /dev/null verify_config "${SjumpsCF}" fi ;; *) # it's not a URL mount -o ro,retry=2 -F nfs ${SjumpsCF} ${SI_CONFIG_DIR} >/dev/null 2>&1 if [ $? -eq 0 ] ; then verify_config "${SjumpsCF}" fi ;; esac fi } # Custom JumpStart profile search property specified on grub menu # Arguments: none # property() { # Check for install_config property on the root node SjumpsCF=`prtconf -v /devices | sed -n '/install_config/{;n;p;}' |cut -f 2 -d \'` if [ -n "${SjumpsCF}" ] ; then case ${SjumpsCF} in *://*) # It's a URL PROXY=`${NETBOOTINFO} SHTTPproxy 2> /dev/null` if [ -n "$PROXY" -a "$PROXY" != "none" ] ; then PROFETCH_ARGS="-p ${PROXY}" fi ${PROFETCH} ${PROFETCH_ARGS} ${SjumpsCF}/${RULES} > /tmp/${RULES}.$$ 2> /dev/null if [ $? -eq 0 ] ; then cat /tmp/${RULES}.$$ > ${SI_CONFIG_DIR}/${RULES} 2> /dev/null verify_config "${SjumpsCF}" fi ;; *) # it's not a URL mount -o ro,retry=2 -F nfs ${SjumpsCF} ${SI_CONFIG_DIR} >/dev/null 2>&1 if [ $? -eq 0 ] ; then verify_config "${SjumpsCF}" fi ;; esac fi } # Factory JumpStart (default) profile search # Arguments: none # cdrom() { # Factory JumpStart is only allowed with factory # stub images, indicated by the file /tmp/.preinstall # if [ -f /tmp/.preinstall ]; then mount -o ro -F lofs ${CD_CONFIG_DIR} ${SI_CONFIG_DIR} >/dev/null 2>&1 if [ $? -eq 0 ]; then verify_config "CDROM" fi fi } ######################################### # Main script # ######################################### # Make the mount point directory used in searching # for the profile # if [ ! -d ${SI_CONFIG_DIR} ]; then mkdir ${SI_CONFIG_DIR} 2>/dev/null else exit 0 fi echo `gettext "Searching for JumpStart directory..."` if [ -f /tmp/.cjfiles_ask -o \ \( -f /tmp/.cjfiles_method -a ! -f /tmp/.cjfiles_dir \) ] ; then # we weren't able to find the sysidcfg/profile information the # first try. So let's try again. /sbin/sysidfind fi # If the `tape' boot option was specified, search for the profile on # an attached tape drive. Otherwise, search for profiles in the # following order: # property (Custom JumpStart) # floppy (Custom JumpStart) # network (Custom JumpStart) # cdrom (Factory JumpStart) if [ -f /tmp/.cjfiles_method -a -f /tmp/.cjfiles_dir ] ; then rmdir ${SI_CONFIG_DIR} mv `head -1 /tmp/.cjfiles_dir` ${SI_CONFIG_DIR} METHOD=`head -1 /tmp/.cjfiles_method|nawk '{print $2}'` case "$METHOD" in tape*) verify_config "tape" ;; *:/*) verify_config "WAN" ;; *) MESSAGE=`gettext "Invalid retrieval method"`" $METHOD" ;; esac else property if [ ${ESTATUS} = 1 ]; then floppy fi if [ ${ESTATUS} = 1 ]; then if [ "X${_INIT_NET_STRATEGY}" = "Xdhcp" -o "X${_INIT_NET_STRATEGY}" = "Xmanual" ]; then dhcp_or_manual else bootparams fi if [ ${ESTATUS} = 1 ]; then cdrom fi fi fi # Print the message and exit with the status returned by # the functions # echo ${MESSAGE} exit ${ESTATUS}