#!/bin/sh
#
#
## Michael Setzer II - Program Modifications
projectname="G4L"
projectlongname="Disk Imaging with Linux"

## changed some default values, and allow passing of values at startup
## Set Tab setting to 2 spaces for best editting
## Date: 6/02/2007
## Optional Startup Parameters  
## $1 - IP address of FTP Server
## $2 - IMAGE NAME WITH EXTENSION
## $3 - USERID and PASSWORD 
##      either of two formats
##      USERID:PASSWORD
##      '-u USERID -p PASSWORD'
## $4 - dhcp    (default to get ipaddress from dhcpd)
## $5 - change default directory from img to this
## $6 - change default device from eth0
## $7 - if not blank, set reboot to Yes
export PATH=$PATH:`pwd`
setterm -blank 0
pcnt=0
xreboot="No"
if [ -n "$7" ]; then
	xreboot="Yes"
fi

device=eth0
#Added ifcheck.sh by dan.s@hostdime.com
#to handle systems with multiple nics and eth0 not default
if [ -n "$6" ]; then
	device=$6
else
	IF_ARRAY=( $(ifconfig -a | grep -E "^eth|^wlan" | awk {'print $1'}) )

	for CURR_INT in "${IF_ARRAY[@]}"
	do
		LINK_CHK=`ethtool $CURR_INT | grep "Link detected" | awk {'print $3'}`

		if [ "$LINK_CHK" == "yes" ]; then
                   device=$CURR_INT
                   break
                fi
        done
fi

mkdir -p /mnt/local
cat /dev/null >/tmp/out

netzip=Lzop
localzip=Lzop
server="$1"
netimagename="$2"
useridpass="$3"
ipaddress=`ifconfig $device | grep inet\  | cut -f 2 -d: | cut -f 1 -d\  `

## Added to support user:password format conversion to ncftp format
if [ -n "$useridpass" ]; then
	if [ `echo $useridpass | awk '{print $1;}' -` != "-u" ] ; then
		useridpass=`echo $useridpass | awk -F: '{print "-u " $1 " -p " $2;}' -`
	fi
fi

## automatcially change default if filename if ext is .lzo
## ext=`echo $2 | cut -d. -f2`
ext=`echo ${2##*.}`
if [ "$ext" = "lzo" ]; then
	netzip="Lzop"
fi
## automatcially change default if filename if ext is .bz
if [ "$ext" = "bz" ]; then
	netzip="BZip2"
fi
if [ "$ext" = "gz" ]; then
	netzip="GZip"
fi

if [ "$4" = "dhcp" ]; then
## 06/23/2007 new busybox changed ip from field 4 to field 3
		ipaddress=`udhcpc -n -i $device | grep Lease | cut -d\  -f3`
		/sbin/ifconfig $device $ipaddress up
fi

## Created a function for the Progress Screen instead of multiple
## copies using multiply files. Just setup 1 function with a msg variable
## to set the minor differnces between earlier versions.

progress()
{
## Added a redirection of stderr from ncftp commands.
## Would get an error message rarely about a register 82 problem with duplex 
## mismatch. This error would message the contents of the screen, but the updates
## of the progress would go on. Redirects output to file, and then displays last 
## two lines of the file.
## This just sets the starting value as being OK

echo "OK" >/tmp/ncftpstatus.out
echo "0.00% Starting" > /tmp/progress.out
## Added the Start time of the process to the progress screen
## Removed - Replaced with modification to jetcat-mod to 
## Display MBs of data transferred of total, and Elapsed time.
## starttime=`date +%T`
(
while test "$pcnt" != "100"
do
## changed to a common progress.out file for all progress
pcnt=`tail -n1 /tmp/progress.out`
echo "XXX"
## Modified Jetcat-mod to display two decimal positions
## have to cut off the decimals for the gauge to work.
echo $pcnt | cut -d. -f 1
echo "\n"
## msg variable set before calling the progress function to 
## make minor variation between different screens.
echo "$msg\n"
echo "The progress bar shows the percentage of the amount written\n"
echo "to the size of the destination.\n\n"
echo "Please stand by, this might take some time!\n\n"
## Percentage displays with 2 decimal places, plus start time and current time.
## This lets one check time status of process in addition to percentage
echo "Progress"
echo "$pcnt\n"
## Removed Current time and Start time for modified jetcat-mod
##echo "Current Time:	`date +%T`"
##echo "Start Time:  	$starttime"
## add display of last four lines of ncftp stderr if any.
echo -n "ncftpstatus: "
ncftpstatus=`tail -n4 /tmp/ncftpstatus.out`
echo $ncftpstatus
echo "XXX"
sleep 5
done
) | 
$DIALOG --backtitle "$backtitle" --title "Working..." --clear --gauge "One moment..." 20 70
## Outputs start time and current time, so it can be checked if one isn't around at end
## of process. Also, note one can use Ctrl-Alt F2 to switch to another screen to review
## the file contents or use the special command option.
tail -n5 /tmp/progress.out >/tmp/time
## removed date process since jetcat-mod does a better job
## echo "$starttime `date +%T`">/tmp/time
rm /tmp/progress.out
touch /tmp/progress.out
## Added a pause to let the user see final results before it returns.
}

: ${DIALOG=dialog}
: ${DIALOG_OK=0}
: ${DIALOG_CANCEL=1}
: ${DIALOG_ESC=255}

# global vars
author="Frank Stephen"
version="v0.26a"
year="2008"
website="http://freshmeat.net/projects/$projectname"

# path to images on ftp server
ftppath=img
if [ -n "$5" ]; then
	ftppath=$5
fi
# window title
backtitle="$projectname $version, $author $year modifications by Michael D. Setzer II"

# parse info about devices to tempfiles
## original netdevices=`cat /proc/net/dev |grep eth |sed -e 's/://g' |awk '{print $1}'`
## Change1  netdevices=`cat /proc/net/dev |grep eth |sed -e 's/:/ /g' |awk '{print $1}'`
## Changed to terminate at the colon since after some options, a number was getting added 
## to the eth0:
netdevices=`cat /proc/net/dev |grep -E "eth|wlan" |cut -d: -f 1`
partitions=`cat /proc/partitions |grep .d |awk '{print $4}'`

# write systeminfo file
echo "Drive/Partition sizes: " >> /tmp/sysinfo
cat /proc/partitions |grep .d | awk '{print $4,$3}' |sort >>/tmp/sysinfo
echo >> /tmp/sysinfo
echo "Drive models: " >> /tmp/sysinfo
for h in $partitions
	do
		length=`echo $h |wc -c`
		if [ $length -lt 5 ]; then
			echo $h >> /tmp/sysinfo
			cat /proc/ide/$h/model >> /tmp/sysinfo 2>/dev/null
		fi
	done

# write menulists
partlist=""
netlist=""

for i in $partitions
	do partlist="$partlist `echo $i detected...OK off`"
	done

## Reset partlist to have size instead of detected message
partlist=""
cat /proc/partitions |grep .d | awk '{print $4,$3}' >/tmp/sysinfo2
while read LINE
	do 
		partlist="$partlist `echo "$LINE off"`"
	done </tmp/sysinfo2

### 2008/5/27 New partlist to have size and partitiion type.
partlist="";
fdisk -l 2>/dev/null | grep /dev | grep -v Disk | sed s/*/\ / | awk '{print $1,$6$7$8}' | cut -b6-30 >/tmp/partout
cat /proc/partitions |grep .d | awk '{print $4,$3}' >/tmp/sysinfo2
while read LINE
	do 
#		xxdev=`echo $LINE | cut -b1-4`;
#		xxsize=`echo $LINE | cut -b5-30`;
		xxdev=`echo $LINE | cut -f1 -d\  `;
		xxsize=`echo $LINE | cut -f2 -d\  `;
		xxsize2=`echo ${#xxsize}`;
#		dev2=`echo $xxdev | cut -b4-4`;
#		if [ "$xxdev2" = "" ]; then
		pad="";
#		else
#			pad="_";
#		fi
		for ((a=xxsize2;a<=12;a++))
		do 
			pad=$pad\_;
		done
		xxtype="";
		xxtype=`cat /tmp/partout | grep $xxdev\  2>/dev/null |  cut -f2 -d\  `;
		if [ -z $xxtype ]; then
			xxtype="DISK";
		fi
		partlist="$partlist `printf "%s %s%s--%s off" $xxdev  $pad $xxsize $xxtype `"; 
	done </tmp/sysinfo2

### End of addition


for j in $netdevices
	do netlist="$netlist `echo $j detected...OK off`"
	done

createTemp()
{
	export tempfile${1}="/tmp/test${1}$$"
}

#
# create tempfiles for menu structure
#

#main menu
createTemp main

#raw mode menu
createTemp rawmenu

# net menu
createTemp netmenu

# net config
createTemp device

# net device
createTemp ip

# net ftp
createTemp ftp

# net filename
createTemp netname

# net zip
createTemp netzip

# netbackup menu
createTemp netback

# netrestore menu
createTemp netrest

# local menu
createTemp localmenu

# local drive
createTemp localdrive

# local filename
createTemp localname

# local split
createTemp localsplit

# local zip
createTemp localzip

# local backup menu
createTemp localback

# local restore menu
createTemp localrest

# clone menu
createTemp clonemenu

# clone source
createTemp clonesource

# clone target
createTemp clonetarget

# file mode menu
createTemp filemenu

# file mode eth device
createTemp fileip

# file mode ip address
createTemp filedevice

# file mode partition
createTemp filepart

# util menu
createTemp utilmenu

# util hdparm
createTemp hdparm

# util zero
createTemp utilzero

# util dd_rescue
createTemp ddres

# util dd_rescue source
createTemp ddressource

# util dd_rescue target
createTemp ddrestarget


$DIALOG --backtitle "$backtitle" \
	--title "INFORMATION" --clear \
		--yesno "$projectname - $projectlongname\n \
		$author $year \n\n \
		$projectname comes with ABSOLUTELY NO WARRANTY ! \n \
		This is free Software, and you are welcome \n \
		to redistribute it freely. Read the online Help\n \
		for more info on this delicate topic. \n\n \
		USE AT OWN RISK! \n\n \
		Accept these conditions? YES to proceed, NO to quit. " 20 60

case $? in
$DIALOG_OK)

	while [ "$retvalmain" != "1" ]
	do

		retvalrawmenu=0
		retvalfilemenu=0
		retvalnetmenu=0
		retvalclonemenu=0
		retvallocalmenu=0
		retvalutilmenu=0

		$DIALOG --backtitle "$backtitle" \
				--title "MAIN MENU" \
				--menu "Choose your desired mode:"  0 0 0 \
					"RAW Mode"  "ANY filesystem, every bit, local+ftp" \
					"File Mode"  "Some filesystems only, only files, local+special server" \
					"Utilities"  "System info and tools" \
					"Show Help"  "Show IMPORTANT help" 2> $tempfilemain
		retvalmain=$?

		choicemain=`cat $tempfilemain`

		case $retvalmain in
		$DIALOG_OK)
			case $choicemain in
			"RAW Mode")
				while [ "$retvalrawmenu" != "1" ]
				do
				$DIALOG --backtitle "$backtitle" \
						--title "RAW MODE" \
						--menu "Choose one of the following options: \n\n" 0 0 0\
							"Network use"  "Backup/Restore to/from network" \
							"Local use"  "Backup/Restore to/from local drive" \
							"Click'n'Clone"  "Directly clone a drive" \
							"Show Help"  "Show IMPORTANT helpfile" 2> $tempfilerawmenu

				retvalrawmenu=$?

				choicerawmenu=`cat $tempfilerawmenu`

				case $retvalrawmenu in
				$DIALOG_OK)
					case $choicerawmenu in
					"Network use")
						retvalnetmenu=0

						while [ "$retvalnetmenu" != "1" ]
						do
## Added leading letters to menu otions
## to allow for selection by using letters.
## Added option C: to allow for DHCP option
## Added option F: to allow for non-anonymous use
## Added option S: for running extra commands during script
## Added option X: to reboot after finished
## Added the displaying of the current value of values

							$DIALOG --clear --backtitle "$backtitle" \
									--title "NETWORK USE" \
									--menu "Choose one of the following options: \n" 0 78 17 \
										"A: Pick device"  "Select ethernet device ($device)" \
										"B: Config device"  "Set IP address" \
										"C: Config with DHCP"  "Set IP address DHCP ($ipaddress)" \
										"D: Config FTP"  "Set IP for FTP server ($server)" \
										"E: Config useridpass"  "Set useridpass option ($useridpass)" \
										"F: Config filename"  "Set filename on FTP ($netimagename)" \
										"G: Toggle compression"  "Select compression types ($netzip)" \
										"H: Backup"  "Backup drive/partition to FTP server" \
										"I: Restore"  "Restore drive/partition from FTP server" \
										"N: NTFSCLONE Backup"  "Backup NTFS partition to FTP server" \
										"O: NTFSCLONE Restore" "Restore NTFS partition from FTP server" \
										"P: Path to Image Directory" "Change default directory ($ftppath)" \
										"S: Special Commands" "example: route, ping, etc.."\
										"T: Display Time"  "result after transfer.."\
										"U: UDP-RECEIVE"  "UDP Multi-cast to process faster restores" \
										"X: Reboot"  "Reboot machine after finished"  2> $tempfilenetmenu

							retvalnetmenu=$?

							choicenetmenu=`cat $tempfilenetmenu`

							case $retvalnetmenu in
							$DIALOG_OK)

								case $choicenetmenu in
								"A: Pick device")

									$DIALOG --backtitle "$backtitle" \
											--title "PICK DEVICE" \
											--radiolist "Choose network device \n(Use Space Bar)\n\
														Select from:" 0 0 0 \
														$netlist 2> $tempfiledevice
									retvaldevice=$?

									choicedevice=`cat $tempfiledevice`

									case $retvaldevice in
									$DIALOG_OK)

										device=$choicedevice
									;;

									$DIALOG_CANCEL)
									;;

									$DIALOG_ESC)
									;;
									esac
									;;

							"B: Config device")
									$DIALOG --backtitle "$backtitle" \
											--title "Set Network" --clear \
											--inputbox "Set IP Address to match your subnet. \
												\nExample: 192.168.0.5 \
												\n\nEnter IP Address:" 0 0 2> $tempfileip

									retvalip=$?
									case $retvalip in
									$DIALOG_OK)

										ipaddress=`cat $tempfileip`
										/sbin/ifconfig $device $ipaddress up
									;;

									$DIALOG_CANCEL)
									;;

									$DIALOG_ESC)
										if test -s $tempfileip ; then
											ipaddress=`cat $tempfileip`
											/sbin/ifconfig $device $ipaddress up
										fi
										;;
									esac
									;;
## Added option to get IP via dhcpd
## Added the udhcpc to the busybox build and udhcpc.sh script

							"C: Config with DHCP")
							ipaddress=`udhcpc -n -i $device |grep Lease|cut -d\  -f3`
							/sbin/ifconfig $device $ipaddress up
									;;
							"D: Config FTP")
								$DIALOG --backtitle "$backtitle" \
										--title "CONFIG FTP" --clear \
										--inputbox "Enter IP Address of FTP Server. \
												\nFTP server must allow anonymous write access! \
												\nExample: 192.168.0.1 \
												\n\nFTP IP:" 0 0 2> $tempfileftp

								retvalftp=$?
								case $retvalftp in
								$DIALOG_OK)

									server=`cat $tempfileftp`
								;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
									if test -s $tempfileftp ; then
										server=`cat $tempfileftp`
									fi
								;;
								esac
								;;


							"F: Config filename")
### Added this since a user report error if Directory was empty.
### This should add a dummy file that goes at end of list
echo "END_OF_LIST" > {END_OF_LIST}
ncftpput $useridpass $server $ftppath/ {END_OF_LIST}
files=`ncftpls $useridpass ftp://$server/$ftppath/ | grep -v 'lost+found' | grep -v 'ncftpls:'`
filelist="`echo Enter Filename on`"
for i in $files
	do filelist="$filelist `echo $i file off`"
	done

							$DIALOG --backtitle "$backtitle" \
										--title "BACKUP" \
										--radiolist "Choose Enter for New File Name(Use Space Bar)\
												\n or Select from following files:" 0 0 0 \
												$filelist 2> $tempfilenetname

								retvalnetback=$?
								netimagename=`cat $tempfilenetname`
if [ "$netimagename" = "Enter" ] ; then
$DIALOG --backtitle "$backtitle" \
										--title "CONFIG FILENAME" --clear \
										--inputbox "Enter filename of the stored image. \
											\nExample: hda_workstation2.img \
											\n\nFilename:" 0 0 2> $tempfilenetname

								retvalnetname=$?
								case $retvalnetname in
								$DIALOG_OK)
									netimagename=`cat $tempfilenetname`
								;;
								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
									if test -s $tempfilenetname ; then
										netimagename=`cat $tempfilenetname`
									fi
								;;
								esac
fi
								;;

							"P: Path to Image Directory")
								$DIALOG --backtitle "$backtitle" \
										--title "Image Directory" --clear \
										--inputbox "Enter image directory of the stored image. \
											\nCurrent setting: $ftppath \
											\n\nDirectory:" 0 0 2> $tempfilenetname

								retvalnetname=$?
								case $retvalnetname in
								$DIALOG_OK)

									ftppath=`cat $tempfilenetname`
									if [ -z $ftppath]; then
										ftppath="."
									fi
								;;
								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
									ftppath=img
								;;
								esac
								;;



## ncftp utility allows for userid and password to be set
## with the -u userid -p password values.
## Added a variable to contain these values.

							"E: Config useridpass")
								$DIALOG --backtitle "$backtitle" \
										--title "CONFIG USERIDPASS" --clear \
										--inputbox "Enter userid and password option. \
											\nExample: -u userx -p password \
											\n      or userx:password\
											\n\nOptions:" 0 0 2> $tempfilenetname

								retvalnetname=$?
								case $retvalnetname in
								$DIALOG_OK)

									useridpass=`cat $tempfilenetname`
## Added to support user:password format conversion to ncftp format
									if [ -n "$useridpass" ]; then
										if [ `echo $useridpass | awk '{print $1;}' -` != "-u" ] ; then
											useridpass=`echo $useridpass | awk -F: '{print "-u " $1 " -p " $2;}' -`
										fi
									fi
								;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
									if test -s $tempfilenetname ; then
										useridpass=`cat $tempfilenetname`
## Added to support user:password format conversion to ncftp format
										if [ -n "$useridpass" ]; then
											if [ `echo $useridpass | awk '{print $1;}' -` != "-u" ] ; then
												useridpass=`echo $useridpass | awk -F: '{print "-u " $1 " -p " $2;}' -`
											fi
										fi
									fi
								;;
								esac
								;;

## Changed default compress to GZIP

							"G: Toggle compression")
								$DIALOG --backtitle "$backtitle" \
										--title "TOGGLE COMPRESSION" \
										--radiolist "Choose whether to use compression or not.\n(Use Space Bar)\
											\nBe careful, compression requires much CPU power!" 0 0 0 \
											"None" "No compression." ON \
											"GZip" "GZip compression." off \
											"Lzop" "Lzop compression." off \
											"BZip2" "BZip2 compression." off 2> $tempfilenetzip

								retvalnetzip=$?

								choicenetzip=`cat $tempfilenetzip`
								case $retvalnetzip in
								$DIALOG_OK)

									netzip=`cat $tempfilenetzip`
								;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
									if test -s $tempfilenetzip ; then
										netzip=`cat $tempfilenetzip`
									fi
								;;

								esac
								;;

							"H: Backup")
								if [ "$ipaddress" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "ERROR" --clear \
											--msgbox "No Network IP Address for eth0 set! \n
													->Back to Main Menu." 0 0
									continue
								fi



								if [ "$server" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
										--title "ERROR" --clear \
										--msgbox "No FTP IP Address set! \n
												->Back to Main Menu." 0 0
									continue
								fi

								if [ "$netimagename" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
										--title "WARNING" --clear \
										--msgbox "No filename for image set, using default \n
												Filename: image.img.gz" 0 0
									netimagename=image.img.gz
								fi



								if [ "$netzip" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
										--title "WARNING" --clear \
										--msgbox "Compression not defined, using default \n
												Compression: None" 0 0
									netzip=None
								fi


								$DIALOG --backtitle "$backtitle" \
										--title "BACKUP" \
										--radiolist "Choose Drive or Partition to backup\n(Use Space Bar)\n\
												Select from:" 0 0 0 \
												$partlist 2> $tempfilenetback

								retvalnetback=$?

								choicenetback=`cat $tempfilenetback`

								case $retvalnetback in
								$DIALOG_OK)

									disk=/dev/$choicenetback

									$DIALOG --backtitle "$backtitle" \
											--title "ABOUT TO BACKUP" --clear \
											--yesno "Collected information: \
													\nLocal IP Address: $ipaddress \
													\nFTP IP Address: $server \
													\nTarget imagename: $netimagename \
													\nFTP path: $ftppath \
													\nCompression: $netzip \
													\nSource Drive: $disk \
													\n\nAre you sure?" 0 0
									case $? in
									$DIALOG_OK)

										readsize=`cat /proc/partitions |grep $choicenetback| head -n 1 |awk '{print $3}'`
										pcnt=0
##  msg set for backups.
										msg="$projectname is backing up your drive.\n"
										if [ "$netzip" = "None" ] ; then
												(dd bs=1M if=$disk 2>/dev/null | jetcat-mod -f 5000 -p $readsize 2>/tmp/progress.out |ncftpput -o "useHELP_SITE=0" -m $useridpass -c -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out) &
## Single progress function
												progress
										fi


										if [ "$netzip" = "GZip" ] ; then
												(dd bs=1M if=$disk 2>/dev/null | jetcat-mod -f 5000 -p $readsize 2>/tmp/progress.out |gzip -c - | ncftpput -o "useHELP_SITE=0" -m $useridpass -c -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out) &
## Single progress function
												progress
										fi

										if [ "$netzip" = "Lzop" ] ; then
												(dd bs=1M if=$disk 2>/dev/null | jetcat-mod -f 5000 -p $readsize 2>/tmp/progress.out |lzop -c - | ncftpput -o "useHELP_SITE=0" -m $useridpass -c -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out) &
## Single progress function
												progress
										fi

										if [ "$netzip" = "BZip2" ] ; then
												(dd bs=1M if=$disk 2>/dev/null | jetcat-mod -f 5000 -p $readsize 2>/tmp/progress.out |bzip2 | ncftpput -o "useHELP_SITE=0" -m $useridpass -c -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out) &
## Single progress function
												progress
										fi

										if [ "$xreboot" = "Yes" ] ; then
												echo "Rebooting"
												sleep 10
												reboot
										fi

									;;

									$DIALOG_CANCEL)
									;;

									$DIALOG_ESC)
									;;
									esac
									;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
								;;

								esac
								;;

							"N: NTFSCLONE Backup")
								if [ "$ipaddress" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "ERROR" --clear \
											--msgbox "No Network IP Address for eth0 set! \n
													->Back to Main Menu." 0 0
									continue
								fi



								if [ "$server" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
										--title "ERROR" --clear \
										--msgbox "No FTP IP Address set! \n
												->Back to Main Menu." 0 0
									continue
								fi

								if [ "$netimagename" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
										--title "WARNING" --clear \
										--msgbox "No filename for image set, using default \n
												Filename: image.img.gz" 0 0
									netimagename=image.img.gz
								fi



								if [ "$netzip" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
										--title "WARNING" --clear \
										--msgbox "Compression not defined, using default \n
												Compression: None" 0 0
									netzip=None
								fi


								$DIALOG --backtitle "$backtitle" \
										--title "BACKUP" \
										--radiolist "Choose NTFS Partition ONLY to backup\n(Use Space Bar)\n\
												Select from:" 0 0 0 \
												$partlist 2> $tempfilenetback

								retvalnetback=$?

								choicenetback=`cat $tempfilenetback`
								date   ### Echo Start Time
								date >/tmp/time
								case $retvalnetback in
								$DIALOG_OK)

									disk=/dev/$choicenetback

									$DIALOG --backtitle "$backtitle" \
											--title "ABOUT TO BACKUP" --clear \
											--yesno "Collected information: \
													\nLocal IP Address: $ipaddress \
													\nFTP IP Address: $server \
													\nTarget imagename: $netimagename \
													\nFTP path: $ftppath \
													\nCompression: $netzip \
													\nSource Drive: $disk \
													\n\nAre you sure?" 0 0
									case $? in
									$DIALOG_OK)

										readsize=`cat /proc/partitions |grep $choicenetback| head -n 1 |awk '{print $3}'`
										pcnt=0
##  msg set for backups.
										msg="$projectname is backing up your drive.\n"
										if [ "$netzip" = "None" ] ; then
												(ntfsclone -s -o - $disk |ncftpput -o "useHELP_SITE=0" -m $useridpass -c -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out) 
										fi


										if [ "$netzip" = "GZip" ] ; then
												(ntfsclone -s -o - $disk|gzip -c - | ncftpput -o "useHELP_SITE=0" -m $useridpass -c -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out) 
										fi

										if [ "$netzip" = "Lzop" ] ; then
												(ntfsclone -s -o - $disk|lzop -c - | ncftpput -o "useHELP_SITE=0" -m $useridpass -c -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out) 
										fi

										if [ "$netzip" = "BZip2" ] ; then
												(ntfsclone -s -o - $disk |bzip2 | ncftpput -o "useHELP_SITE=0" -m $useridpass -c -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out) 
										fi

										if [ "$xreboot" = "Yes" ] ; then
												echo "Rebooting"
												sleep 10
												reboot
										fi

									;;

									$DIALOG_CANCEL)
									;;

									$DIALOG_ESC)
									;;
									esac
									date           ### Echo End Time
									date >>/tmp/time
									sleep 10       ### Pause 
									;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
								;;

								esac
								;;


#### Adding option to multi-cast image to many machines at one time
#### with multi-cast instead of uni-cast.
#### need to use udp-sender --file imagename 
#### so far only set to work with lzop image
#### might want to use --max-bitrate 80M or other value to no overload hubs/switches

							"U: UDP-RECEIVE")
								if [ "$ipaddress" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "ERROR" --clear \
											--msgbox "No Network IP Address for eth0 set! \n
													->Back to Main Menu." 0 0
									continue
								fi

								$DIALOG --backtitle "$backtitle" \
										--title "BACKUP" \
										--radiolist "Choose Drive or Partition to backup\n(Use Space Bar)\n\
												Select from:" 0 0 0 \
												$partlist 2> $tempfilenetback

								retvalnetback=$?

								choicenetback=`cat $tempfilenetback`

								case $retvalnetback in
								$DIALOG_OK)

									disk=/dev/$choicenetback

									$DIALOG --backtitle "$backtitle" \
											--title "ABOUT TO UDP-RECEIVE" --clear \
											--yesno "Collected information: \
													\nLocal IP Address: $ipaddress \
													\nCompression: $netzip \
													\nDestination Drive: $disk \
													\n\nThis uses UDPCAST - udp-receiver \
													\nFrom http://udpcast.linux.lu/ \n \
													\n\nAre you sure?" 0 0
									case $? in
									$DIALOG_OK)

										readsize=`cat /proc/partitions |grep $choicenetback | head -n 1 |awk '{print $3}'`
										pcnt=0
##  msg set for backups.
										msg="$projectname is using udp-receive restore your drives.\n"

										if [ "$netzip" = "Lzop" ] ; then
												(udp-receiver --interface $device --pipe 'lzop -d -c -' -f $disk)
										fi

										if [ "$netzip" = "GZip" ] ; then
												(udp-receiver --interface $device --pipe 'gunzip -c -' -f $disk)
										fi

										if [ "$netzip" = "BZip2" ] ; then
												(udp-receiver --interface $device --pipe 'bzcat' -f $disk)
										fi

										echo "10 Second Pause"
										sleep 10

									;;

									$DIALOG_CANCEL)
									;;

									$DIALOG_ESC)
									;;
									esac
									;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
								;;

								esac
								;;




## added the ability to run other commands within the script
## This includes all the functions that are included in the busybox
## system. There were a number of symbolic links on the original $projectname
## that actually where not included in the build of busybox.
## I rebuilt the busybox to include all the commands that had symbolic 
## links that I could find in busybox. Running busybox will show the 
## list of commands. The only ones that I could not find in the current
## busybox were dutmp, loadacm and update. Many of the commands probable 
## are not needed, but since the links where already included I built them
## into the busybox. 
## There are also a number of other programs in addition to the busybox collection
## bc, bzip2, jetcat-mod, ncftpget, ncftpls, ncftpput, partimage, partimaged
## split, tr, wc, brep, bash, cat, dialog, busybox, hdparm, dd_rescue, dd_rhelp, parted
## some of these are used in other options of the $projectname.

							"S: Special Commands")
									$DIALOG --backtitle "$backtitle" \
											--title "Run Special Commands" --clear \
											--inputbox "Enter Commands to run. \
												\nExample: route, ping -c 10 ipaddress, ifconfig, etc.\
												\nethtool - to set parameters if autoneg doesn't work\
												\nTwo Special Options I added that some might find useful\
												\nBuffy (case sensitive) does directory of ftpserver\
												\nXena (case sensitive) does special route gateway\
												\nReboot (case sesitive) does reboot after backup/restore\
												\n	my college network is setup with 4 logical Class C\
												\n	networks, but 1 physical network. This command sets\
												\n	a direct route rather than going thru the 10M router\
												\n	not pretty, but it makes it work at 100M instead of 10\
												\n\nEnter Command with parameters (10 second pause):" 0 0 2> $tempfileip

									retvalip=$?
									case $retvalip in
									$DIALOG_OK)

									specialcommand=`cat $tempfileip`
									if [ "$specialcommand" = "Xena" ] ; then
											specialcommand="route add $server gw $ipaddress"
									fi
									if [ "$specialcommand" = "Buffy" ] ; then
											specialcommand="ncftpls $useridpass ftp://$server/$ftppath/"
									fi
									if [ "$specialcommand" = "Reboot" ] ; then
                      xreboot="Yes"
											specialcommand="echo xreboot set to Yes"
									fi

## Some commands don't produce output
## So I have it display the command being run
## Before and After, so you can see 
## Exactly what you entered
									echo Begin: $specialcommand
									$specialcommand
									echo Done:  $specialcommand
									echo "10 Second Pause"
									sleep 10
									;;

									$DIALOG_CANCEL)
									;;

								esac
								;;

			"T: Display Time")
				$DIALOG --clear --backtitle "$backtitle" \
						--title "TIME RESULTS" \
						--textbox /tmp/time 20 78
			;;



## Instead of having to exit all the way out of the script
## or pressing the reset button, just added a reboot option.

							"X: Reboot")
								reboot
									;;

							"O: NTFSCLONE Restore")
								if [ "$ipaddress" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "ERROR" --clear \
											--msgbox "No Network IP Address for eth0 set! \n
													->Back to Main Menu." 0 0
									continue
								fi

								if [ "$server" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "ERROR" --clear \
											--msgbox "No FTP IP Address set! \n
													->Back to Main Menu." 0 0
									continue
								fi

								if [ "$netimagename" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "WARNING" --clear \
											--msgbox "No filename for image set, using default \n
													Filename: image.img.gz" 0 0
									netimagename=image.img.gz
								fi

								if [ "$netzip" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "WARNING" --clear \
											--msgbox "Compression not defined, using default \n
													Compression: None" 0 0
									netzip=None
								fi

								$DIALOG --backtitle "$backtitle" \
										--title "RESTORE" \
										--radiolist "Choose NTFS partition to restore the image to\n(Use Space Bar)\
													\n\nSelect from:" 0 0 0 \
													$partlist 2> $tempfilenetrest

								retvalnetrest=$?

								choicenetrest=`cat $tempfilenetrest`
								case $retvalnetrest in
								$DIALOG_OK)

										rest=/dev/$choicenetrest

										$DIALOG --backtitle "$backtitle" \
												--title "About to restore disk" --clear \
												--yesno "Collected information: \
														\nLocal IP Address: $ipaddress \
														\nFTP IP Address: $server \
														\nSource imagename: $netimagename \
														\nFTP path: $ftppath \
														\nCompression: $netzip \
														\nTarget disk: $rest \n\n \
														\n\nAre you sure?" 0 0
										case $? in
										$DIALOG_OK)
											writesize=`cat /proc/partitions |grep $choicenetrest | head -n 1 |awk '{print $3}'`
											pcnt=0
## msg for the restore options
											msg="$projectname is restoring your drive.\n"
											date >/tmp/time

											if [ "$netzip" = "None" ] ; then
													(ncftpget -o "useHELP_SITE=0" $useridpass -c -V -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out | ntfsclone -r --overwrite $rest - ) 
											fi

											if [ "$netzip" = "GZip" ] ; then
													(ncftpget -o "useHELP_SITE=0" $useridpass -c -V -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out | gunzip -c -| ntfsclone -r --overwrite $rest - ) 
											fi

											if [ "$netzip" = "Lzop" ] ; then
													(ncftpget -o "useHELP_SITE=0" $useridpass -c -V -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out | lzop -d  -c -| ntfsclone -r --overwrite $rest - ) 
											fi

											if [ "$netzip" = "BZip2" ] ; then
													(ncftpget -o "useHELP_SITE=0" $useridpass -c -V -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out | bzcat | ntfsclone -r --overwrite $rest - ) 
											fi
											date >>/tmp/time
											rm /tmp/out
											touch /tmp/out
										if [ "$xreboot" = "Yes" ] ; then
												echo "Rebooting"
												sleep 10
												reboot
										fi

										;;

										$DIALOG_CANCEL)
										;;

										$DIALOG_ESC)
										;;

										esac
										;;

									$DIALOG_CANCEL)
									;;

									$DIALOG_ESC)
									;;

									esac
									;;



							"I: Restore")
								if [ "$ipaddress" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "ERROR" --clear \
											--msgbox "No Network IP Address for eth0 set! \n
													->Back to Main Menu." 0 0
									continue
								fi

								if [ "$server" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "ERROR" --clear \
											--msgbox "No FTP IP Address set! \n
													->Back to Main Menu." 0 0
									continue
								fi

								if [ "$netimagename" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "WARNING" --clear \
											--msgbox "No filename for image set, using default \n
													Filename: image.img.gz" 0 0
									netimagename=image.img.gz
								fi

								if [ "$netzip" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "WARNING" --clear \
											--msgbox "Compression not defined, using default \n
													Compression: None" 0 0
									netzip=None
								fi

								$DIALOG --backtitle "$backtitle" \
										--title "RESTORE" \
										--radiolist "Choose drive or partition to restore the image to\n(Use Space Bar)\
													\n\nSelect from:" 0 0 0 \
													$partlist 2> $tempfilenetrest

								retvalnetrest=$?

								choicenetrest=`cat $tempfilenetrest`
								case $retvalnetrest in
								$DIALOG_OK)

										rest=/dev/$choicenetrest

										$DIALOG --backtitle "$backtitle" \
												--title "About to restore disk" --clear \
												--yesno "Collected information: \
														\nLocal IP Address: $ipaddress \
														\nFTP IP Address: $server \
														\nSource imagename: $netimagename \
														\nFTP path: $ftppath \
														\nCompression: $netzip \
														\nTarget disk: $rest \n\n \
														\n\nAre you sure?" 0 0
										case $? in
										$DIALOG_OK)
											writesize=`cat /proc/partitions |grep $choicenetrest | head -n 1 |awk '{print $3}'`
											pcnt=0
## msg for the restore options
											msg="$projectname is restoring your drive.\n"


											if [ "$netzip" = "None" ] ; then
													(ncftpget -o "useHELP_SITE=0" $useridpass -c -V -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out | jetcat-mod -f 5000 -p $writesize 2>/tmp/progress.out | dd bs=1M of=$rest 2>/dev/null) &
## Single progress function
													progress

											fi

											if [ "$netzip" = "GZip" ] ; then
													(ncftpget -o "useHELP_SITE=0" $useridpass -c -V -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out | gunzip -c -| jetcat-mod -f 5000 -p $writesize 2>/tmp/progress.out |dd bs=1M of=$rest 2>/dev/null) &
## Single progress function
													progress	
											fi

											if [ "$netzip" = "Lzop" ] ; then
													(ncftpget -o "useHELP_SITE=0" $useridpass -c -V -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out | lzop -d  -c -| jetcat-mod -f 5000 -p $writesize 2>/tmp/progress.out |dd bs=1M of=$rest 2>/dev/null) &
## Single progress function
													progress	
											fi

											if [ "$netzip" = "BZip2" ] ; then
													(ncftpget -o "useHELP_SITE=0" $useridpass -c -V -d /tmp/out $server "$ftppath/$netimagename" 2>>/tmp/ncftpstatus.out | bzcat | jetcat-mod -f 5000 -p $writesize 2>/tmp/progress.out |dd bs=1M of=$rest 2>/dev/null) &
## Single progress function
													progress
											fi
											rm /tmp/out
											touch /tmp/out
										if [ "$xreboot" = "Yes" ] ; then
												echo "Rebooting"
												sleep 10
												reboot
										fi

										;;

										$DIALOG_CANCEL)
										;;

										$DIALOG_ESC)
										;;

										esac
										;;

									$DIALOG_CANCEL)
									;;

									$DIALOG_ESC)
									;;

									esac
									;;
								esac
								;;
							$DIALOG_CANCEL)
							;;

							$DIALOG_ESC)
							;;
							esac


						done
					;;


				"Local use")

					retvallocalmenu=0
					localsplit="Off"	
					localzip="Lzop"
					
					while [ "$retvallocalmenu" != "1" ]
					do
						$DIALOG --clear --backtitle "$backtitle" \
								--title "LOCAL USE" \
								--menu "Choose one of the following options: \n\n" 0 0 0 \
										"A: Pick drive"  "target/source partition for IMAGE file ($localdrive)" \
										"B: Config filename"  "Set filename ($localimagename)" \
										"C: Toggle split"  "Activate file splitting ($localsplit)" \
										"D: Toggle compression"  "Select compression types ($localzip)" \
										"E: Backup"  "Backup drive/partition to local drive" \
										"F: Restore"  "Restore drive/partition from local drive" \
										"N: NTFSCLONE Backup"  "Backup NTFS partition to Local" \
										"O: NTFSCLONE Restore" "Restore NTFS partition from Local" \
										"S: Special Commands" "example: route, ping, busybox, etc.."\
										"T: Display Time"  "result after transfer.."\
										"X: Reboot"  "Reboot machine after finished"  \
												2> $tempfilelocalmenu

						retvallocalmenu=$?

						choicelocalmenu=`cat $tempfilelocalmenu`

						case $retvallocalmenu in
						$DIALOG_OK)

							case $choicelocalmenu in

							"A: Pick drive")

								$DIALOG --backtitle "$backtitle" \
										--title "PICK DRIVE" \
										--radiolist "Choose drive to write to/read from.\n(Use Space Bar)\n\
												The drive that contains or will contain the image\
												\nSupported FS are:\n\
												ext2 - Linux\n\
												ext3 - Linux\n\
												reiserfs - Linux\n\
												fat32 - Windows95/98/NT/2k/XP\n\
												ntfs - Windows NT/2k/XP\
												\n\nSelect partition (example: /dev/hda1):" 0 0 0 \
												$partlist 2> $tempfilelocaldrive


								retvallocaldrive=$?

								choicelocaldrive=`cat $tempfilelocaldrive`
								case $retvallocaldrive in
								$DIALOG_OK)

									localdrive=$choicelocaldrive
###
                  umount /mnt/local 2>/dev/null
									mount /dev/$localdrive /mnt/local >/tmp/mount 2>&1
									retvalmount=$?
									if [ $retvalmount != 0 ] ; then
										$DIALOG --backtitle "$backtitle" \
												--title "ERROR" \
												--textbox /tmp/mount 0 0
										localdrive=""
										umount /mnt/local
									else
										testntfs=`cat /etc/mtab | grep /dev/$localdrive | cut -f 3 -d\  ` 
										if [ "$testntfs" = "ntfs" ]; then
											umount /mnt/local 2>/dev/null
											ntfs-3g /dev/$localdrive /mnt/local >/tmp/mount 2>&1
										fi
									fi

								;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
								;;

								esac
								;;

							"T: Display Time")
								$DIALOG --clear --backtitle "$backtitle" \
									--title "TIME RESULTS" \
									--textbox /tmp/time 20 78
								;;

							"X: Reboot")
								reboot
									;;

### Modified to give list of files on /mnt/local
							"B: Config filename")
files=`ls -1 -p /mnt/local | grep -v /`
filelist="`echo Enter Filename on`"
for i in $files
	do filelist="$filelist `echo $i file off`"
	done

							$DIALOG --backtitle "$backtitle" \
										--title "BACKUP" \
										--radiolist "Choose Enter for New File Name(Use Space Bar)\
												\n or Select from following files:" 0 0 0 \
												$filelist 2> $tempfilelocalname

								retvallocalname=$?
								localimagename=`cat $tempfilelocalname`
if [ "$localimagename" = "Enter" ] ; then
$DIALOG --backtitle "$backtitle" \
										--title "CONFIG FILENAME" --clear \
										--inputbox "Enter filename of the stored image. \
											\nExample: hda_workstation2.img \
											\n\nFilename:" 0 0 2> $tempfilelocalname

								retvallocalname=$?
								case $retvallocalname in
								$DIALOG_OK)
									localimagename=`cat $tempfilelocalname`
								;;
								$DIALOG_CANCEL)
								;;

###
###								$DIALOG --backtitle "$backtitle" \
###										--title "CONFIG FILENAME" --clear \
###										--inputbox "Enter filename of the stored image. \
###												\nExample: hda_workstation2.img \
###												\n\nFilename:" 0 0 2> $tempfilelocalname
###
###								retvallocalname=$?
###								case $retvallocalname in
###								$DIALOG_OK)
###
###									localimagename=`cat $tempfilelocalname`
###								;;
###
###								$DIALOG_CANCEL)
###								;;

								$DIALOG_ESC)

									if test -s $tempfilelocalname ; then
										localimagename=`cat $tempfilelocalname`
									fi
								;;
								esac
fi								
;;

							"C: Toggle split")
								$DIALOG --backtitle "$backtitle" \
										--title "TOGGLE SPLIT" \
										--radiolist "Choose if the imagefile should be split.\n(Use Space Bar)\
													\nIf the FS limits filesize to 2GB, enable splitting!" 0 0 0 \
													"Off" "Splitting off." ON \
													"On" "Splitting on." off  2> $tempfilelocalsplit

								retvallocalsplit=$?

								choicelocalsplit=`cat $tempfilelocalsplit`
								case $retvallocalsplit in
								$DIALOG_OK)

									localsplit=`cat $tempfilelocalsplit`
								;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)

									if test -s $tempfilelocalsplit ; then
										localsplit=`cat $tempfilelocalsplit`
									fi
								;;
								esac
								;;


							"D: Toggle compression")

								$DIALOG --backtitle "$backtitle" \
										--title "TOGGLE COMPRESSION" \
										--radiolist "Choose whether to use compression or not.\n(Use Space Bar)\
													\nBe careful, compression requires much CPU power!" 0 0 0 \
													"None" "No compression." off \
													"GZip" "GZip compression." off \
													"Lzop" "Lzop compression." ON \
													"BZip2" "BZip2 compression." off 2> $tempfilelocalzip

								retvallocalzip=$?

								choicelocalzip=`cat $tempfilelocalzip`
								case $retvallocalzip in
								$DIALOG_OK)

									localzip=`cat $tempfilelocalzip`
								;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
									if test -s $tempfilelocalzip ; then
										localzip=`cat $tempfilelocalzip`
									fi
								;;

								esac
								;;


							"E: Backup")

								if [ "$localdrive" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "ERROR" --clear \
											--msgbox "No target drive set! \n
													->Back to Main Menu." 0 0
									continue
								fi


								if [ "$localimagename" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "WARNING" --clear \
											--msgbox "No filename for image set, using default \n
													Filename: image.img.gz" 0 0
									localimagename=image.img.gz
								fi

								if [ "$localsplit" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "WARNING" --clear \
											--msgbox "Splitting not defined, using default \n
													Splitting: Off" 0 0
									localsplit=Off
								fi


								if [ "$localzip" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "WARNING" --clear \
											--msgbox "Compression not defined, using default \n
													Compression: None" 0 0
									localzip=None
								fi

								$DIALOG --backtitle "$backtitle" \
										--title "BACKUP" \
										--radiolist "Choose Drive or Partition to backup\n(Use Space Bar)\n\
													Select from:" 0 0 0 \
													$partlist 2> $tempfilelocalback

								retvallocalback=$?

								choicelocalback=`cat $tempfilelocalback`

								case $retvallocalback in
								$DIALOG_OK)

									localback=/dev/$choicelocalback

									$DIALOG --backtitle "$backtitle" \
											--title "ABOUT TO BACKUP" --clear \
											--yesno "Collected information: \
													\nTarget drive in /mnt/local: $localdrive \
													\nFilename for image: $localimagename \
													\nSplitting: $localsplit \
													\nCompression: $localzip \
													\nSource drive: $localback \
													\n\nAre you sure?" 0 0

									case $? in
									$DIALOG_OK)

										localreadsize=`cat /proc/partitions |grep $choicelocalback | head -n 1 |awk '{print $3}' `
										pcnt=0
## Message for local backup
										msg="$projectname is backing up your drive locally.\n"
										if [ "$localzip" = "None" ] ; then

											if [ "$localsplit" = "Off" ] ; then
													dd bs=1M if=$localback 2>/dev/null |jetcat-mod -f 5000 -p $localreadsize 2>/tmp/progress.out | dd bs=1M of=/mnt/local/$localimagename 2>/dev/null &
## Single Progress function
													progress
											fi

											if [ "$localsplit" = "On" ] ; then
													(dd bs=1M if=$localback 2>/dev/null |jetcat-mod -f 5000 -p $localreadsize 2>/tmp/progress.out |split -b 1000m - /mnt/local/$localimagename. ) &
## Single Progress function
													progress
											fi
										fi


										if [ "$localzip" = "GZip" ] ; then
											if [ "$localsplit" = "Off" ] ; then
													(dd bs=1M if=$localback 2>/dev/null |jetcat-mod -f 5000 -p $localreadsize 2>/tmp/progress.out |gzip -c - >/mnt/local/$localimagename) &
## Single Progress function
													progress

											fi

											if [ "$localsplit" = "On" ] ; then
													(dd bs=1M if=$localback 2>/dev/null |jetcat-mod -f 5000 -p $localreadsize 2>/tmp/progress.out | gzip -c - | split -b 1000m - /mnt/local/$localimagename. ) &
## Single Progress function
													progress
											fi

										fi

### lzop ??
										if [ "$localzip" = "Lzop" ] ; then
											if [ "$localsplit" = "Off" ] ; then
													(dd bs=1M if=$localback 2>/dev/null |jetcat-mod -f 5000 -p $localreadsize 2>/tmp/progress.out |lzop -c - >/mnt/local/$localimagename) &
## Single Progress function
													progress

											fi

											if [ "$localsplit" = "On" ] ; then
													(dd bs=1M if=$localback 2>/dev/null |jetcat-mod -f 5000 -p $localreadsize 2>/tmp/progress.out | lzop -c - | split -b 1000m - /mnt/local/$localimagename. ) &
## Single Progress function
													progress
											fi

										fi

### lzop ??


										if [ "$localzip" = "BZip2" ] ; then
											if [ "$localsplit" = "Off" ] ; then
													(dd bs=1M if=$localback 2>/dev/null |jetcat-mod -f 5000 -p $localreadsize 2>/tmp/progress.out | bzip2 >/mnt/local/$localimagename) &
## Single Progress function
													progress
											fi
											if [ "$localsplit" = "On" ] ; then
													(dd bs=1M if=$localback 2>/dev/null |jetcat-mod -f 5000 -p $localreadsize 2>/tmp/progress.out | bzip2 | split -b 1000m - /mnt/local/$localimagename. ) &
## Single Progress function
													progress
											fi
										fi

###									umount /mnt/local
										rm /tmp/out
										touch /tmp/out
									;;

									$DIALOG_CANCEL)
									;;

									$DIALOG_ESC)
									;;

									esac
									;;
								esac
								;;
							"N: NTFSCLONE Backup")

								if [ "$localimagename" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
										--title "WARNING" --clear \
										--msgbox "No filename for image set, using default \n
												Filename: image.img.gz" 0 0
									localimagename=image.img.gz
								fi

								if [ "$localzip" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
										--title "WARNING" --clear \
										--msgbox "Compression not defined, using default \n
												Compression: None" 0 0
									localzip=None
								fi


								$DIALOG --backtitle "$backtitle" \
										--title "BACKUP" \
										--radiolist "Choose NTFS Partition ONLY to backup\n(Use Space Bar)\n\
												Select from:" 0 0 0 \
												$partlist 2> $tempfilelocalback

								retvallocalback=$?

								choicelocalback=`cat $tempfilelocalback`
								date   ### Echo Start Time
								date >/tmp/time
								case $retvallocalback in
								$DIALOG_OK)

									disk=/dev/$choicelocalback

									$DIALOG --backtitle "$backtitle" \
											--title "ABOUT TO BACKUP" --clear \
											--yesno "Collected information: \
													\nTarget imagename: $localimagename \
													\nFTP path: $ftppath \
													\nCompression: $localzip \
													\nSource Drive: $disk \
													\n\nAre you sure?" 0 0
									case $? in
									$DIALOG_OK)

										readsize=`cat /proc/partitions |grep $choicelocalback| head -n 1 |awk '{print $3}'`
										pcnt=0
##  msg set for backups.
## 07/21/2007
										msg="$projectname is backing up your drive.\n"
										if [ "$localzip" = "None" ] ; then
											if [ "$localsplit" = "Off" ] ; then
												(ntfsclone -s -o - $disk >/mnt/local/$localimagename ) 
											fi
											if [ "$localsplit" = "On" ] ; then
												(ntfsclone -s -o - $disk |split -b 1000m - /mnt/local/$localimagename. ) 
											fi
										fi


										if [ "$localzip" = "GZip" ] ; then
											if [ "$localsplit" = "Off" ] ; then
												(ntfsclone -s -o - $disk |gzip -c - >/mnt/local/$localimagename ) 
											fi
											if [ "$localsplit" = "On" ] ; then
												(ntfsclone -s -o - $disk |gzip -c - | split -b 1000m - /mnt/local/$localimagename. ) 
											fi
										fi

										if [ "$localzip" = "Lzop" ] ; then
											if [ "$localsplit" = "Off" ] ; then
												(ntfsclone -s -o - $disk |lzop -c - >/mnt/local/$localimagename ) 
											fi
											if [ "$localsplit" = "On" ] ; then
												(ntfsclone -s -o - $disk |lzop -c - | split -b 1000m - /mnt/local/$localimagename. ) 
											fi
										fi

										if [ "$netzip" = "BZip2" ] ; then
											if [ "$localsplit" = "Off" ] ; then
												(ntfsclone -s -o - $disk |bzip2 >/mnt/local/$localimagename ) 
											fi
											if [ "$localsplit" = "On" ] ; then
												(ntfsclone -s -o - $disk |bzip2 | split -b 1000m - /mnt/local/$localimagename. ) 
											fi
										fi

										if [ "$xreboot" = "Yes" ] ; then
												echo "Rebooting"
												sleep 10
												reboot
										fi

									;;

									$DIALOG_CANCEL)
									;;

									$DIALOG_ESC)
									;;
									esac
									date           ### Echo End Time
									date >>/tmp/time
									sleep 10       ### Pause 
									;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
								;;

								esac
								;;

							"O: NTFSCLONE Restore")
								if [ "$localimagename" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "WARNING" --clear \
											--msgbox "No filename for image set, using default \n
													Filename: image.img.gz" 0 0
									localimagename=image.img.gz
								fi

								if [ "$localzip" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "WARNING" --clear \
											--msgbox "Compression not defined, using default \n
													Compression: None" 0 0
									localzip=None
								fi

								$DIALOG --backtitle "$backtitle" \
										--title "RESTORE" \
										--radiolist "Choose NTFS partition to restore the image to\n(Use Space Bar)\
													\n\nSelect from:" 0 0 0 \
													$partlist 2> $tempfilelocalrest

								retvallocalrest=$?

								choicelocalrest=`cat $tempfilelocalrest`
								case $retvallocalrest in
								$DIALOG_OK)

										rest=/dev/$choicelocalrest

										$DIALOG --backtitle "$backtitle" \
												--title "About to restore disk" --clear \
												--yesno "Collected information: \
														\nSource imagename: $localimagename \
														\nFTP path: $ftppath \
														\nCompression: $localzip \
														\nTarget disk: $rest \n\n \
														\n\nAre you sure?" 0 0
										case $? in
										$DIALOG_OK)
											writesize=`cat /proc/partitions |grep $choicelocalrest | head -n 1 |awk '{print $3}'`
											pcnt=0
## msg for the restore options
											msg="$projectname is restoring your drive.\n"
											date >/tmp/time
### 07/21/2007
                      multifiles="";
											if [ "$localsplit" = "On" ] ; then
													multifiles=".*";
											fi

											if [ "$localzip" = "None" ] ; then
													(cat /mnt/local/$localimagename$mulifiles | ntfsclone -r --overwrite $rest - ) 
											fi

											if [ "$localzip" = "GZip" ] ; then
													(cat /mnt/local/$localimagename$multifiles | gunzip -c -| ntfsclone -r --overwrite $rest - ) 
											fi

											if [ "$localzip" = "Lzop" ] ; then
													(cat /mnt/local/$localimagename$multifiles | lzop -d  -c -| ntfsclone -r --overwrite $rest - ) 
											fi

											if [ "$localzip" = "BZip2" ] ; then
													(cat /mnt/local/$localimagename$multifiles | bzcat | ntfsclone -r --overwrite $rest - ) 
											fi
											date >>/tmp/time
											sleep 10
											rm /tmp/out
											touch /tmp/out
										if [ "$xreboot" = "Yes" ] ; then
												echo "Rebooting"
												sleep 10
												reboot
										fi

										;;

										$DIALOG_CANCEL)
										;;

										$DIALOG_ESC)
										;;

										esac
										;;

									$DIALOG_CANCEL)
									;;

									$DIALOG_ESC)
									;;

									esac
									;;

							"S: Special Commands")
									$DIALOG --backtitle "$backtitle" \
											--title "Run Special Commands" --clear \
											--inputbox "Enter Commands to run. \
												\nExample: route, ping -c 10 ipaddress, ifconfig \
												\n         busybox for list of supported commands \
												\nethtool - to set parameters if autoneg doesn't work\
												\nTwo Special Options I added that some might find useful\
												\nBuffy (case sensitive) does directory of ftpserver\
												\nXena (case sensitive) does special route gateway\
												\nReboot (case sesitive) does reboot after backup/restore\
												\n	my college network is setup with 4 logical Class C\
												\n	networks, but 1 physical network. This command sets\
												\n	a direct route rather than going thru the 10M router\
												\n	not pretty, but it makes it work at 100M instead of 10\
												\n\nEnter Command with parameters (10 second pause):" 0 0 2> $tempfileip

									retvalip=$?
									case $retvalip in
									$DIALOG_OK)

									specialcommand=`cat $tempfileip`
									if [ "$specialcommand" = "Xena" ] ; then
											specialcommand="route add $server gw $ipaddress"
									fi
									if [ "$specialcommand" = "Buffy" ] ; then
											specialcommand="ncftpls $useridpass ftp://$server/$ftppath/"
									fi
									if [ "$specialcommand" = "Reboot" ] ; then
                      xreboot="Yes"
											specialcommand="echo xreboot set to Yes"
									fi

## Some commands don't produce output
## So I have it display the command being run
## Before and After, so you can see 
## Exactly what you entered
									echo Begin: $specialcommand
									$specialcommand
									echo Done:  $specialcommand
									echo "10 Second Pause"
									sleep 10
									;;

									$DIALOG_CANCEL)
									;;

								esac
								;;

							"F: Restore")

								if [ "$localdrive" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "ERROR" --clear \
											--msgbox "No target drive set! \n
													->Back to Main Menu." 0 0
									continue
								fi


								if [ "$localimagename" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "WARNING" --clear \
											--msgbox "No filename for image set, using default \n
													Filename: image.img.gz" 0 0
									localimagename=image.img.gz
								fi

								if [ "$localsplit" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "WARNING" --clear \
											--msgbox "Splitting not defined, using default \n
													Splitting: Off" 0 0
									localsplit=Off
								fi


								if [ "$localzip" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "WARNING" --clear \
											--msgbox "Compression not defined, using default \n
													Compression: None" 0 0
									localzip=None
								fi


								$DIALOG --backtitle "$backtitle" \
										--title "RESTORE" \
										--radiolist "Choose Drive or Partition to restore\n(Use Space Bar)\n\
													Select from:" 0 0 0 \
													$partlist 2> $tempfilelocalrest


								retvallocalrest=$?

								choicelocalrest=`cat $tempfilelocalrest`
								case $retvallocalrest in
								$DIALOG_OK)

									localrest=/dev/$choicelocalrest

									$DIALOG --backtitle "$backtitle" \
											--title "ABOUT TO RESTORE" --clear \
											--yesno "Collected information: \
													\nTarget drive in /mnt/local: $localdrive \
													\nFilename for image: $localimagename \
													\nSplitting: $localsplit \
													\nCompression: $localzip \
													\nTarget drive: $localrest \
													\n\nAre you sure?" 0 0

									case $? in
									$DIALOG_OK)

										localwritesize=`cat /proc/partitions |grep $choicelocalrest | head -n 1 |awk '{print $3}' `
										pcnt=0
## msg for local restore
										msg="$projectname is locally restoring your drive.\n"
										if [ "$localzip" = "None" ] ; then
											if [ "$localsplit" = "Off" ] ; then
													(dd bs=1M if=/mnt/local/$localimagename 2>/dev/null |jetcat-mod -f 5000 -p $localwritesize 2>/tmp/progress.out |dd bs=1M of=$localrest 2>/dev/null) &
## Single Progress function
													progress
											fi

											if [ "$localsplit" = "On" ] ; then
													(cat /mnt/local/$localimagename.* |jetcat-mod -f 5000 -p $localwritesize 2>/tmp/progress.out |dd bs=1M of=$localrest 2>/dev/null) &
## Single Progress function
													progress
											fi
										fi


										if [ "$localzip" = "GZip" ] ; then
											if [ "$localsplit" = "Off" ] ; then
													(dd bs=1M if=/mnt/local/$localimagename 2>/dev/null |gunzip -c - |jetcat-mod -f 5000 -p $localwritesize 2>/tmp/progress.out |dd bs=1M of=$localrest 2>/dev/null) &
## Single Progress function
													progress
											fi

											if [ "$localsplit" = "On" ] ; then
													(cat /mnt/local/$localimagename.* |gunzip -c - |jetcat-mod -f 5000 -p $localwritesize 2>/tmp/progress.out |dd bs=1M of=$localrest 2>/dev/null) &
## Single Progress function
													progress
											fi
										fi

### lzop ??
										if [ "$localzip" = "Lzop" ] ; then
											if [ "$localsplit" = "Off" ] ; then
													(dd bs=1M if=/mnt/local/$localimagename 2>/dev/null |lzop -d -c - |jetcat-mod -f 5000 -p $localwritesize 2>/tmp/progress.out |dd bs=1M of=$localrest 2>/dev/null) &
## Single Progress function
													progress
											fi

											if [ "$localsplit" = "On" ] ; then
													(cat /mnt/local/$localimagename.* |lzop -d  -c - |jetcat-mod -f 5000 -p $localwritesize 2>/tmp/progress.out |dd bs=1M of=$localrest 2>/dev/null) &
## Single Progress function
													progress
											fi
										fi

### lzop ??


										if [ "$localzip" = "BZip2" ] ; then
											if [ "$localsplit" = "Off" ] ; then
													(dd bs=1M if=/mnt/local/$localimagename 2>/dev/null |bzcat |jetcat-mod -f 5000 -p $localwritesize 2>/tmp/progress.out |dd bs=1M of=$localrest 2>/dev/null) &
## Single Progress function
													progress
											fi

											if [ "$localsplit" = "On" ] ; then
													(bzip2 -dc /mnt/local/$localimagename.* | jetcat-mod -f 5000 -p $localwritesize 2>/tmp/progress.out | dd bs=1M of=$localrest 2>/dev/null) &
## bzcat not using multiple files...
##												(bzcat /mnt/local/$localimagename.* |jetcat-mod -f 5000 -p $localwritesize 2>/tmp/progress.out | dd bs=1M of=$localrest 2>/dev/null) &

## Single Progress function
													progress
											fi
										fi

###										umount /mnt/local
										rm /tmp/out
										touch /tmp/out
									;;

									$DIALOG_CANCEL)
									;;

									$DIALOG_ESC)
									;;

									esac
									;;
								esac
								;;

							esac
							;;

						$DIALOG_CANCEL)
						;;

						$DIALOG_ESC)
						;;

						esac
					done
					;;

				"Click'n'Clone")

					while [ "$retvalclonemenu" != "1" ]
					do
						$DIALOG --clear --backtitle "$backtitle" \
								--title "CLICK'n'CLONE" \
								--menu "Choose one of the following options: \n\n" 0 0 0 \
										"A: Select source"  "Select source drive ($clonesource)" \
										"B: Select target"  "Select target drive ($clonetarget)" \
										"C: Click'n'Clone"  "Clone the drive now!" 2> $tempfileclonemenu

						retvalclonemenu=$?

						choiceclonemenu=`cat $tempfileclonemenu`

						case $retvalclonemenu in
						$DIALOG_OK)

							case $choiceclonemenu in
							"A: Select source")

								$DIALOG --backtitle "$backtitle" \
										--title "SELECT SOURCE" \
										--radiolist "Choose source drive to clone.\n(Use Space Bar)\n\
													Select from:" 0 0 0 \
													$partlist 2> $tempfileclonesource

								retvalclonesource=$?

								choiceclonesource=`cat $tempfileclonesource`
								case $retvalclonesource in
								$DIALOG_OK)

									clonesource=/dev/$choiceclonesource
								;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
								;;

								esac
								;;

							"B: Select target")
								$DIALOG --backtitle "$backtitle" \
										--title "SELECT TARGET" \
										--radiolist "Choose target drive to clone to.\n(Use Space Bar)\n\
													Attention: Select a drive with at least\n\
													the same capacity. Higher capacity is OK.\n\
													Select from:" 0 0 0 \
													$partlist 2> $tempfileclonetarget


								retvalclonetarget=$?

								choiceclonetarget=`cat $tempfileclonetarget`
								case $retvalclonetarget in
								$DIALOG_OK)

									clonetarget=/dev/$choiceclonetarget
								;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
								;;

								esac
								;;


							"C: Click'n'Clone")
								if [ "$clonesource" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "ERROR" --clear \
											--msgbox "No source drive for cloning set! \n
													->Back to Main Menu." 0 0
									continue
								fi

								if [ "$clonetarget" = "" ] ; then

									$DIALOG --backtitle "$backtitle" \
											--title "ERROR" --clear \
											--msgbox "No target drive for cloning set! \n
													->Back to Main Menu." 0 0
									continue
								fi

								$DIALOG --backtitle "$backtitle" \
										--title "ABOUT TO CLONE" --clear \
										--yesno "Collected information: \
												\nSource drive: $clonesource \
												\nTarget drive: $clonetarget \
												\n\nAre you sure?" 0 0
								case $? in
								$DIALOG_OK)

									clonesize=`cat /proc/partitions |grep $choiceclonesource | head -n 1 |awk '{print $3}' `
									pcnt=0
## msg for cloneing drive
									msg="$projectname is cloning drive\n"
									dd bs=1M if=$clonesource 2>/dev/null |jetcat-mod -f 5000 -p $clonesize 2>/tmp/progress.out |dd bs=1M of=$clonetarget 2>/dev/null &
## Single Progress function
									progress
								;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
								;;
								esac
								;;
							esac
							;;

						$DIALOG_CANCEL)
						;;

						$DIALOG_ESC)
						;;

						esac
					done
					;;

					$DIALOG_CANCEL)
					;;

					$DIALOG_ESC)
					;;

					esac
					;;
				$DIALOG_ESC)
				;;

				esac

			done
			;;
			"File Mode")
				while [ "$retvalfilemenu" != "1" ]
				do
					$DIALOG --clear --backtitle "$backtitle" \
							--title "FILE MODE" \
							--menu "Choose one of the following options: \n\n" 0 0 0 \
								"A: Pick device"  "Select ethernet device (client/server mode only) ($filedevice)" \
								"B: Config device"  "Set IP address (client/server mode only) ($fileipaddress)" \
								"C: Select partition"  "Select partition to mount (server/local mode only) ($filepart)" \
								"D: Launch client"  "Launch 'partimage' in client/local mode" \
								"E: Launch server"  "Launch 'partimage' in server mode" 2> $tempfilefilemenu

					retvalfilemenu=$?

					choicefilemenu=`cat $tempfilefilemenu`

					case $retvalfilemenu in
					$DIALOG_OK)

						case $choicefilemenu in
						"A: Pick device")

							$DIALOG --backtitle "$backtitle" \
									--title "PICK DEVICE" \
									--radiolist "Choose network device \n(Use Space Bar)\n\
												Select from:" 0 0 0 \
												$netlist 2> $tempfilefiledevice
							retvalfiledevice=$?

							choicefiledevice=`cat $tempfilefiledevice`

							case $retvalfiledevice in
							$DIALOG_OK)

								filedevice=$choicefiledevice
							;;

							$DIALOG_CANCEL)
							;;

							$DIALOG_ESC)
							;;
							esac
							;;

						"B: Config device")
							$DIALOG --backtitle "$backtitle" \
									--title "CONFIG DEVICE" --clear \
									--inputbox "Set IP Address to match your subnet. \
										\nExample: 192.168.0.5 \
										\n\nEnter IP Address:" 0 0 2> $tempfilefileip

							retvalfileip=$?
							case $retvalfileip in
							$DIALOG_OK)

								fileipaddress=`cat $tempfilefileip`
								/sbin/ifconfig $filedevice $fileipaddress up
							;;

							$DIALOG_CANCEL)
							;;

							$DIALOG_ESC)
								if test -s $tempfilefileip ; then
									fileipaddress=`cat $tempfilefileip`
									/sbin/ifconfig $filedevice $fileipaddress up
								fi
								;;
							esac
							;;


						"C: Select partition")
							$DIALOG --backtitle "$backtitle" \
									--title "SELECT PARTITION" \
									--radiolist "Choose drive to mount.\n(Use Space Bar)\
												\nThe selected drive will be mounted to /mnt/local
												\nand partimage may write to this directory.\n
												\nSupported FS are:\n\
												ext2 - Linux\n\
												ext3 - Linux\n\
												reiserfs - Linux\n\
												fat32 - Windows95/98/NT/2k/XP\n\
												ntfs - Windows NT/2k/XP\n\
												JFS and XFS\
												\n\nSelect partition(!) (example: /dev/hda1):" 0 0 0 \
												$partlist 2> $tempfilefilepart

							retvalfilepart=$?

							choicefilepart=`cat $tempfilefilepart`
							case $retvalfilepart in
							$DIALOG_OK)

								filepart=$choicefilepart
								mount /dev/$filepart /mnt/local >/tmp/filemount 2>&1
								retvalfilemount=$?

								if [ $retvalfilemount != 0 ] ; then
									$DIALOG --backtitle "$backtitle" \
											--title "ERROR" \
											--textbox /tmp/filemount 0 0
									filepart=""
									umount /mnt/local
								else
									$DIALOG --backtitle "$backtitle" \
											--title "STATUS" \
											--msgbox "Partition mounted in /mnt/local. \
													\nYou can now launch partimage to create or restore an image.\
													\nAs target file enter a filename in /mnt/local/, \
													\nfor example: /mnt/local/backup_hda1.img.gz \
													\n\n \
													\nYou can also launch partimage in network mode." 10 50

								fi
							;;

							$DIALOG_CANCEL)
							;;

							$DIALOG_ESC)
							;;

							esac
							;;
						"D: Launch client")
							clear
							partimage -f3
							umount /mnt/local
							;;

						"E: Launch server")
							$DIALOG --backtitle "$backtitle" \
									--title "INFO" \
									--msgbox "'partimage' server will be launched now. \
											\nAfter it started, remove the CD and use it \
											\nto launch the 'partimage' client on another machine." 10 50

							clear
							partimaged
							umount /mnt/local

						esac
						;;
					esac

				done
				;;

			"Utilities")

				while [ "$retvalutilmenu" != "1" ]
				do
					$DIALOG --clear --backtitle "$backtitle" \
							--title "UTILITIES" \
							--menu "Choose one of the following options: \n\n" 0 0 0 \
								"System info"  "Show drives, partitions and models" \
								"hdparm"  "Set 32-bit I/O and UDMA66 (NEW hardware only!)" \
								"Zero-Tool"  "Zero-out free space on a partition" \
								"dd_rescue"  "Rescue defective drive and clone to new one" \
								"Parted"  "Launch 'parted' partition manager (EXPERT USE!)" 2> $tempfileutilmenu

					retvalutilmenu=$?

					choiceutilmenu=`cat $tempfileutilmenu`

					case $retvalutilmenu in
					$DIALOG_OK)

						case $choiceutilmenu in
						"System info")

							$DIALOG --backtitle "$backtitle" \
									--title "SYSTEM INFO" \
									--textbox /tmp/sysinfo 20 35
						;;


						"hdparm")
							$DIALOG --backtitle "$backtitle" \
								--title "WARNING" --clear \
									--yesno "This option tries to enable 32-bit I/O mode \
									\nand UDMA/66 mode on your IDE Controller and drive. \
									\n \
									\nThe system might hang and require a reboot! \
									\nUse this option only on quite new computers! \
									\n \
									\nContinue at own risk?" 0 0

							case $? in
							$DIALOG_OK)

								$DIALOG --backtitle "$backtitle" \
										--title "HDPARM" \
										--radiolist "Choose drive(!) to enable.\n(Use Space Bar)\
													\n\nExample: /dev/hda" 0 0 0 $partlist 2> $tempfilehdparm

								retvalhdparm=$?

								choicehdparm=`cat $tempfilehdparm`
								case $retvalhdparm in
								$DIALOG_OK)

									hdparmdrive=/dev/$choicehdparm
									hdparm -c3 -X66 $hdparmdrive >/tmp/hdparmout

									$DIALOG --backtitle "$backtitle" \
											--title "HDPARM OUTPUT" \
											--textbox /tmp/hdparmout 0 0


								;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
								;;

								esac
								;;

							$DIALOG_CANCEL)
							;;

							$DIALOG_ESC)
							;;
							esac
							;;

						"Zero-Tool")

							$DIALOG --backtitle "$backtitle" \
									--title "ZERO-TOOL" \
                  --msgbox "Removed this, since it was linked to the OS\
														\nbetter to use the cleandrive script on Unix/Linux\
														\nor the blank4 or blank5 program for the FAT/NTFS\
														\npartitions." 10 60

## Delete Zeroing too, since it didn't always work at supporting varous partitions
## The FAT would create the zero file, but not delete them. Better to use the other
## programs to do this job via te OS
##									--radiolist "Choose drive to zero-out.\
##												\nSupported FS are:\n\
##												ext2 - Linux\n\
##												ext3 - Linux\n\
##												reiserfs - Linux\n\
##												fat32 - Windows95/98/NT/2k/XP\n\
##												ntfs - Windows NT/2k/XP\
##												\n\nSelect partition (example: /dev/hda1):" 0 0 0 \
##									$partlist 2> $tempfileutilzero

							retvalutilzero=$?

##							choiceutilzero=`cat $tempfileutilzero`
							case $retvalutilzero in
							$DIALOG_OK)

##								zerodrive=$choiceutilzero
##								mount /dev/$zerodrive /mnt/local >/tmp/zeromount 2>&1
##								retvalzeromount=$?

##								if [ $retvalzeromount != 0 ] ; then
##									$DIALOG --backtitle "$backtitle" \
##											--title "ERROR" \
##											--textbox /tmp/zeromount 0 0
##									zerodrive=""
##									umount /mnt/local
##
##								else
##
##									freesize=`df |grep -w $zerodrive |awk '{print $4}'`
##									pcnt=0
## msg for zeroing free space
##									msg="$projectname is zeroing out free space.\n"
##									(dd bs=1M if=/dev/zero 2>/dev/null |jetcat-mod -f 5000 -p $freesize 2>/tmp/progress.out |split -b 1000m - /mnt/local/zerofile. 2>/dev/null ) &
## Single Progress function
##									progress
##							fi
							;;

							$DIALOG_CANCEL)
							;;

							$DIALOG_ESC)
							;;

							esac
							;;

						"dd_rescue")
							while [ "$retvalddres" != "1" ]
							do
								$DIALOG --clear --backtitle "$backtitle" \
										--title "DD_RECSCUE" \
										--menu "Choose one of the following options: \n\n" 0 0 0 \
												"Select source"  "Select (defective) source drive" \
												"Select target"  "Select (new/clean) target drive" \
												"Rescue"  "Rescue the drive now!" 2> $tempfileddres

								retvalddres=$?

								choiceddres=`cat $tempfileddres`

								case $retvalddres in
								$DIALOG_OK)

									case $choiceddres in
									"Select source")

										$DIALOG --backtitle "$backtitle" \
												--title "SELECT SOURCE" \
												--radiolist "Choose (defective) source drive to clone.\n(Use Space Bar)\n\
															Select from:" 0 0 0 \
															$partlist 2> $tempfileddressource

										retvalddressource=$?

										choiceddressource=`cat $tempfileddressource`
										case $retvalddressource in
										$DIALOG_OK)

											ddressource=/dev/$choiceddressource
										;;

										$DIALOG_CANCEL)
										;;

										$DIALOG_ESC)
										;;

										esac
										;;

									"Select target")
										$DIALOG --backtitle "$backtitle" \
												--title "SELECT TARGET" \
												--radiolist "Choose (new/clean) target drive to clone to.\n(Use Space Bar)\n\
															Attention: Select a drive with at least\n\
															the same capacity. Higher capacity is OK.\n\
															Select from:" 0 0 0 \
															$partlist 2> $tempfileddrestarget


										retvalddrestarget=$?

										choiceddrestarget=`cat $tempfileddrestarget`
										case $retvalddrestarget in
										$DIALOG_OK)

											ddrestarget=/dev/$choiceddrestarget
										;;

										$DIALOG_CANCEL)
										;;

										$DIALOG_ESC)
										;;

										esac
										;;


									"Rescue")
										if [ "$ddressource" = "" ] ; then

											$DIALOG --backtitle "$backtitle" \
													--title "ERROR" --clear \
													--msgbox "No source drive to rescue set! \n
															->Back to Main Menu." 0 0
											continue
										fi

										if [ "$ddrestarget" = "" ] ; then

											$DIALOG --backtitle "$backtitle" \
													--title "ERROR" --clear \
													--msgbox "No target drive for rescue set! \n
															->Back to Main Menu." 0 0
											continue
										fi

										$DIALOG --backtitle "$backtitle" \
												--title "ABOUT TO RESCUE" --clear \
												--yesno "Collected information: \
														\nDefective source drive: $ddressource \
														\nNew/Clean target drive: $ddrestarget \
														\n\
														\nIt might take VERY long to rescue the drive, \
														\nbut as long as you do NOT reboot, you can press \
														\nCTRL-C at any time and dd_rhelp will continue \
														\nfrom the same position it stopped if you re-enter \
														\nthis menu. If dd_rhelp is almost done and is only \
														\ntrying to read the defective sectors, it is OK to CTRL-C. \
														\n\
														\n\nAre you sure?" 0 0
										case $? in
										$DIALOG_OK)
											clear
											dd_rhelp $ddressource $ddrestarget
										;;

										$DIALOG_CANCEL)
										;;

										$DIALOG_ESC)
										;;
										esac
										;;
									esac
									;;

								$DIALOG_CANCEL)
								;;

								$DIALOG_ESC)
								;;

								esac
							done
						;;

						"Parted")

							clear
							parted
						;;

						esac
						;;


					$DIALOG_CANCEL)
					;;

					$DIALOG_ESC)
					;;

					esac
				done
				;;


			"Show Help")
				$DIALOG --clear --backtitle "$backtitle" \
						--title "HELP" \
						--textbox /usr/doc/RIPLinuX/g4l/help 20 70
			;;

			esac
			;;

			$DIALOG_CANCEL)
				echo "Thanks for using $projectname. visit $website"
## Don't know about deleteing all file from temp
## on the CD boot doesn't make a difference, but when I test
## the script on my regular linux box, it is trying to delete 
## things not related to $projectname
				##rm /tmp/*
				rm /tmp/test*
				touch /tmp/out
				touch /tmp/zeroout
			;;

			$DIALOG_ESC)
				echo "ESC pressed."
			;;


		esac

	done
	;;
$DIALOG_CANCEL)
	exit 0
;;

$DIALOG_ESC)
	exit 0
;;

esac
