3 # purpose : create a node-specific CD ISO image
5 # given a CD ISO image, and a node-specific config file, this command
6 # creates a new almost identical ISO image with the config file
7 # embedded as boot/plnode.txt
10 COMMAND=$(basename $0)
14 echo "Usage: $0 generic-iso node-config [node-configs]"
15 echo "Creates a node-specific ISO image"
16 echo "with the node-specific config file embedded as /boot/plnode.txt"
20 ### read config file in a subshell and echoes host_name
21 function host_name () {
22 export CONFIG=$1; shift
23 ( . $CONFIG ; echo $HOST_NAME )
29 echo "Cleaning mount-point"
31 if [ -f $NODECONFPLAIN ] ; then
32 echo Cleaning $NODECONFPLAIN
38 echo "Cleaning $ISOOUT"
45 [[ -n "$TRACE" ]] && set -x
47 [[ -z "$@" ]] && usage
49 [[ -z "$@" ]] && usage
51 for NODECONF in "$@" ; do
53 NODENAME=$(host_name $NODECONF)
54 if [ -z "$NODENAME" ] ; then
55 echo "HOST_NAME not found in $NODECONF - exiting"
59 ISODIR=$(dirname "$ISOIN")
60 ISOOUT=$ISODIR/$NODENAME.iso
61 ISOLOG=$ISODIR/$NODENAME.log
64 ### temporary mount point
65 ISOINROOT=$(basename $ISOIN .iso)
68 if [ ! -f $ISOIN ] ; then
69 echo "Could not find template ISO image - exiting" ; exit 1
71 if [ ! -f $NODECONF ] ; then
72 echo "Could not find node-specifig config - exiting" ; exit 1
74 if [ -e "$ISOINROOT" ] ; then
75 echo "Temporary mount point $ISOINROOT exists, please clean up first - exiting" ; exit 1
77 if [ -e "$ISOOUT" ] ; then
78 echo "$ISOOUT exists, please remove first - exiting" ; exit 1
81 ### in case the NODECONF is a symlink
83 cp $NODECONF $NODECONFPLAIN
86 echo -e "Generic ISO image:\r\t\t\t$ISOIN"
87 echo -e "Node-specific config:\r\t\t\t$NODECONF"
88 echo -e "Node-specific ISO:\r\t\t\t$ISOOUT"
89 echo -e "Temporary mount-point:\r\t\t\t$ISOINROOT"
94 echo -n "Creating mount-point "
98 echo -n "Mounting generic image "
99 mount -o ro,loop $ISOIN $ISOINROOT
102 ### mkisofs needs to have write access on the boot image passed with -b
103 ### and we cannot use the same name as isolinux.bin either, so we change it to isolinux
104 ### the good news is that this way we can check we start from a fresh image
106 if [ -e $ISOINROOT/isolinux ] ; then
107 echo "$ISOIN already contains isolinux"
108 echo "It looks like this is not a first-hand image - exiting"
113 echo -n "Copying isolinux.bin in /tmp/isolinux "
114 cp $ISOINROOT/isolinux.bin /tmp/isolinux
117 echo -n "Writing custom image ... "
118 trap abort int hup quit err
119 mkisofs -o $ISOOUT -R -allow-leading-dots -J -r -b isolinux \
120 -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
121 --graft-points $ISOINROOT isolinux=/tmp/isolinux plnode.txt=$NODECONFPLAIN > $ISOLOG 2>&1
127 echo "CD ISO image for $NODENAME in $ISOOUT"