#!/bin/sh
# *************************************************************************
# *                                                                       *
# * Menu-driven backup script using tar. Author Jonathan Warburton-Brown  *
# *                                                                       *
# * This utility is freely distributable under the terms of the GNU GPL.  *
# *                                                                       *
# *************************************************************************
#

#
# ------- UNCOMMENT THIS LINE IF YOUR CONSOLE TYPE (eg con80x25) IS NOT
# ------- DEFINED IN THE TERMINFO DATABASE. NOTE MOST USERS OF LINUX USE
# ------- con80x25 SO THIS HAS BEEN INCLUDED WITH THE DISTRIBUTION.
# ------- Also con80x25 makes LBU look much prettier

# TERM=vt100 ; export TERM

#
# ------- SET THIS VARIABLE TO yes IF ONLY ROOT IS TO BE ALLOWED TO RUN LBU
#
TVERSION="Linux Business Systems V1.2                    `date`"
lbu_root_only=no

#
# ------- CHANGE THIS IF YOU CHANGE THE NAME OF THE BACKUP SCRIPT
#

lbu_program_name=lbu

#
# ------- CHANGE THIS TO POINT TO THE LBU LIBRARY & HELP FILES
#

lbu_dir=/usr/lib/LBU

#
# ------- PER USER TEMPORARY STORAGE FILE
#

lbu_tmpfile="/tmp/$LOGNAME"lbu_sel

# *************************************************************************
# *                        L.B.U Processing sub-routines                  *
# *************************************************************************


lbu_proceed() {
	lbu_loop1=1
	while [ $lbu_loop1 = 1 ]; do
	dialog --title "$lbu_title" \
	--backtitle " $TVERSION" \
	--menu " " 20 74 14 \
	"Device"   "Select bkup/rstr/cmpr device.   ($lbu_dsply_dev)" 	\
	"File/Dir" "Select data to bkup/rstr/cmpr.  ($lbu_dsply_dfl)" 	\
	"Options"  "(Un)Set run-time option flags."			\
	"Begin"	   "Start the backup procedure."			\
	"Schedule" "Schedule backup/restore for later."			\
	"Restore"  "Restore previous backup."				\
	"Look"     "Look at status screen."				\
	"Compare"  "Check for differences between backup & file-system."\
	"Inspect"  "Look at latest bkup/rstr/cmpr log."			\
	"View"	   "View the contents of a previous backup."		\
	"Write"    "Save currently selected details to disk."		\
	"Exclude"  "Create/Modify an exclusion list"			\
	"Help"     "Help regarding the L.B.U."		 		\
	"Quit"     "Quit Linux Backup Utility."				2> $lbu_tmpfile

# ------- Get selection and act accordingly

	if [ $? = 1 -o $? = 255 ]; then
		rm $lbu_tmpfile
		lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
		lbu_hgt=5 ; lbu_wth=34
		lbu_message
		reset ; clear
		exit
	fi

	lbu_chc=`cat $lbu_tmpfile`
	rm -f $lbu_tmpfile
	case $lbu_chc in
		Device) 	lbu_devsel;;
		File/Dir)	lbu_fstsel;;
		Options)	lbu_options;;
		Begin)		lbu_begin;;
		Schedule)	lbu_schedule;;
		Restore)	lbu_restore;;
		Look)		lbu_look;;
		Compare)	lbu_comp;;
		Inspect)	lbu_inspect;;
		View)		lbu_view;;
		Write)         	lbu_write;;
		Exclude)	lbu_exclude;;
		Help)
				lbu_hlpfile="$lbu_dir/lbu_help1"
				lbu_help
				;;

		Quit)		lbu_quit;;
		*)		lbu_invent;;
	esac
	done
}

# *********************************************************************
# *             Backup device selection subroutine                    * 
# *********************************************************************

lbu_devsel() {
	lbu_loop2=1
	lbu_devtype=""
	lbu_dsply_dev=""
	while [ $lbu_loop2 = 1 ]; do
	lbu_devexist=yes
	lbu_ext=$lbu_orig_ext
	lbu_loop2=0
	dialog --title "L.B.U device selection" --inputbox "Select backup/restore device (? for help)" 8 48 2> $lbu_tmpfile
	lbu_device=`tr -s [*\ ] [?_] < $lbu_tmpfile`
	rm -f $lbu_tmpfile

# ------- check for no input provided

  	if [ -z "$lbu_device" ]; then
		lbu_msgtyp="Error" ; lbu_msgtxt="No backup/restore device specified\n        Aborting"
		lbu_hgt=6 ; lbu_wth=38
		lbu_message
		lbu_loop2=0
	else

# ------- asking for help ?

		if [ $lbu_device = ? ]; then
			lbu_hlpfile="$lbu_dir/lbu_help2"
			lbu_help
			lbu_loop2=1
			lbu_dsply_dev="" ; lbu_device=""
		else

# ------- validate that either a block device or a filename is entered

			if [ -a $lbu_device ]; then
				lbu_devtype=`ls -ld $lbu_device | cut -c1`
				if [ $lbu_devtype = b ]; then
					lbu_ext=""
				fi
				if [ $lbu_devtype = c ]; then
					lbu_msgtyp="Warning" ; lbu_msgtxt="You have selected a character special\ndevice. Normally such a device is\nselected only if it is a tapedrive\nor similar stream device."
					lbu_hgt=8 ; lbu_wth=45
					lbu_message
					lbu_ext=""
				fi	

				if [ $lbu_devtype = d ]; then
					lbu_msgtyp="Error" ; lbu_msgtxt="File specified is a directory.\nPlease specify a file or device."
					lbu_hgt=6 ; lbu_wth=40
					lbu_message
					lbu_loop2=1	
				fi

				if [ $lbu_devtype = l ]; then
					lbu_msgtyp="Error" ; lbu_msgtxt="File specified is a link.\nPlease specify a file or device."
					lbu_hgt=6 ; lbu_wth=40
					lbu_message
					lbu_loop2=1	
				fi

			else
				if [ -a $lbu_device$lbu_ext ]; then
					lbu_msgtyp="Informational" ; lbu_msgtxt="The file $lbu_device$lbu_ext exists and \nis not a device file. If a BACKUP is being performed\nit will be overwritten. If this is not OK, reselect the device."
					lbu_hgt=7 ; lbu_wth=70
					lbu_message
				else
					touch $lbu_device$lbu_ext 2> /dev/null
					rm $lbu_device$lbu_ext 2> /dev/null
					if [ $? != 0 ]; then
						lbu_msgtyp="Error" ; lbu_msgtxt="Path to file $lbu_device$lbu_ext not present.\nPlease re-enter."
						lbu_hgt=6 ; lbu_wth=70
						lbu_message
						lbu_loop2=1
					else
						lbu_msgtyp="Warning" ; lbu_msgtxt="The file $lbu_device$lbu_ext does NOT exist.\nIf a BACKUP is being performed it will be created as\nan ordinary file.\nIf you are about to perform a RESTORE operation\nit will FAIL unless you specify an existing file or device."
						lbu_hgt=9 ; lbu_wth=70
						lbu_message
						lbu_devexist=no
					fi
				fi
			fi
		fi
	fi

	if [ ! -z "$lbu_device" ]; then
		lbu_device=$lbu_device$lbu_ext
		lbu_dsply_dev=`echo $lbu_device | cut -c1-20`'...'
	fi
	done
}

# ********************************************************************
# *         Backup directory / file selection subroutine             *
# ********************************************************************

lbu_fstsel() {
	lbu_loop2=1
	lbu_dirfil=""
	lbu_dsply_dfl=""
	while [ $lbu_loop2 = 1 ]; do
		lbu_loop2=0
		dialog --title "L.B.U directory / file selection" --inputbox "Enter a comma (,) separated list of dirs and/or files (? for help)" 8 77 2> $lbu_tmpfile
		lbu_dirfil=`tr -s "[ ]" "[,]" < $lbu_tmpfile`
		case $lbu_dirfil in
			'')
				lbu_msgtyp="Warning" ; lbu_msgtxt="No dirs / files specified."
				lbu_hgt=5 ; lbu_wth=35
				lbu_message
				lbu_loop2=0
				;;

			\*)	;;

			\?)
				lbu_hlpfile="$lbu_dir/lbu_help3"
				lbu_help
				lbu_loop2=1
				;;

			*)
				lbu_dirfil=$lbu_dirfil','
				echo $lbu_dirfil > $lbu_tmpfile
				lbu_loop3=1
				lbu_ctr=1
				while [ $lbu_loop3 = 1 ]; do
					lbu_field=`cut -f$lbu_ctr -d, < $lbu_tmpfile`
					case $lbu_field in
						$lbu_dirfil)	lbu_loop3=0;;
						*\**)		;;
						*\?*)		;;
						*)
						if [ ! -a $lbu_field ]; then
							lbu_msgtyp="Informational" ; lbu_msgtxt="One of the files or directories specified\ndoes not exist. If doing a BACKUP this will\ncause the Status Screen to show FAILURE\neven though existing files WILL have been\nbacked up. Be sure to check the logfile."
							lbu_hgt=9 ; lbu_wth=50
							lbu_message
							lbu_loop3=0
						fi;;
					esac
				lbu_ctr=`expr $lbu_ctr + 1`
				done;;
		esac	
	done
	echo $lbu_dirfil > $lbu_tmpfile
	case $lbu_dirfil in
	'')
		rm -f $lbu_tmpfile
		;;
	*)
		lbu_dirfil=`tr "[,]" "[ ]" <$lbu_tmpfile`
		lbu_dsply_dfl=`echo $lbu_dirfil | cut -c1-20`'...'
		;;
	esac
}

# **********************************************************************
# *                (Un)Set runtime options                             *
# **********************************************************************
	
lbu_options() {

	lbu_loop2=1
	while [ $lbu_loop2 = 1 ]; do
		dialog --title "$lbu_title" \
		--backtitle "$TVERSION"\
		--menu "\n			**** RUNTIME OPTIONS ****\n" 20 74 14 \
		"Done"     "Return to Main Menu."					\
		"Multi"    "Multi-volume archive.                  ($lbu_dsply_multi)" 	\
		"Absolute" "Preserve absolute pathnames.           ($lbu_dsply_absol)" 	\
		"Inform"   "Mail log file to self.                 ($lbu_dsply_mail)"	\
		"Block"	   "Specify Block-size.                    ($lbu_dsply_blcks)"	\
		"Perms"	   "Preserve permissions.                  ($lbu_dsply_perms)"	\
		"Owner"	   "Preserve ownership.                    ($lbu_dsply_owner)"	\
		"Totals"   "Log total byte-count.                  ($lbu_dsply_total)"	\
		"Verbose"  "Verbose logging.                       ($lbu_dsply_vbose)"	\
		"Compress" "Select compression type.               ($lbu_dsply_cmprs)"	\
		"Exclude"  "Enable/Disable file exclusion          ($lbu_dsply_excl)"	\
		"Help"     "Help regarding Options"					2> $lbu_tmpfile

# ------- Get the selection made and act accordingly

		if [ $? = 1 -o $? = 255 ]; then
			rm $lbu_tmpfile
			lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
			lbu_hgt=5 ; lbu_wth=34
			lbu_message
			lbu_loop2=0
		else

			lbu_sel=`cat $lbu_tmpfile`
			rm -f $lbu_tmpfile

			case $lbu_sel in
			Multi) 		
				if [ $lbu_dsply_multi = yes ]; then
					lbu_dsply_multi=no ; lbu_multi=""
				else
					lbu_dsply_multi=yes ; lbu_multi="-M"
					if [ $lbu_cmprs != "" ]; then
						lbu_dsply_cmprs="none" ; lbu_cmprs=''
						lbu_device="" ; lbu_dsply_dev="" ; lbu_orig_ext=".tar"
						lbu_msgtyp="Informational" ; lbu_msgtxt="Cannot have compressed multi-volume archives.\nCompression parameter set to 'none'.\nYOU MUST RE-SELECT THE BACKUP DEVICE."
						lbu_hgt=7 ; lbu_wth=55
						lbu_message
					fi
				fi
				;;
			Absolute)
				if [ $lbu_dsply_absol = yes ]; then 
					lbu_dsply_absol=no  ; lbu_absol=""
				else
					lbu_dsply_absol=yes ; lbu_absol="P"
				fi
				;;
			Inform)
				if [ $lbu_dsply_mail = yes ]; then 
					lbu_dsply_mail=no  ; lbu_mail=no
				else
					lbu_dsply_mail=yes ; lbu_mail=yes
				fi
				;;
			Block)
				lbu_blocksize
				;;
			Perms)	
				if [ $lbu_dsply_perms = yes ]; then 
					lbu_dsply_perms=no  ; lbu_perms=""
				else
					lbu_dsply_perms=yes ; lbu_perms="p"
				fi
				;;
			Owner)
				if [ $lbu_dsply_owner = yes ]; then 
					lbu_dsply_owner=no  ; lbu_owner=""
				else
					lbu_dsply_owner=yes ; lbu_owner='--same-owner'
				fi
				;;
			Totals)
				if [ $lbu_dsply_total = yes ]; then 
					lbu_dsply_total=no  ; lbu_total=""
				else
					lbu_dsply_total=yes ; lbu_total='--totals'
				fi
				;;
			Verbose)
				if [ $lbu_dsply_vbose = yes ]; then 
					lbu_dsply_vbose=no  ; lbu_vbose=""
				else
					lbu_dsply_vbose=yes ; lbu_vbose="v"
				fi
				;;
			Compress)
				lbu_compress
				;;
			Exclude)
				if [ $lbu_dsply_excl = yes ]; then 
					lbu_dsply_excl=no  ; lbu_excl=""
				else
					lbu_dsply_excl=yes ; lbu_excl='-X $HOME/.lbu_exclude'
				fi
				;;
			Help)
				lbu_hlpfile="$lbu_dir/lbu_help4"
				lbu_help
				;;
			Done)
				lbu_loop2=0
				;;
			*)		lbu_invent
				;;
			esac
		fi
	done
}

# *********************************************************************
# *                   Select Blocksize sub-routine                    *
# *********************************************************************

lbu_blocksize() {
		dialog --title "Block-size selection" \
		--backtitle "$TVERSION"\
		--menu "" 14 45 7 \
		"5"	   "2,560  bytes per block." 			\
		"10"	   "5,120  bytes per block." 			\
		"15"       "7,680  bytes per block."			\
		"20"	   "10,240 bytes per block. (default)"		\
		"25"	   "12,800 bytes per block."			\
		"30"	   "15,360 bytes per block."			\
		"35"	   "17,920 bytes per block."			2> $lbu_tmpfile

# ------- Get the selection made and act accordingly

		if [ $? = 1 -o $? = 255 ]; then
			rm $lbu_tmpfile
			lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
			lbu_hgt=5 ; lbu_wth=34
			lbu_message
		else
			lbu_dsply_blcks=`cat $lbu_tmpfile` ; lbu_blcks=$lbu_dsply_blcks
			rm -f $lbu_tmpfile
		fi
}

# ******************************************************************
# *                  Select compression method                     *
# ******************************************************************

lbu_compress() {
		dialog --title "Blocksize selection" \
		--backtitle "$TVERSION"\
		--menu "** REMEMBER to re-select DEVICE after changing compression mode **" 22 75 6 	\
		"gzip"	   "Use a gzipped tar archive (default)    (ext = .tgz)"	\
		"compress" "Use a compressed tar archive           (ext =.tar.Z)" 	\
		"none"     "Do not use any compression on archive  (ext = .tar)" 	2> $lbu_tmpfile

# ------- Get the selection made and act accordingly

		if [ $? = 1 -o $? = 255 ]; then
			rm $lbu_tmpfile
			lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
			lbu_hgt=5 ; lbu_wth=34
			lbu_message
		else

			lbu_dsply_cmprs=`cat $lbu_tmpfile`
			if [ $lbu_dsply_cmprs = gzip ]; then lbu_orig_ext='.tgz'; lbu_cmprs=z ; fi
			if [ $lbu_dsply_cmprs = compress ]; then lbu_orig_ext='.tar.Z' ; lbu_cmprs=Z ; fi
			if [ $lbu_dsply_cmprs = none ]; then lbu_orig_ext='.tar' ; lbu_cmprs='' ;  fi
			rm -f $lbu_tmpfile
			if [ $lbu_dsply_multi = yes ]; then
				if [ $lbu_cmprs != "" ]; then 
					lbu_msgtyp="Informational"
					lbu_msgtxt="Cannot combine compressed format with\na Multi-volume archive. 'Multi' set to 'no'"
					lbu_hgt=6 ; lbu_wth=60
					lbu_message
					lbu_dsply_multi=no ; lbu_multi=""
				fi
			fi
			lbu_device="" ; lbu_dsply_dev=""
			lbu_msgtyp="Informational" ; lbu_msgtxt="Compression mode changed.\nPLEASE BE SURE TO RE-SELECT DEVICE."
			lbu_hgt=6 ; lbu_wth=40
			lbu_message
		fi
}

# ***********************************************************************
# *                       Start the backup process                      *
# ***********************************************************************

lbu_begin() {
	if [ -z "$lbu_device" ]; then
		lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nstarting the Backup"
		lbu_hgt=6 ; lbu_wth=45
		lbu_message
	else
		if [ -z "$lbu_dirfil" ]; then
			lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Dir/File selection before\nstarting the Backup"
			lbu_hgt=6 ; lbu_wth=45
			lbu_message
		else
			lbu_cxtd=c
			lbu_buildcmd
# 
# --------- DO THE BACKUP !!!!!
# 
			lbu_status="BACKUP IN PROGRESS"
			echo $lbu_status > $HOME/.lbu_last_backup
			lbu_devexist=yes
			if [ $lbu_dsply_multi = yes ]; then
				lbu_hlpfile=$lbu_dir/lbu_Minfo
				lbu_help
				clear
				lbu_status=`date`"\n\n========================== BACK-UP IN PROGRESS ============================\n"
				echo $lbu_status > $HOME/.lbu_last_backup
				echo "BACKUP STARTED : " `date` > $lbu_logfile
				eval $lbu_cmd_line | tee -a $lbu_logfile

				if [ $? = 0 ]; then
					lbu_status=`date`"\n\n=================== BACK-UP COMPLETION STATUS: SUCCESS ======================\n"
				else
					lbu_status=`date`"\n\n=================== BACK-UP COMPLETION STATUS: FAILURE ======================\n"
				fi
				echo $lbu_status > $HOME/.lbu_last_backup
#
# ------- If required mail log to user
#

				if [ $lbu_mail = yes ]; then
					mail -s "L.B.U BACKUP LOG" $LOGNAME < $lbu_logfile
				fi

			else
				lbu_bkup_rest_comp=BACK-UP
				lbu_bldsh_bg
				exec $lbu_bkup_bg &

			fi


		fi
	fi
}

# *********************************************************************
# *              Build shellscript for background run                 *
# *********************************************************************

lbu_bldsh_bg() {
		echo "#!/bin/sh" > $lbu_bkup_bg
		echo '' >> $lbu_bkup_bg
		echo 'lbu_dir='$lbu_dir >> $lbu_bkup_bg
		echo 'lbu_bkup_rest_comp='$lbu_bkup_rest_comp >> $lbu_bkup_bg
		echo 'home='$HOME >> $lbu_bkup_bg
		echo 'lbu_logfile='$lbu_logfile >> $lbu_bkup_bg
		echo 'lbu_status=`date`"\n\n========================= $lbu_bkup_rest_comp IN PROGRESS ===========================\n"' >> $lbu_bkup_bg
		echo 'echo $lbu_status > $HOME/.lbu_last_backup' >> $lbu_bkup_bg
		echo 'echo $lbu_bkup_rest_comp STARTED : `date` > $lbu_logfile' >> $lbu_bkup_bg
		echo "$lbu_cmd_line >> $lbu_logfile 2>&1" >> $lbu_bkup_bg
		echo 'if [ $? = 0 ]; then' >> $lbu_bkup_bg
		echo 'lbu_status=`date`"\n\n================= $lbu_bkup_rest_comp COMPLETION STATUS: SUCCESS ====================\n+++++++++++++++++ (Check the log-file for messages.) ++++++++++++++++++++\n"' >> $lbu_bkup_bg
		echo 'else' >> $lbu_bkup_bg
		echo 'lbu_status=`date`"\n\n================= $lbu_bkup_rest_comp COMPLETION STATUS: FAILURE ====================\n+++++++++++++++++ (Check the log-file for messages.) ++++++++++++++++++++\n"' >> $lbu_bkup_bg
		echo 'fi' >> $lbu_bkup_bg
		echo 'echo $lbu_status > $HOME/.lbu_last_backup' >> $lbu_bkup_bg
		echo '' >> $lbu_bkup_bg
		echo 'lbu_mail='$lbu_mail >> $lbu_bkup_bg
		echo '' >> $lbu_bkup_bg
		echo '#' >> $lbu_bkup_bg
		echo '# ------- If required mail log to user' >> $lbu_bkup_bg
		echo '#' >> $lbu_bkup_bg
		echo '' >> $lbu_bkup_bg
		echo 'if [ $lbu_mail = yes ]; then' >> $lbu_bkup_bg
		echo '	mail -s "L.B.U $lbu_bkup_rest_comp LOG" $LOGNAME < $lbu_logfile' >> $lbu_bkup_bg
		echo 'fi' >> $lbu_bkup_bg

		chmod 755 $lbu_bkup_bg
}

# *********************************************************************
# *                      Build the command line                       *
# *********************************************************************

lbu_buildcmd() {
	lbu_cmd_line="" ; echo $lbu_cmd_line > $lbu_logfile
	lbu_cmd_line='tar '$lbu_multi' '$lbu_total' '$lbu_excl' '$lbu_owner' -b '$lbu_blcks' -'$lbu_cxtd$lbu_absol$lbu_vbose$lbu_perms$lbu_cmprs'f '$lbu_device' '$lbu_dirfil
}

# **********************************************************************
# *                         L.B.U Scheduling                           *
# **********************************************************************

lbu_schedule() {

	case $LOGNAME in
		root)	;;
		*)	
			lbu_msgtyp="Error" ; lbu_msgtxt="Only the System Manager can set up\nschedules. This function is not\navailable to you."
			lbu_hgt=7 ; lbu_wth=45
			lbu_message
			return
			;;
	esac		

	if [ $lbu_dsply_multi = "yes" ]; then
		lbu_msgtyp="Error" ; lbu_msgtxt="Multi-volume flag is set. Only\nforeground operations allowed."
			lbu_hgt=6 ; lbu_wth=45
			lbu_message
		
 	else
		lbu_loop2=1
		while [ $lbu_loop2 = 1 ]; do
		dialog --title "$lbu_title" --menu "\n			**** L.B.U Scheduling ****\n" 22 74 5 \
		"Back"   "Schedule a backup for later." 		\
		"Rest"	  "Schedule a restore for later."		\
		"Clear"  "Remove a previous schedule." 			\
		"Help"    "Help regarding Scheduling"			\
		"Done"    "Return to Main Menu."			2> $lbu_tmpfile

# ------- Get selection and act accordingly

		if [ $? = 1 -o $? = 255 ]; then
			rm $lbu_tmpfile
			lbu_msgtyp="Informational" ; lbu_msgtxt="Operation cancelled."
			lbu_hgt=5 ; lbu_wth=34
			lbu_message
			lbu_loop2=0
			return
		fi

		lbu_sel=`cat $lbu_tmpfile`
		rm -f $lbu_tmpfile
		case $lbu_sel in
			Back) 	
					if [ -z "$lbu_device" ]; then
						lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nscheduling the Backup"
						lbu_hgt=6 ; lbu_wth=45
						lbu_message
					else
						if [ -z "$lbu_dirfil" ]; then
							lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Dir/File selection before\nscheduling the Backup"
							lbu_hgt=6 ; lbu_wth=45
							lbu_message
						else

							lbu_cxtd=c
							lbu_bkup_rest_comp=BACK-UP
							lbu_schedl
						fi
					fi
					;;

			Rest)	
					if [ $lbu_devexist = no ]; then
						lbu_msgtyp="Error" ; lbu_msgtxt="The restore device is not valid.\nPlease re-enter."
						lbu_hgt=6 ; lbu_wth=45
						lbu_message
					else
						if [ -z "$lbu_device" ]; then
							lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nscheduling the Restore."
							lbu_hgt=6 ; lbu_wth=45
							lbu_message
						else

							lbu_cxtd=x
							lbu_bkup_rest_comp=RESTORE
							lbu_schedl
						fi
					fi
					;;

			Clear)		lbu_delsch;;
			Help)		lbu_hlpfile=$lbu_dir/lbu_help5
					lbu_help
					;;
			Done)		lbu_loop2=0
					;;
			*)		lbu_invent;;
		esac
		done
	fi
}

# **********************************************************************
# *                       Set up a schedule                            *
# **********************************************************************

lbu_schedl() {
#
# ------- look for atrun
#
	lbu_cronerr=0
	if [ $LOGNAME = root ]; then
		if [ ! -a /var/spool/cron/crontabs/root ]; then
			lbu_msgtyp="Informational" ; lbu_msgtxt="A crontab file does not exist for $LOGNAME.\nOne will be created."
			lbu_hgt=6 ; lbu_wth=50
			lbu_message
			mkdir /var 2> /dev/null
			mkdir /var/spool 2> /dev/null
			mkdir /var/spool/cron 2> /dev/null
			mkdir /var/spool/cron/crontabs 2> /dev/null
			touch /var/spool/cron/crontabs/$LOGNAME
			if [ $LOGNAME=root ]; then
				echo "* * * * * * /usr/lib/atrun" >> /var/spool/cron/crontabs/$LOGNAME
			fi
		fi
	fi
	lbu_cdrun=`ps -ax | grep crond | wc -l`
	if [ $lbu_cdrun -lt 2 ]; then
		if [ $LOGNAME = root ]; then
			lbu_msgtyp="Warning" ; lbu_msgtxt="The cron daemon (crond) is not running.\nAttempting to start."
			lbu_hgt=6 ; lbu_wth=45
			lbu_message
			/usr/sbin/crond 2> /dev/null
			if [ $? = 0 ]; then
				lbu_msgtyp="Status" ; lbu_msgtxt="Crond started."
				lbu_hgt=5 ; lbu_wth=25
				lbu_message
			else
				lbu_msgtyp="Status" ; lbu_msgtxt="Crond FAILED to start.\Please start manually."
				lbu_hgt=7 ; lbu_wth=35
				lbu_message
				lbu_cronerr=1
			fi
		else
			lbu_msgtyp="Warning" ; lbu_msgtxt="The cron daemon (crond) is not running.\nSCHEDULES CANNOT BE RUN.\nPlease contact your system manager."
			lbu_hgt=7 ; lbu_wth=45
			lbu_message
			lbu_cronerr=1
		fi	
	fi

#
# ------- get run date build the script to be run by using the at command
#
	if [ $lbu_cronerr = 0 ]; then
		lbu_date
		if [ ! -z "$lbu_date" ]; then
			lbu_buildcmd
			lbu_bldsh_bg
			at -f $lbu_bkup_bg $lbu_hr$lbu_min $lbu_mth$lbu_day$lbu_yr >$lbu_tmpfile 2>&1
			if [ $? = 0 ]; then
				lbu_jobno=`awk -F\  '{print $2}' < $lbu_tmpfile`
				lbu_status="SCHEDULED. Job : $lbu_jobno\n\n=========== SCHEDULED $lbu_bkup_rest_comp RUN-TIME IS $lbu_hr:$lbu_min on $lbu_day/$lbu_mth/$lbu_yr ==========="
				echo $lbu_status > $HOME/.lbu_last_backup
				lbu_msgtyp="Status" ; lbu_msgtxt="Job has been submitted for execution.\n\nJOB NUMBER IS : $lbu_jobno\n\nPlease make note of this number."
				lbu_hgt=9 ; lbu_wth=45
				lbu_message
			else
				lbu_msgtyp="Status" ; lbu_msgtxt="Job **FAILED** to be submitted."
				lbu_hgt=5 ; lbu_wth=45
				lbu_message	
			fi
		fi
	fi
}

# **********************************************************************
# *                         Delete a scheduled backup                  *
# **********************************************************************

lbu_delsch() {

	lbu_loop3=1
	while [ $lbu_loop3 = 1 ]; do
		dialog --title "L.B.U DELETE Schedule" --inputbox "Enter job number (? for help)" 8 40 2> $lbu_tmpfile
		lbu_jobno=`cat $lbu_tmpfile`
		rm -f $lbu_tmpfile

# ------- check for no input provided

	  	if [ -z $lbu_jobno ]; then
			lbu_msgtyp="Error" ; lbu_msgtxt="No job number specified\n        Aborting"
			lbu_hgt=6 ; lbu_wth=30
			lbu_message
			lbu_loop3=0
		else

# ------- asking for help ?

			if [ $lbu_jobno = ? ]; then
				lbu_hlpfile=$lbu_dir/lbu_help7
				lbu_help
				lbu_loop3=1
			else
				if [ ! -a /var/spool/atjobs/$lbu_jobno ]; then
					lbu_msgtyp="Error" ; lbu_msgtxt="The specified job number does not exist.\nPlease re-enter."
					lbu_hgt=6 ;lbu_wth=50
					lbu_message
				else
					lbu_isval=`cat /var/spool/atjobs/$lbu_jobno | grep lbu | wc -l`
					if [ $lbu_isval = 0 ]; then
						lbu_msgtyp="Error" ; lbu_msgtxt="This does not appear to be an L.B.U schedule.\nPlease re-enter."
						lbu_hgt=6 ;lbu_wth=50
						lbu_message
					 else
						atrm $lbu_jobno >/dev/null 2>&1
						lbu_status="SCHEDULE DELETED"
						echo $lbu_status > $HOME/.lbu_last_backup
						lbu_msgtyp="Informational" ; lbu_msgtxt="The schedule has been DELETED."
						lbu_hgt=5 ;lbu_wth=50
						lbu_message
						lbu_loop3=0
					fi
				fi
			fi
		fi
	done
}


# **********************************************************************
# *                         L.B.U Restore Backup                       *
# **********************************************************************

lbu_restore() {
	if [ $lbu_devexist = no ]; then
		 lbu_msgtyp="Error" ; lbu_msgtxt="The restore device is not valid.\nPlease re-enter."
		lbu_hgt=6 ; lbu_wth=45
		lbu_message
	else
		if [ -z "$lbu_device" ]; then
			lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nstarting the Restore"
			lbu_hgt=6 ; lbu_wth=45
			lbu_message
		else
			if [ -z "$lbu_dirfil" ]; then
				lbu_msgtyp="Informational" ; lbu_msgtxt="No Dir/File specified. All will be restored."
				lbu_hgt=5 ; lbu_wth=50
				lbu_message
			fi
			lbu_cxtd=x
			lbu_buildcmd
# 
# --------- DO THE RESTORE !!!!!
# 
			lbu_status="RESTORE IN PROGRESS"
			echo $lbu_status > $HOME/.lbu_last_backup
			if [ $lbu_dsply_multi = yes ]; then
				lbu_hlpfile=$lbu_dir/lbu_Minfo
				lbu_help
				clear
				lbu_status=`date`"\n\n====================== RESTORE IN PROGRESS =========================\n"
				echo $lbu_status > $HOME/.lbu_last_backup
				echo "RESTORE STARTED : " `date` > $lbu_logfile
				eval $lbu_cmd_line | tee -a $lbu_logfile

				if [ $? = 0 ]; then
					lbu_status=`date`"\n\n================== RESTORE COMPLETION STATUS: SUCCESS ===================\n+++++++++++++++++ (Check the log-file for messages.) ++++++++++++++++++++\n"
				else
					lbu_status=`date`"\n\n================== RESTORE COMPLETION STATUS: FAILURE ===================\n+++++++++++++++++ (Check the log-file for messages.) ++++++++++++++++++++\n"
				fi
				echo $lbu_status > $HOME/.lbu_last_backup
#
# ------- If required mail log to user
#

				if [ $lbu_mail = yes ]; then
					echo DIR = $lbu_dir
					mail -s "L.B.U RESTORE LOG" $LOGNAME < $lbu_logfile
				fi

			else
				lbu_bkup_rest_comp=RESTORE
				lbu_bldsh_bg
				exec $lbu_bkup_bg &

			fi
		fi
	fi
}



# **********************************************************************
# *                          Show STATUS message                       *
# **********************************************************************

lbu_look() {
	if [ -f $HOME/.lbu_last_backup ]; then
		lbu_lbu="$lbu_line\nLast L.B.U action / date                   : `cat $HOME/.lbu_last_backup`\n$lbu_line"
	else
		lbu_lbu="$lbu_line\n		   No previous L.B.U backup has been performed\n$lbu_line"
	fi

	lbu_pwd="Current directory 			     : `pwd`"
	lbu_dat="Current date				     : `date`"
	dialog --title "$lbu_title" --msgbox "$lbu_author\n\n$lbu_line\n$lbu_pwd\n$lbu_dat\n$lbu_lbu" 21 79
}

# **********************************************************************
# *               Compare backup with file-system                      *
# **********************************************************************

lbu_comp() {
	if [ $lbu_devexist = no ]; then
		lbu_msgtyp="Error" ; lbu_msgtxt="The compare device is not valid.\nPlease re-enter."
		lbu_hgt=6 ; lbu_wth=45
		lbu_message
		return
	fi

	if [ -z "$lbu_device" ]; then
		lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nstarting the Backup"
		lbu_hgt=6 ; lbu_wth=45
		lbu_message
	else
		lbu_vbose_orig=$lbu_vbose
		lbu_vbose='v'
		lbu_cxtd=d
		lbu_buildcmd
		lbu_vbose=$lbu_vbose_orig
# 
# --------- DO THE COMPARE
# 
		lbu_status="COMPARE IN PROGRESS"
		echo $lbu_status > $HOME/.lbu_last_backup
		if [ $lbu_dsply_multi = yes ]; then
			lbu_hlpfile=$lbu_dir/lbu_Cinfo
			lbu_help
			clear
			lbu_status=`date`"\n\n======================= COMPARE IN PROGRESS =========================\n"
			echo $lbu_status > $HOME/.lbu_last_backup
			echo "COMPARE STARTED: " `date` > $lbu_logfile
			eval $lbu_cmd_line | tee -a $lbu_logfile

			if [ $? = 0 ]; then
				lbu_status=`date`"\n\n================== COMPARE COMPLETION STATUS: SUCCESS =====================\n"
			else
				lbu_status=`date`"\n\n================== COMPARE COMPLETION STATUS: FAILURE =====================\n"
			fi
			echo $lbu_status > $HOME/.lbu_last_backup
#
# ------- If required mail log to user
#
			if [ $lbu_mail = yes ]; then
				mail -s "L.B.U COMPARE LOG" $LOGNAME < $lbu_logfile
			fi

		else
			lbu_bkup_rest_comp=COMPARE
			lbu_bldsh_bg
			exec $lbu_bkup_bg &
		fi

	fi
}

# **********************************************************************
# *              Backup log file inspection subroutine                 *
# **********************************************************************

lbu_inspect() {
	if [ ! -a $lbu_logfile ]; then
		lbu_msgtyp="Error" ; lbu_msgtxt="There is no log file to view."
		lbu_hgt=5 ; lbu_wth=40
		lbu_message
	else
		dialog --title "Linux Backup Log Inspection" --textbox $lbu_logfile 21 77
	fi
	return 0
}

# **********************************************************************
# *               Backup file view subroutine                          *
# **********************************************************************

lbu_view() {
	if [ -z "$lbu_device" ]; then
		lbu_msgtyp="Error" ; lbu_msgtxt="Please enter a Device selection before\nattempting a view operation"
		lbu_hgt=6 ; lbu_wth=45
		lbu_message
	else
		if [ $lbu_devexist = no ]; then
			lbu_msgtyp="Error" ; lbu_msgtxt="The view device is not valid.\nPlease re-enter."
			lbu_hgt=6 ; lbu_wth=45
			lbu_message
		else
			lbu_cxtd=t
			lbu_excl_orig=$lbu_excl
			lbu_excl=''
			lbu_buildcmd
			lbu_excl=$lbu_excl_orig
			clear
			eval $lbu_cmd_line | more
			echo ''
			echo ''
			echo "======================== Please press RETURN to continue ==================="
			read lbu_null
		fi
	fi
}

# **********************************************************************
# *                      L.B.U Save Config Subroutine                  *
# **********************************************************************

lbu_write() {
	if [ -f $HOME/.lburc ]; then
		rm $HOME/.lburc
	fi

	lbu_quote='"'
	echo "lbu_devtype=$lbu_quote"$lbu_devtype$lbu_quote > $HOME/.lburc
	echo "lbu_dsply_dev=$lbu_quote"$lbu_dsply_dev$lbu_quote >>$HOME/.lburc
	echo "lbu_ext=$lbu_quote"$lbu_ext$lbu_quote >>$HOME/.lburc
	echo "lbu_orig_ext=$lbu_quote"$lbu_orig_ext$lbu_quote >>$HOME/.lburc
	echo "lbu_device="$lbu_quote$lbu_device$lbu_quote >>$HOME/.lburc

	echo "lbu_dirfil="$lbu_quote$lbu_dirfil$lbu_quote >>$HOME/.lburc
	echo "lbu_dsply_dfl="$lbu_quote$lbu_dsply_dfl$lbu_quote >>$HOME/.lburc
	echo "lbu_multi="$lbu_quote$lbu_multi$lbu_quote >>$HOME/.lburc
	echo "lbu_dsply_multi="$lbu_quote$lbu_dsply_multi$lbu_quote >>$HOME/.lburc
	echo "lbu_absol="$lbu_quote$lbu_absol$lbu_quote >>$HOME/.lburc
	echo "lbu_dsply_absol="$lbu_quote$lbu_dsply_absol$lbu_quote >>$HOME/.lburc
	echo "lbu_mail="$lbu_quote$lbu_mail$lbu_quote >>$HOME/.lburc
	echo "lbu_dsply_mail="$lbu_quote$lbu_dsply_mail$lbu_quote >>$HOME/.lburc
	echo "lbu_blcks="$lbu_quote$lbu_blcks$lbu_quote >>$HOME/.lburc
	echo "lbu_dsply_blcks="$lbu_quote$lbu_dsply_blcks$lbu_quote >>$HOME/.lburc
	echo "lbu_perms="$lbu_quote$lbu_perms$lbu_quote >>$HOME/.lburc
	echo "lbu_dsply_perms="$lbu_quote$lbu_dsply_perms$lbu_quote >>$HOME/.lburc
	echo "lbu_owner="$lbu_quote$lbu_owner$lbu_quote >>$HOME/.lburc
	echo "lbu_dsply_owner="$lbu_quote$lbu_dsply_owner$lbu_quote >>$HOME/.lburc
	echo "lbu_total="$lbu_quote$lbu_total$lbu_quote >>$HOME/.lburc
	echo "lbu_dsply_total="$lbu_quote$lbu_dsply_total$lbu_quote >>$HOME/.lburc
	echo "lbu_vbose="$lbu_quote$lbu_vbose$lbu_quote >>$HOME/.lburc
	echo "lbu_dsply_vbose="$lbu_quote$lbu_dsply_vbose$lbu_quote >>$HOME/.lburc
	echo "lbu_cmprs="$lbu_quote$lbu_cmprs$lbu_quote >>$HOME/.lburc
	echo "lbu_dsply_cmprs="$lbu_quote$lbu_dsply_cmprs$lbu_quote >>$HOME/.lburc
	echo "lbu_excl="$lbu_quote$lbu_excl$lbu_quote >>$HOME/.lburc
	echo "lbu_dsply_excl="$lbu_quote$lbu_dsply_excl$lbu_quote >>$HOME/.lburc
	echo "==END==" >>$HOME/.lburc

	dialog --title "L.B.U Write config" --msgbox "Current configuration saved to\n$HOME.lburc" 6 35
}

# **********************************************************************
# *                    L.B.U Exclusion list subroutine                 *
# **********************************************************************

lbu_exclude() {
	lbu_hlpfile="$lbu_dir/lbu_help8"
	lbu_help
	lbu_editor=$EDITOR
	if [ -z $lbu_editor ]; then
		vi $HOME/.lbu_exclude
	else
		$lbu_editor $HOME/.lbu_exclude
	fi
}
		
# **********************************************************************
# *                    L.B.U Quit subroutine                           *
# **********************************************************************

lbu_quit() {
	exit
}

# ***********************************************************************
# *  Invalid Entry subroutine alias 'Bummer I missed THAT possibility'  *
# ***********************************************************************

lbu_invent() {
	dialog --title "L.B.U inv_ent subroutine" \
	--backtitle "$TVERSION"\
	--msgbox "Invalid Entry" 5 25
	return 0
}

# ************************************************************************
# *                Generlised L.B.U utility subroutines                  *
# ************************************************************************

#
# ------- General help display sub-routine
#

lbu_help() {
	dialog --title "Linux Backup Utility Help Screen" \
	--backtitle "$TVERSION"\
	--textbox "$lbu_hlpfile" 21 77
}

# ------- General error message sub-routine

lbu_message() {
	dialog --title "L.B.U $lbu_msgtyp message" \
	--backtitle "$TVERSION"\
	--msgbox "$lbu_msgtxt" $lbu_hgt $lbu_wth
	return 0
}

# **********************************************************************
# *               L.B.U Date entry/validation sub-routine              *
# **********************************************************************

lbu_date() {
	lbu_curdate
	lbu_loop3=1
	while [ $lbu_loop3 = 1 ]; do
		lbu_dterr=1
	dialog --title "L.B.U Time/Date" \
	--backtitle "$TVERSION"\
	--inputbox "Example:\nHH:MM DD Mn YYYY\n15:18 23 02 1995" 10 25 2>$lbu_tmpfile
	
		lbu_date=`cat $lbu_tmpfile`
	
# ------- check for no input provided

	  	if [ -z "$lbu_date" ]; then
			lbu_msgtyp="Error" ; lbu_msgtxt="No date has been specified\n        Aborting"
			lbu_hgt=6 ; lbu_wth=35
			lbu_message
			lbu_loop3=0
		else
#
# ------- asking for help ?
#
			if [ "$lbu_date" = "?" ]; then
				lbu_hlpfile=$lbu_dir/lbu_help6
				lbu_help
				lbu_loop3=1
				lbu_dterr=0
			else
				lbu_ccnt=`echo $lbu_date | wc -c`
				if [ $lbu_ccnt != 17 ]; then
					lbu_msgtyp="Error" ; lbu_msgtxt="The date entered is invalid.\nPlease see the example or\nenter ? for help."
					lbu_hgt=7 ; lbu_wth=35
					lbu_message
				else
					lbu_hr=`echo $lbu_date  | cut -c1-2`
					lbu_min=`echo $lbu_date | cut -c4-5`
					lbu_day=`echo $lbu_date | cut -c7-8`
					lbu_mth=`echo $lbu_date | cut -c10-11`
					lbu_yr=`echo $lbu_date  | cut -c13-16`
					lbu_now=`date +%Y%m%d%H%M`
					lbu_reset=`date +%m%d%H%M%Y`
					lbu_dval=$lbu_mth$lbu_day$lbu_hr$lbu_min$lbu_yr
					lbu_dent=$lbu_yr$lbu_mth$lbu_day$lbu_hr$lbu_min
					if [ $lbu_now -ge $lbu_dent ]; then
						lbu_msgtyp="Error" ; lbu_msgtxt="The date/time has already passed.\nPlease re-enter."
						lbu_hgt=6 ; lbu_wth=40
						lbu_message
					else
						rm -f $lbu_tmpfile
#
# ------- date validation
#
# ------- use the date command to perform basic validation
#
						date $lbu_dval >/dev/null 2>$lbu_tmpfile
						date $lbu_reset >/dev/null 2>&1
						if [ -s $lbu_tmpfile ]; then
							lbu_msgtyp="Error" ; lbu_msgtxt="Date validation error. Date entered is invalid.\nPlease re-enter."
							lbu_hgt=6 ; lbu_wth=50
							lbu_message
						else
#
# ------- use bc to check if leap year
#
							echo $lbu_yr%4 > $lbu_tmpfile
							lbu_lyr=`bc < $lbu_tmpfile`
							if [ $lbu_lyr != 0 ]; then
								if [ $lbu_day -gt 28 ]; then
									lbu_msgtyp="Error" ; lbu_msgtxt="Date 1validation error. Date entered is invalid.\nPlease re-enter."
									lbu_hgt=6 ; lbu_wth=50
									lbu_message
								else		
									lbu_dterr=0
									lbu_loop3=0
								fi
							else
								lbu_dterr=0
								lbu_loop3=0
							fi
						fi
					fi
				fi
			fi
		fi
	done

rm -f $lbu_tmpfile

}

# *************************************************************************
# *               Display the current date and time                       *
# *************************************************************************

lbu_curdate() {
	lbu_cdat=`date`
	lbu_msgtyp="Informational" ; lbu_msgtxt="The current date and time is :\n$lbu_cdat"
			lbu_hgt=6 ; lbu_wth=35
			lbu_message
}

# *************************************************************************
# *               Main body of the Linux Backup Utility			  *
# *************************************************************************

lbu_1st_time=`ls -a $HOME | grep .lbu_ | wc -l`
if [ $lbu_1st_time = 0 ]; then
	dialog --title "Linux Backup Utility Introduction Screen" \
	--backtitle "$TVERSION"\
	--textbox "$lbu_dir/lbu_1stintro" 21 77
fi

lbu_line="-------------------------------------------------------------------------"
lbu_orig_term=$TERM
lbu_title="Linux Backup Utility v1.10"
lbu_author="   ( jwb@uvo.dec.com )                           Jonathan Warburton-Brown"
lbu_orig_ext=".tgz"
lbu_bkup_bg=$HOME/.lbu_bkup_bg
lbu_logfile=$HOME/.lbu_backup_log
lbu_redir=''
lbu_devexist=yes
lbu_dsply_multi=no	; lbu_multi=''
lbu_dsply_absol=yes 	; lbu_absol='P'
lbu_dsply_mail=no	; lbu_mail=no
lbu_dsply_blcks=20	; lbu_blcks='20'
lbu_dsply_perms=yes	; lbu_perms='p'
lbu_dsply_owner=yes	; lbu_owner='--same-owner'
lbu_dsply_total=yes	; lbu_total='--totals'
lbu_dsply_vbose=yes	; lbu_vbose='v'
lbu_dsply_cmprs=gzip	; lbu_cmprs='z'
lbu_dsply_excl=no	; lbu_excl=''
#
# -------- Look for saved configuration details
#

# -------- Root only access ?

if [ $lbu_root_only = yes ]; then
	if [ $LOGNAME != root ]; then
		lbu_msgtyp="Error" ; lbu_msgtxt="\n Sorry but you must be\n 'root' to run backups"
		lbu_hgt=8 ; lbu_wth=30
		lbu_message
		TERM=$lbu_orig_term ; export TERM
		reset ; clear
		exit
	fi
fi	
	

#
# -------- Is another backup process running ?
#

lbu_inprg=`ps -ax | grep lbu | wc -l`
if [ $lbu_inprg != 3 ]; then
	lbu_msgtyp="Error" ; lbu_msgtxt="Another backup is running or the\nbackup script is being modified.\nPlease try again later."
	lbu_hgt=7 ; lbu_wth=40
	lbu_message
	reset ; clear
	exit
fi

#
# ------- if you change the name of LBU then you're on your own to
# ------- change the logo below !!!  ;-)
#

if [ -f $HOME/.lburc ]; then

	dialog --title "$lbu_title" --infobox "\n\n\n\
           _/_/              _/_/_/_/_/            _/_/    _/_/ \n\
          _/_/              _/_/    _/_/          _/_/    _/_/  \n\
         _/_/              _/_/    _/_/          _/_/    _/_/   \n\
        _/_/              _/_/_/_/_/            _/_/    _/_/    \n\
       _/_/              _/_/     _/_/         _/_/    _/_/     \n\
      _/_/       _/_/   _/_/     _/_/  _/_/   _/_/    _/_/      \n\
     _/_/_/_/_/  _/_/  _/_/_/_/_/_/    _/_/  _/_/_/_/_/_/       \n\n\
              ( Jonathan Warburton-Brown @ 1995 )\n\n\
     The Linux Backup Utility is now restoring its saved\n\
                     configuration details" 20 70

	lbu_reccnt=`wc -l < $HOME/.lburc`
	lbu_pcnt=`expr 100 / $lbu_reccnt`
	lbu_loop=1
	lbu_ctr=0
	while [ $lbu_loop = 1 ]; do
		lbu_ctr=`expr $lbu_ctr + 1`
		lbu_var=`cat $HOME/.lburc | head -n $lbu_ctr | tail -n 1`
		echo -ne `expr $lbu_pcnt \* $lbu_ctr`' %'\\b\\b\\b\\b\\b
		case $lbu_var in
			==END==)	break;;
			*)		eval $lbu_var;;
		esac
	done
	loop=0
	echo -n '100 %'
fi

if [ -a $lbu_device ]; then
	lbu_devexist=yes
else
	lbu_devexist=no
fi

#
# ------- What is the latest status message ?
#

lbu_look

lbu_proceed
reset ; clear
exit

# ***********************************************************************
# *                         That's all Folks                            *
# ***********************************************************************
