6055 changes to create-client from 4194 codereview
authorSue Sohn <Susan.Sohn@Sun.COM>
Mon, 12 Jan 2009 13:25:22 -0700
changeset 403 763ab176522c
parent 402 97a45e564c5c
child 404 7f93956e959a
6055 changes to create-client from 4194 codereview
usr/src/cmd/installadm/create-client.sh
usr/src/cmd/installadm/installadm-common.sh
usr/src/cmd/installadm/installadm.c
usr/src/cmd/installadm/installadm.h
usr/src/cmd/installadm/setup-tftp-links.sh
--- a/usr/src/cmd/installadm/create-client.sh	Mon Jan 12 11:57:11 2009 -0700
+++ b/usr/src/cmd/installadm/create-client.sh	Mon Jan 12 13:25:22 2009 -0700
@@ -284,133 +284,18 @@
 	}'`
 
 
-
 # Perform x86/sparc specific setup activities
 #
 if [ "${IMAGE_TYPE}" = "${X86_IMAGE}" ]; then
 	echo "Setting up X86 client..." 
-	# lofs mount /boot directory under /tftpboot
-	#
-	mount_lofs_boot
-
-
-	# CLEAN file is used so delete-client can undo the setup
-	#
-	CLEAN="${Bootdir}/rm.${DHCP_CLIENT_ID}"
-	CLEANUP_FOR="${MAC_ADDR}"
-
-	# if config file already exists, run the cleanup - before
-	# checking tftpboot
-	#
-	if [ -f "${CLEAN}" ] ; then
-	    # do the cleanup (of old stuff)
-	    if [ ! -x ${DIRNAME}/delete-client ] ; then
-	        echo "WARNING: could not execute: ${DIRNAME}/delete-client"
-	        echo "  cannot clean up preexisting install client, " 
-	        echo "  \"${CLEANUP_FOR}\", continuing anyway"
-	    else
-	        echo "Cleaning up preexisting install client \"${CLEANUP_FOR}\""
-	        ${DIRNAME}/delete-client -q ${CLEANUP_FOR}
-	    fi
+	${DIRNAME}/setup-tftp-links client ${SERVICE_NAME} ${IMAGE_PATH} \
+				${DHCP_CLIENT_ID} ${BOOT_FILE}
+	status=$?
+	if [ $status -ne 0 ]; then
+		echo "${myname}: Unable to setup x86 client"
+		exit 1
 	fi
 
-	# Obtain a unique name for file in tftpboot dir.
-	#
-	aBootfile=${IMAGE_PATH}/boot/grub/pxegrub
-	Bootfile=`tftp_file_name $aBootfile pxegrub`
-
-	# If the caller has specified a boot file name, we're going to
-	# eventually create a symlink from the pxegrub file to the caller
-	# specified name.  If that link already exists, make sure it points
-	# to the boot file we're going to use.
-	#
-	if [ "X$BOOT_FILE" != "X" ] ; then
-	    if [ -h "${Bootdir}/$BOOT_FILE" -a \
-				! -f "${Bootdir}/$BOOT_FILE" ] ; then
-		    echo "ERROR: Specified boot file ${BOOT_FILE} already"
-		    echo "       exists, but does not point to anything."
-		    exit 1
-	    fi
-
-	    if [ -f "${Bootdir}/$BOOT_FILE" ] ; then
-		    cmp -s "${Bootdir}/${Bootfile}" "${Bootdir}/${BOOT_FILE}"
-		    if [ $? != 0 ] ; then
-			    echo "ERROR: Specified boot file ${BOOT_FILE}"
-			    echo "       already exists and is of a different" 
-			    echo "       version than the one needed for this"
-			    echo "       client."
-			    exit 1
-		    fi
-	    fi
-   	fi
-
-	# Create the boot file area, if not already created
-	#
-	if [ ! -d "${Bootdir}" ]; then
-	    echo "making ${Bootdir}"
-	    mkdir ${Bootdir}
-	    chmod 775 ${Bootdir}
-	fi
-
-	# start tftpd if needed
-	#
-	start_tftpd
-
-
-	# start creating clean up file
-	#
-	echo "#!/sbin/sh" > ${CLEAN}			# (re)create it
-	echo "# cleanup file for ${CLEANUP_FOR} - sourced by installadm " \
-	    "delete-client"  >> ${CLEAN}
-
-	# install boot program (pxegrub)
-	if [ ! -f ${Bootdir}/${Bootfile} ]; then
-	    echo "copying boot file to ${Bootdir}/${Bootfile}"
-	    cp ${aBootfile} ${Bootdir}/${Bootfile}
-	    chmod 755 ${Bootdir}/${Bootfile}
-	fi
-
-	# create tftp symlink to bootfile
-	#
-	Menufile=${Bootdir}/menu.lst.${DHCP_CLIENT_ID}
-	setup_tftp "${DHCP_CLIENT_ID}" "${Bootfile}"
-
-
-	# create the menu.lst.<macaddr> file
-	#
-	create_menu_lst_file
-
-
-	# prepare for cleanup action
-	#
-	printf "rm -f ${Menufile}\n" >> ${CLEAN}
-
-
-	# Make tftpboot symlink if caller specified boot file
-	#
-	if [ "X$BOOT_FILE" != "X" ] ; then
-	    # Link from the pxegrub file to the user-specified name
-	    # We don't want to use setup_tftp because we don't want
-	    # to save removal commands in the cleanup file
-	    #
-	    ln -s ${Bootfile} ${Bootdir}/$BOOT_FILE
-
-	    cat <<-EOF >>${CLEAN}
-		if [ -h "${Bootdir}/${BOOT_FILE}" -o \
-				-f "${Bootdir}/${BOOT_FILE}" ] ; then
-		    echo "Not removing manually specified boot file"
-		    echo "\"${BOOT_FILE}\" because other clients may be"
-		    echo "using it."
-		else
-		    echo "The pxegrub file corresponding to the boot file,"
-		    echo "\"${BOOT_FILE}\", does not exist."
-		    echo "Deleting \"${BOOT_FILE}\"."
-		    rm -f ${Bootdir}/${BOOT_FILE}
-		fi
-		EOF
-	fi
-
-
 	# Set value of DHCP_BOOT_FILE.
 	DHCP_BOOT_FILE=${DHCP_CLIENT_ID}
 	if [ "X${BOOT_FILE}" != "X" ] ; then
--- a/usr/src/cmd/installadm/installadm-common.sh	Mon Jan 12 11:57:11 2009 -0700
+++ b/usr/src/cmd/installadm/installadm-common.sh	Mon Jan 12 13:25:22 2009 -0700
@@ -107,11 +107,13 @@
 #	    we are trying to create for this service/ethernet address
 #
 # Arguments : 
-#	$1 - Boot File Name
+#	$1 - client or server
+#	$2 - Boot File Name
 #
 clean_entry()
 {
-	bname=$1
+	type=$1
+	bname=$2
 	# See if there's a cleanup file corresponding to the passed 
 	# boot file 
 	#
@@ -123,6 +125,9 @@
 	# If a cleanup file exists, source it
 	#
 	if [ -f ${CLEAN} ]; then
+		if [ "${type}" = "client" ]; then
+		    echo "Cleaning up preexisting install client \"${bname}\""
+		fi
 		. ${CLEAN}
 	fi
 
--- a/usr/src/cmd/installadm/installadm.c	Mon Jan 12 11:57:11 2009 -0700
+++ b/usr/src/cmd/installadm/installadm.c	Mon Jan 12 13:25:22 2009 -0700
@@ -541,8 +541,9 @@
 	    }
 	} else {
 	    /* x86 only */
-	    snprintf(cmd, sizeof (cmd), "%s %s %s %s",
-		SETUP_TFTP_LINKS_SCRIPT, srv_name, target_directory, bfile);
+	    snprintf(cmd, sizeof (cmd), "%s %s %s %s %s",
+		SETUP_TFTP_LINKS_SCRIPT, TFTP_SERVER, srv_name,
+		target_directory, bfile);
 	    if (installadm_system(cmd) != 0) {
 		(void) fprintf(stderr, MSG_CREATE_TFTPBOOT_FAIL);
 		return (INSTALLADM_FAILURE);
--- a/usr/src/cmd/installadm/installadm.h	Mon Jan 12 11:57:11 2009 -0700
+++ b/usr/src/cmd/installadm/installadm.h	Mon Jan 12 13:25:22 2009 -0700
@@ -57,6 +57,7 @@
 #define	DHCP_ASSIGN		"assign"
 
 #define	SETUP_TFTP_LINKS_SCRIPT	"/usr/lib/installadm/setup-tftp-links"
+#define	TFTP_SERVER		"server"
 
 #define	SETUP_SPARC_SCRIPT	"/usr/lib/installadm/setup-sparc"
 #define	SPARC_SERVER		"server"
--- a/usr/src/cmd/installadm/setup-tftp-links.sh	Mon Jan 12 11:57:11 2009 -0700
+++ b/usr/src/cmd/installadm/setup-tftp-links.sh	Mon Jan 12 13:25:22 2009 -0700
@@ -37,18 +37,24 @@
 # Main
 #
 
-if [ $# -lt 3 ]; then
+if [ $# -lt 4 ]; then
 	exit 1
 fi
 
-SERVICE_NAME=$1
-IMAGE_PATH=$2
-IMAGE_BOOT=$2/boot
-BOOT_FILE=$3
+TYPE=$1 		# "client" or "server"
+SERVICE_NAME=$2
+IMAGE_PATH=$3
+DHCP_CLIENT_ID=$4
+
+if [ "$TYPE" = "client" ]; then
+	BOOT_FILE=$5
+elif [ "$TYPE" != "server" ]; then
+	echo " $TYPE - unsupported TFTP service action"
+	exit 1
+fi
 
 Bootdir=/tftpboot
 
-DHCP_CLIENT_ID=$BOOT_FILE
 CLEAN="${Bootdir}/rm.${DHCP_CLIENT_ID}"
 CLEANUP_FOR="${DHCP_CLIENT_ID}"
 IMAGE_IP=`get_server_ip`
@@ -58,11 +64,11 @@
 mount_lofs_boot
 
 # Clean the entry in /tftpboot if there is one already
-clean_entry $DHCP_CLIENT_ID
+clean_entry $TYPE $DHCP_CLIENT_ID
 
 # Obtain a unique name for file in tftpboot dir.
 #
-aBootfile=${IMAGE_BOOT}/grub/pxegrub
+aBootfile=${IMAGE_PATH}/boot/grub/pxegrub
 Bootfile=`tftp_file_name $aBootfile pxegrub`
 
 # If the caller has specified a boot file name, we're going to eventually
@@ -117,11 +123,27 @@
 Menufile=${Bootdir}/menu.lst.${DHCP_CLIENT_ID}
 setup_tftp "${DHCP_CLIENT_ID}" "${Bootfile}"
 
-create_menu_lst_file ${Menufile}
+create_menu_lst_file
 
 # prepare for cleanup action
-if [ "X${DHCP_CLIENT_ID}" != "X" ]; then
-	printf "rm -f ${Menufile}\n" >> ${CLEAN}
+printf "rm -f ${Menufile}\n" >> ${CLEAN}
+
+# if called from create-client and the user specified a boot file,
+# then make tftpboot symlink
+#
+if [ "${TYPE}" = "client" -a "X$BOOT_FILE" != "X" ]; then
+	# Link from the pxegrub file to the user-specified name
+	# We don't want to use setup_tftp because we don't want
+	# to save removal commands in the cleanup file
+	#
+	ln -s ${Bootfile} ${Bootdir}/$BOOT_FILE
+
+	cat <<-EOF >>${CLEAN}
+	if [ -h "${Bootdir}/${BOOT_FILE}" ] ; then
+	        rm -f ${Bootdir}/${BOOT_FILE}
+	
+	fi
+	EOF
 fi
 
 exit 0