#!/bin/ksh # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # bos720 src/bos/usr/lib/nim/methods/c_alloc_boot.sh 1.22.2.1 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 1993,1995 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#)99 1.22.2.1 src/bos/usr/lib/nim/methods/c_alloc_boot.sh, cmdnim, bos720 5/17/12 09:26:43 # COMPONENT_NAME: CMDNIM # # FUNCTIONS: ./usr/lib/nim/methods/c_alloc_boot.sh # # # ORIGINS: 27 # # # (C) COPYRIGHT International Business Machines Corp. 1993, 1995 # All Rights Reserved # Licensed Materials - Property of IBM # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # include common NIM shell defines/functions NIMPATH=${0%/*} NIMPATH=${NIMPATH%/*} [[ ${NIMPATH} = ${0} ]] && NIMPATH=/usr/lpp/bos.sysmgt/nim NIM_METHODS="${NIMPATH}/methods" . ${NIM_METHODS}/c_sh_lib #---------------------------- local defines -------------------------------- BOOTPTAB_TOK_STR="token-ring" BOOTPTAB_ETH_STR="ethernet" BOOTPTAB_FDDI_STR="fddi" BOOTPTAB_HFI_STR="hfi" BOOTPTAB_IEEE_ENT_STR="ieee802" # NOTE - order is important here, as "ht" MUST come before "ha" or the BOOTP # daemon will barf TAB_ENTRIES="bf ip ht ha sa gw sm" #---------------------------- module globals -------------------------------- REQUIRED_ATTRS="hostname bf ip ht sa" OPTIONAL_ATTRS="ha gw sm ieee_ent export_boot spot" hostname="" bf="" ip="" ha="" ht="" sa="" gw="" sm="" ipl_rec="" ieee_ent="" spot="" #---------------------------- alloc_boot -------------------------------- # # NAME: alloc_boot # # FUNCTION: # allocates a NIM boot image by: # 1) creating sym link to target's boot image # 2) adding an entry in the BOOTPTAB for the client # # EXECUTION ENVIRONMENT: # # NOTES: # calls error on failure # # RECOVERY OPERATION: # # DATA STRUCTURES: # parameters: # global: # # RETURNS: (int) # 0 = success # 1 = failure # # OUTPUT: #------------------------------------------------------------------------------- function alloc_boot { typeset boot_image=${TFTPBOOT}/${hostname} typeset ip_loc=${TFTPBOOT}/${ip} typeset info_file=${TFTPBOOT}/${hostname}.info typeset iplrec_file=${TFTPBOOT}/${spot}.iplrecord.${ht} typeset tags="" # verify that SPOT has specified boot image [[ ! -s ${bf} ]] && error ${ERR_FILE_ACCESS} ${bf} # if client already has BOOTPTAB stanza, cut it out if [[ -s ${BOOTPTAB} ]] then ${AWK} -vhostname=${hostname} 'BEGIN{FS=":"};$1!=hostname{print}' \ ${BOOTPTAB} >${TMPDIR}/bootptab 2>${ERR} || err_from_cmd ${AWK} fi # if client already has boot image, remove sym link ${RM} ${boot_image} 2>/dev/null # create sym link to the boot image ${LN} -s ${bf} ${boot_image} 2>${ERR} || err_from_cmd ${LN} bf=${boot_image} if [[ -n ${ip} ]] && [[ -n ${spot} ]] then # if spot is non-null, then allow this to be created ${RM} ${ip_loc}.boot 2>/dev/null ${LN} -s ${bf} ${ip_loc}.boot 2>${ERR} || err_from_cmd ${LN} #These three are needed for the POC boot ${RM} ${ip_loc}.info 2>/dev/null ${LN} -s ${info_file} ${ip_loc}.info 2>${ERR} || err_from_cmd ${LN} #Links for the iplrecord ${RM} ${bf}.iplrecord 2>/dev/null ${LN} -s ${iplrec_file} ${bf}.iplrecord 2>${ERR} || err_from_cmd ${LN} ${RM} ${ip_loc}.iplrecord 2>/dev/null ${LN} -s ${bf}.iplrecord ${ip_loc}.iplrecord 2>${ERR} || err_from_cmd ${LN} ${RM} ${ip_loc} 2>/dev/null ${LN} -s ${bf} ${ip_loc} 2>${ERR} || err_from_cmd ${LN} fi # if export_boot was specified, then instead of tftp'ing the # boot image, it will be mounted at the client. Just return. if [[ ${export_boot} = "yes" ]] then return fi # convert the ht value to a valid bootpd ht value case ${ht} in tok) ht=${BOOTPTAB_TOK_STR} ;; ent) ht=${BOOTPTAB_ETH_STR} ;; fddi) ht=${BOOTPTAB_FDDI_STR} ;; hfi) ht=${BOOTPTAB_HFI_STR} ;; *) error ${ERR_SYS} "unknown network adapter type \"${ht}\"";; esac # if the ieee_ent flag was set, then we need to change the # hardware type accordingly. if [[ -n ${ieee_ent} ]] then ht=${BOOTPTAB_IEEE_ENT_STR} fi # add the entry to the bootptab file. stanza="${hostname}:" for tags in ${TAB_ENTRIES} do eval [[ -z \$${tags} ]] || eval stanza="\${stanza}${tags}=\$${tags}:" done if print ${stanza} >>${TMPDIR}/bootptab 2>${ERR} then ${CAT} ${TMPDIR}/bootptab >${BOOTPTAB} 2>${ERR} || err_from_cmd ${CAT} else error ${ERR_FILE_MOD} ${BOOTPTAB} fi # Create an entry in the DHCP equivalent to bootptab if applicable. # (NOTE: dhcpsd handles boot requests rather than bootpd in a DHCP env) if [ -f ${DHCPSD} ] && [ -f ${BOOTPTODHCP} ] then pid=`${PS} -ef | ${GREP} dhcpsd | ${GREP} -v grep | \ ${AWK} '{ print $2 }'` if [ -n "${pid}" ] then # remove entries for this host if they exist ${BOOTPTODHCP} -r ${hostname} > /dev/null 2>&1 # save stanza to temp file BOOTPTAB2=${TMPDIR}/bootptab.2 print ${stanza} >>${BOOTPTAB2} 2>${ERR} || err_from_cmd "print" # add entries to the file ${BOOTPTODHCP} -b ${BOOTPTAB2} 2>${ERR} || err_from_cmd ${BOOTPTODHCP} # clean up ${RM} -f ${BOOTPTAB2} # Tell the daemon to reread the config file. # The reason we don't do a refresh is that refreshes # are synchronous and the signal delivery is # asynchronous. Since, we are calling this from # within dhcpsd and dhcpsd is not threaded, we need # asynchronous delivery. kill -1 ${pid} > /dev/null 2>/dev/null fi fi # add allow:/tftpboot to /etc/tftpaccess.ctl if needed ${C_FUNCTION} -o secure_tftp_access >/dev/null 2>&1 } # end of alloc_boot # ---------------------------- c_alloc_boot -------------------------------- # # NAME: c_alloc_boot # # FUNCTION: # # # DATA STRUCTURES: # parameters: # All parameters MUST be passed as valid environment varible # assignment syntax (ie. name=value.. ) # # REQUIRED: # hostname -- The clients NIM name # spot -- Name of the SPOT # ip -- Clients IP address # ht -- Hardware type # sa -- server IP address put in bootp reply packet # # Optional: # ha -- Hardware address # gw -- Gateways # sm -- Netmask # # RETURNS: (int) # 0 = no errors # >0 = failure # # --------------------------------------------------------------------------- # signal processing trap cleanup 0 trap err_signal 1 2 11 15 # NIM initialization nim_init # initialize local variables typeset c="" # set parameters from command line while getopts :a:qv c do case ${c} in a) # validate the attr ass parse_attr_ass "${OPTARG}" # include the assignment for use in this environment eval ${variable}=\"${value}\" ;; q) # show attr info cmd_what exit 0 ;; v) # verbose mode (for debugging) set -x for i in $(typeset +f) do typeset -ft $i done ;; \?) # unknown option error ${ERR_BAD_OPT} ${OPTARG} ;; esac done # check for missing attrs ck_attrs # alloc boot resource alloc_boot exit 0