Added cloner 3 install scripts
Kyle Sheumaker [Wed, 25 Apr 2012 21:33:30 +0000 (16:33 -0500)]
etc/cloner3/cloner_server.sh [new file with mode: 0755]
etc/cloner3/detect_cd.sh [new file with mode: 0755]
etc/cloner3/get_setup.sh [new file with mode: 0755]
etc/cloner3/include.sh [new file with mode: 0755]
etc/cloner3/installer.sh [new file with mode: 0755]
etc/cloner3/prep_disks.sh [new file with mode: 0755]
etc/cloner3/remount-fs.sh [new file with mode: 0755]
etc/cloner3/startup.sh [new file with mode: 0755]
etc/cloner3/switch_cd.sh [new file with mode: 0755]
etc/cloner3/test.sh [new file with mode: 0755]

diff --git a/etc/cloner3/cloner_server.sh b/etc/cloner3/cloner_server.sh
new file mode 100755 (executable)
index 0000000..b522c51
--- /dev/null
@@ -0,0 +1,130 @@
+#!/bin/sh
+
+
+PORT=5555
+NETCAT="/usr/bin/nc"
+
+server_log() {
+       MSG=$1
+       NODE=$2
+       
+       if [ "${_server}" = "" ]
+       then
+               return
+       fi
+       
+       if [ "${_node}" != "" ]
+       then
+               NODE="${_node}"
+       fi
+
+       echo "clonerlog|$NODE|$MSG" | $NETCAT -w 5 ${_server} ${PORT} > /tmp/nc.log
+       if [ "$?" != "0" ];
+       then
+               echo "Can't send message to $_server on port $PORT"
+       else
+               RESULTS=`cat /tmp/nc.log`
+               STATUS=`echo $RESULTS | cut -d "|" -f1`
+               MSG=`echo $RESULTS | cut -d "|" -f2`
+
+               if [ "${STATUS}" != "OK" ]
+               then
+                       echo ${MSG}
+               fi
+       fi
+}
+
+server_log_fail() {
+       MSG=$1
+       NODE=$2
+
+       if [ "${_server}" = "" ]
+       then
+               return
+       fi
+       
+       echo "clonerfail|$NODE|$MSG" | $NETCAT -w 5 ${_server} ${PORT} > /tmp/nc.log
+       if [ "$?" != "0" ];
+       then
+               echo "Can't send message to $_server on port $PORT"
+       else
+               RESULTS=`cat /tmp/nc.log`
+               STATUS=`echo $RESULTS | cut -d "|" -f1`
+               MSG=`echo $RESULTS | cut -d "|" -f2`
+
+               if [ "${STATUS}" != "OK" ]
+               then
+                       echo ${MSG}
+               fi
+       fi
+}
+
+server_get_image() {
+       MACADDR=$1
+
+       echo "clonerimage|${MACADDR}" | $NETCAT -w 5 ${_server} ${PORT} > /tmp/nc.log
+       if [ "$?" != "0" ];
+       then
+               echo "Can't send message to $_server on port $PORT"
+       else
+               RESULTS=`cat /tmp/nc.log`
+               echo $RESULTS
+       fi
+}
+
+server_clone_done() {
+       NODE=$1
+       NEXTBOOT=$2
+       
+       echo "clonerdone|${NODE}|${NEXTBOOT}" | $NETCAT -w 5 ${_server} ${PORT} > /tmp/nc.log
+       if [ "$?" != "0" ];
+       then
+               echo "Can't send message to $_server on port $PORT"
+       else    
+               RESULTS=`cat /tmp/nc.log`
+               STATUS=`echo $RESULTS | cut -d "|" -f1`
+               MSG=`echo $RESULTS | cut -d "|" -f2`
+
+               if [ "${STATUS}" != "OK" ]
+               then
+                       clone_fatal_error "${MSG}"
+               fi      
+       fi
+}
+
+server_get_netcfg() {
+       NODE=$1
+
+       RELEASE=`chroot /cloner/mnt lsb_release -i | awk '{print $3}'`
+       server_log "Get netcfg data for ${NODE} release ${RELEASE}"
+       
+       echo "clonernetcfg|${NODE}|${RELEASE}" | $NETCAT -w 5 ${_server} ${PORT} > /tmp/nc.log
+       if [ "$?" != "0" ];
+       then
+               echo "Can't send message to $_server on port $PORT"
+       else
+               RESULTS=`cat /tmp/nc.log`
+               FILE=""
+               while read LINE 
+               do
+                       if [ "${LINE}" = "++++ DONE" ]
+                       then
+                               FILE=""
+                       elif [ `echo ${LINE} | awk '/^\+\+\+\+ / {print $2}'` ]
+                       then
+                               # overwrite the file here...
+                               FILE=`echo ${LINE} | awk '/^\+\+\+\+ / {print $2}'`
+                               echo -n "" > /cloner/mnt/${FILE}
+                       elif [ `echo ${LINE} | awk '/OK/ {print $1}'` ]
+                       then
+                               echo -n ""
+                       elif [ `echo ${LINE} | awk '/^ERR/ {print $1}'` ]
+                       then
+                               clone_fatal_error "Can't get ${NODE} netconfig data from ${_server}"
+                       else
+                               echo "${LINE}" >> /cloner/mnt/${FILE}
+                       fi
+               done < /tmp/nc.log
+       fi
+}
+
diff --git a/etc/cloner3/detect_cd.sh b/etc/cloner3/detect_cd.sh
new file mode 100755 (executable)
index 0000000..caf5ed5
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/ash
+
+. /etc/library.sh
+. /etc/cloner3/include.sh
+. /tmp/cmdline.dat
+
+# find the CD-ROM device and create a symlink to it
+
+header "Trying to locate CD/DVD-ROM device"
+
+for i in `ls -1 /dev/cdrom*`
+do
+       msg -n "Mounting ${ANSI_BLUE}${i}${ANSI_DONE} on /mnt/media"
+       mount -t udf ${i} /mnt/media >> /tmp/stdout.log \
+               2>> /tmp/stderr.log
+
+       if [ "$?" = "0" ]
+       then
+               ok_msg
+               ln -s ${i} /dev/media >> /tmp/stdout.log \
+                       2>> /tmp/stderr.log     
+               break
+       else
+               fail_msg
+       fi
+done
+       
+if [ ! -e /dev/media ]
+then
+       fatal_error "Can't find a valid CD/DVD-ROM on this machine"
+fi
diff --git a/etc/cloner3/get_setup.sh b/etc/cloner3/get_setup.sh
new file mode 100755 (executable)
index 0000000..c8fe38a
--- /dev/null
@@ -0,0 +1,153 @@
+#!/bin/ash
+
+. /etc/cloner3/cloner_server.sh
+. /etc/library.sh
+. /etc/cloner3/include.sh
+. /tmp/hardware.dat
+
+write_client_conf () {
+       # Takes $SERVER, $IMAGE and $NODE as arguments and makes 
+       # /etc/cloner-client.conf
+       mkdir -p /cloner/setup/node/etc
+       if [ "${1}x" != "x" ]; then
+               echo "SERVER=${1}" >> /cloner/setup/node/etc/cloner-client.conf
+       fi
+       if [ "${2}x" != "x" ]; then
+               echo "IMAGE=${2}" >> /cloner/setup/node/etc/cloner-client.conf
+       fi
+       if [ "${3}x" != "x" ]; then
+               echo "NODE=${3}" >> /cloner/setup/node/etc/cloner-client.conf
+       fi
+               
+}
+
+if [ "${_srcpath}" != "" ]
+then
+       header "Copying setup information from ${_srcpath}"
+else
+       if [ "${_server}" = "" ]
+       then
+               clone_fatal_error "The server must be specified on the command line"
+               exit
+       fi
+       header "Getting setup information from cloner server (${_server})"
+fi
+
+if [ "${_image}" = "" ]
+then
+       # user has not specified the cloner image from the command line
+
+       USE_SETTINGS=""
+
+       MACLIST=""
+       I=0
+       while [ "${I}" -lt "${NIC_COUNT}" ]
+       do
+               MACADDR=`eval "echo \\\${NIC_${I}_HWADDR}"`
+               ADDR=`echo ${MACADDR} | sed 's/://g'`
+               
+               MACLIST="${MACLIST}${ADDR}|"
+               I=`expr ${I} + 1`
+       done
+       RESULT=`server_get_image ${MACLIST}`
+       
+       CODE=`echo ${RESULT} | cut -d"|" -f1`   
+       IMAGE=`echo ${RESULT} | cut -d"|" -f2`  
+       NODE=`echo ${RESULT} | cut -d"|" -f3`   
+       
+       
+       if [ "${CODE}" = "ERR" ]
+       then
+               clone_fatal_error "Failed to get image for ${MACLIST}"
+       elif [ "${CODE}" != "OK" ]
+       then
+               clone_fatal_error "Failed to connect to server"
+       fi
+       if [ "${CODE}" = "OK" ]
+       then
+               msg "Using settings image=${ANSI_BLUE}${IMAGE}${ANSI_DONE} node=${ANSI_BLUE}${NODE}${ANSI_DONE}"
+
+               replace_setting "_image" "${IMAGE}"
+               replace_setting "_node" "${NODE}"
+       fi
+       
+fi
+
+if [ "${_image}" = "" ]
+then
+       clone_fatal_error "No image was specified or downloaded from the server"
+fi
+       
+# if we are installing from a disk or CD-ROM
+
+if [ "${_srcpath}" != "" ]
+then
+       msg -n "Copying setup data for image ${_image}"
+       rsync -v /mnt/media/setup/* /cloner/setup \
+               >> /tmp/stdout.log 2>> /tmp/stderr.log
+       if [ "$?" = 0 ]
+       then
+               ok_msg
+       else
+               fail_msg
+       
+               clone_fatal_error "Can't get setup information from /mnt/media/setup"
+       fi
+
+       if [ "${_node}" != "" ]
+       then
+               msg -n "Copying node specific data for image=${_image} node=${_node}"
+               cp -av /mnt/media/setup/nodes/${_node}/* /cloner/setup/node \
+                       >> /tmp/stdout.log 2>> /tmp/stderr.log
+               if [ "$?" = 0 ]
+               then
+                       ok_msg
+               else
+                       fail_msg
+                       clone_fatal_error "Can't get node specific information from /mnt/media"
+               fi
+       fi
+
+# we are installing from the network
+else
+       msg -n "Downloading setup data for image ${_image}"
+       server_log "Downloading setup data for image ${_image}" "${_node}"
+       
+       rsync -v ${_server}::${CLONER_IMAGE_PATH}/${_image}/* /cloner/setup \
+               >> /tmp/stdout.log 2>> /tmp/stderr.log
+       if [ "$?" = 0 ]
+       then
+               ok_msg
+       else
+               fail_msg
+       
+               clone_fatal_error "Can't get setup information from ${_server}::${CLONER_IMAGE_PATH}/${_image}"
+       fi
+
+       if [ "${_node}" != "" ]
+       then
+               msg -n "Downloading node specific data for image=${_image} node=${_node}"
+               server_log "Downloading node specific data for image=${_image} node=${_node}" "${_node}"
+               rsync -av ${_server}::${CLONER_IMAGE_PATH}/${_image}/nodes/${_node}/ \
+                       /cloner/setup/node >> /tmp/stdout.log 2>> /tmp/stderr.log
+       
+               if [ "$?" = 0 ]
+               then
+                       ok_msg
+               else
+                       fail_msg
+       
+                       #fatal_error "Can't get node specific information from ${_server}::${CLONER_IMAGE_PATH}/${_image}/nodes/${_node}"
+               fi
+               msg -n "Writing /etc/cloner-client.conf"
+               write_client_conf ${_server} ${_image} ${_node}
+               if [ "$?" = 0 ]
+               then
+                       ok_msg
+               else
+                       fail_msg
+       
+                       clone_fatal_error "Could not write /cloner/setup/etc/cloner-client.conf"
+               fi
+       fi
+fi
diff --git a/etc/cloner3/include.sh b/etc/cloner3/include.sh
new file mode 100755 (executable)
index 0000000..1ce26aa
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/ash
+
+PRODUCT_NAME="Advanced Clustering's Cloner"
+PRODUCT_VERSION="3.0"
+
+CLONER_IMAGE_PATH="cloner-2/images"
+CLONER_HOST_PATH="cloner-2/hosts"
+
+. /tmp/cmdline.dat
+
+replace_setting() {
+
+       KEY=${1}
+       VALUE=${2}
+
+       sed 's/${KEY}=.*//' /tmp/cmdline.dat > /tmp/cmdline.new
+       echo "${KEY}=\"${VALUE}\"" >> /tmp/cmdline.new
+
+       mv /tmp/cmdline.new /tmp/cmdline.dat
+       . /tmp/cmdline.dat
+}
+
+clone_fatal_error() {
+
+       MSG=${1}
+       
+       server_log_fail "${MSG}" "${_node}"
+       fatal_error "${MSG}"
+       
+}
diff --git a/etc/cloner3/installer.sh b/etc/cloner3/installer.sh
new file mode 100755 (executable)
index 0000000..8c172b1
--- /dev/null
@@ -0,0 +1,251 @@
+#!/bin/ash
+
+. /etc/library.sh
+. /etc/cloner3/include.sh
+. /etc/cloner3/cloner_server.sh
+. /tmp/cmdline.dat
+
+# TODO
+#  * Further testing of GRUB / LILO bootloader
+
+header "Starting the installation process"
+
+# --------------
+#  Perform a multicast install
+# --------------
+if [ "${_multicast}" = "1" ]
+then
+
+       msg "Starting multicast receiver, server will initiate transfer"
+       server_log "Starting multicast receiver, server will initiate transfer" "${_node}"
+       /usr/bin/udp-receiver --nokbd --pipe 'tar -xvf - -C /cloner/mnt'
+
+       if [ "$?" = "0" ]
+       then
+               ok_msg
+       else
+               fail_msg
+               clone_fatal_error "Failed to untar multicasted image"
+       fi
+
+# --------------
+#  A CD-DVD based install
+# --------------
+elif [ "${_srcpath}" != "" ]
+then
+       msg "Starting the unpacking from CD/DVD-ROM"
+
+       # change to our install directory
+       cd /cloner/mnt >> /tmp/stdout.log 2>>/tmp/stderr.log
+
+       if [ -e /cloner/setup/disk_size ]
+       then
+               . /cloner/setup/disk_size
+       else
+               fatal_error "No disk size specified on setup directory"
+       fi
+
+       afio -i -Z -v -s $DISK_SIZE -H /etc/cloner2/switch_cd.sh \
+               /mnt/media/${_image}.afio
+
+       if [ "$?" != 0 ]
+       then
+               fail_msg
+               fatal_error "Failed to extract filesystem from CD/DVD drive"
+       fi
+
+       # revert back to our old directory
+       cd - >> /tmp/stdout.log 2>>/tmp/stderr.log
+
+# --------------
+#  A standard network RSYNC based install
+# --------------
+else
+
+       #msg "The installation process can take a while, check ${ANSI_RED}[ALT-F4]${ANSI_DONE} to view progress"
+
+       msg -n "Syncing data from ${ANSI_BLUE}${_server}${ANSI_DONE} image ${ANSI_BLUE}${_image}${ANSI_DONE}"
+       server_log "Syncing data from ${_server} image ${_image}" "${_node}"
+       /usr/bin/rsync -avz --numeric-ids \
+               ${_server}::${CLONER_IMAGE_PATH}/${_image}/data/  /cloner/mnt/
+       if [ "$?" = "0" ]
+       then
+               ok_msg
+       else
+               fail_msg
+               clone_fatal_error "Failed to sync filesystem data from server!"
+       fi
+       
+fi
+       
+# remake an directories we excluded from our rsync process
+sort -k1 /cloner/setup/makedirectories \
+       > /cloner/setup/makedirectories.sorted 2>> /tmp/stderr.log
+
+header "Making missing directories"
+while read line
+do
+
+       DIR=`echo $line | awk '{print $1}'`
+       DIR_MODE=`echo $line | awk '{print $2}'`
+       DIR_UID=`echo $line | awk '{print $3}'`
+       DIR_GID=`echo $line | awk '{print $4}'`
+
+       if [ "${DIR}" != "" ]
+       then
+               msg -n "Making directory ${ANSI_BLUE}${DIR}${ANSI_DONE}"
+               mkdir -p /cloner/mnt/${DIR} >> /tmp/stdout.log \
+                       2>> /tmp/stderr.log
+
+               chmod ${DIR_MODE} /cloner/mnt/${DIR} >> \
+                       /tmp/stdout.log 2>> /tmp/stderr.log
+       
+               chown ${DIR_UID}:${DIR_GID} /cloner/mnt/${DIR} \
+                       >> /tmp/stdout.log 2>> /tmp/stderr.log
+       
+               if [ "$?" = "0" ]
+               then
+                       ok_msg
+               else
+                       fail_msg
+               fi
+       fi
+
+done < /cloner/setup/makedirectories.sorted
+       
+if [ "${_node}" != "" ]
+then
+
+       if [ "${_srcpath}" != "" ]
+       then
+               header "Installing node specific data"
+               msg -n "Syning node ${ANSI_BLUE}${_node}${ANSI_DONE} data from /mnt/media"
+               rsync -avzc -I --numeric-ids --exclude /.valid \
+                       /cloner/setup/node/ /cloner/mnt \
+                       >> /tmp/stdout.log 2>> /tmp/stderr.log
+
+               if [ "$?" = "0" ]
+               then
+                       ok_msg
+               else
+                       fail_msg
+                       fatal_error "Failed to sync node data from CD/DVD"
+               fi
+       else
+               header "Installing node specific data"
+               server_log "Syncing node ${_node} data from ${_server}" "${_node}"
+               msg -n "Syning node ${ANSI_BLUE}${_node}${ANSI_DONE} data from ${_server}"
+
+               rsync -avzc --numeric-ids --exclude /.valid \
+                       ${_server}::${CLONER_IMAGE_PATH}/${_image}/nodes/${_node}/ \
+                       /cloner/mnt >> /tmp/stdout.log 2>> /tmp/stderr.log
+               if [ "$?" = "0" ]
+               then
+                       ok_msg
+               else
+                       fail_msg
+                       #clone_fatal_error "Failed to sync node data from server!"
+               fi
+               
+               header "Getting node netconfig settings"
+               msg -n "Getting data from ${_server} for ${_node}"
+               server_get_netcfg "${_node}"
+               ok_msg
+       fi
+fi
+
+header "Installing bootloader"
+while read line
+do
+       BL_DEVICE=`echo $line | awk '{print $1}'`
+       BL_TYPE=`echo $line | awk '{print $2}'`
+
+       if [ "${BL_TYPE}" = "grub" ]
+       then
+               msg -n "Installing grub bootloader on ${ANSI_BLUE}${BL_DEVICE}${ANSI_DONE}"
+               server_log "Installing grub on ${BL_DEVICE}" "${_node}"
+
+               GRUB_PATH=""
+               if [ -x /cloner/mnt/sbin/grub-install ]
+               then
+                       GRUB_PATH="/sbin/grub-install"
+               elif  [ -x /cloner/mnt/usr/sbin/grub-install ]
+               then
+                       GRUB_PATH="/usr/sbin/grub-install"
+                elif [ -x /cloner/mnt/sbin/grub2-install ]
+                then
+                        GRUB_PATH="/sbin/grub2-install"
+                elif  [ -x /cloner/mnt/usr/sbin/grub2-install ]
+                then
+                        GRUB_PATH="/usr/sbin/grub2-install"
+               else
+                       clone_fatal_error "Can't find the grub-install binary on mounted filesystem, no bootloader installed"
+               fi
+
+               chroot /cloner/mnt ${GRUB_PATH} --no-floppy ${BL_DEVICE} \
+                       >> /tmp/stdout.log 2>> /tmp/stderr.log
+               if [ "$?" = "0" ]
+               then
+                       ok_msg
+               else
+                       fail_msg
+                       msg -n "Trying alternative grub installation "
+                       server_log "Trying alternative grub install" "${_node}"
+                       echo "root (hd0,0)" > /cloner/mnt/grub.txt
+                       echo "setup (hd0)" >> /cloner/mnt/grub.txt
+
+                       chroot /cloner/mnt ""/sbin/grub --device-map=/boot/grub/device.map --no-floppy --batch < /cloner/mnt/grub.txt"" \ 
+                               >> /tmp/stdout.log 2>> /tmp/stderr.log
+                       if [ "$?" = "0" ]
+                       then
+                               ok_msg
+                       else
+                               fail_msg
+                               clone_fatal_error "Failed to install grub bootloader"
+                       fi
+               fi
+       elif [ "${BL_TYPE}" = "lilo" ]
+       then
+               msg -n "Installing lilo bootloader on ${ANSI_BLUE}${BL_DEVICE}${ANSI_DONE}"
+               server_log "Installing lilo on ${BL_DEVICE}" "${_node}"
+               chroot /cloner/mnt /sbin/lilo >> /tmp/stdout.log 2>> /tmp/stderr.log
+               if [ "$?" = "0" ]
+               then
+                       ok_msg
+               else
+                       fail_msg
+                       clone_fatal_error "Failed to install grub bootloader"
+               fi
+       fi
+
+done < /cloner/setup/bootloader
+
+# we want to sort our filesystems via the mntpoint field so we can unmount them in
+# the reverse order
+sort -r -k2 /cloner/setup/filesystems \
+       > /cloner/setup/filesystems.revsorted 2>> /tmp/stderr.log
+
+header "Unmounting filesystems"
+server_log "Unmounting filesystems" "${_node}"
+while read line
+do
+       FS_DEVICE=`echo $line | awk '{print $1}'`
+       FS_MNTPOINT=`echo $line | awk '{print $2}'`
+       FS_TYPE=`echo $line | awk '{print $3}'`
+       FS_LABEL=`echo $line | awk '{print $4}'`
+
+       case "${FS_TYPE}"
+       in
+               swap)
+                       msg -n "Turning off swap partitions"
+                       swapoff ${FS_DEVICE} >> /tmp/stdout.log 2>> /tmp/stderr.log
+                       ok_or_fail $?
+                       ;;
+               *)
+                       msg -n "Unmounting ${FS_DEVICE} -> ${FS_MNTPOINT}"
+                       umount /cloner/mnt${FS_MNTPOINT} >> /tmp/stdout.log 2>> /tmp/stderr.log
+                       ok_or_fail $?
+                       ;;
+       esac
+done < /cloner/setup/filesystems.revsorted
+
diff --git a/etc/cloner3/prep_disks.sh b/etc/cloner3/prep_disks.sh
new file mode 100755 (executable)
index 0000000..4f2f9bc
--- /dev/null
@@ -0,0 +1,478 @@
+#!/bin/ash
+
+. /etc/library.sh
+. /etc/cloner3/include.sh
+. /etc/cloner3/cloner_server.sh
+
+
+#
+
+if [ "${_nomkfs}" = "" ]
+then
+
+       header "Partiting disks and formating filesystems"
+
+       DELAY=15
+       server_log "Staring disk partitioning" "${_node}"
+       msg "Going to partition and format disks in ${DELAY} seconds, press [CTRL-C] to abort"
+       msg -n "${ANSI_BLUE}"
+       while [ "${DELAY}" != "0" ]
+       do
+               msg -n " ${ANSI_BLUE}${DELAY} ${ANSI_DONE} "
+               sleep 1
+               DELAY=`expr ${DELAY} - 1`
+       done
+       msg ""
+       
+
+       header "Partition the disk devices"
+       
+       for i in `ls -1 /cloner/setup/*.sfdisk`
+       do
+               DEVICE=`basename ${i}`
+               DEVICE=`echo ${DEVICE} | sed 's/\..*//g'`
+       
+       
+               server_log "Partition device ${DEVICE}" "${_node}"
+               
+               msg -n "Partition device ${ANSI_BLUE}${DEVICE}${ANSI_DONE} "
+       
+               /usr/bin/sfdisk --force --no-reread -uM /dev/${DEVICE} < ${i} \
+                       >> /tmp/stdout.log 2>>/tmp/stderr.log
+       
+               if [ "$?" != "0" ];
+               then
+                       fail_msg
+                       clone_clone_fatal_error "Failed to partition disk device ${DEVICE} check /tmp/stdout.log or /tmp/stderr.log for details"
+               else
+                       ok_msg
+               fi
+       done
+       
+       for i in `ls -1 /cloner/setup/*.sec_fdisk 2> /dev/null`
+       do
+               DEVICE=`basename ${i}`
+               DEVICE=`echo ${DEVICE} | sed 's/\..*//g'`
+       
+               msg -n "Partition device ${ANSI_BLUE}${DEVICE}${ANSI_DONE} "
+               server_log "Partition device ${DEVICE}" "${_node}"
+               
+               /usr/bin/sfdisk --force --no-reread /dev/${DEVICE} < ${i} \
+                       >> /tmp/stdout.log 2>>/tmp/stderr.log
+       
+               if [ "$?" != "0" ];
+               then
+                       fail_msg
+                       clone_clone_fatal_error "Failed to partition disk device ${DEVICE} check /tmp/stdout.log or /tmp/stderr.log for details"
+               else
+                       ok_msg
+               fi
+       done
+
+       for i in `ls -1 /cloner/setup/*.parted 2> /dev/null`
+       do
+
+               count=0
+               while read line
+               do
+                       if [ "${count}" == "0" ]
+                       then
+                               echo -n ""              
+                       # this is the disk label info
+                       elif [ "${count}" == "1" ]
+                       then
+                               PED_DEV_NAME=`echo $line | cut -d":" -f1`
+                               PED_DEV_END=`echo $line | cut -d":" -f2`
+                               PED_DEV_TRANS=`echo $line | cut -d":" -f3`
+                               PED_DEV_SECTOR=`echo $line | cut -d":" -f4`
+                               PED_DEV_PHYS=`echo $line | cut -d":" -f5`
+                               PED_DEV_LABEL=`echo $line | cut -d":" -f6`
+                               PED_DEV_MODEL=`echo $line | cut -d":" -f7`
+               
+                               msg -n "Creating ${ANSI_BLUE}${PED_DEV_LABEL}${ANSI_DONE} label on $PED_DEV_NAME"
+                               server_log "Creating ${PED_DEV_LABEL} on ${PED_DEV_NAME}" "${_node}"
+                               CMD="mklabel $PED_DEV_LABEL"
+                               /usr/sbin/parted -s $PED_DEV_NAME $CMD
+               
+                               if [ "$?" != 0 ]
+                               then
+                                       fail_msg
+                                       clone_clone_fatal_error "Failed to create disk label"
+                               else
+                                       ok_msg
+                               fi
+
+               
+                       # this is the partition
+                       else
+                               PED_PART_NUM=`echo $line | cut -d":" -f1`
+                               PED_PART_START=`echo $line | cut -d":" -f2`
+                               PED_PART_END=`echo $line | cut -d":" -f3`
+                               PED_PART_LENGTH=`echo $line | cut -d":" -f4`
+                               PED_PART_FSTYPE=`echo $line | cut -d":" -f5`
+                               PED_PART_NAME=`echo $line | cut -d":" -f6`
+                               PED_PART_FLAGS=`echo $line | cut -d":" -f7`
+                               PED_PART_FLAGS=`echo $PED_PART_FLAGS | sed s/\;//g`
+                               PED_PART_FLAGS=`echo $PED_PART_FLAGS | sed s/\,//g`
+
+                               if [ "${PED_PART_FSTYPE}" == "" ]
+                               then
+                                       PED_PART_FSTYPE="ext4"
+                               fi
+               
+                               if [ "${PED_DEV_LABEL}" == "msdos" ]
+                               then
+               
+                                       PED_PART_TYPE="primary"
+                                       if [ "${PED_PART_FLAGS}" == "lba" ]
+                                       then
+                                               PED_PART_TYPE="extended"
+                                       elif [ "${PED_PART_NUM}" -gt "4" ]
+                                       then
+                                               PED_PART_TYPE="logical"
+                                       fi
+               
+                                       msg -n "Creating partition ${ANSI_BLUE}${PED_PART_START} - ${PED_PART_END}${ANSI_DONE} on $PED_DEV_NAME"
+                                       server_log "Creating partition ${PED_PART_START} - ${PED_PART_END} on $PED_DEV_NAME" "${_node}"
+                                       CMD="mkpart $PED_PART_TYPE $PED_PART_FSTYPE $PED_PART_START $PED_PART_END"
+                                       /usr/sbin/parted -s $PED_DEV_NAME $CMD
+       
+                                       if [ "$?" != 0 ]
+                                       then
+                                               fail_msg
+                                               clone_clone_fatal_error "Failed to create disk partition"
+                                       else
+                                               ok_msg
+                                       fi
+
+                               elif [ "${PED_DEV_LABEL}" == "gpt" ]
+                               then
+                                       msg -n "Creating partition ${ANSI_BLUE}${PED_PART_START} - ${PED_PART_END}${ANSI_DONE} on $PED_DEV_NAME"
+                                       server_log "Creating partition ${PED_PART_START} - ${PED_PART_END} on $PED_DEV_NAME" "${_node}"
+                                       CMD="mkpart $PED_PART_FSTYPE $PED_PART_START $PED_PART_END"
+                                       /usr/sbin/parted -s $PED_DEV_NAME $CMD
+                                       if [ "$?" != 0 ]
+                                       then
+                                               fail_msg
+                                               clone_clone_fatal_error "Failed to create disk partition"
+                                       else
+                                               ok_msg
+                                       fi
+               
+                               fi
+                               if [ "${PED_PART_FLAGS}" != "" ]
+                               then
+                                       for flag in ${PED_PART_FLAGS}
+                                       do
+                                               server_log "Setting flag ${flag} on ${PED_PART_NUM}" "${_node}"
+                                               msg -n "Setting flag ${ANSI_BLUE}${flag}${ANSI_DONE} on $PED_PART_NUM"
+                                               CMD="set $PED_PART_NUM $flag on"
+                                               /usr/sbin/parted -s $PED_DEV_NAME $CMD
+
+                                               if [ "$?" != 0 ]
+                                               then
+                                                       fail_msg
+                                                       clone_fatal_error "Failed to create disk partition"
+                                               else
+                                                       ok_msg
+                                               fi
+                                       done
+                               fi
+               
+                       fi
+               
+                       count=`expr ${count} + 1`
+               done < $i
+       done
+fi
+       
+if [ -e /cloner/setup/raidconf2 ]
+then
+       header "Setting up software RAID devices"
+
+       while read line
+       do
+               MD_DEVICE=`echo $line | awk '{print $1}'`
+               MD_LEVEL=`echo $line | awk '{print $2}'`
+               MD_METADATA=`echo $line | awk '{print $3}'`
+               MD_DISK_QTY=`echo $line | awk '{print $4}'`
+               MD_SPARE_QTY=`echo $line | awk '{print $5}'`
+               MD_DISKS=`echo $line | awk '{print $6}'`
+               MD_SPARES=`echo $line | awk '{print $7}'`
+
+               T1=`echo $MD_DISKS | sed 's/,/ /g'`
+               T2=`echo $MD_SPARES | sed 's/,/ /g'`
+               MD_DISK_STRING="${T1} ${T2}"
+               
+
+               msg -n "Creating ${ANSI_BLUE}${MD_DEVICE}${ANSI_DONE} - $MD_LEVEL on $MD_DISK_QTY disk(s)"
+               server_log "Creating ${MD_DEVICE} - ${MD_LEVEL} on ${MD_DISK_QTY} disk(s)" "${_node}"
+               if [ ${MD_LEVEL} == "raid0" ];
+               then
+                       /usr/bin/mdadm --create ${MD_DEVICE} --metadata=${MD_METADATA} --force --run --level=${MD_LEVEL} --chunk=128 --raid-devices=${MD_DISK_QTY} ${MD_DISK_STRING} >> /tmp/stdout.log 2>> /tmp/stderr.log
+               else
+                       /usr/bin/mdadm --create ${MD_DEVICE} --metadata=${MD_METADATA} --force --run --level=${MD_LEVEL} --chunk=128 --raid-devices=${MD_DISK_QTY} --spare-devices=${MD_SPARE_QTY} ${MD_DISK_STRING} >> /tmp/stdout.log 2>> /tmp/stderr.log
+               fi
+
+               if [ "$?" != "0" ];
+               then
+                       fail_msg
+                       clone_fatal_error "Failed to create RAID device ${MD_DEVICE}"
+               else
+                       ok_msg
+               fi
+       done < /cloner/setup/raidconf2
+elif [ -e /cloner/setup/raidconf ]
+then
+       header "Setting up software RAID devices"
+
+       while read line
+       do
+               MD_DEVICE=`echo $line | awk '{print $1}'`
+               MD_LEVEL=`echo $line | awk '{print $2}'`
+               MD_DISK_QTY=`echo $line | awk '{print $3}'`
+               MD_SPARE_QTY=`echo $line | awk '{print $4}'`
+               MD_DISKS=`echo $line | awk '{print $5}'`
+               MD_SPARES=`echo $line | awk '{print $6}'`
+
+               T1=`echo $MD_DISKS | sed 's/,/ /g'`
+               T2=`echo $MD_SPARES | sed 's/,/ /g'`
+               MD_DISK_STRING="${T1} ${T2}"
+               
+
+               msg -n "Creating ${ANSI_BLUE}${MD_DEVICE}${ANSI_DONE} - $MD_LEVEL on $MD_DISK_QTY disk(s)"
+               server_log "Creating ${MD_DEVICE} - ${MD_LEVEL} on ${MD_DISK_QTY} disk(s)" "${_node}"
+               if [ ${MD_LEVEL} == "raid0" ];
+               then
+                       /usr/bin/mdadm --create ${MD_DEVICE} -e 0.90 --force --run --level=${MD_LEVEL} --chunk=128 --raid-devices=${MD_DISK_QTY} ${MD_DISK_STRING} >> /tmp/stdout.log 2>> /tmp/stderr.log
+               else
+                       /usr/bin/mdadm --create ${MD_DEVICE} -e 0.90 --force --run --level=${MD_LEVEL} --chunk=128 --raid-devices=${MD_DISK_QTY} --spare-devices=${MD_SPARE_QTY} ${MD_DISK_STRING} >> /tmp/stdout.log 2>> /tmp/stderr.log
+               fi
+
+               if [ "$?" != "0" ];
+               then
+                       fail_msg
+                       clone_fatal_error "Failed to create RAID device ${MD_DEVICE}"
+               else
+                       ok_msg
+               fi
+       done < /cloner/setup/raidconf
+
+fi
+
+if [ -e /cloner/setup/pv_devices ]
+then
+
+       header "Setting up LVM groups"
+
+       while read line
+       do
+               PV_DEVICE=`echo $line | awk '{print $1}'`
+               PV_VG=`echo $line | awk '{print $2}'`
+               PV_UUID=`echo $line | awk '{print $3}'`
+
+               msg -n "Setting UUID on ${ANSI_BLUE}${PV_DEVICE}${ANSI_DONE}"
+               server_log "Setting LVM UUID on {$PV_DEVICE}" "${_node}"
+
+               /usr/bin/lvm pvcreate -ff -y --uuid ${PV_UUID} \
+                       --restorefile /cloner/setup/lvm.${PV_VG} \
+                       ${PV_DEVICE} >> /tmp/stdout.log 2>> /tmp/stderr.log
+
+               if [ "$?" != "0" ];
+               then
+                       fail_msg
+                       clone_fatal_error "Failed to restore LVM UUID ${PV_UUID} to ${PV_DEVICE}";
+               else
+                       ok_msg
+               fi
+       done < /cloner/setup/pv_devices
+
+       for i in `ls -1 /cloner/setup/lvm.*`
+       do
+               FILENAME=`basename $i`
+               VG_NAME=`echo $FILENAME | cut -d"." -f2`        
+
+               msg -n "Restoring volume group ${ANSI_BLUE}${VG_NAME}${ANSI_DONE}"
+               server_log "Restoring volume group ${VG_NAME}" "${_node}"
+
+               /usr/bin/lvm vgcfgrestore -f $i ${VG_NAME} \
+                       >> /tmp/stdout.log 2>> /tmp/stderr.log
+
+               if [ "$?" != "0" ];
+               then
+                       fail_msg
+                       clone_fatal_error "Failed to restore LVM volume ${VG_NAME}";
+               else
+                       ok_msg
+               fi
+               msg -n "Activating volume group ${ANSI_BLUE}${VG_NAME}${ANSI_DONE}"
+               server_log "Activating volume group ${VG_NAME}" "${_node}"
+               /usr/bin/lvm vgchange -a y ${VG_NAME} \
+                       >> /tmp/stdout.log 2>> /tmp/stderr.log
+
+               if [ "$?" != "0" ];
+               then
+                       fail_msg
+                       clone_fatal_error "Failed to bring LVM volume ${VG_NAME} online";
+               else
+                       ok_msg
+               fi
+       done
+fi
+
+# we want to sort our filesystems via the mntpoint field so we can mount them in
+# the correct order
+sort -k2 /cloner/setup/filesystems \
+       > /cloner/setup/filesystems.sorted 2>> /tmp/stderr.log
+
+header "Creating/mounting filesystems"
+while read line
+do
+       FS_DEVICE=`echo $line | awk '{print $1}'`
+       FS_MNTPOINT=`echo $line | awk '{print $2}'`
+       FS_TYPE=`echo $line | awk '{print $3}'`
+       FS_LABEL=`echo $line | awk '{print $4}'`
+
+       if [ "${_noddfs}" = "1" ]
+       then
+               msg "Skipping erasing first 5MB on partitions"
+       else
+               msg -n "Erasing first 5MB of data on partition"
+               dd if=/dev/zero of=${FS_DEVICE} bs=1M count=5 \
+                       >> /tmp/stdout.log 2>> /tmp/stderr.log
+               ok_or_fail $?
+       fi
+
+       if [ "${_nomkfs}" = "" ]
+       then
+
+               msg -n "Creating ${ANSI_BLUE}${FS_TYPE}${ANSI_DONE} filesystem on ${ANSI_BLUE}${FS_DEVICE}${ANSI_DONE}"
+               server_log "Creating ${FS_TYPE} filesystem on ${FS_DEVICE}" "${_node}"
+
+               case "${FS_TYPE}"
+               in
+                       ext4)
+                                       CMD="/usr/bin/mke2fs -F -T ext4 ${FS_DEVICE}"
+                                       if [ "${FS_LABEL}" != "" ]
+                                       then
+                                               CMD="/usr/bin/mke2fs -F -T ext4 -L ${FS_LABEL} ${FS_DEVICE}"
+                                       fi
+
+                                       $CMD >> /tmp/stdout.log 2>> /tmp/stderr.log
+                                       if [ "$?" = "0" ]
+                                       then
+                                               # try to tune it out of fsck's but dont care if it fails
+                                               /usr/bin/tune2fs -c 0 ${FS_DEVICE}
+                                               ok_msg
+                                       else
+                                               fail_msg
+                                               clone_fatal_error "Failed to make ext4 filesystem on ${FS_DEVICE}"
+                                       fi
+                               ;;
+                       ext3)
+                                       CMD="/usr/bin/mke2fs -F -T ext3 ${FS_DEVICE}"
+                                       if [ "${FS_LABEL}" != "" ]
+                                       then    
+                                               CMD="/usr/bin/mke2fs -F -T ext3 -L ${FS_LABEL} ${FS_DEVICE}"
+                                       fi
+       
+                                       $CMD >> /tmp/stdout.log 2>> /tmp/stderr.log
+                                       if [ "$?" = "0" ]
+                                       then
+                                               # try to tune it out of fsck's but dont care if it fails
+                                               /usr/bin/tune2fs -c 0 ${FS_DEVICE}
+                                               ok_msg
+                                       else
+                                               fail_msg
+                                               clone_fatal_error "Failed to make ext3 filesystem on ${FS_DEVICE}"
+                                       fi
+                               ;;
+                       ext2)
+                                       CMD="/usr/bin/mke2fs -F -T ext2 ${FS_DEVICE}"
+                                       if [ "${FS_LABEL}" != "" ]
+                                       then    
+                                               CMD="/usr/bin/mke2fs -F -T ext2 -L ${FS_LABEL} ${FS_DEVICE}"
+                                       fi
+       
+                                       $CMD >> /tmp/stdout.log 2>> /tmp/stderr.log
+                                       if [ "$?" = "0" ]
+                                       then
+                                               ok_msg
+                                       else
+                                               fail_msg
+                                               clone_fatal_error "Failed to make ext2 filesystem on ${FS_DEVICE}"
+                                       fi
+                               ;;
+                       xfs)
+                                       /usr/bin/mkfs.xfs -f ${FS_DEVICE} \
+                                               >> /tmp/stdout.log 2>> /tmp/stderr.log
+                                       if [ "$?" = "0" ]
+                                       then
+                                               ok_msg
+                                       else
+                                               fail_msg
+                                               clone_fatal_error "Failed to make xfs filesystem on ${FS_DEVICE}"
+                                       fi
+                               ;;
+       
+                       reiserfs)
+                                       /usr/bin/mkreiserfs -ff ${FS_DEVICE} \
+                                               >> /tmp/stdout.log 2>> /tmp/stderr.log
+       
+                                       if [ "$?" = "0" ]
+                                       then
+                                               ok_msg
+                                       else
+                                               fail_msg
+                                               clone_fatal_error "Failed to make reiserfs filesystem on ${FS_DEVICE}"
+                                       fi
+                               ;;
+                       swap)
+                                       /usr/bin/mkswap -f ${FS_DEVICE} \
+                                               >> /tmp/stdout.log 2>> /tmp/stderr.log
+                                       if [ "$?" = "0" ]
+                                       then
+                                               ok_msg
+                                       else
+                                               fail_msg
+                                               clone_fatal_error "Failed to make swap filesystem on ${FS_DEVICE}"
+                                       fi
+       
+                                       msg -n "Activating swap device ${FS_DEVICE}"
+                                       swapon ${FS_DEVICE} >> /tmp/stdout.log 2>> /tmp/stderr.log
+                                       if [ "$?" = "0" ]
+                                       then
+                                               ok_msg
+                                       else
+                                               fail_msg
+                                               clone_fatal_error "Failed to activate swap filesystem on ${FS_DEVICE}"
+                                       fi
+                               ;;
+                       *)
+                               clone_fatal_error "Don't know how to handle filesystem type ${FS_TYPE}"
+                               ;;
+               esac
+
+       fi
+       
+       # if it starts with a / it's going to be mounted
+       if [ `echo ${FS_MNTPOINT} | grep '^/'` ]
+       then
+               MNT_POINT=`echo ${FS_MNTPOINT} | sed 's/^\///'`
+               msg -n "Mounting ${ANSI_BLUE}${FS_DEVICE}${ANSI_DONE} on ${ANSI_BLUE}/cloner/mnt/${MNT_POINT}${ANSI_DONE}"
+
+               mkdir -p /cloner/mnt/${MNT_POINT} >> /tmp/stdout.log 2>> /tmp/stderr.log
+
+               mount -t ${FS_TYPE} ${FS_DEVICE} /cloner/mnt/${MNT_POINT} >> /tmp/stdout.log 2>> /tmp/stderr.log
+               if [ "$?" = "0" ]
+               then
+                       ok_msg
+               else
+                       fail_msg
+                       clone_fatal_error "Failed to mount ${FS_DEVICE} to /cloner/mnt/${MNT_POINT}"
+               fi
+       fi
+
+done < /cloner/setup/filesystems.sorted
+
+
diff --git a/etc/cloner3/remount-fs.sh b/etc/cloner3/remount-fs.sh
new file mode 100755 (executable)
index 0000000..c87db97
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/ash
+
+. /etc/library.sh
+
+# we want to sort our filesystems via the mntpoint field so we can mount them in
+# the correct order
+sort -k2 /cloner/setup/filesystems \
+       > /cloner/setup/filesystems.sorted 2>> /tmp/stderr.log
+
+header "Mounting filesystems"
+while read line
+do
+       FS_DEVICE=`echo $line | awk '{print $1}'`
+       FS_MNTPOINT=`echo $line | awk '{print $2}'`
+       FS_TYPE=`echo $line | awk '{print $3}'`
+       FS_LABEL=`echo $line | awk '{print $4}'`
+
+       
+       # if it starts with a / it's going to be mounted
+       if [ `echo ${FS_MNTPOINT} | grep '^/'` ]
+       then
+               MNT_POINT=`echo ${FS_MNTPOINT} | sed 's/^\///'`
+               msg -n "Mounting ${ANSI_BLUE}${FS_DEVICE}${ANSI_DONE} on ${ANSI_BLUE}/cloner/mnt/${MNT_POINT}${ANSI_DONE}"
+
+               mkdir -p /cloner/mnt/${MNT_POINT} >> /tmp/stdout.log 2>> /tmp/stderr.log
+
+               mount -t ${FS_TYPE} ${FS_DEVICE} /cloner/mnt/${MNT_POINT} >> /tmp/stdout.log 2>> /tmp/stderr.log
+               if [ "$?" = "0" ]
+               then
+                       ok_msg
+               else
+                       fail_msg
+                       fatal_error "Failed to mount ${FS_DEVICE} to /cloner/mnt/${MNT_POINT}"
+               fi
+       fi
+
+done < /cloner/setup/filesystems.sorted
+
diff --git a/etc/cloner3/startup.sh b/etc/cloner3/startup.sh
new file mode 100755 (executable)
index 0000000..c9826ab
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/ash
+
+. /etc/library.sh
+. /etc/cloner3/include.sh
+. /etc/cloner3/cloner_server.sh
+
+# first thing we do is bring up the network interface if we are not
+# installing from a sourcepath
+if [ "${_srcpath}" != "" ]
+then
+       /etc/cloner2/detect_cd.sh
+fi
+
+/etc/cloner2/get_setup.sh
+if [ $? != 0 ]; then
+       exit 1
+fi
+
+
+# if we are supposed to automatically format disks
+if [ "${_manualdisk}" = "" ]
+then
+       /etc/cloner2/prep_disks.sh
+       if [ $? != 0 ]; then
+               exit 1
+       fi
+       /etc/cloner2/installer.sh
+       if [ $? != 0 ]; then
+               exit 1
+       fi
+       
+       server_clone_done "${_node}" "${_nextboot}"
+       
+       if [ "${_reboot}" != "" ]
+       then
+               server_log "Rebooting machine" "${_node}"       
+               reboot
+       fi
+       
+
+       header "Cloner install finished"
+       echo -e "The cloner install has finished successfully.  You may now reboot"
+       echo -e "the machine.  If you would like to re-mount the destination filesystems"
+       echo -e "to make any changes manually please run ${ANSI_BLUE}/etc/cloner2/remount-fs.sh${ANSI_DONE}"
+       echo -e ""
+       echo -en "Press ${ANSI_BLUE}[ENTER]${ANSI_DONE} for a command prompt"
+       read PROMPT
+
+else
+
+       header "Partition and format disks"
+       echo -e "You have selected to manually partition and format your hard disk drives"
+       echo -e "please do that now, and mount them under /cloner/mnt as they will be in"
+       echo -e "the installed OS.  When finished execute /etc/cloner2/installer.sh on the command"
+       echo -e "line to finish the installation of this system."
+
+       echo -en "Press ${ANSI_BLUE}[ENTER]${ANSI_DONE} for a command prompt"
+       read PROMPT
+fi
diff --git a/etc/cloner3/switch_cd.sh b/etc/cloner3/switch_cd.sh
new file mode 100755 (executable)
index 0000000..17393fe
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/ash
+
+. /etc/library.sh
+. /etc/cloner3/include.sh
+. /tmp/cmdline.dat
+
+VOLUME=${1}
+FILENAME=${2}
+CONTINUE=0
+
+header "End of CD/DVD-ROM reached"
+
+while  [ "$CONTINUE" = "0" ]; do
+    umount /mnt/media >> /tmp/stdout.log 2>> /tmp/stderr.log
+
+    msg "Please insert disk ${ANSI_BLUE}#${VOLUME}${ANSI_DONE} and press enter:"
+    read INPUT <&1
+
+    mount -t udf /dev/media /mnt/media >> /tmp/stdout.log \
+               2>> /tmp/stderr.log
+
+    if [ -e "/mnt/media/DISK_${VOLUME}" ]; then
+        CONTINUE=1
+    else
+        msg "${ANSI_RED}**** INVALID DISK ****${ANSI_DONE}"
+    fi
+done
+
+exit
diff --git a/etc/cloner3/test.sh b/etc/cloner3/test.sh
new file mode 100755 (executable)
index 0000000..e408977
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+. /etc/library.sh
+. /etc/cloner3/include.sh
+. /etc/cloner3/cloner_server.sh
+
+
+
+server_clone_done "${_node}" "${_nextboot}"