#!/bin/bash
#!  "CTB-SLX"
#!  from "CTB-SL-v.4.1.sh"  rename to "CTB-SL.sh"     
#!  (B)asic version 4.1 , plus ScanList plus ONE HelpPage
#!  Runs Auto, pmount/umount, CTA
#!
#!  "CTB-SLX"  [ plus Pmnt, CTB-SLX, Umnt ]
#!  called by MGR, page Util, CTB-SLX , includes Pmnt + Umnt
#!  called by MGR, page Util, CTB-SLX , includes Pmnt + Umnt
#!
#!   Standard GNU General Public License Software:
#! 


#(:==========================================================
#! System Developer Initial DOB is "gcSysDevDob'
#! ----------------------------------------------------------------
#~ export gcSysDevDob="230308-1018"
export gcSysDevDob="240630-0920"
#! export gcSysDevDob="240315-1636  neatness
#! ----------------------------------------------------------------
#(: System Developer ID name of this Linux BASH script is "CTB"
export gcSysDevId="CTB-SLX"    # ScanList	called by MGR, "E3+CTB+Quit"  includes UpPmnt + DnUmnt
export gcSysDevVer="4.1"
#! ----------------------------------------------------------------
#(:==========================================================
#(: Development "CTB-SL"    (B)asic version plus ScanList plus HelpPages
#(: written for Linux Puppy OS, frugal install.
#(: tested on all "official" distributions. 
#(:
#(:==========================================================
#(:
#(: CTB-SL, v4, is a "B"asic version with GUI and SCAN options. 
#(: CTB-SL can SCAN other HD , and cast Backup.tar.gz 
#(:    out to mounted HD , via a list of standard HD names (sda1, sdb1, sdc1, etc)
#(: 
#(: We have "Auto" and "Utility" and "NoSMP-Auto" versions of the CTB series,  
#(:    which skip all the Main Gui Screen control options.
#(:	Other versions are controlled by user modifiable tags  
#(:    in the f(Sys_SetVerDts) module 
#(:    which is the first code module in this Source File.
#(:
#(:==========================================================
#(: System Docs and Legal are at far bottom of code
#(:==========================================================

#(: method of Programmer Docs and Linux Comments.
#(: "#(:" Docs are "Transferred"  by "TXN" into "comments.txt"
#(:       used for Prog Dox to build Documentation for project . 
#(:       TXN will pull these out to a separate file for project. 
#(:         #(: effectively becomes a 'cut' line
#(:
#(: "#(!" Docs are "KEEP" in code.sh and also "Transferred" into comments text file.
#(:
#(: "#:"  Comments are culled via "TXN"
#(:       used for common comments added by gae
#(:       TXN will kill these common comments, for min prog/script size.
#(: 

# lcSetCtrl=1
# if [ lcSetCtrl ] ; then
    # set -e
    # set +e
# else
    # set +e
    # set +e
# fi

lcSetCtrl=0

    set +x
    set +e


#:-----------------------------------------------------------------------------------
#: rc.sysinit uses this PATH statement: 
#: PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R7/bin:/etc/rc.d:/root/my-applications/ 
#:--- CTB.sh expands to this --------------------------------------------------------
PATH=$PATH:/usr/lib/gtkdialog/
#:-----------------------------------------------------------------------------------


#(: ===================;;;;;;;;
#(: fx(Sys_SetVerDts) === default global specs
#(: called by: f(CTB_StartUp)  
#(:		for required Developer's Data Entry Code.
#(: param: none
#(: purpose: gather parameters , accept declarations by user, assign mode control
#(: calls: none
#(: method: declare/assign/export 
#(: sends: 
#(: rationale: 
#(: note : 
#(: ============================
function Sys_SetVerDts() {
# capture all params (future development)
export gcCTBparam1="$1"	## "B"  , "U"  , "A"  ## options for "local" control .
export gcCTBparam2="$2" ## "RS" , "RB" , "RQ" ## options to match manager "MGN.sh" .
export gcCTBparam3="$3"
#(: fx(Sys_SetVerDts)
#(: ============================

#: ================================================ end "else case"
#(:  declare "mode" for CTB  control
#(:  "B" Backup+Scan  by selecting "Scan" button directly, standard version. 
#(:  "U" Utility "NO GUI" , local copy only, used only in "CTU.sh" version. 
#(:	 "A" Auto-Scan, NO-GUI. 
#: ================================================ end "else case"
case "${gcCTBparam1}" in	## capture param : 
	"B") gcCTBmode="B"  && gcCTBmodeName="Basic"   && gcCTBmodeId="CTB" ;;	
	"U") gcCTBmode="U"  && gcCTBmodeName="Utility" && gcCTBmodeId="CTU" ;;	
	"A") gcCTBmode="A"  && gcCTBmodeName="Auto"    && gcCTBmodeId="CTA" ;;	
	#: ================================================ begin "else case"
	#~ *)   gcCTBmode="U"	&& gcCTBmodeName="Utility" ;;	
	#~ *)   gcCTBmode="B"	&& gcCTBmodeName="Basic" && gcCTBmodeId="CTB" ;;	
    #! for CTB-SLX run as AUTO and ScanList
	*) gcCTBmode="A"	  &&  gcCTBmodeName="Auto"   &&  gcCTBmodeId="CTA" ;;	
esac
#: ================================================ end "else case"
# 
. /etc/DISTRO_SPECS
. /etc/rc.d/PUPSTATE
# ## export gcVerDtsTmpPS=""	# temp var,  used before/after loading PUPSTATE
export gcCTBmode="${gcCTBmode}"	## export a "gc-mode-control"
export gcCTBmodeName="${gcCTBmodeName}"	## export for "GUI display control" 2808
#(: ... For "SCAN" to work, 
#(: ... each target drive must have subdir at the "/home" level 
export gcCTBbackupSubDir="/CTB_Backup_"
#(:     (The user can substitute a custome name for the value in gcCTBbackupSubDir. ) 
#(:     (But, the Author sees no good reason to change this subdir name. )
#(:     It is up to the 'user' to provide this target subdir : 
#(:     for example "/initrd/mnt/dev_save/CTB_Backup_". 
#(:     for example "/mnt/sdc1/CTB_Backup_". 
#(:     for example "/mnt/sdd1/CTB_Backup_". 
#(:     for example "/mnt/sde1/CTB_Backup_". 
#(:     for example "/mnt/sdf1/CTB_Backup_". 
#(: note: 
#(:		Author aimed for the generic SDA1, SDB1, SDC1, et al 
#(:		User can substitute any drive name, 
#(:        even system networked drives. 
#(:		Enter new names in subroutine "CTB_ScanList"
#(:
#(: fx(CTB_ScanOne) will test if exist subdir, 
#(:                if  [ -d ${lcFileOutDir} ]   
#(:           then begin: ScanOne splash & COPY
#(: fx(CTB_ScanOne) has method: Test for Target SubDir exist 
#(:   	if  [ -d ${lcFileOutDir} ]  
#(:        then continue. 
#(:     else will skip any non-qualifiying hard drive target. 
#(: 
#~ #(:  Control Test mode :  "T"est can skip Back-Up code ,  "0" is normal run Back-Up. 
#~ export gcCTBtest="0"	
#(:  $0   is used to restart this program, after looping through options.  
#(:  Note: Written in BASH. 
#(:   so ,sometimes , with call/return to subroutines/subscripts, 
#(:   BASH will loose this environmental variable, due encapsulation errors. 
#(:   This code is written in BASH, and BASH has limits. 
export gcCtbZeroRun="$0"
#(:  So "gcCtbZeroRun" is declared and assigned the value "$0" 
#(:     which refers directly to "this" script.    
#(:  Capture now, before any changes to call-stack level. 
#(:
#(: end: f(CTB initial control) === default global specs
#
# 
#(: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#(:  Note:  CTB.sh  cannot be "dependent" on library rc.z_SLP.sh 
#(:  So, utility routines are written internal in this source. 
#(:  Note: this version CTB was developed in UpupBB BionicBeaver v10, 
#(:     which included GTK.2.0 
#(: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#(: fx(Sys_SetVerDts)
#(: === begin: Config Reader ===============================================
#(: Should be after f(Sys_PupState)
#(: === begin: Config Reader ===============================================
# read early, save to inject into data stream later. 
# this method of 'cat' skips requirement for 'permissions' 
# note: "A"utomatic works in the local code mode. 
# note: "B"asic (distributed version) can be re-directed.
gcCtbConfigFN="/CTB_config.sh"		# placed in '/' below '/root' 
# 
if [ ${gcCTBmode} = "B" ] ; then	# read config
		#: "B"asic (distributed version) always reads config on every startup
		# NOT: "A"utomatic mode (defaults to local in 'saveDATA' location.
		# IS: "B"asic (distributed version)
		# therefore: reading  config is OK. 
	if [ -f ${gcCtbConfigFN} ]  ; then
		# if config, then read AS-IS 
		n=0
		gcCtbConfigTrgPrefix=""				# default null
		# this cats a single line of data 
		gcCtbConfigTrgPrefix=`cat ${gcCtbConfigFN}`
		# this method of 'cat' skips requirement for 'permissions' 
			#~ lcMsgStr="---1--- trace ---------------" && Sbr_Str2DevTrm "$lcMsgStr" "4" "3"
			#~ lcMsgStr=">>> CTB_config.sh" && Sbr_Str2DevTrm "$lcMsgStr" "1" "3"
			#~ lcMsgStr="FN : ${gcCtbConfigFN}" && Sbr_Str2DevTrm "$lcMsgStr" "3" "3"
			#~ lcMsgStr="Trg: '${gcCtbConfigTrgPrefix}'" && Sbr_Str2DevTrm "$lcMsgStr" "5" "3"
			#~ echo ":${gcCtbConfigTrgPrefix}:" 
			#~ lcMsgStr="-----------------------------" && Sbr_Str2DevTrm "$lcMsgStr" "4" "3"
		# now we have the alternate target subdir for casting saveDATA.tar.gz
	else	
		# else not config file found.
		# writing an informative 'configfile' is confusing to user. 
		gcCtbConfigTrgPrefix=""				# default null
		n=0
	fi
fi	# [ ${gcCTBmode} = "B" ] 
	# export config READ results 
	export gcCtbConfigTrgPrefix="${gcCtbConfigTrgPrefix}"
#(:=== end: Config Reader ==============================================
#(:=== end: Config Reader ==============================================
#(:=== end: Config Reader ==============================================
} # end: Sys_SetVerDts


#(: ======================================================================
#(: fx(Sbr_Ctb_Cold_Splash_It)   #: ACTIVE
#(: called by:
#(: param:
#(: purpose:
#(: calls:
#(: method:  Sbr_Ctb_Cold_Splash_It "message" "fg" "bg" "slp" "special"
#(: sends:
#(: rationale:
#(: note :
#! =========================
#! ### Sbr_Ctb__Cold_Splash_It ########################################
function Sbr_Ctb_Cold_Splash_It() {   # Active # Simple Splash : param "Str" "fg" "bg" "sleep" "opt"
	n=0 
    #! param = "." will trigger a default value, sometimes 
    #!               " "  or "0" not allowed.  
    #!               ""   converts to 'sleep "0"'  
    #! color: system, red, yellow, orange, green, blue, purple
    #!
lcMsgStr="$1"
lcMsgColorFg="$2"   # ForeGround
if [ ! $2  ] ; then 
    lcMsgColorFg="yellow"   # good default 
fi    

lcMsgColorBg="$3"   # BackGround
if [ ! $3  ] ; then 
    lcMsgColorBg="purple"  # good default
fi    

lcMsgSlp="$4"
if [ ! $4 ] ; then  # Sleep 
    lcMsgSlp="3"  # < 1  usually does not make it to the screen, timing issues. 
fi    
    #! -D---
/usr/lib/gtkdialog/box_splash -fg ${lcMsgColorFg} -bg ${lcMsgColorBg} -border true  -close never -text "${lcMsgStr}     " &
    RETVAL=$?
	GTKPID_Cold_Splash=$!
	sleep ${lcMsgSlp}
    #
lcMsgOpt="$5"   # standard is do the kill 
if [ ! $5 ] ; then  # IF   No Option,  THEN   kill pid NOW !   ( compatible / normal)
    kill ${GTKPID_Cold_Splash}
    #! if has flag, then No Kill.  Must "kill" pid later. 
else
    n=0
    #! kill pid later 
fi    
#!
} #
export -f Sbr_Ctb_Cold_Splash_It
#!



#!
#(: ===================;;;
#(: System Pmount
#(: ===================;;;
#(:
#!
#(:===========================================================
#(: fx(Sbr_Ctb_pMount_One)
#(: called by:   Sbr_Ctb_pMount_All calls "Sbr_Ctb_pMount_One"
#(: purpose:  pMOUNT  only one hard-drive
#(: receives param: "/mnt/sd?1"
#(: returns:
#(: note:
#(:
#! ############################################################
function Sbr_Ctb_pMount_One() {   # ACTIVE # Sbr_Ctb_pMount_All
    n=0
    lcParam1="${1}" # trg drive ID
    lcMsgStr="${1}:trg drive ID"
    gcActiveGui="1"
    #!
if [ "$gcActiveGui" = "1" ] ; then 
    #! -D---   Small splash 
/usr/lib/gtkdialog/box_splash -fg yellow -bg purple -border true  -close never -text "\
.      Quick _pMount_One
.             '${1}'                              "&
    RETVAL=$?
    GTKPIDPMNTsbr=$! 
    #! kill ${GTKPIDPMNTsbr} is split
fi
#! IF -d /root THEN already mounted, OK to run !
    mkdir -pv /mnt/${1} drv
    mount         /dev/${1} /mnt/${1}
    mount -t ext3 /dev/${1} /mnt/${1}
    mount -t vfat /dev/${1} /mnt/${1}
if [ "$gcActiveGui" = "1" ] ; then 
    sleep .5
    kill ${GTKPIDPMNTsbr}       #! kill ${GTKPIDPMNTsbr} is split
fi
} #
export -f Sbr_Ctb_pMount_One
#!
#!
#!
#(: ====================================================================
#(: fx(Sbr_Ctb_pMount_All)
#(: called from gui
#(: called by: E3R_Main_Int_Long_List    and gui-P-MntInt
#(: method: code is INTERNAL to CTB
#(: param:
#(: purpose:
#(: calls: fx(Sbr_Ctb_pMount_One)
#(: method: calls internal script with lowercase HD names
#(: sends:
#(: rationale:
#(: note :
#(:
#(:Dump calls Sbr_Ctb_pMount_One with internal prep.
#(:
#! ############################################################
#! ############################################################
function Sbr_Ctb_pMount_All() {   #: ACTIVE ### (???  each Mount All via E3R ) ###
    n=0
    gcActiveGui="1"
    lcActiveMntId="P"   # Id    # Not Used
    #!
if [ "$gcActiveGui" = "1" ] ; then 
    #! -D---  Big Splash BackGround 
/usr/lib/gtkdialog/box_splash -fg yellow -bg blue -border true  -close never -text "\
.      _pMount_All INTERNAL
.
.
.
.
.
.                                                   "&
    RETVAL=$?
    GTKPIDPMNT1=$!
    sleep .5
fi
#!
#~ #set +x +e   # Sbr_Ctb_pMount_All
#! if -d /root then already mounted
#;;; multiple calls to subroutine , which runs a single "mount" routine
#;;; begin looping internal code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#;;; DO NOT USE ON SDA1, which is the primary drive. 
Sbr_Ctb_pMount_One "sda2"
Sbr_Ctb_pMount_One "sdb1"
Sbr_Ctb_pMount_One "sdc1"
Sbr_Ctb_pMount_One "sdd1"
Sbr_Ctb_pMount_One "sde1"
Sbr_Ctb_pMount_One "sdf1"
Sbr_Ctb_pMount_One "sdg1"
Sbr_Ctb_pMount_One "sdh1"
Sbr_Ctb_pMount_One "sdi1"
Sbr_Ctb_pMount_One "sdj1"
Sbr_Ctb_pMount_One "sdk1"
Sbr_Ctb_pMount_One "sdl1"
Sbr_Ctb_pMount_One "sdm1"
Sbr_Ctb_pMount_One "sdn1"
Sbr_Ctb_pMount_One "sdo1"
Sbr_Ctb_pMount_One "sdp1"
#;;; end looping ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if [ "$gcActiveGui" = "1" ] ; then 
    Sbr_Cold_Splash_It  "DONE : __pMount_All" "yellow" "red" "3"           #! -D---
    kill ${GTKPIDPMNT1} # background splash yel/red 
fi #
} # 
export -f Sbr_Ctb_pMount_All
#!
#!
#(: ===================;;;
#(: System Umount 
#(: ===================;;;
#!
#(:======================================================================
#(: fx(Sbr_Ctb_uMount_One)	#: Active
#(: called by:   ft(EXIT:guiUMntInt)  (each one)
#(: calls:
#(: purpose:  uMOUNT only one hard-drive
#(: receives param: "/mnt/sd?1"
#(: returns:
#(: note:
#(:    funxtion "Sbr_Ctb_uMount_All"  calls "Sbr_Ctb_uMount_One"
#! ############################################################
function Sbr_Ctb_uMount_One() {  # ACTIVE
    n=0
    lcParam1="${1}" # trg drive ID
    gcActiveGui="1"
    #~ #lcActiveMntId="U"   # Id    # Not Used
    #!
if [ "$gcActiveGui" = "1" ] ; then 
    #! -D--- Small Splash
/usr/lib/gtkdialog/box_splash -fg yellow -bg purple -border true  -close never -text "\
.      unMount__One INTERNAL
.             '${1}'                              "&
    RETVAL=$?
    GTKPIDUMNTsbr=$!
fi
    # # # todo: ? choose a different test subdir.  Not /root, which is the Current Active drive /root
    # # # check for conflict.   None on 7 drives and 17 OS.  240205-0710
        lcDirName="/root"
        if [ -d ${lcDirName} ] ; then # IF target directory is real 
            umount -lv      /mnt/${1}
        else    # ELSE /root is the /root/home and cannot be unMounted !
            n="0"
        fi
if [ "$gcActiveGui" = "1" ] ; then 
       sleep 1
       kill ${GTKPIDUMNTsbr}
fi
} #
export -f Sbr_Ctb_uMount_One
#!
#!
#(: ============================================================
#(: fx(Sbr_Ctb_uMount_All)
#(: calls: Sbr_Ctb_pMount_One
#(: called from: Gui
#(: called by: E3R_Main_Int_Long_List    and gui-P-MntInt
#(: method: Fall-Thru and code is INTERNAL to CTB
#(: param:
#(: purpose:
#(: calls:
#(: method: calls internal script with lowercase HD names
#(: sends:
#(: rationale:
#(: note :
#(:
#(: calls Sbr_Ctb_uMount_One with internal prep.
#(:
#! ############################################################
function Sbr_Ctb_uMount_All() {   # ACTIVE
    n=0
    gcMntAllLogP="/tmp/CTB_MntAllU.log "
    #~ #lcMntAllTrg=${gcMntAllLogU} # Not Used
    gcActiveGui="1"
    #~ #lcActiveMntId="U"      # Not Used
if [ "$gcActiveGui" = "1" ] ; then 
    #! -D---   Big Splash BackGround
/usr/lib/gtkdialog/box_splash -fg yellow -bg blue -border true  -close never -text "
.        __unMount__All_Internal
.        :${lcMntAllLogFn}:
.
.
.
.
.                                                          "&
    RETVAL=$?
    GTKPIDUMNT1=$!
    sleep .5
fi
#;;; never try to unmount /dev/SDA
#;;; begin looping subroutine umount process ;;;;;;;;;;;;;;;;;;;
#;;; DO NOT USE ON SDA1, which is the primary drive. 
Sbr_Ctb_uMount_One "sda2"
Sbr_Ctb_uMount_One "sdb1"
Sbr_Ctb_uMount_One "sdc1"
Sbr_Ctb_uMount_One "sdd1"
Sbr_Ctb_uMount_One "sde1"
Sbr_Ctb_uMount_One "sdf1"
Sbr_Ctb_uMount_One "sdg1"
Sbr_Ctb_uMount_One "sdh1"
Sbr_Ctb_uMount_One "sdi1"
Sbr_Ctb_uMount_One "sdj1"
Sbr_Ctb_uMount_One "sdk1"
Sbr_Ctb_uMount_One "sdl1"
Sbr_Ctb_uMount_One "sdm1"
Sbr_Ctb_uMount_One "sdn1"
Sbr_Ctb_uMount_One "sdo1"
Sbr_Ctb_uMount_One "sdp1"
#;;; end looping ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#!
if [ "$gcActiveGui" = "1" ] ; then  
    Sbr_Cold_Splash_It  "DONE : __unMount__All" "yellow" "red" "3"           #! -D---
    kill ${GTKPIDUMNT1} # background
fi
} #
export -f Sbr_Ctb_uMount_All
#(: ====================================================================




#(: ===================;;;;;;;;;;;;;
#(: System Utility Sub-Program "Sbr_Str2DevTrm ()". 
#(: ===================;;;
#(: fx(Sbr_Str2DevTrm)
#(: called by: all messages directed to /dev/console or Geany Terminal 
#(: called by: rc.sysinit and rc.shutdown 
#(: param : "string" "color" "margin"
#(: purpose: Str2DevTrm is Standard "Message-2-Display" routine 
#(:     polymorphic design for use from Geany Execute LxTerminal 
#(:     does not display into /dev/console 
#(: 	controlled via :  lcDevConsole=" > /dev/console" 
#(: calls: /bin/echo
#(: method:  polymorphic active "String to Display" 
#(: 	terminal = /usr/bin/xterm -e bash -c -e "/bin/sh %c"
#(: sends: 
#(: rationale : for Geany "terminal" use.
#(:             copied into CTB for encapsulation 
#(: usage:
#(:     Sbr_Str2DevTrm "string" "color" "margin"
#(: 	like this:
#(:     Sbr_Str2DevTrm "$lcMsgStr" "2" "3"
#(:     Sbr_Str2DevTrm "$lcMsgStr" "grn" 15
#(:     Sbr_Str2DevTrm "$lcMsgStr"  2  10
#(: note: BASH will 'type convert'  char vs number 
#(: 	example:
#(:     lcMsgStr="xxx" && Sbr_Str2DevTrm "$lcMsgStr" "2" "3"
#(:     lcMsgStr="xxx" && Sbr_Str2DevTrm "$lcMsgStr"  2    3
#(: 
#(:  Sys2DevTrm displays to "/Dev/Console" or "Terminal" . 
#(:  this version is for "Geany" "BASH" "LxTerminal"  
#(: 		( "Sbr_Str2DevTrm" used by MGN.sh is embedded in MGN.sh , also)
#(: 
#(:  if using Geany "BASH terminal" for tracing, 
#(:  then must use Sbr_Str2DevTrm for "terminal" display. 
#(:  same process is done in 
#(:		MGN.sh, E2R.sh, S2F.sh, C3C.sh, CTB.sh, CTU.sh, etc.  
#(: 
#(: 
#(:  note: todo: dev param zero check and substitution:
#(:  [ -z "${1}" ] && lcParStr="message"	for string
#(:  [ -z "${2}" ] && lcParClr="5"	
#(:			for color : 1,2,3,4,5   or  red,grn,yel,blu,pur
#(:  [ -z "${3}" ] && lcParMrg="3"	
#(:			for  margin : 1,2,3,4,5 where mrg=5,10,15,20,25,30
#(:
function Sbr_Str2DevTrm() {  # Active 
#(: ===================;;;;;;;;;;;;;;;;;
#(:       "String to Display/Terminal" 
#(:
#(:  capture all message params: ${1} string, ${2} color, ${3} margin . 
lcS2TStr=${1}   # STRING message 
lcS2TClr=${2}   # COLOR name or number
lcS2TMrg=${3}  	# MARGIN number 1,5,10 ... 2,3,4,5,etc
lcS2Topt=${4}	# "C"onsole  or  "T"erminal, Default is "User Defined" below. 
#:
#(: note: designed for use from Geany Execute Terminal as "local" output. 
#(:       does not display into /dev/console 
#(: 			unless lcDevConsole=" > /dev/console" 
#(:       terminal = /usr/bin/xterm -e bash -c -e "/bin/sh %c"
#(: note: BASH may "Re-Type" var sometimes. 
#(: note: f(Sbr_Str2DevTrm) does not display into /dev/console 
#(: note: lcDevConsole controls where display occurs. 
#(: IF lcDevConsole=" > /dev/console" THEN std out is "Terminal"
#(:
lcDevConsole=""  
#(: lcDevConsole = ""  is local default to GEANY "T"erminal Only Display
#(: IF " > /dev/console" = lcDevConsole   
#(:      THEN std out display is "Terminal"     ( CTB runs in the light ). 
#(: IF "" 
#(:      THEN std out display is to "Console"   ( CTB runs in the dark ).
#(: Standard Output Trap from param#1 
lcS2Topt=${4}	## "C"onsole  or  "T"erminal
case "${lcS2Topt}" in
   "C") lcDevConsole=" > /dev/console" ;; ## not used by CTB 
   "T") lcDevConsole="" ;; ## "T"erminal display for Geany Execute Terminal 
    *)  lcDevConsole="" ;; ## default to Std Out is "T"erminal display
esac 
#(: Margin Trap from param#3  as "number" | "char"   
#(:  default left-margin=10  
#(: case Margin 
case "${lcS2TMrg}" in
   0|"0") /bin/echo -n -e "\\033[0G"    >/dev/console ;; 
    *) /bin/echo -n -e "\\033[${lcS2TMrg}G"    >/dev/console ;;
esac
#(: 
#(: Color Pattern for "most" BASH versions: 
#(: color trap  from param#2  "name"|"number"   ## default is "3" 
#(: Color: 1    2    3    4    5    6    7    8     9     10
#(: Color: red, grn, yel, blu, pur, cyn, wht, wblu, wgrn, wgry
#(:
#(: Color Trap from user defined:
case "${lcS2TClr}" in
		 #(:  numbers only version 
		 ""|"0")      /bin/echo -n -e "\\033[1;33m"   ${lcDevConsole} ;;
		 *)  /bin/echo -n -e "\\033[1;3${lcS2TClr}m"   ${lcDevConsole} ;; 
esac
#(: 
#(: string ending 
	/bin/echo -n "$lcS2TStr"  ${lcDevConsole} 
	/bin/echo -e "\\033[0;m"  ${lcDevConsole} 
	return  0
} # end: Sbr_Str2DevTrm  







#(: ===================;;;;;;;;;;;;;;;;;;
#(: begin: FLAG control 


#(: ===================
#(: fx(CTB_ClearFlgLockFile)
#(: called by: 
#(: param: 
#(: purpose: clear flags in /tmp , prep for ReStart 
#(: calls: 
#(: method: 
#(: sends: 
#(: rationale: 
#(: note : 
#(:
#(: ===================;;;;
function CTB_ClearFlgLockFile {    #(:  Not Active
	n=0
    #~ lcMsgStr="*** ClearFlgLockFile" && Sbr_Str2DevTrm "$lcMsgStr" "5" "3"
    rm -f "${CTB_FlgLockFile}"   #   ClearFlag --- release 'Running' flag.
} # end: CTB_ClearFlgLockFile


#(: ===================;;;;;;;;;
#(: fx(CTB_ClearFlgBugger_SD)
#(: called by: 
#(: param: 
#(:  purpose: clear "Bugger" SD flag in /tmp #(:  Standard 
#(: calls: 
#(: method: 
#(: sends: 
#(: rationale: 
#(:  	This "Bugger" process is an extended version
#(:  	which scans drives (SD) ; scans all mounted HardDrives/USB 
#(:		which calls the BackUpOne process.
#(: note : 
#(: 
#(: ===================;;;;;;;;;;;;;;;
function CTB_ClearFlgBugger_SD() {    #(:  not active
    #
	n=0
    #~ lcMsgStr="*** ClearFlgBugger_SD" && Sbr_Str2DevTrm "$lcMsgStr" "5" "3"
    rm -f "${CTB_FlgBugger_SD}" 
} # end: CTB_ClearFlgBugger_SD


#(: ===================
#(: fx(CTB_ClearFlgSys)
#(: called by: CTB_BackUpRun, 
#(:		and FT(EXIT="BackUpCall+"), 
#(:		and FT("$EXIT" = "QuitCall+")
#(: param: 
#(: purpose:  clear flags in /tmp , prep for "ReStart" into "CTB" program.
#(: calls: rm
#(: method: rm -f 
#(: sends: 
#(: rationale: clear flags so they do not interfer with "ReStart" into "CTB" program. 
#(: note : All /tmp files are cleared by OS at shutdown. 
#(:
#(: ===================;;;;;;;;;;;;;;;
function CTB_ClearFlgSys() {    #  active
	n=0
    rm -f "${CTB_FlgLockFile}"     #(: ClearFlags : release 'Running' flag.
    rm -f "${CTB_FlgBugger_SD}" 
    rm -f "${CTB_FlgBackupStatus}" 
    rm -f "/tmp/box_help"       #(: ClearFlags : used by fx HELP and fx FAQ  
    rm -f "/tmp/box_source"     #(: ClearFlags : used by fx SOURCE  
	rm -f /tmp/flagnextpassthru			#(:  from SMP or TarOpt
	rm -f /tmp/snapmergepuppy-error		#(:  from SMP
	rm -f /tmp/delayedrun_finished_flag	#(: during CTB, via call from MGN. 
} # end: CTB_ClearFlgSys

#(: end: FLAG control 
#(: ===================;;;;;;;;;;;;;;;;;;






# #############################################################
#(: ===================;;;
#(: begin: Sbr Box DATA Dump SubRoutines 

#(: ===================;;;;;;;;;;
#(: fx(Sbr_Box_Splash)	# internal
#(: called by : anyone
#(: call with:  parm1 text, + parm2 (fg) , + parm2 (bg) 
#(: purpose :  Simple Splash
#(: receives param : none
#(: returns : GtkPid_Sbr_Box_Splash
#(: method: gtkdialog box_splash
#(: note: 
#(: example:
#(: Sbr_Box_Splash "... Message ... " "yellow" "red" 
#(: kill ${GtkPid_Sbr_Box_Splash}
#(: ===================;;;;;; 
function Sbr_Box_Splash() {  # Not Active
    n=0
# left margin dependent
#: ---------------------------------------------------------------------
/usr/lib/gtkdialog/box_splash -fg ${2} -bg ${3} -close never -text "\
.     ${1}  "&
#: ----------------------------------------------------------------------
    RETVAL=$?
	GtkPid_Sbr_Box_Splash=$!	# capture PID
	# kill ${GtkPid_Sbr_Box_Splash} # later
} # end: Sbr_Box_Splash



#(: ===================;;;;;;;;
#(: fx(Sbr_Box_Message)	  # internal mod on gtkdialog box_help 
#(: called by : 
#(:    GuiHLP+  to  f(Sys_Box_HLP)  to  Sbr_Box_Message
#(:    GuiFAQ+  to  f(Sys_Box_FAQ)  to  Sbr_Box_Message
#(:
#(: receives param : Header$1 and loads '/tmp/box_help'
#(: purpose : custom Simple Message sbr 
#(:   based on gtkdialog box_help code processes.
#(: usage :
#(:   HEADING is a short "title bar" description. 
#(:   XML code is custom written to format "/tmp/box_help".
#(: returns: 
#(: method: 
#(:     gtkdialog --center -p XML-Format-file (which loads /tmp/box_help ) 
#(:
#(: note:
#(: purpose :  Simple Message sbr based on gtkdialog box_help
#(:   which allows author to change the "lead-in" XML code 
#(:   and thus change the "format" of this custom "message_box". 
#(:   Sbr_Box_Message does provide a "OK" user button. 
#(:   Sbr_Box_Message does provide a "markup" on text. 
#(:   Sbr_Box_Message does allow dimension changes. 
#(:   Sbr_Box_Message does not require a "URL" param.
#(: note:
#(:   XML assumes /tmp/box_help and "gtkdialog -p" internal code. 
#(:   XML sets up the markup and color options for the imported text. 
#(:   XML sets up the "OK" control button, and will show/close/"OK"
#(:
#(: ===================;;;;;;;;;;;; 
function Sbr_Box_Message() {  # CTB Active called by HLP and FAQ
    n=0
export TEXTDOMAIN=libstardust
export OUTPUT_CHARSET=UTF-8
# we are allowing a param for "HEADING"
if [ "$1" ] ; then
	Box_Msg_Heading="${1}"	# parm #1 if sent. 
else	# else simple standard 'heading'.
	Box_Msg_Heading="$(gettext '---Sbr_Box_Message---')"
fi
export Box_MessageXML='
<window title="'!$Box_Msg_Heading'" default-height="550" default-width="750">
<vbox space-expand="true" space-fill="true">
  <vbox space-expand="true" space-fill="true">
    <vbox scrollable="true" shadow-type="3" space-expand="true" space-fill="true">
      <vbox space-expand="false" space-fill="false">
        <text xpad="10" ypad="15" use-markup="true"><input file>'/tmp/box_help'</input></text>
      </vbox>
    </vbox>
  </vbox>
  <hbox space-expand="false" space-fill="false">
    <button>
      '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
      <label>'$(gettext 'Ok')'</label>
    </button>
  </hbox>
</vbox>
</window>'
 # same as eval "`gtkdialog --center -p Box_MessageXML`" 
                  gtkdialog --center -p Box_MessageXML	# assumes /tmp/box_help
#
# This gtk box sub-routine shows text via "gtkdialog box_help" code.
# This "gtkdialog -p" will read the default '/tmp/box_help' file via "XML" code block. 
# The XML code block sets up the markup and color options for the imported text. 
# (1) Markup/color are valid
# (2) Sets up the "OK" control button, and will show/close/"OK"
} # end: Sbr_Box_Message

#(: end: Sbr Box DATA Dump SubRoutines
#(: ===================;;;;;;;;;;;;;
########################################################################





#(: ===================
#(: fx(Sys_Box_HLP)
#(: called by : Main_GUI GuiHLP+
#(: receives param : none and /tmp/box_help .
#(: requires output Help-Text-File: > /tmp/box_help
#(: purpose :  display Help Text from this program in GTK box.
#(: calls: /usr/lib/gtkdialog/box_help  and "/tmp/box_help"  
#(: method:	called from: Main_GUI line.
#(: cleanup: rm -f /tmp/box_help
#(: purpose :  direct link from Main_GUI , returns to same.
#(: rationale : "Help" and "FAQ" Information for user. 
#(:	returns focus back into: Main_GUI line.
#(: note: 
#(:		gae 191119-0900, first mod
#(:		reduce this to HLP only and allow sending parameters. 
#! 
#!: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
function Sys_Box_HLP() {    #  CTB Active
    n=0
	lcFileHelpTxt="/tmp/box_help"	#(:  required by gtkdialog original source code. 
	#
    echo "\
<span background='"'brown'"'><span foreground='"'yellow'"'> "====="</span></span>\
<span background='"'yellow'"'><span foreground='"'blue'"'>"  CTB HLP "</span></span>\
<span background='"'brown'"'><span foreground='"'yellow'"'> "=====" </span></span>
<span foreground='"'green'"'>"  "  v: ${gcSysDevDob}"  "</span> " glene77is --- v.4 "
.
<b><span foreground='"'red'"'>"---------------------------------------------------------"</span></b>
<b><span foreground='"'red'"'>" 	Cold-Tar-Backup method is this  : "</span></b>
<b><span foreground='"'green'"'>" Click "BackUp" for simple single Backup "</span></b>
	or
<b><span foreground='"'red'"'>"IF you want to SCAN other HD "</span></b>
<b><span foreground='"'brown'"'>"... and cast Backup.tar.gz out to HD "</span></b>
<b><span foreground='"'brown'"'>"... into  "${gcCTBbackupSubDir}" "</span></b>
<b><span foreground='"'brown'"'>"THEN "</span></b>
<b><span foreground='"'brown'"'>"...   First:  click the SCAN button, "</span></b>
<b><span foreground='"'brown'"'>"...   Second: click the BACKUP button !"</span></b>
.
<b><span foreground='"'red'"'>"---------------------------------------------------------"</span></b>
<b><span foreground='"'red'"'>" IF you want to write the Tar.Gz file to SPECIAL subdir"</span></b>
<b><span foreground='"'brown'"'>"THEN write '/CTB_config.sh'  "</span></b>
<b><span foreground='"'brown'"'>"... Read method is 'cat' into 'var' "</span></b>
<b><span foreground='"'brown'"'>"... cat will pull out ALL contents"</span></b>
<b><span foreground='"'brown'"'>"...   including any embedded quote marks"</span></b>
<b><span foreground='"'brown'"'>"... good example is:   /mnt/home/   "</span></b>
.
<span foreground='"'red'"'>"CTB calls Tar.gz for fast backup "</span>
<b><span foreground='"'green'"'>"'TAR' the 'Unix Tape ARchive' method"</span></b>
.
<span foreground='"'blue'"'>"CTB is designed specifically for "</span>
<span foreground='"'red'"'>"    "Official" Puppy Linux"</span>
<b><span foreground='"'green'"'>"Puppy 32/64-bit FRUGAL SaveFOLDER"</span></b>
<b><span foreground='"'green'"'>"Puppy 32/64-bit FRUGAL SaveFILE.4fs"</span></b>
.
<b>1)</b> CTB <b>automatically appends
   the "DTS yr-mo-dy-seconds" stamp</b>
   to the Backup file .tar.gz name.
   This kills possible duplications !
<b>2)</b> CTB <b>automatically pre-Runs 
	"SnapMergePuppy"</b> to update/merge 
	the RAM into the 'saveDATA'.
.
.
<b><span foreground='"'darkred'"'>CTB will back-up from 'source'->'target'</span></b>
... exactly as prescribed in 'PUPSTATE'.
<b><span foreground='"'darkred'"'>CTB is controlled by the 'PUPSTATE' var</span></b>
... as written by the Puppy Linux OS .
<b><span foreground='"'darkred'"'>CTB 'PUPSTATE' contains the "State" values</span></b>
... of the currently running Puppy OS.
<b><span foreground='"'darkred'"'>CTB will use <span foreground='"'green'"'>'PUPSTATE'</span> data</span></b>
... to find the Source and Target .
<b><span foreground='"'darkred'"'>CTB can be <span foreground='"'green'"'>MODIFIED</span> to back-up</span></b>
... ANY 'source' to any 'target'.
<b><span foreground='"'darkred'"'>CTB can <span foreground='"'green'"'>SCAN list of Mounted hard-drives </span></span></b>
... Click the SCAN button at top of screen  
    to copy back-up onto alternate hard-drives
    into a folder named "${gcCTBbackupSubDir}" .
... User must Select option button 'SCAN' 
    on main splash screen .
<b><span foreground='"'darkred'"'>CTB can SCAN list of Mounted hard-drives </span></b>
... CTB can cast the Backup.tar.gz 
    out to SDA2 thru SDG1
    into a folder named "${gcCTBbackupSubDir}" .
... On our OS, limit is 8 hard-drives, 
    as mounted at bootup. 
... Limit is usually 8, 
    depends on BIOS hardware and OS distro. 
... Authors systems are MS-XP class computers,
      with bios dated 2009 thru 2012  
      so our limit is 8 .
... One secondary Backup Hard-Drive is sufficient.  
... Each target must have subdir at the "/home" level 
...    as "${gcCTBbackupSubDir}" . 
    for example "/mnt/sdc1""${gcCTBbackupSubDir}". 
    for example "/mnt/sdd1""${gcCTBbackupSubDir}". 
    for example "/mnt/sde1""${gcCTBbackupSubDir}". 
    for example "/mnt/sdf1""${gcCTBbackupSubDir}". 
.
To RESTORE:
''XArchive', will 'Extract all' from inside 
<b>saveDATA-CTB---tar.gz</b> file.
.
<b><span foreground='"'darkred'"'>"Note: When Running Executable BASH script :"</span></b>
Always check the file "\'set action\'"
... ' $ @ '  'Use-Command'
Always check the file "\'type\'"
... 'Exec'
Always check the file "\'Properties\'"
... 'Exec'
Always check the file "\'Permissions\'"
...'Executable'
Always examine other running scripts
to see how Your System is setting things.
#:
#: uses:  /tmp/box_help
#:
... end of file 'HELP' text ..................................."\
> ${lcFileHelpTxt}   # /tmp/box_help	
#  "/tmp/box_help"	was required by orig GTK source code for /usr/lib/gtkdialog/box_help . 
# 
# first param is only for the "title" top line. 
Sbr_Box_Message "=${DISTRO_NAME} = HELP = gtk 'Sbr_Box_Message' and /tmp/box_help"
# 
#: ------------------------------------------------------------
#(:  BasePIDfile is "/tmp/box_help"
#(:  output storage file MUST BE "/tmp/box_help" 
#(:  due to hard-code in "/usr/lib/gtkdialog/box_help" 
#(:  Modifying would create a "dependency" problem for users. 
#: ------------------------------------------------------------
} #(: end: Sys_Help_Box








#(: ===================
#(: fx(Sys_PupState)
#(: called by: CTB_StartUp ()
#(: param: requires Linux Puppy  /etc/rc.d/PUPSTATE  system "state" file.
#(: purpose: 
#(:      gather PUPSTATE var/constants into this CTB .
#(:      control generation of local var/constants .
#(: calls: f(Sys_PupState)
#(: method: 
#(: sends: 
#(: rationale :
#(:      Puppy writes the "state" variables into /etc/rc.d/PUPSTATE .
#(:      Puppy OS writes the 'Linux Puppy universe' into this file !!!
#(:      this routine reads the "state" file to gather constants.
#(:      this routine declares/assigns more local CTB var.
#(:  returns: numerous memvar 
#(: note : 
#(:
#(: 
#(: -----------------------------------------------------------------
#(: - load PUPSTATE --- from system location : "/etc/rc.d/"
#(: - Puppy OS writes the 'whole known universe' into this file !!!
#(: - At end of rc.sysinit  or  library rc.zSLP.sh  user can append more lines.
#(:
#(: ===================;;;;;;;;;;;;;;;
function Sys_PupState() {    #(:  active

#(: fx(Sys_PupState)
#: -----------------------------------------------------------------
#(:  begin: maintain gcSysDevDob ( Developer's DTS ) .
#(:  (1) save   before PUPSTATE into tmp 
tcVerDtsTmpPS="${gcSysDevDob}"  # before PUPSTATE
#(:  (2) load PUPSTATE )
. /etc/rc.d/PUPSTATE
#(:  (3) restore after PUPSTATE from tmp
gcSysDevDob="${tcVerDtsTmpPS}"  # after PUPSTATE
#(:  end: maintain gcSysDevDob ( Developer's DTS ) .
#: -----------------------------------------------------------------

#(:  Note: grave-mark in date ( ) !!!
gcCtbDts=""
export gcCtbDts="`date +%y%m%d-%H%M-%S`"   #(:  was gcSysDts
#(:  Note: grave-mark in date ( ) !!!

    #(: Not Used
	#(:  Date : grave-mark in date () !!!		
	#(:   Dts="`date +%y%m%d-%H%M-%S`"
	#(:  addust from default >"z" time 
	#(:    to local mid-america dts ( -5 hours ).
	#~ lcNowDts=""									
	#~ lcNowDts="`date +%y%m%d%H%M-S`"	
	#~ # lcNowDts="${lcNowDts:0:6}-${lcNowDts:6:4}"
	#~ lcNowDts="${lcNowDts:0:9}-${lcNowDts:6:7}"	
	#~ gcNowDts=""									
	#~ gcNowDts="${lcNowDts}-local"					
	#~ export gcNowDts="${lcNowDts}"				
	#: Not Used 

#(:  now:  have exported "Dts Ver" and "Dts Sys" 

#(:  in: f(Sys_PupState)

#(: ===========================================================
#(:  direct import to similar varname, used local to CTB
lcPupSave=${PUPSAVE}
lcPupMode=${PUPMODE}
lcPupSubDir=${PSUBDIR}
lcPupHome=${PUP_HOME}


# xxxlcPupSubDir is not used 
# xxxlcPupSubDir="${lcPsubDir}-CTB-`date +%y%m%d-%H%M-%S`" #(:  gcVerDts #(:  grave-mark in date () !!!

#: ===========================================================
# working gae
#(:  build-std: maintain similarity to PUPSTATE "name"
lcMsgStr="build-std: maintain similarity to PUPSTATE" && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"

lcPupSaveNamePUPSAVE="PUPSAVE : ${PUPSAVE}"  # CTB 'raw' savefilename from PUPSTATE file
lcMsgStr="build-std:lcPupSaveNamePUPSAVE: ${lcPupSaveNamePUPSAVE}" && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"

#(:  build-std: basic PupSaveNameSrc 

lcPupSaveNameCut="`echo $lcPupSave | cut -f 3 -d "/"`" # CTB 'cut' savefilename from PUPSTATE file
lcMsgStr="build-std: lcPupSaveNameCut: ${lcPupSaveNameCut}" && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"

lcPupSaveNameSrc="${lcPupSaveNameCut}"
#~ lcPupSaveNameSrcStd="${lcPupSaveNameCut}"
lcMsgStr="build-std: lcPupSaveNameSrc: ${lcPupSaveNameSrc}" && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"

#: =======================================================================
# working gae
lcMsgStr="build BK method into TarOpt"  && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"

#~ lcPupSaveNameSrc="${lcPupSaveSrc##*/}"
#~ lcMsgStr="lcPupSaveNameSrc whole: ${lcPupSaveNameSrc}" && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"
#~ lcPupSaveNameSrc="${lcPupSaveNameSrc##*/}"
#~ lcMsgStr="lcPupSaveNameSrc: ${lcPupSaveNameSrc}" && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"

#: here: simply lay BK var over existing lcPupSaveNameSrc

#(:  begin === from Barry Kauler =======================================
#(:  SrcName from "/sys/fs/aufs/si_*/br1" created after bootup/running : 
#(:  lcPupSaveNameSrc="`cat /sys/fs/aufs/si_*/br1 | head -1 | cut -f1 -d'='`"
#(:  generates /initrd/mnt/dev_save/pup_UpupBB+24-slx/upupbbsave+24-slx=ro+wh
#(:  === from Barry Kauler ================================== 
#(:  requires: "/sys/fs/aufs/si_*/br1" to already have been running. 
#(:  usable results:
#(:  lcPupSaveNameSrcAufs="`cat /sys/fs/aufs/si_*/br1 | head -1 | cut -f1 -d'='`"
#(:  lcPupSaveNameSrc="${lcPupSaveNameAufs##*/}"

export lcPupSaveNameAufs="`cat /sys/fs/aufs/si_*/br1 | head -1 | cut -f1 -d'='`"
export lcPupSaveNameSrc="${lcPupSaveNameAufs##*/}"  # currently, this shows in gui display

#: build results 
lcPupSaveNameAufsBK="lcPupSaveNameAufs"	# long full BK extraction
lcPupSaveNameSrcBK="lcPupSaveNameSrc"	# to display FileNameSRC on main Red Splash screen 

#: trace results
lcMsgStr="lcPupSaveNameAufsBK : ${lcPupSaveNameAufs}" && Sbr_Str2DevTrm "$lcMsgStr" "5" "3"
lcMsgStr="lcPupSaveNameSrcBK : ${lcPupSaveNameSrc}" && Sbr_Str2DevTrm "$lcMsgStr" "5" "3"

#:  todo: finish BK install 
#:  todo: clearup this overlapping display code
#(:  end === from Barry Kauler =========================================


#: ===========================================================
#(:  begin: create a record sysDTS marker
#~ lcPupSaveNameDts="`date +%y%m%d-%H%M-%S`"  #(:  not used
lcMsgStr="build-std: date-time-seconds string" && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"
lcFileNameDTS="/0-CTB-DTS"
touch -f "${lcFileNameDTS}"	#(:  record sysDTS marker
#(:  end: create a record sysDTS marker

#: ===========================================================
#(:  build intermediate string from "Src" with DTS appended.
lcPupSaveNameTrgTmp="${lcPupSaveNameSrc}-CTB-`date +%y%m%d-%H%M-%S`"     
#(:  grave-mark in date () !!!


#: =====================================================================
#(:   build Target filename for TarOpt , no subdir , before GUI , GUI is 2808
# this version, assumes subdir is local to Puppy OS "saveDATA"
lcPupSaveNameTrg="${lcPupSaveNameTrgTmp}.tar.gz"
#(: 
#(:  lcPupSaveNameTrg  is required by the TarOpt string 
#(:  TarOpt will assume subdir is local to Puppy OS "saveDATA"
#(:       tar ${TAROPT} -f ${lcPupSaveNameTrg} ${lcTarOptSaveNameSrc} 

#(: ------------------------------------------------------------------------
#(:      saveDATA source name is from PUPSTATE 
# lcPupSaveNameSrc="${lcPupSaveName##*/}" 
#(:  via ${PUPSAVE} via PUPSTATE file. 


#(:  pulled from rc.zSLP.sh
export gcCtbDistroVer=${gcSysDistroVer}
export gcCtbKernVer="`uname -r`"	 

lcMsgStr="PupSaveNameRaw : ${lcPupSaveNameRaw}" && Sbr_Str2DevTrm "$lcMsgStr" "5" "3"

#(: 
#(: 
#(:  Later in the CTB Code, you will find several "export" expressions.
#(:  'export' empowers the "CTB_Main_Gui", this is a "requirement" for Main GUI.
#(:  'export' Marks each NAME/SubRoutine for automatic export 
#(: 		to the environment of subsequently executed commands
#(: 		providing "global" visibility of var.
#(:  If VALUE is supplied, then assign VALUE during the export.
#(:
} # end: Sys_PupState



#(: ===================
#(: fx(CTB_ReStart)
#(: called by: GTK, other selections, but not 'QUIT'
#(: param: 
#(: purpose: Handle several fx for ReStart CTB script.
#(: calls: 
#(: method: 
#(: sends: 
#(: rationale: 
#(: note : 
#(:  >>> Control Flags for Interlocking of user Options.
#(:  do NOT call ClearFlgSys , maintain Scan Flag . 
#(:
#(: ===================;;;;;;;;;;;;;;;;
function CTB_ReStart() {    #(:  active
#
lcMsgStr="*** ClearFlgLockFile" && Sbr_Str2DevTrm "$lcMsgStr" "5" "3"
rm -f "${CTB_FlgLockFile}"     #(:  ClearFlags --- release 'Running' flag.

#(:  XXX CTB_ClearFlgBugger_SD	
#(:  do NOT clear Scan Flag. Required for next cycle GUI. 

#(: control flag CTB_ClearFlgBackupStatus for display	
lcMsgStr="*** ClearFlgBackupStatus" && Sbr_Str2DevTrm "$lcMsgStr" "5" "3"
#(: Note:
#(:  this trace shows only in Terminal Mode, 
#(:  simply indicates "Popping the Stack" 
#(:		because BASH does not impliment a strict "Scope" control.
#(:  Repeated calls to some routines can subvert (stack) the calls. 
#(:  This kind of Non-Fatal error will only be indicated if running in "Terminal". 
rm -f "${CTB_FlgBackupStatus}" 
#(:
#(: Note:
#(:  Do Clear :  LockFile and BackupStatus 
#(:  Do Not clear Scan flag. 

${gcCtbZeroRun}      
#(:  this will restart this "$0" program 
#(:  this must be a "Maintained" as a global contstant. 
#: -------------------------------------------------------
} # end: CTB_ReStart
 


#(: ===================
#(: fx(CTB_StartUp)
#(: called by: Main 
#(: param: 
#(: purpose: general StartUp process , export. 
#(: calls: 
#(: method: 
#(: sends: 
#(: rationale: 
#(: note : 
#(: ===================;;;;;;;;;;;;;;;
function CTB_StartUp() {    #(:  active

#(:  CTB_StartUp calls to Set Version DTS subroutine
Sys_SetVerDts   
#(:  CTB_StartUp calls for Puppy "STATE" file data to be loaded. 
Sys_PupState        
#(:  
#(:  ref:
#(:  Surprised me !    
#(:  Pupsave_Zipit original , v1 and later,  had "export LOCDEFAULT="/mnt/home"
#(:  LOCDEFAULT was 'hard-coded', in original v1 .  
#(:  LOCDEFAULT was NOT calculated from available values, per BK example. 
#(:  Surprised me !    
#(:  ref:

#(:  V.1 info is   /initrd/mnt/save_dev  +plus+  /pup_UpupBB+24/upupbbsave-BB+24_gen 
#(:  but, V.1 HotBackUp Select-Box failed to 'see' this forked location 
#(:  on author's multi-boot USB Flash-Drive OS , 
#(:  which is like this :
#(:      sda1 for "/initrd/mnt/dev_save" for running subdir.   
#(:      /mnt/ (sdb1, sdc1, sdd1, sde1) for remaining drive specs. 
#(: 
#(:  specific fileNAME for saveDATA is known via PUPSTATE. 
#(:  PUPSFS='sda1,ext3,/pup_UpupBB+21/puppy_upupbb_19.03.sfs'
#(:  PUPSAVE='sda1,ext3,/pup_UpupBB+21/upupbbsave-BB+21_1202'
#(: 
#(:  ex. saveDATA subdir is "/pup_UpupBB+24" 
#(:  ex. saveDATA name is "pup_UpupBB+24-slx" 
#(:  ex. /subdir/saveDATAname is /pup_UpupBB+24/upupbbsave-BB+24-slx
#(: 
#(:  in "hot backup v.1.2" from 2010, 2byte, assumed a HardDrive Boot. 
#(:  Thus, in our specific /subdir for PuppyOS was not detected properly. 
#(:  We use a USB booted system across all our workstations.  
#(:  ex. "/mnt/home/"  versus  "/initrd/mnt/dev_save"  caused some failures. 
#(:  
#(: Note: SaveDATA" refers to the name of the Linux Top-Layer Saved data 
#(: 	which is written by "snapmergepuppy" 
#(:		and also the reference to the TarOpt output file.tar.gz .
#(:  lcSaveData is required to calculate "Backup Free Disk Space" for main GUI
#(:  generate in fx(CTB_StartUp) as "lcSaveData", subroutine is near line 1138. 
lcSaveData="`echo $lcPupSave | cut -f 3 -d ","`"
#(:  

export CTB="CTB"	# entered by Dev at top of source code. 

export CTB_REFRESH_INTERVAL=1000 
#(:  1 second refresh rate for Date-Time-Stamp name of TarOpt output file.  
#(:		used in Main Gui . 

#(: Export-Declare-Assign names of 'Bugger' activity markers in /tmp 
#(:     as required by fx(CTB_ScanList) and fx(CTB_ScanOne), et al. 
export CTB_FlgBugger_SD="/tmp/CTB_FlgBugger_SD"
#(:    these show the "BackUp" or "DONE" status in "BackUp buttom" of GUI.
export CTB_BackUpStatus="/tmp/CTB_BackUp_Status"
#(: generate/export the name of the 'lock-file', unique to "CTB" program.
export CTB_FlgLockFile="/tmp/CTB_FlgLockFile"
# export CTB_FlgLockVal='0'	#(:  not used
#(:
#(: Note: Puppy Linux System "STATE" file is "/etc/rc.d/PUPSTATE"
#(:    PUPSTATE is used to control the operations of "CTB" 
#(: SaveDATA name is Required for " du -c -m -s ${} "  for "directory usage" via PUPSTATE .
export CTB_PupSaveDataName="/mnt/home"`grep PUPSAVE /etc/rc.d/PUPSTATE | cut -f 3 -d "," | cut -f 1 -d "'" ` 

#(: Note:
#(:   required for cd ${1%/*} 
#(:   dirname $CTB_PUPSAVE_PATH   is  location of saveDATA     
export CTB_PUPSAVE_PATH="/mnt/home${lcSaveData}"

#(:  export CTB_PUPSAVE_NAME="${SF##*/}" #(:  not used. 
#(:  was just left over from original code in hot-backup_v.1.2. 2010. 
#(:  ${SF##*/} = basename $SF was not properly assigned.
#(:  orig: export PUPSAVE_Fn="${PUPSAVE_NAME}-CTB-`date +%y%m%d-%H%M-%S`"

#(:  required exports of fx() subroutine names 

#~ export -f Sys_Box_HLP   
#~ export -f Sys_Box_SRC 
export -f Sbr_Str2DevTrm
export -f  CTB_TrgFilename
export -f  CTB_ReStart
export -f  CTB_ScanList
export -f  CTB_ScanOne

#  these fx/exports not called 
#  still here as hard-code as progressive reference. 
# export -f CTB_playbell	# Not Active
# export -f CTB_SrcFilename	# Not Active
# export -f CTB_SetFlgLockFile	# Not Active  
# export -f CTB_SetFlgBugger_SD	# Not Active
# export -f CTB_SetFlgBackupStatus # Not Active
# export -f CTB_SetFlgSys			# Not Active
# export -f CTB_ClearFlgBackupStatus	# Not Active

export -f CTB_ClearFlgSys
export -f CTB_ClearFlgLockFile
export -f CTB_ClearFlgBugger_SD

#(: #(: # CTB  standard #(: #(: #
export -f  CTB_BackUpRun

echo "" > /dev/console	#(:  bump the running/trace terminal window display . 

#(:  saveDATA PupRamObj size calc 
#(:  this is run at "startup" only, so to be 'stable'. 
#(:  calc: aa="$(du -c -m -s ${CTB_PupSaveDataName} )"     
aa="$(du -c -m -s ${CTB_PupSaveDataName} )"     

#(: options: -c = --total, -m = --block-size=1m, -s = --summarize
#(: read -r b ccc <<< "$aa"
#(: lcPupRamObj="${b}"
read -r b ccc <<< "$aa"
lcPupRamObj="${b}"

#(:  collect for use in Main_GUI , requires this for static <label>  , 2808
#  lcMsgStr=" " 
#(:  left margin spacing for lcPupRamObjMsg ${lcMsgStr}
export lcPupRamObjMsg=" # Source saveDATA Size : ${lcPupRamObj} MB # "

echo "" > /dev/console

} # end: CTB_StartUp



#(: ===================
#(: fx(CTB_TrgFilename) 	# Active on main gui splash
#(: called by: main gui : <action>refresh:CTB_TrgDts</action>
#(: param: 
#(: purpose: echo PUPSAVE_NAME to Main_GUI () REFRESHED by timer
#(: calls: 
#(: method: active "echo" inside GUI  like this   "Backup DTS .ext :"
#(: sends: echo to Main_GUI command line, 
#(:      to refresh Target Filename every second. 
#(: rationale: 
#(: note : GUI 2808
#(: ===================;;;;;;;;;;;;;;;
function CTB_TrgFilename() {   # Active on main gui splash

    n=0
#(:  fx() name used in Main_GUI,  
#(: active "echo" inside GUI 
#(: called by: main gui : <action>refresh:CTB_TrgDts</action>
#(:      to refresh Target Filename every second. 
# lcMsgStr="           Target: " #  used for display spacer on gui screen.
lcMsgSpacer="           : " #  used for display spacer on gui screen.
# "Backup DTS .ext" is an active "echo" inside GUI 
echo -n " ${lcMsgSpacer} Backup DTS .ext : -CTB-`date +%y%m%d-%H%M-%S`        "  
#(:  for GUI-Display #  grave-mark in date () !!!  

} # end: CTB_TrgFilename


# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#!!!!!!!!!!!!!!!!!!!!!!!!!!!!


#(: ===================
#(: fx(CTB_ScanOne)
#(: called by: fx(CTB_ScanList)
#(: param: Src, Als, Trg
#(:  	required : lcBkpSaveNameSrc , lcBkpSaveNameAls , lcBkpSaveNameTrg 
#(: purpose: BackUpCopy to ONE HardDrive/USB device
#(: requires: "alias" for ONE HardDrive/USB device ( ie, sda3, sdb1, sdc1, sdd1 )
#(: calls: 
#(: method:   CTB_ScanOne will test if exist subdir, 
#(:                if  [ -d ${lcFileOutDir} ]   
#(:           then begin: ScanOne splash & COPY
#(: sends: 
#(: rationale: 
#(: note : 
#(:    TarOpt is writing to lcTarOptSaveNameTrg, possibly controlled by /CTB_config.sh
#(:
#(: --------------------------------------------------------------
function CTB_ScanOne() {     #(:  Active

#(: local var: lcBucSaveNameSrc, lcBucSaveNameAls, lcBucSaveNameDirTrg
lcBucSaveNameSrc=${1}      
#(:    Src of fileDATA to be archived 
lcBucSaveNameAls=${2}      
#(:    Als of one Target Hard-Drive  
lcBucSaveNameDirTrg=${3}      
#(:    Trg [ "CTB_BackUp_"  base name wo "Ext" ] not developed. 

#(:  fx(CTB_BackUpOne) will assign "EXT" = "_All" or "" as required

lcMsgStr=" " && Sbr_Str2DevTrm "$lcMsgStr"
lcMsgStr=">>>  CTB_ScanOne  with {$lcBucSaveNameAls} >>>" && Sbr_Str2DevTrm "$lcMsgStr" "5" "0"
lcMsgStr=" " && Sbr_Str2DevTrm "$lcMsgStr"

#(:  begin clear colors for terminal trace
/bin/echo -en "\\033[0;39m"     >  /dev/console #(:  color clear
/bin/echo -en "\\033[70G"    >/dev/console 
/bin/echo -en "\\033[1;33m "    >/dev/console 
/bin/echo -e  "\\033[0;39m"   >/dev/console 
#(:  end clear colors for terminal trace

n=0

#: ----------------------------------------------------------------------------
#(:  in fx(CTB_ScanOne)
#(:  build the "_EXT" : "_All" or "_Cur"
lcBucSubDirTrgBaseAll="CTB_Backup_"
#                                    
#!~ lcPupSaveNameWod="${lcPupSaveName}-CTB"   
#!~ lcPupSaveNameSrcCat="`cat /sys/fs/aufs/si_*/br1 | head -1 | cut -f1 -d'='`"
#!~ lcPupSaveNameSrcSpl="${lcPupSaveName##*/}"
#!~ lcPupSaveName="${lcPupSaveSrcCat##*/}"

#(:  in: fx(CTB_ScanOne)
#(:  todo: build names for COPY to saveDATA-CUR  
#(:  todo: copy to "-cur"  TarOutSubdir to CurSubdir

#(: 
#(:  Each Call to this "BackUpOne" 
#(:  will setup and send the specific special parameters. 
#(:  boot drive will be "/initrd/dev_save" on author's OS
#(:  non-boot drives will be "/mnt/home/sd??"  on author's OS
#(: 
#
lcBucPSaveNameDts="`date +%y%m%d-%H%M-%S`"  #(:  "now" DTS 

#(:  that was a 'new' dts comared to DTS from 'tar' TarOt . 
#(:  todo: Require : the exact 'DTS' from 'tar' TarOpt .
### lcBucPSaveNameRaw="${lcPupSave}"  # 'raw' savefilename from PUPSTATE file
### lcPupSaveNameBasic="`echo $lcPupSave | cut -f 3 -d "/"`"  #(:  at this point in evolution. 

#(:  below are   
#(:  Run Modules 

#===================;;;;;;;;;;;;;;;;;;;;;;;
#(: Test for Flags Up 
#(: Control BackUpOne Gui Display process 
if [ -f "${CTB_FlgBugger_SD}" ]  || [ ${gcCTBmode} = "A" ]  ; then # Control Scan
    lcBackOneStatusSD="SD"  #(:  Normal First Run Label
	lnScanOneOk=1	# used in next block
else
	lnScanOneOk=0
fi

#===================;;;;;;;;;;;;;;;;;;;;;;;;
# if [ "${lcBackOneStatusSD}" = "SD" ] ; then  ScanOneOk is true  
if [ ${lnScanOneOk} -eq 1 ] ; then 	
#(: begin: ScanOne Splash Main Splash "SEEKING"

#! xmessage can linger as a background. 
#! xmessage  -title "Scan-One-Status" -name 'CTB' -timeout 3 -center -bg yellow -fg blue " seeking ? ${lcBucSaveNameAls}  "
/usr/lib/gtkdialog/box_splash -fg yellow -bg blue -border true -title "Scan-One-Status"  -close never -text ".   Scan  Seeking ? ${lcBucSaveNameAls}  
.      
.
.                                         " &
			GTKPIDXSOS=$!   # kill ${GTKPIDXSOS}"
			sleep 1

#(: end: ScanOne Splash Main Splash "SEEKING"

	lcFileOutDir="/mnt/${lcBucSaveNameAls}/${lcBucSubDirTrgBaseAll_}"
	lcMsgStr="DirTrg All :${lcFileOutDir}:" && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"
                #
                # if find target OutPut subdir , then OK to copy one 
                #~ if  [ -d ${lcFileOutDir} ]  ; then  	#(:  if Find Directory 

		#(: *(1)* Copy  save-DATA-dts ALL 
		#(:	Special for SDA1 
		#(: ************************************************


                    lcFileIN="${lcBucSaveNameSrc}"  #(:  directly from "TarOpt" 
                    lcFileIN="${lcTarOptSaveNameTrg}"  #(:  directly from "TarOpt"  tarptit
                    lcFileOutDir="/mnt/${lcBucSaveNameAls}/${lcBucSubDirTrgBaseAll}"
                    lcMsgStr="DirTrg All :${lcFileOutDir}:" && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"

		#: ----------------------------------------------------------------
		lcMsgGtk="--- saveDATA <<< ${lcBucSaveNameAls} >>>>"
		#: ----------------------------------------------------------------

		#(: CTB_ScanOne will test if exist subdir, 
		#(: then begin: ScanOne splash & COPY
		if  [ -d ${lcFileOutDir} ] ; then 
            #(:  >>> Now OK to copy saveDATA to extended subdir >>> 
#! box_splash can pop-up as a quick message
/usr/lib/gtkdialog/box_splash -fg yellow -bg grey -border true  -close never -text "     :Find SubDir OK: ${lcBucSaveNameAls}:     " &
			GTKPIDFC=$!
			sleep 1
				#! >>> ScanList COPY one
				cp -r  ${lcFileIN} ${lcFileOutDir}
				#! <<< ScanList COPY one
			sleep 1
			kill ${GTKPIDFC}
			#!  <<< Now OK to copy saveDATA to extended subdir >>> 
		else
            n=0
		fi #  [ -d ${lcFileOutDir} ] 

	kill ${GTKPIDSOM}   #(:  clear Scan One Main 
    kill ${GTKPIDXSOS}	
fi  # end:  if [ ${lnScanOneOk} -eq 1 ] ; then 	
} # 
export -f CTB_ScanOne



#(: ===================
#(: fx(CTB_ScanList)
#(: called by: fx(CTB_BackUpRun)
#(: param: 
#(: purpose: control calls to fx(CTB_ScanOne)
#(: calls: fx(CTB_ScanOne)
#(: method: refers to backup target subdir as "/CTB_Backup_" 
#(: method: 
#(: sends: 
#(: rationale: 
#(: note : On our OS, limit is usually 8 mounted hard drives , 
#(:    as seen by OS at bootup.  
#(: Note:
#(:		copy is for the generic SDA1, SDB1, SDC1, et al 
#(:		user can substitute any drive name, even system networked drives. 
#(: Note: 
#(:  common name local var is "Bkp"
#(:
#(: ==============================
function CTB_ScanList() {     #(:  Active
   
#(:  NOTE: 
#(:  --- tar process was into "Trg" from "Src" ---
#(:  --- f(CTB_ScanList) process is :
#(:      Source is "Src" and "Target"is "Trg" 

#(:  REQUIRED value WAS previously used in "tar Opt" 
lcBkpSaveNameSrc="${lcPupSaveNameTrg}"  #(:  from TarOpt process
#: ---------------------------------------------------------------  
 
#(:
#(:  Each Call to "BackUpOne" 
#(:  will setup and send the specific special parameters. 
#(:  boot drive will be "/initrd/dev_save" 
#(:  non-boot drives will be "/mnt/home/sd##"
#(:

#(:  if  sda1 is "/initrd/mnt/dev_save" and "_Cur" 
#(:  else    others are "/mnt/home/sda?"  and "_Cur" "  
#(:  fi

#(:  req label for subdir on each mounted hard-drive 
#(:		which receives the CTB Backup.tar.gz output file
export lcBkpSaveNameDirTrg="${gcCTBbackupSubDir}"	# "CTB_Backup_"
#(:   

#(:  Send Param: lcBucSaveNameSrc, lcBucSaveNameAls, lcBucSaveNameDirTrg
#(:  Send: lcBkpSaveNameSrc, lcBkpSaveNameAls, lcBkpSaveNameDirTrg
#(: 
#(:  each call to HardDrive/USB : Same "Src", Different "Als", Same "Trg" .
#(: 
#(:  NOTE: sda1 is the primary booting hard-drive. 
#(:  CTB copies out-of primary booting hard-drive into other mounted hard-drives .
#(:
#(:  begin: Hard coded 'list' of possible mounted hard-drives. 
#(:  limit is usually 8, depends on BIOS hardware and OS distro. 
#(:  Authors systems are MS-XP class computers, 2010, so limit for us is 8.
#(:  But, each must have subdir "/home""${gcCTBbackupSubDir}" 
#(:    to receive the ".tar.gz" Scan Transferred files. 
#(:

# TarOpt is writing to lcTarOptSaveNameTrg, possibly controlled by /CTB_config.sh

	#(:  begin CTB_Backup sda2 ===
	lcBkpSaveNameAls="sda2"     #(:  Prefix name
	CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
	#(:  end CTB_Backup sda2 ===

	#(:  begin CTB_Backup sda3 ===
	lcBkpSaveNameAls="sda3"     #(:  Prefix name #(:  not in this system 
	CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
	#(:  end CTB_Backup sda3 ===

	#(:  begin CTB_Backup sdb1 ===
	lcBkpSaveNameAls="sdb1"         #(:  Prefix name
	CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
	#(:  end CTB_Backup sdb1 ===

	#(:  begin CTB_Backup sdb2 ===
	lcBkpSaveNameAls="sdb2"         #(:  Prefix name
	CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
	#(:  end CTB_Backup sdb2 ===

    #(:  begin CTB_Backup sdc1 ===
	lcBkpSaveNameAls="sdc1"         #(:  Prefix name
    CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
    #(:  end CTB_Backup sdc1 ===

    #(:  begin CTB_Backup sdc2 ===
	lcBkpSaveNameAls="sdc2"         #(:  Prefix name
    CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
    #(:  end CTB_Backup sdc2 ===

    #(:  begin CTB_Backup sdd1 ===
	lcBkpSaveNameAls="sdd1"         #(:  Prefix name
    CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
    #(:  end CTB_Backup sdd1 ===

    #(:  begin CTB_Backup sde1 ===
	lcBkpSaveNameAls="sde1"         #(:  Prefix name
    CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
    #(:  end CTB_Backup sde1 ===

    #(:  begin CTB_Backup sdf1 ===
    lcBkpSaveNameAls="sdf1"         #(:  Prefix name
    CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
    #(:  end CTB_Backup sdf1 ===

    #(:  begin CTB_Backup sdg1 ===
    lcBkpSaveNameAls="sdg1"         #(:  Prefix name
    CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
    #(:  end CTB_Backup sdg1 ===

    #(:  begin CTB_Backup sdh1 ===
    lcBkpSaveNameAls="sdh1"         #(:  Prefix name
    CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
    #(:  end CTB_Backup sdh1 ===

    #(:  begin CTB_Backup sdi1 ===
    lcBkpSaveNameAls="sdi1"         #(:  Prefix name
    CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
    #(:  end CTB_Backup sdi1 ===

    #(:  begin CTB_Backup sdj1 ===
    lcBkpSaveNameAls="sdj1"         #(:  Prefix name
    CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
    #(:  end CTB_Backup sdj1

    #(:  begin CTB_Backup sdk1 ===
    lcBkpSaveNameAls="sdk1"         #(:  Prefix name
    CTB_ScanOne ${lcBkpSaveNameSrc} ${lcBkpSaveNameAls} ${lcBkpSaveNameDirTrg}
    #(:  end CTB_Backup sdk1

#(: ===================;;;;;;;
#(:  ScanLis must be run before change dir back to original CWDIR 
#(:         cd "$CWDir"    #  will point back to 'home' 
#(: ===================;;;;;;;
} #
export -f CTB_ScanList




#(: ===================
#(: fx(CTB_BackUpRun)    #(:  Active CTB_Backup "TarOpt" 
#(: called by: Main, Main_GUI, EXIT:BackUpCall+ , to activate the BackUpRun
#(: param (1) : $CTB_PUPSAVE_PATH
#(: param (2) : $CTB_BACKUP_PATH
#(: purpose: Build DestFileName : $CTB_PUPSAVE_PATH $CTB_BACKUP_PATH
#(: calls: CTB_ScanList
#(: method: refers to backup target subdir as "/CTB_Backup_" 
#(: sends: 
#(: rationale: 
#(:  note :
#(:      When Running in 'Geany', use the 'Execute', 'BASH Terminal' mode,
#(:  note: 
#(:      during backup process, "du" has system error msg .
#(:      "   du: invalid zero-length file name  "
#(:      Which is displayed in the Terminal window.
#(:      Which arises when parsing past end of stack,
#(: 	 Which is a BASH system problem. 
#(:		 Which was always present in the HotBackup programs. 	
#(:      Which is NON-fatal in this program.
#(: ===================;;;;;;;;;;;;;;;
function CTB_BackUpRun() {    #(:  Active CTB_Backup "TarOpt" 
    	n=0
    lcRunParStr=${1}	#  from f(CTB_BackUpRun)    # Not Used 
    lcRunParStr=${2}	#  from f(CTB_BackUpRun)    # Not Used 

#(:  splash "RUNNING" ======= background yel/red splash 
lcMsgStr="--- CTB Running Backup ---"

# testing: gcCTBmode="A" # Not useful.  Selection already done. 

#(:  position dependent on left margin 
/usr/lib/gtkdialog/box_splash -fg yellow -bg darkred -border true  -close never \
-text " 
.              ${lcMsgStr}              
.
.
.
.
.
" &
		GTKPIDRUNNING=$!
		sleep 1  

#(: splash "SYNC" =======
lcMsgStr=">>> SYNC <<<"

lcDialogColor="  -fg blue -bg lightgreen  " # Wierd
/usr/lib/gtkdialog/box_splash ${lcDialogColor} -border true  -close never \
-text "     $lcMsgStr   " &
		GTKPIDSYNC=$!
		sleep 1.5  

	#(:  SnapMergePuppy  runs under default ' nice -10 '  to inhibit any other process. 			
	#(:  'sync' will lock-up if SnapMergePuppy is still running. 

	#(:  write all buffered blocks to disk, before SnapMergePuppy ! 
    sync    

	#(: kill last splash "SYNC" 
	kill $GTKPIDSYNC

	#(:  Snap-Merge-Puppy save2flash into "saveDATA" -----------
    Sys_SMP #(:  calls for splash and  "nice -## SnapMergePuppy" 
    
    #(:  begin: these notes show in Geany Execute Terminal mode : 
        #(:  "CWDir" is anacronym for "Current Working Directory" .
        #(:  "PWD" is system var for "/root" , base of current sys ops.
        PWDir="$PWD"

	#(: Geany Execute Terminal Display 
        #(:  param (1) is $CTB_PUPSAVE_PATH
        lcMsgStr="+++CTB_BackUpRun =========================================" && Sbr_Str2DevTrm   "${lcMsgStr}"   "4" "3"
        lcMsgStr=">>> $ { 1% } is ${1} <<< param #1" && Sbr_Str2DevTrm   "${lcMsgStr}"   "3" "3"
        lcMsgStr=">>> $ { 1% /* } is ${1%/*} <<< subdir of source saveDATA" && Sbr_Str2DevTrm   "${lcMsgStr}"   "3" "3"
        lcMsgStr="PWDir points to '/root' path level (sys var) <" && Sbr_Str2DevTrm   "${lcMsgStr}"   "3" "3"
        lcMsgStr="CWDir=PWdir : $PWdir  <" && Sbr_Str2DevTrm   "${lcMsgStr}"   "3" "3"
        lcMsgStr="+++CTB_BackUpRun =========================================" && Sbr_Str2DevTrm   "${lcMsgStr}"   "4" "3"
    #(:  end: these notes show in Geany Execute Terminal mode : 

        CWDir=$PWDir  #(:  Swap Working Directories, /Root into /Current . 

    #(:  now, CWDir points to "local" path level, where Puppy OS is installed. 
    #(:     'tar' thinks it is 'home'.
    #
    #(:  this "flipping" between PWDir and CWDir is necessary because
    #(:      program is receiving full /mnt/home/path/subdir/filenames
    #(:      whereas 
    #(:      'tar' is using a "local" /path/subdir/filenames 
    #(:  Perhaps we will write a future version of CTB 
    #(:  including a re-write of these obtuse file-name handling methods,  
    #(:  to be more simple, and still pull data from 'PUPSTATE' .
	#(: 
    #(:  Use of 'PUPSTATE' is key to standard Puppy Linux System ops. 
	#(:  Use of Barrie Kauler's code is best method, 
	#(:		and was useful on author's "USB boot mounting methods" 
	#(:		to treat all drives on any Hard-Drive system as "Slave-Hard-Drives". 
    #(: 
    #(:  This "flipping" method from early PuppyBackup code seems obtuse, 
    #(:  but other methods are also cumbersome and just as hard to read. 
    #(: 
    #(:  ref #(:  "Pupsave_Zipit" original "v1.2" had this: 
    #(: 		export LOCDEFAULT="/mnt/home" as "hard-code" . 
    #(: 	CTB uses Barry Kauler method, stated in introduction 
    #(: 	for determining the "system location". 
    #(: 
    #(:  -------------------------------------------------------------------
    #(:  CTB system runs from /root , PWDir, like most other Linux routines, 
    #(:  but this "tar" routine is written to run from 'local', 
    #(:  therefore we "swap" directories during the "TarOpt" BackUp process.  
    #(: 
    #(:  In this version of CTB :
    #(:  CTB system runs from '/root' like most Linux programs,
    #(:  but 'tar' routine is written 
    #(:      to use the short-form 'local' file-names .
    #(:  (1) we flip from original '/root' to working 'local' /path/subdir
    #(:      when calling 'tar' for saveData .
    #(:  or
    #(:  (2) we flip from '/root' to  '/path/subdir/filename.4fs'
    #(:      when calling for saveData .   Same thing. 
    #(: 
    #(:  we 'flip' back to original '/root' after 'tar' runs .
    #(: 
    #(:  that is why we have kept the 'flipping' code 
    #(:          PWDir="$PWD"
    #(:          CWDir=$PWDir    #(:  save points to /root
    #(:          cd "$CWDir"     #(:  points back to /orig
    #(: 
    #(:  Alternative methods have their own complexities. 
    #(:  
    #(:  -----------------------------------------------------------------
    #(:  CTB  gets control info from the system
    #(:     via the system file "/etc/rc.d/PUPSTATE"
    #(:     PUPSTATE is always valid at runtime for Puppy OS.
    #(:  It is important to have PUPSTATE control things, 
    #(:  and program is written around that idea.
    #(:  -----------------------------------------------------------------
    #(: 
    #(:  NOTE: about paramters sent to 'tar'
    #(:  'tar' does not care what kind of data is the Source Data .
    #(:  SaveDATA can be "upupbb-???.4fs" or "upupbb-???"
    #(:     or some other subdir or file . 
    #(:  SaveDATA is just an "object" to be archived by "tar". 
    #(: 
    #(:  CTB takes the saveDATA as Source name and runs it thru 'Tar' .
    #(:   source can be  /subdirname , containing Linux data set .
    #(:   source can be  file.4fs , containing a '.4fs' Linux data set .
    #(:   source can be  anything that 'tar' can read .
    #(:  CTB could be written to handle back-up for any file set.
    #(:  "tar" will return "RETVAL" for testing.  Traps are set for that.
    #(:  -----------------------------------------------------------------

#(: Splash === "Main TarOpt Splash" ====
#(:  must maintain this "character measured" format 
#(:  so multiple splash will fit inside the Main Splash format !
#(:  This splash is the major "BackGround" Image, 
#(:     and subsequent minor splash will display inside Main.
#(:  main box_splash width is 40, fill it so multiple splashes fit good.

#(:  USER MODIFIABLE FLAGS : because some distro / monitor combo are different.

#(: begin : SPLASH TarOpt MAIN ===BackGround==== Progress Report
lcDialogColor="  -fg yellow -bg darkred  "	# Splash Main 
lcMsgStr="  MAIN Splash BackGround ... Tar from : ${1%/*}" && Sbr_Str2DevTrm "$lcMsgStr" "1" "3"
/usr/lib/gtkdialog/box_splash ${lcDialogColor} -border true  -close never -text "
.     ... Please Wait ... ${gcSysDevDob} ... ${gcCTBmodeName}
.  Cold-Tar-Backup is Creating 'tar.gz' BackUp
.    Source saveDATA Size > ${lcPupRamObj} MB
.    Source File:  ^${lcPupSaveNameSrc}^
.
.
.
.              ... Progress Dialog ...
.
.
.
.
         TarOut: ${gcCtbConfigTrgPrefix}
 ${lcPupSaveNameTrg##*/} :
.
" &

# read	# taroptit

GTKPIDTOP=$!    #(:  This is the Main "BackGround" screen.
sleep 2

#(: end : SPLASH TarOpt MAIN =======
#(: 
	#(: 
	#(:  the Main Splash is open during TarOpt as background . 
	#(:  other Splash will display inside this Main Splash .
	#(: 

	#(:  Subsequent Splash will layer over / blend with the large Main Splash.
	#(:  Master Splash should linger until after the final dialog splash "Done" is cleared.

	#(:  Careful !  Must maintain sequence of change dir .
	#(:  change dir from PWDir to  ${1%/*}
	#(:  then run TarOpt .

	#(:  this "change dir" is only necessary if PWDir was NOT local.
	#(:  because CTB will never move away from the "saveDATA" subdir.
	#(:  cd ${1%/*} 	#  dirname $CTB_PUPSAVE_PATH

	#(:  tar calls zip with "1" fast compression, Trg , Src
	#(:  tar -c -z  -f ${destfile##*/} ${1##*/}/    

	#(: --- CTB_Backup -------
	#(:  This is Before 'Tar' executable process 
	#(:  echo this trace to terminal 

	#(:  ref #(:  Pupsave_Zipit original v.1.2 had "export LOCDEFAULT="/mnt/home"
	#(:  ref #(:  Pupsave_Zipit original v.1.2 had "export LOCDEFAULT="/mnt/home"
	#(:  ref #(:  Pupsave_Zipit original v.1.2 had "export LOCDEFAULT="/mnt/home"

	#(:  CD into subdir of "saveDATA"
	#(:  ... use /path/name chopped, "short form".
	#(:  so,  ${1} is last param in buffer.	Good reason for "global" var of ${0} 
	#(:  so,  ${1%/*} is "short form" of last param in buffer.
	#(:  so,  cd ${1%/*} is cd /mnt/home/pup_UpupBB+19

	#(:  Note:
	#(:  200603-0958 gae, ref to Pupsave_Zipit original v:1.2 
	#(:  had "export LOCDEFAULT="/mnt/home" 
	#(:  as Hard-Coded data. 
	#(:  Did NOT RUN on author's USB-FlashDrive boot-up system, 
	#(:  which linked "/mnt/home" as "/initrd/dev_save" on initial USB BootUp 
	#(: 

	lcMsgStr="<<< cd ${1%/*} >>>" && Sbr_Str2DevTrm   "${lcMsgStr}"   "1" "3"
	cd ${1%/*} #(:  dirname $CTB_PUPSAVE_PATH   <<< loc of saveDATA

	#(: 
	#(:  the Main Splash yellow/red is still open as background .
	#(:  other Splash will display on top the Main Splash .
	#(: 

#(: begin : SPLASH: tar < Running > 
lcDialogColor="  -fg yellow -bg blue "
lcMsgStr="CTB < Tar.Gz Running > ${gcCTBmodeName}" && Sbr_Str2DevTrm "$lcMsgStr" "1" "3"
/usr/lib/gtkdialog/box_splash  $lcDialogColor -border true  -close never -text "
$lcMsgStr  
		 " &

			GTKPIDRUNBLUE=$!
			sleep .5

#(: end : SPLASH: tar < Running > 
	
		#(:  Below, splash will overlay all previous splash
		#(:  and over the Main_Splash 
		#(:  kill later after tar opt finishes.
        #(: 
        #(:  We declare/assign value to var 'TAROPT' and 'TAREXT'
        #(:  gae,
        #(:      simple default to "tar.gz" format for 'simple local backup'
        #(:      with No Questions Asked.
        #(: 

	n=0

#(: ==========================================================
#(: begin: section name " TAROPT " ======================================
#(: ==========================================================

#(:
#(: >>> begin: taropt process ===

#(:  TarOpt will assume subdir is local to Puppy OS "saveDATA"
#(:  "CWDir" is anacronym for "Current Working Directory" .
#(:  "PWD" is system var for "/root" , base of current sys ops.
#(:         PWDir="$PWD"
#(:         CWDir=$PWDir  #(:  Swap Working Directories, /Root into /CurrentWorking . 
#(:  cd "$PWDir" #(:  point /root so tar has simple focus. 
#(:  cd "$CWDir" #(:  point back to /CurrentWorking
	lcTarRetVal=0	#(:  default preset parameters 
	export lcTarOptSaveNameSrc="${lcPupSaveNameSrc}"
#	export lcTarOptSaveNameTrg="${gcCtbConfigTrgPrefix}${lcPupSaveNameTrg}"		# apply New SubDir here !
# 	export lcTarOptSaveNameTrg="${lcPupSaveNameTrg}"				# writes to 'local'
# 	export lcTarOptSaveNameTrg="/${lcPupSaveNameTrg}"				# writes to '/' 
#	export lcTarOptSaveNameTrg="/mnt/home/${lcPupSaveNameTrg}"		# writes to '/mnt/home/' 
	export lcTarOptSaveNameTrg="${gcCtbConfigTrgPrefix}${lcPupSaveNameTrg}"		# apply Config SubDir here !
# all this is AFTER the GUI, so no indication of TARGET from here. 
        lcMsgStr="-----------------------------" && Sbr_Str2DevTrm "$lcMsgStr" "4" "3"
        lcMsgStr=">>> begin TarOpt.Gz process" && Sbr_Str2DevTrm "$lcMsgStr" "3" "3"
        lcMsgStr="Src: ${lcTarOptSaveNameSrc}" && Sbr_Str2DevTrm "$lcMsgStr" "5" "3"
        lcMsgStr="Trg: ${lcTarOptSaveNameTrg}" && Sbr_Str2DevTrm "$lcMsgStr" "5" "2"
        lcMsgStr="-----------------------------" && Sbr_Str2DevTrm "$lcMsgStr" "4" "3"
        # 
	TAROPT="-c -z --checkpoint=1000" #(: ----'c'reate 'v'erbose 'z'ip)
	#(: TAROPT="-c -z --checkpoint=1000" #(: ----'c'reate 'v'erbose 'z'ip)
	#: - begin Special Control During Testing ===
	#: =============================================
	# if [ 1 -eq 1 ] ; then	
		# Special <TarOpt>, BackUp, ScanList Test Option 
		#(: fx "TarOpt" : real-time tar executable process
		#(: --- tar.gz   (parameters)  (into Trg)  (from   Src)   
		tar ${TAROPT} -f ${lcTarOptSaveNameTrg} ${lcTarOptSaveNameSrc} 
		#(: tar ${TAROPT} -f ${lcTarOptSaveNameTrg} ${lcTarOptSaveNameSrc} 
		#(: --- tar.gz   (parameters)  (into Trg)  (from   Src)   
		lcTarRetVal=0	
		lcTarRetVal=$?  #  capture Return Value of "0" or "1" into local var.
	# fi	#  [ 1 -eq 1 ] 
	#: =============================================
	#: - end Special Control During Testing ===
		#(:  remove a lingering sys flag that may block fx(Help_Box), etc.
		#(:  deposited from SMP and taropt
		rm -f /tmp/flagnextpassthru	   # after TarOpt 
# 
#(: <<< end: taropt process ===
# 
#(: end: secton name " TAROPT " ============================
#(: ============================

        lcMsgStr="<<< End:  TarOpt process" && Sbr_Str2DevTrm   "${lcMsgStr}"   "3" "3"
        echo

        #(: simple color string to terminal so tar process shows on black in terminal.   
        /bin/echo -e "\\033[0;m" 

        #(: kill running splash
		kill ${GTKPIDRUNNING}
        #(: kill running blue
        kill ${GTKPIDRUNBLUE}  

        #(: --- begin: calculate --- for DONE Splash , for "Tar Out Size" 
		
        #~ lcMsgStr=">>> begin: calc the tar output filesize :" &&  Sbr_Str2DevTrm "$lcMsgStr" "1" "3"
        
        aa="$(du -c -m -s ${lcTarOptSaveNameTrg} )"     
		#(:  -c = --total, -m = --block-size=1m, -s = --summarize
        read -r b ccc <<< "$aa"

		#(: show calcs in terminal 
        lcMsgStr="ccc:${ccc}" &&  Sbr_Str2DevTrm "$lcMsgStr" "2" "3"
        lcMsgStr="b: ${b}" &&  Sbr_Str2DevTrm "$lcMsgStr" "2" "3"
		#(: maintain "Tar Out Size" for splash
        lcPupRamObjStr="${b}" 
        lcMsgTos="tar-out-size :${lcPupRamObjStr}: MB" && Sbr_Str2DevTrm "$lcMsgTos" "2" "3"
		#
        #~ lcMsgStr="<<< end: calc the tar output filesize :" &&  Sbr_Str2DevTrm "$lcMsgStr" "1" "3"
        #(: --- end: calculate ---
        #(: --- begin: TarOpt Testing ---
		gcCTBerror="0"	# this will control the ScanList process. 
        #(:  begin: parse for the 'RETVAL' from tar :  0=no-error , 1=error .
        if [ ${lcTarRetVal} -eq 1 ] ; then	 # based on local var lcTarRetVal 
            #
			gcCTBerror="1"	# this event will kill the ScanList process. 
            lcMsgStr="Error:  [ ${lcTarRetVal} -eq '1'"  && Sbr_Str2DevTrm "$lcMsgStr" "3" "3"
#(: *** begin : SPLASH TarOpt Process Error Condition ***
lcMsgStr="... Tar Process Message Error : 'File NOT Found' / 'InValid' ..." && Sbr_Str2DevTrm "$lcMsgStr" "3" "3"
lcDialogColor="  -fg yellow -bg blue  "
#(:  position dependent on left margin 
/usr/lib/gtkdialog/box_splash  $lcDialogColor -border true  -close never -text "
 $lcMsgStr :$lcMsgTos:    
                    		 " &
GTKPIDtpem=${!}
sleep 5
kill "${GTKPIDtpem}"
#(: *** end : SPLASH TarOpt Process Error Condition ***
            #(: 
            #(:  we decided to make this a "non-fatal" error , 
			#(:  and continue program. 
            #(:  the user should 'report' this error .
            #(: 
        else
            lcMsgStr="else NOT [ ${lcTarRetVal} -eq '1'"  && Sbr_Str2DevTrm "$lcMsgStr" "3" "3"
			gcCTBerror="0"	# this will enable the ScanList process. 
        fi
        #(:  end: parse for the 'RETVAL' from tar :  0=no-error , 1=error .
        #(: --- end: TarOpt Testing ---
		#(:  "TarOpt" is finished. 
		#(:  Now, continue regular code
        #(: --- CTB_Backup ---
        #(:  the Main Splash is still open as background
        #(:  other Splash will now display inside the Main Splash.
		#(: 
#(: *** begin : SPLASH: tar < DONE > ***
# lcMsgTos is lcMsgTos="tar-out-size :${lcPupRamObjStr}: MB" 
lcMsgStr=" Tar < DONE > " && Sbr_Str2DevTrm "$lcMsgStr" "1" "3"
# 
lcDialogColor="  -fg yellow -bg red  "
/usr/lib/gtkdialog/box_splash  $lcDialogColor -border true  -close never -text " 
.
.     $lcMsgStr :$lcMsgTos:     
.                                " &
GTKPIDdone=${!}
sleep 1
kill "${GTKPIDdone}"
lcDialogColor="  -fg yellow -bg green  "
/usr/lib/gtkdialog/box_splash  $lcDialogColor -border true  -close never -text " 
.
.     $lcMsgStr :$lcMsgTos:     
.                                " &
GTKPIDdone=${!}
sleep 1
kill "${GTKPIDdone}"
lcDialogColor="  -fg yellow -bg blue  "
/usr/lib/gtkdialog/box_splash  $lcDialogColor -border true  -close never -text " 
.
.     $lcMsgStr :$lcMsgTos:     
.                                " &
GTKPIDdone=${!}
sleep 5
kill "${GTKPIDdone}"
#
#(: *** end: SPLASH: tar < DONE > ***
        #(:  Below, splash will overlay all previous splash
        #(:  and over the Main_Splash 
        #(:  will kill later.
		#(:  global Mode Detection 
		#(:  CTB_ScanList is a list of subdir to be 'cp' backed-up 
		#(:  to a list of mounted HardDrive/USB storage drives 
		lcMsgStr=" " && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"
		lcMsgStr=">>> before fx(CTB_ScanList) " && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"
				if [ ${gcCTBerror} = "0" ] ; then	# "0" is ok  ( "1" is error 'file not found' )
                    if [ lcSetCtrl ] ; then
                        set +e
                    fi
					if [ -f ${CTB_FlgBugger_SD} ]  || [ ${gcCTBmode} = "A" ] ; then 
						# state is "Scan" or "Automatic" 
						# if [ 1 -eq 1 ] ; then	# Special TarOpt, BackUp, <ScanList> Test Option 
							#(: ==============================================================
							#(: fx  CTB_ScanList : 'Scan List Control' & 'CopyOne' process.
							CTB_ScanList    
							#(: ==============================================================
						# fi	# Special TarOpt, BackUp, <ScanList> Test Option 
						#
						#(:  remove Bugger flags for extended backup , always.
						lcMsgStr="*** ClearFlgBugger_SD" && Sbr_Str2DevTrm "$lcMsgStr" "5" "3"
						rm -f "${CTB_FlgBugger_SD}" 
						#(:  remove Bugger flags for extended backup , always.
						# "CTB_ScanList" is done. 
					else
						lndummy=0
						lcMsgStr="***  Bugger and mode flags not set" && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"
					fi
				else
					n=0
					#(: 
					#(: *** begin : SPLASH: tar < ERROR > ***
					lcMsgStr=" Tar < ERROR > file not found" && Sbr_Str2DevTrm "$lcMsgStr" "1" "3"
					lcDialogColor="  -fg yellow -bg red  "
					/usr/lib/gtkdialog/box_splash  $lcDialogColor -border true  -close never -text "$lcMsgStr" &
					GTKPIDerror=${!}
					sleep 7
					kill ${GTKPIDerror}
					echo "==========> kill $GTKPIDerror ---"
					#(:    end : SPLASH: ERROR **************
                    if [ lcSetCtrl ] ; then
                        set -e
                    fi
				fi #  [ ${gcCTBerror} = "0" ]  
				lcMsgStr="<<< after fx(CTB_ScanList) " && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"
				lcMsgStr=" " && Sbr_Str2DevTrm "$lcMsgStr" "7" "3"
        #(: --------------------------------------------------------------
        #(:  Before and After the 'tar' process , the subdir is different:
        #(:  this 'cd' "$CWDir" is :
        #(:     after 'execute' tar
        #(:     after 'if' test on RetVal
        #(:  So, Main processes have run
        #(:  ... now, it is time to "change dir" back to 'home' subdir .
        #(: 
        lcMsgStr="cd  CWDir= $ CWDir  is $CWDir <<<" && Sbr_Str2DevTrm   "${lcMsgStr}"   "3" "3"
        lcMsgStr="cd  orig subdir in long 'path' form <<<" && Sbr_Str2DevTrm   "${lcMsgStr}"   "3" "3"
        cd "$CWDir" #(:  point back to /root
        lcMsgStr="change dir 'CWDir' ... point back to /root dir " && Sbr_Str2DevTrm   "${lcMsgStr}"   "2" "3"
        #(: 
        #(:  terminal messages for user : 
        # echo "trace: GtkDialog boxes will return 'terminated' message "
        # echo "... when the 'kill' PID command is applied"
        # echo "trace: wait for USB-Flash-Drive to shuffle data at 10 MB per second ."
		#(:  Back-Step thru all "kill PID"
		#(:  Killing all previous splash in reverse order .
		sleep .1
		kill ${GTKPIDTOP}
		echo "==========> kill $GTKPIDTOP ---"
		#(: 
		#~ sleep .1
		#~ kill ${GTKPIDdone}
		#~ echo "==========> kill $GTKPIDdone ---"
		#~ #(: 
		#(:  Note:  sync    #(:  write all buffered blocks to disk
        #(:  will lock if SnapMergePuppy is running. 
        #(:  will not run if PartEd is running. 
	#(:  Main_Gui calls EXIT:BackUpCall, calls fx CTB_BackUpRun ()
	#(:  runs thru to here.
	#(:  release 'running' "File-Lock" flg.
	#(:  could also run "stat" 
	rm -f "${CTB_FlgLockFile}"  
	#(:  State: is "BackUp DONE" 
	CTB_ClearFlgSys	#(:  end: fx(CTB_BackUpRun)
    #(:  raise special "Status" flag for main_GUI message "Backup is Done" 
    touch  "${CTB_BackUpStatus}"   # set STATUS flag to "active"
	#
} #
export -f CTB_BackUpRun

#(: ====================================================================
#(: fx(Sys_SMP)
#(: called by: CTB_BackUpRun
#(: param: 
#(: purpose: calls to snapmergepuppy prior to TAROPT 
#(: calls: 
#(: method: 
#(: sends: 
#(: rationale: 
#(: note : 
#(:  "Snap Merge Puppy"  is a "merge" process.   
#(: 	ie, SMP maintains pre-existing files. 
#(: note:   
#(:  	" nice -n " : "-n 19" gives max priority to SMP 
#(:     use of "nice" inhibits file changes by other processes during SMP
#(:
#(! ===================;;;;;;;;;;;;;;;;
function Sys_SMP() {    # ACTIVE snapmergepuppy
n=0   
#!  multiple runs through "snapmergepuppy" for "CTX", "CTB", "CTA"
#!    ### CTU will run SMP with NO GUI 

if [ ${gcCTBmode} = "B" ] || [ ${gcCTBmode} = "A" ]   ; then   # SMP 

    lcRunNum="19"
    lcRunSeq="1"
    lcDialogColorBg="  -fg yellow -bg black "  # background
    lcMsgStr="${gcCTBmodeId} SnapMergePuppy nice -n ${lcRunNum}  [${lcRunSeq}]"
    /usr/lib/gtkdialog/box_splash ${lcDialogColorBg} -border true -close never -text "$lcMsgStr" &
            GTKPIDSMP1=$!
            sleep .5  
fi # [ ${gcCTBmode} = "B" ] || [ ${gcCTBmode} = "A" ]   ; then   # SMP
# 
# ### CTU will run SMP with NO GUI
# === Run SMP "C" syntax LoopCnt ====================================
lcDialogColorFg="  -fg yellow    -bg black "  # foreground
lcRunNum="19"
lcLoopCnt="1"
if [ ! -s ${lcLoopCnt} ] ; then 
    ii=${lcLoopCnt}
else
    ii=1
fi
for (( i = 1; i <= $ii ; i++ )) ## "C"syntax "C" syntax 'C'syntax 'C' syntax
do 
    n=0
    if [ ${gcCTBmode} = "B" ] || [ ${gcCTBmode} = "A" ]   ; then   # SMP
        lcMsgStr=" <$i>  nice -n ${lcRunNum} SnapMergePuppy"  # foreground 
        /usr/lib/gtkdialog/box_splash ${lcDialogColorFg} -border true -close never -text ".  $lcMsgStr  ." &
        GTKPIDSMP0=$!
    fi # [ ${gcCTBmode} = "B" ] || [ ${gcCTBmode} = "A" ]   ; then   # SMP
       #~ Sys_Splash_Flip " <$i>  nice -n ${lcRunNum} SnapMergePuppy" ###     kill ${GtkPidFlip1} && kill ${GtkPidFlip2}  2>/dev/null
        # ----------------------------------------------------------------
            nice -n ${lcRunNum} snapmergepuppy /initrd/pup_ro1 /initrd/pup_rw    2>/dev/null 
        # ----------------------------------------------------------------
    if [ ${gcCTBmode} = "B" ] || [ ${gcCTBmode} = "A" ]   ; then   # SMP
        sleep .2    # expose splash during SMP
        #~ kill ${GtkPidFlip2}  2>/dev/null
        kill $GTKPIDSMP0 2>/dev/null
    fi # [ ${gcCTBmode} = "B" ] || [ ${gcCTBmode} = "A" ]   ; then   # SMP
    #
done # end: for (( i = 1; i <= $ii ; i++ ))
#!
#! ######################################################
if [ ${gcCTBmode} = "B" ] || [ ${gcCTBmode} = "A" ]   ; then   # SMP
		sleep .5
		kill $GTKPIDSMP1 2>/dev/null
fi # [ ${gcCTBmode} = "B" ] || [ ${gcCTBmode} = "A" ]   ; then   # SMP
# 
} #
export -f Sys_SMP


#######################################################
# End of High SubRoutines 
#######################################################


#(:-----------------------------------------------------------
#(:  all System fx() moved to top of code 
#(:  all Auxillary fx() writen below the System fxunctions 
#(:  all "funxtions" are written above. 
#(:-----------------------------------------------------------
#(:  all [ if "Fall-Thru" ] routines are written below the main GUI 
#(:  all Main_Gui fx("Fall-Thru") are below the main GUI
#(:-----------------------------------------------------------



#(!   MAIN()  #===================
#(!   MAIN()  #===================
#(!   MAIN()  #===================

#(:  CTB main running module begins here: 
 
echo 

#(:  Check if "OK" to run #(: 
#(:  if frugal install.
MODE="`grep PUPMODE /etc/rc.d/PUPSTATE | cut -f 2 -d "="`" # from PUPSTATE
if [ "$MODE" = "12" ] || [ "$MODE" = "13" ]; then
    n=0
    lcMsgStr="grep PupMode in PUPSTATE is OK " && Sbr_Str2DevTrm "$lcMsgStr" "5" "3"
else
	#
	lcMsgStr="MODE is not FRUGAL mode '12' or '13' " && Sbr_Str2DevTrm "$lcMsgStr" "5" "3"
#: ---------------------------------------------------------------------
/usr/lib/gtkdialog/box_splash -bg yellow -fg red -border true  -close never -text "\
.     
.     ${lcMsgStr}
'                        "&
#: ----------------------------------------------------------------------
    RETVAL=$?
	GtkPid_Sbr_Box_Splash=$!
	sleep 5
	kill ${GtkPid_Sbr_Box_Splash}
	#
    exit 1
fi # end: if if [ "$MODE" = "12" ] || [ "$MODE" = "13" ]

#(:  must exit at this " main ( ) " stack level in order to Quit/Clear the program. 
#  
#(:  Now, continue through all normal Start-Up routines.
#
#(: Marker String for 'find' while editing code. 
#(:  ... Main() #(:  ... Main_()    #(:  ... Main ()
#(: Marker String for 'find'


#(:  At this point, CTB is OK to Execute
#(:  gather all values required for running the GUI .
    CTB_StartUp     #  note: Must be First-Call in Main () 
#(: 
#(: === begin fx(CTB_lock_file) code.   
#(:
#(: check on "already running" status  
#(: CTB_check_lock_file
#(:    must be written at this level of program stack
#(:    because we require a full 'exit 1' from CTB script.
#(:	
#(: Note:
#(:		Error results if written as a 'function' named like fx(CTB_Check_Lock_File) 
#(:		Proper Termination of Program must occur at "top of stack" . 
#(:		ie, else Process Stack will not 'pop' fully.
#(:     ie, terminating process will 'pop' to previous residual layers
#(:			in a sequence (each with a note to terminal screen). 
#(:		IF user selects "Scan", "Help", "FAQ", "Source" 
#(:			from top of main page this problem may occur. 
#(:		THEN "stack popping" error exists 
#(:		EVIDENCE shows in terminal screen as a succession of "un-pop" messages
#(:			which indicate this 'non-fatal' error . 
#(:
#(:  So, we wrote this check FlgLockFile into "Main", right here !
#(:     so that a single 'exit 1'  , right now, 
#(:     will exit the program script totally .
#(:  This is a 'clean' fix for a possible 'non-fatal' error .
#(: 
#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if [ -f ${CTB_FlgLockFile} ]  ; then
 
	#(:  potential procedural conflict: 
	#(:  if Set Flg Bugger _SD, then Restart, must clear FlgLockFile
	#(:  conflict over FlgLockFile Hard-Lock method. 
	#(:  based on this test:  [ ! -f ${CTB_FlgSD} ]
	#(:
	#(:  resolved by writing a "SOFT-LOCK". 
	#(:		IF previous lockfile is found, 
	#(:		THEN we throw a flag, throw "Error Message" 
	#(:		THEN we continue ! 
#(:
#(:	Note: 
#(:	Most gtkdialog and xmessage require a 'left-margin' position. 

#: ---------------------------------------------------------------------
/usr/lib/gtkdialog/box_splash -fg yellow -bg red -border true  -close never -text "\
.
.     Found! ${CTB_FlgLockFile} : Soft-Lock !!!      
.       ... ---> Will Continue Running <---
. "&
#: ----------------------------------------------------------------------
	sleep 3
    RETVAL=$?
	GtkPid_Sbr_Box_Splash=$!	# capture PID
	kill ${GtkPid_Sbr_Box_Splash} # after return
#: ----------------------------------------------------
		#(:
        #(:  System Control and User-Factors  to consider :
        #(: 
        #(:  "IF": 
        #(:  	"Soft-Lock" Method: 
		#(:  THEN 
        #(:  	(1) Provide a "Warning"
        #(:  	(2) "Continue" running the CTB program. 
        #(:  	(3) program will automatically correct Lock-File status. 
        #(:  	(4) Running CTB on top of itself will NOT cause a "Fatal-Error". 
        #(: 
        #(:  "ELSE":
        #(:  	"Hard-Lock" Method: 
        #(:  THEN 
        #(: 	The user will be locked-out immediately .
        #(:  	Re-Starting CTB will find "Lock-File" still blocking. 
		#(:     Possible to become "locked out" !  
		#(:  Note:
        #(:  	If "Lock-File" process is deleted here,  
        #(: 		then the currently "Running" prg gives no warning. 
        #(:  	and 
        #(: 		then User must know how to clear the Lock-File manually. 
        #(: 
        #(:  "THEREFORE":
        #(: 	 CTB uses a "Soft-Lock" which simply "continues" running .
        #(: 	 CTB will correct the "lock-File" automatically. 
        #(: 	 Running CTB on top of itself will NOT cause a "Fatal-Error" 
        #(: 	 	because "snapmergepuppy" and "tar" run at highest priority level. 
        #(: 
        #(: --------------------------------------------------------------

		#(:  Notes:
        #(:  file unlock
        #(:  rm -f "${CTB_FlgLockFile}"  #(:  release 'running' status.
        #(:  will also remove the lockfile protecting the First Run CTB .
        #(:  As a general philosphy, 
        #(: 		having an "un-Locked" program is dangerous.
        #(:  
        #(:  Current "Soft-Lock" Method : 
        #(:  (1) User has been warned, and can select "QUIT" to be safe.
        #(:  (2) but, this also allows next run program to be 
        #(:      a possible "twice run" non-fatal error.
        #(:  (3) thus, the user will not be 'locked-out' 
        #(: 		and prg will correct flags 
        #(:      and user can "Quit" program. 
		#(: 
        #(:  Current 'Soft-Lock-file' method will allow user to "continue" 
        #(:      even though there may be a 'currently running' CTB session.
		#(:  IF Tar.gz is currently running, 
		#(: 		THEN  Tar.gz has highest system priority. 
		#(: 			and nothing is allowed to interfere. 
		#(: 
        #(:  We find no 'fatal' problems  as long as 
        #(: 		(1) the saveDATA is "STATIC" 
        #(: 		(2) snapmergepuppy nice -19  
		#(: 	
        #(:  Notes: 
        #(:  SaveDATA (File or Folder) must be "Static" ( so the data will be pure )  
        #(:  Any Other system processes which write into the saveDATA must be on 'hold'.  
        #(:  Otherwise, there is (logical) possible erroneous data
        #(: 	can be transferred into the Backup.tar.gz file.  
		#(:  One method of control is to use "nice" for "snapmergepuppy" and "tar" . 
        #(:  This cautionary note is to point out that our CTB program 
        #(:  makes use of the "nice" process to prioritize "snapmergepuppy" to a high level, 
        #(:  thus placing other system fxunctions on 'hold' during the CTB operation. 
        #(: 
        #
		#(:  Note: 
		#(:  'strict' lockfile method NOT Recomended. 
		#(:  'strict' lockfile method could possibly be implemented at this point.
		#(:  	as     exit 1   #(:  which will exit from script at this stack level. 
		#(:  
		#(:  'strict' lockfile method NOT Recomended. 
		#(:  'strict' lockfile method NOT Implemented.
		#(: 
		#(:  'strict' WILL exit from CTB script at this 'base' stack level.
		#(:  IF 'strict' block is written as a written fxunction  fx(CTB_Lock_File_Check) , 
		#(:  THEN exit would only "pop" one level
		#(:  and will not quit the CTB script program. 
		#
        #(:  ideally, using this "Soft-Lock" method 
        #(:      user will Select "QUIT" from menu 
        #(:      then restart 'CTB' program.
        #(:  however, 
		#(: 	There will be NO Fatal fault if CTB is 'restarted' twice. 
        #(: 
		#(:  IF using the "Hard-Lock" method, 
        #(:  THEN 
        #(: 		IF CTB  is  "Ctrl-C" halted    
        #(:      		THEN lock-file flag is not removed. 
        #(: 			THEN 're-entry' would NOT be possible.
        #(: 			THEN  the only fix is to REBOOT, 
        #(:      			or call the IT tech to manually 'rm' the lock-file.
        #(: 
        #(:  There are logical issues here, with some solutions,
        #(:  but that is getting beyond the scope of the CTB process.
        #(: 
fi	# end: if  [ -f ${CTB_FlgLockFile} ] 
#

#(:  Always Set Flag ! because we use a "Soft-Lock" method. 
touch  "${CTB_FlgLockFile}" 

#(:  >>> begin: 'Test' for integrity of 'touch' operation via 'stat' 
#(:  for formatspec in 'file touched :\t%n' 'accessed:\t%x'
#(:  	do stat --printf="$formatspec\n" ${CTB_FlgLockFile}
#(:  done
#(:  so, 
#(: 	remove /tmp/CTB_LockFile at end of "QUIT", bottom of CTB code 
#(:  	which is at the 'base' level of program stack.
#(:  <<< end: 'Test' for integrity of 'touch' operation via 'stat'  

lcMsgStr="<<< end Lock-File code <<<" && Sbr_Str2DevTrm "$lcMsgStr" "1" "3"
lcMsgStr="<<< " && Sbr_Str2DevTrm "$lcMsgStr" "2" "3"

#(: === end fx(CTB_lock_file}




#(:  MAIN GUI setup/prepration begins:

    #(:  #(:  "CTB_TrgDts" has local usage within Main_Gui()
    #(:  #(:  this "CTB_TrgDts" var receives the
    #(:  #(:       <action>refresh:CTB_TrgDts</action>
    #(:  #(:  and shows one-second interval refreshed info.

    #(:  export Marks each NAME for automatic export to the environment
    #(:  of subsequently executed commands.
    #(:  If VALUE is supplied, assign VALUE before exporting.

    #(:  note:
    #(:      calling HELP via command 'embedded' in 'button' .
    #(:          will force a return to the 'button'
    #(:          No program 'restart' required.
    #(:              <label>  'Help=' </label>
    #(:              <action>Sys_Help_Box</action>
    #(:  note:
    #(:      calling "BackUp" via routine outside the Main_Gui() .
    #(:          allows good control.
    #(:          <label>  'Backup+' </label>
    #(:          <action>EXIT:BACKUP+</action>
    #(:          Capture and Execute via "Fall-Thru" method. 
	#(:			 Fall-Thru if/fi section can contain complex code. 	
	#(:			 All "direct" calls from Gui will load the stack, not good. 
	#(:	 note: 
	#(:			We have calls to "HLP", "FAQ", "SRC", "UPL" , and all others . 
	#(:			So, we call everything via a "Fall-Thru" 
	#(:			and then a "funxtion" call to subroutine. 
    #(: 		All gui calls are handled in same manner. 
    #(: 



#(:  CTB control before Main Gui 	2808

#(: "B"asic mode with a GUI. 
if [ ${gcCTBmode} = "B" ] ; then 	 	# "B"asic version 	
	lcSD_Flg_SD=" Scan "   		#(:  label <tool-tip>
	lcSD_Flg_HLP=" H "     		#(:  label <tool-tip> 
	lcSD_Flg_FAQ=" F "      	#(:  label <tool-tip> 
	lcSD_Flg_SRC=" S "   		#(:  label <tool-tip> 
	lcSD_Flg_UPL=" L "	   		#(:  label <tool-tip> 
	#
#(: "A"utomatic  or  "U"tility : have no options
else 
	#(:  "U"tility mode or "A"uto-Scan   =    NO GUI. 
	#(:  so, kill display and prep to fall out, return to caller/MGN
	lcSD_Flg_SD=""
	lcSD_Flg_HLP=""
	lcSD_Flg_FAQ=""
	lcSD_Flg_SRC=""
	lcSD_Flg_UPL=""
	#
fi


#(: === begin: check for status flag
#
lcBackUpStatus="---"  #(:  default preset gui display-status "Help/Source" string in gui
# Control "who" has "focus" in main gui 
if [ ! -f "${CTB_BackUpStatus}" ]; then #(:  if backup not already run, then it has no flag up.
	#(:  if No Flag Up #(:  therefore continue BackUp process
	export lcBackUpFocus="true"		#(:  gui control
	export lcQuitFocus="false"		#(:  gui control
    export lcBackUpStatus="Backup"  #(:  Normal "BackUp" First Run Label w/o flag
    # allow STATUS flag to remain, as is, for gui display. 
else
	#(:  if Yes Flag Up #(:  therefore Stop BackUp process  and  remove Back-Up flag 
	export lcBackUpFocus="false"	#(:  gui control
	export lcQuitFocus="true"		#(:  gui control
    export lcBackUpStatus="Done"  	#(:  Has Been "Done" on Button message. 
    rm -f ${CTB_BackUpStatus} 		#(:  clear flag BackUpStatus display in gui.
    # fall thru into main GUI 
fi

if [ -f "${CTB_FlgBugger_SD}" ]   ; then    #(:  Active SCAN process 
	n=0
    export lcBackUpStatus="${lcBackUpStatus}+Scan"  
		#(:  refresh the curent Main Gui Display variable "+Scan" 
		#(:  indicates Selection("Scan") is active. 
		#(:  available funxtions are: 
		#(:  (1) "Backup to Local saveDATA"   
		#(: 		or 
		#(:  (2a) 'Backup to Local saveDATA , and then ...
		#(:  (2b) 'Scan & Copy' to all mounted harddrives.
fi
		#  [ "${gcCTBmode}" = "A"utomatic ] has No GUI 
		#  [ "${gcCTBmode}" = "U"tility   ] has No GUI 
#(: === end: check for status flag

lcGuiColor3="green"
lcGuiColor2="blue"
lcGuiColor1="darkred"
lcGuiColor0=${lcGuiColor3}	# GUI display color for main title.


#:============================================================  
#: ### Top of mainGUI ############################################
#: ### Top of maingui ############################################
#: ### Top of main-GUI ###########################################
#:============================================================   


#(: ---------------------------------------------------------------------------
#(: CTB Master GUI method : 
#(: called by: main program via fall-thru
#(: param: only the Fall-Thru <ACTION> sub-name .
#(: purpose: Master gtkdialog XML Menu structure. 
#(: calls: 
#(:    every thing via gui buttons to [ gui fall-thru "IF/ ft(name) /FI" ] 
#(:
#(: method: 
#(:   (1) gui <action> "EXIT:ft(name)" 
#(:   (2) 'gui fall-thru to "IF/ ft(name) /FI" (at bottom of source code)
#(:   (3) call with param to "subroutines"     (at top of source code) . 
#(:
#(: sends: "EXIT" = choice 
#(: rationale: 
#(: note : 
#(: 	this width=1500 works good on UpupBB. Other Distro may require adjustment. 
#(: note:
#(: Standard Gui Button Call Method is TWO-STEP: 
#(:  (1) gui-Buttons "call" to a "Fall-Thru funxtion written as "IF/FI" (in lower part of source). 
#(:  (2) "IF/FI" funxtions then call regular subroutine funxtion() (at top of code). 
#(: EXAMPLE:  button "MntAll" is <action>'EXIT:MNT+'</action>
#(: which will exit and fall-thru to "ft( 'EXIT:MNT+' )" 
#(: which will then call "funxtion Sys_MGN_pMount()" (written in top part of source).	
#(: This is the Standard Method written into this MainGui, 
#(:   which allows parameters to be sent to complex sub-routines . 
#(:   which avoids lack of parameter passing inside the gtkdialog process. 
#(: ------------------------------------------------------------------------------


#(: begin fx(export CTB_Main_Gui= XML script )   2850
#
# based on :  
#     eval "`gtkdialog --center -p CTB_Main_Gui`"  is  based on gtk box_help code. 
#gcSysDevId   Cold-Tar-Backup_to_save_DATA_
export CTB_Main_Gui\
='<window title="'${DISTRO_NAME}'..'CTB-SLX'...'${gcSysDevDob}'" icon-name="gtk-convert" default_width="700" >
<vbox>

    <frame>
        <hbox>
			<hseparator width-request="1"></hseparator>
            <text editable="false" use-markup="true" xalign="0">
                <label> 
"<span  color='"'$lcGuiColor0'"'> <b>'Cold-Tar-Backup..${gcCTBmodeName}..v.${gcSysDevVer}' </b> </span>  <span color='"'$lcGuiColor3'"'><b>''</b></span><span color='"'$lcGuiColor2'"'></span>" 
                </label>
            </text>
			<hseparator width-request="7"></hseparator>
			<button  tooltip-text="set Scan-All-Drives flag, xmessage"  label="'${lcSD_Flg_SD}'"
				has-focus="false">  <action>EXIT:"GuiSCN+"</action>  </button>
			<button  tooltip-text="Display Help-Notes, box_help" label="'${lcSD_Flg_HLP}'" 
				has-focus="false">  <action>EXIT:"GuiHLP+"</action>  </button>
			<hseparator width-request="23"></hseparator>
        </hbox>
    </frame>

    <frame>  
        <text editable="false" use-markup="true" >
            <label> "for Puppy Frugal Systems" </label>
        </text>
        <text editable="false" use-markup="true" >
            <label> "<b>Source: '${lcPupSaveNameSrc}' </b>" </label>
        </text>
        <text editable="false" use-markup="true" >
            <label> "<b>Target Subdir : '${gcCtbConfigTrgPrefix}' :</b>" </label>
        </text>
       <text height-request="36"  >
                <variable>'CTB_TrgDts'</variable>
                <input> 'CTB_TrgFilename' '\$CTB_PUPSAVE_PATH' </input>
        </text>
        <timer milliseconds="true" interval="'${CTB_REFRESH_INTERVAL}'" visible="false">
               <action>refresh:CTB_TrgDts</action>
        </timer>
        <hbox>   
            <text editable="false" >
                <label> "*'${lcPupRamObjMsg}'*                   "</label>
            </text>
        </hbox>
    </frame>

	<frame> 
		<hbox>
			<hseparator width-request="10"></hseparator>
			<text editable="false" use-markup="true" xalign="1">
				<label>"     " </label>  </text>
			<button label=" '${lcBackUpStatus}'  "  
				has-focus="'${lcBackUpFocus}'"
				tooltip-text="    ALWAYS read the <HELP> page and <FAQ> file ! " >
                <action>'EXIT':"'GuiBackUpCall+'"</action>	 </button>
			<text editable="false" use-markup="true" xalign="1">
				<label>"     " </label>  </text>
			<button   has-focus="'${lcQuitFocus}'">
				<label> " 'Quit' " </label>
				<input file icon="gtk-no"></input>
				<action>EXIT:"GuiQuitCall+"</action>  </button>
			<text editable="false" use-markup="true" xalign="1">
				<label>"          " </label>  </text>
			<text editable="false" use-markup="true" xalign="0">
				<label>"                " </label>  </text>
		</hbox>
    </frame>
</vbox>

</window>
'
#(: 
#(: use <action>lN:NameThisObj</action>, so to locate via terminal dialog.  
#(:
#(: 
#(:  NOW , eval/execute the main_GUI code.
#(:  NOW , prg can Execute arguments as a shell funxtion command, and stack-up the call.
#(:  NOW , prg control can "Fall-Thru" down the page of code, and do clean "Re-Start". 
#(: 
#(: 
#(: 
#
#: ------------------------------------------------------------------------------
#(: >>>  begin: fg(eval CTB_Main Gui )
#
#(: eval "`gtkdialog --center -p CTB_Main_Gui`"  is  based on gtk "box_help" code. 
if [ ${gcCTBmode} = "B" ]  ; then  
	eval "`gtkdialog --center -p CTB_Main_Gui`"     
else
	#(:  Fall-Thru mode is "U" or "A" with default value. 
	EXIT="GuiBackUpCall+"    #(:  Fall Thru to QUIT : CTU and CTA have NO GUI   
	#(:  will Fall-Thru until it hits "EXIT:BackUpCall+" for Auto Local Backup Now ! 
fi
#(: eval continues through this point in code. 
#
#(: <<<  end: fg(eval CTB_Main_Gui)
#(: --------------------------------------------------------------------------------

#(:=========================================================
#(:  Results from main_GUI will "FALL-THRU" to if/fi routines : 
#(:  'if/fi' routines will handle setup and call to real subroutines up the page. 
#(:  'if/fi' routines call and send parameters to main subroutines at top of source code.
#(:=========================================================

#(:  End of MAIN GUI 
#(:  End of MAIN GUI 
#(:  End of MAIN GUI 








#(:=========================================================
#(: Begin of "Low" Fall-Thru "IF/FI" Routines 
#(: Begin of "Low" Fall-Thru "IF/FI" Routines 
#(: Begin of "Low" Fall-Thru "IF/FI" Routines 
#(:=========================================================


#(:
#(: function CTB_Fall_Thru
#(: ===================;;;;;;;;;;;;
function CTB_Fall_Thru() { # marker
    n=0
#!	 CTB: Fall-Thru to Sequential Test on If/Fi routines. 
#!	 CTB: Fall-Thru to Sequential Test on If/Fi routines. 
#!	 CTB: Fall-Thru to Sequential Test on If/Fi routines. 
} # end: CTB_Fall-Thru

#(:=========================================================
#(:  CTB: Note
#(:  Simple "Fall-Thru Method" finds 
#(:       and initiates action in "low" subroutines. 
#(:  These blocks run after MAIN GUI "Button" selections and "eval" 
#(:  These are normal "if-fi" running blocks.
#(:  These offer a "Re-Start" call 
#(:     (1) to avoid BASH process stack-up, 
#(:     (2) maintain consistent code process. 
#(:     (3) allow sending parameters to main sub-routines.
#(:  These may branch to regular "fx"unction" processes 
#(:     written at top of source code as "high" subroutines. 
#(:=========================================================



#(: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#(: ft(EXIT:"GuiBackUpCall+")
#(: called by: GUI button "BackUp"
#(: param: 
#(: purpose:  call "M.A.I.N." "BackUp" routines 
#(: method: 
#(: sends: 
#(: rationale: 
#(: note : 
#(:
#!  <action>'EXIT':"'GuiBackUpCall+'"</action>
#(! --------------------------------------------------------------------
if [ "$EXIT" = "GuiBackUpCall+" ] ; then
    n=0

	#(: Simple flags in button for "Backup" or Backup+SCAN 
	#(: First, check two GUI var which are set when user selects options.
	#(: Then, check mode="A" which over-rides . 
	if [ "$lcBackUpStatus" = "Backup" ] ||  [ "$lcBackUpStatus" = "Backup+Scan" ] || [ "${gcCTBmode}" = "A" ] ; then  

		lcTarRetVal=0	#(:  default value before CTB_BackUpRun

    #! Pmnt
    Sbr_Ctb_pMount_All

	CTB_BackUpRun "${CTB_PUPSAVE_PATH} --- ${CTB_BACKUP_PATH}"	 # Not Used 

    gcCTBmodeRef=${gcCTBmode}
    gcCTBmode="A"
    
    #! Umnt   Un-Mount ALL 
    Sbr_Ctb_uMount_All

		if [ ${gcCTBmode} = "B" ]   ; then 
			CTB_ReStart   
		else
			EXIT="QUIT"  #(:  will cause Fall-Thru Quit and NO ReStart 
		fi
		# 
	else
		#(: else gcCTBmode = "U" or "A" or "Done"  , will Fall-Out Quit
	    EXIT="QUIT"  #(:  Fall-Thru Quit and NO ReStart  
	fi
    gcCTBmode=${gcCTBmodeRef}

    EXIT="QUIT"  #(: setup Fall-Thru
	CTB_ClearFlgSys	
    rm -f ${CTB_BackUpStatus} 
		#(:  NOT READY for Fall-Thru to "Quit w/o ReStart"
		#(:  Because Primary Process "CTB" is still on stack.
		#(:  Allow Fall-Thru to clear stack, and startup GUI. 
		#(:  DO NOT call  CTB_ReStart  
fi # end: ft(EXIT:"GuiBackUpCall+")




#(: ===================
#(: ft(EXIT:"GuiSCN+")
#(: called by: GUI button "SCAN" 
#(: param: 
#(: purpose: set "SCAN" flag,to cast saveDATA to attached hard-drives "/CTB_Backup_"
#(: calls: xmessage
#(: method: calls 'touch' and 'gtkdialog/box_splash'  
#(: sends: 
#(: rationale: 
#(: note : 
#(:
#(: ------------------------------------------------------------------
#(! --------------------------------------------------------------------
if [ "$EXIT" = "GuiSCN+" ] ; then
    n=0 
	if [ ${gcCTBmode} = "B" ] ; then 	
		touch  ${CTB_FlgBugger_SD} 	#(:  mode "A" or "B" 
		lcDialogColor="  -fg blue -bg yellow  "
		lcMsgStr="---SCAN Auto Flag is Set for Extended Scanning BackUp ---"
		/usr/lib/gtkdialog/box_splash  $lcDialogColor -border true  -close never -text "$lcMsgStr" &
		GTKPIDerror=${!}
		sleep 3
		kill ${GTKPIDerror}
	fi
    CTB_ReStart  
fi # end: EXIT:"GuiSCN+"



#(: ===================
#(: ft(EXIT:"GuiHLP+")
#(: called by:  GuiHLP+  to  fx(Sys_Box_HLP)  to  Sbr_Box_Message
#(: param: 
#(: purpose:  Display Help  Code in 'gtkdialog/box_help'  
#(: method: calls  Sys_Box_HLP
#(: sends: 
#(: rationale: 
#(: note : 
#(:
#(: ===================
#(! --------------------------------------------------------------------
if [ "$EXIT" = "GuiHLP+" ] ; then
    n=0
    Sys_Box_HLP    
    CTB_ReStart	
fi # end: EXIT:"GuiHLP+"

#(: ===================;;;;;;;;;;;;;
#(: ft(EXIT:"GuiQuitCall+")  "QUIT"  "X" 
#(: called by: GUI button "Quit" 
#(: param: 
#(: purpose: 
#(: method: 
#(: sends: 
#(: rationale: 
#(: note : Catch All ! 
#(:
#(: ===================;;;;;;;;;;;;;;;;;;;;;;;;;
#(! --------------------------------------------------------------------
if [ "$EXIT" = "GuiQuitCall+" ] || [ "$EXIT" = "QUIT" ]  || [ "$EXIT" = "X" ] ; then
	n=0
	#(:  Passed Through all functioning code 
    #(:  At this point in program :  
	#(:		QUIT: DO NOT RESTART CTB script auto 
    #(:  	QUIT: DO NOT !!!  ReStart
    #(:  SIMPLY FALL OUT !
    #(:  	When run via "MGN" 'manager' 
    #(:  	then "MGN" will handle a "restart" back into the "MGN" program.
	#(:  if all else has failed to "QUIT", then prg falls to this. 
	#(:  this is manual method  
	CTB_ClearFlgSys	#(:  before actual fall-out to "exit 0"
	#(: Backup is finished, so remove flag
    rm -f ${CTB_BackUpStatus} 
    #(:  Next display is for the "Ending of the Terminal DeBug Session Message" : 
    lcMsgStr="..." && Sbr_Str2DevTrm "${lcMsgStr}" "5" "7"
    lcMsgStr="... CTB : Terminal ReadMe :"  && Sbr_Str2DevTrm "${lcMsgStr}" "2" "7"
    lcMsgStr="...   Tar has Created '.tar.gz' BackUp" && Sbr_Str2DevTrm "${lcMsgStr}" "3" "7"
    lcMsgStr="...   Wait for USB devices to flush" && Sbr_Str2DevTrm "${lcMsgStr}" "5" "7"
    lcMsgStr="..." && Sbr_Str2DevTrm "${lcMsgStr}" "5" "7"
    lcMsgStr=">>>  Hit 'Enter' to clear Terminal <<< "
    Sbr_Str2DevTrm "$lcMsgStr" "3" "7"
    Sbr_Str2DevTrm "$lcMsgStr" "2" "7"
    Sbr_Str2DevTrm "$lcMsgStr" "6" "7"
    lcMsgStr="...................................." && Sbr_Str2DevTrm "${lcMsgStr}" "5" "7"
    lcMsgStr="<<< Quit Fall-Out <<<" && Sbr_Str2DevTrm "$lcMsgStr" "1" "3"
    lcMsgStr="=== Will Show STACKED processes ===" && Sbr_Str2DevTrm "$lcMsgStr" "3" "3"
	#(: part of "Quit" process, so NO Re-Start ! 
fi # end: EXIT:"QuitCall+"

#(: Any other OPTION, or "function not found"  will allow Fall-Out of program. 
#(:  Now, Prg is one level from "termination", so simple "exit 0" will kill ALL !
#
exit 0
#
#(: ===================================================================
#(:  end of CTB program
#(: ===================================================================




#(:=======================================================
#(:=======================================================
#(:=======================================================
#(:=======================================================
#(: System Docs and Legal are here 
#(:=======================================================
#(: 
#(:   Standard GNU General Public License Header :
#(: 
#(:   2020 root <glen.e77is@Gmail.com>
#(:   website : www.GeoCities.WS/glene77is
#(: 
#(:   This program is free software; you can redistribute it and/or modify
#(:   it under the terms of the GNU General Public License as published by
#(:   the Free Software Foundation; either version 2 of the License, or
#(:   (at your option) any later version.
#(: 
#(:   This program is distributed in the hope that it will be useful,
#(:   but WITHOUT ANY WARRANTY; without even the implied warranty of
#(:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#(:   GNU General Public License for more details.
#(: 
#(:   To received a copy of the GNU General Public License
#(:   write to the Free Software Foundation, Inc.,
#(:   51 Franklin Street, Fifth Floor, Boston,
#(:   MA 02110-1301, USA.
#(:  
 
#(:=======================================================
#(: 
#(:  191113-1116
#(:      gae, first bug killed was the lingering splash banner 
#(:			 /usr/sbin/pupsave-backup    1.2.1 
#(:         which persisted forever, 
#(:			and was not killed properly at end of orig program.
#(:          ( persisted forever on desktop, until Refresh "X" or "Reboot")
#(:      gae, that bug, and other unreadable complexities, 
#(:          led to total re-write from scratch.
#(:		 gae, then to our development of "Cold-Tar-Backup".sh 
#(:      gae, Design Philosophy : "Simple, Readable, Modular, Modifiable" 
#(: 
#(:=======================================================
#(:  
#(:  Pecuiliar code !    
#(:      /usr/sbin/pupsave-backup    (v.1.2.1)   
#(:  Pupsave_Zipit original , v1 and later,  had "export LOCDEFAULT="/mnt/home"
#(:  LOCDEFAULT was 'hard-coded', in original v1 .  
#(:  LOCDEFAULT was NOT calculated from available values, 
#(:		as per Barry Kauler's example. 
#(:  Surprised me !  
#(:  That caused published HotBackup to fault on my system. 
#(:		which is a USB FlashDrive booting system. 
#(:     onto first drive SDA1 which has a M$-XP Master Boot Record.
#(:  Use of Barry Kauler method to determine the LOCDEFAULT works OK.   
#(:  
#(:=======================================================
#(: 
#(: peculiar bug from original Back-2-Tar  (v.1.2.1): now under control :
#(: splash "saving session to savefolder..." was left to linger forever. 
#(: 
#(:=======================================================
#(: 
#(: peculiar bug from original Back-2-Tar  (v.1.2.1): now under control :
#(: On Error, was falling back to original /usr/sbin/   !!!!!!!!!!!!!!!
#(: IF : we are warning only to run on 32bit Frugal save-FOLDER, else failure,
#(: THEN : we do not need to check nor warn-n-exit here !
#(: THEREFORE : this litle block was culled.
#(: lcSF is lcPupSave via "cut -f 3 -d "  above
#(:		if [ ! "$SF" ] ; then   
#(:			### gae, then this is a "full install" and B2T will not handle it.
#(:	    	### /usr/lib/gtkdialog/box_ok 
#(:			###	"Pupsave Backup" error "Currently using a full partition..."
#(:	    	B2T_cleanup
#(:	    	exit
#(:		fi
#(: 
#(:

#(: Frame-Work "header" for each subroutine. 
#(: ===================;;;
#(: fx(Sys_Functional-Name) 
#(: called by: 
#(: param: 
#(: purpose: 
#(: calls: 
#(: method: 
#(: sends: 
#(: rationale: 
#(: note : 
#(:

#(:----------------------------------------------------
#(: System Notes, and 
#(:   Standard GNU General Public License Header 
#(:----------------------------------------------------

#(:----------------------------------------------------
#(: "CTB" 
#(: "Cold-Tar-Backup" 
#(: based on "tar" and "GZ" compression methods
#(:		which have been around since year 0 . 
#(: features tar.gz.out file with DTS stamp (Year-Month-Day-Seconds). 
#(: features Scanning-BackUp-to-Multiple-Drives.
#(:
#(: the "Cold-Tar-Backup" program for Puppy Linux saveDATA 
#(:		tested in Official Puppy Linux distros (long list is below). 
#(:
#(: Script name format is 'XXX.sh' so GEANY 
#(:		(1) sees a 'script' executable file.
#(:		(2) sees a 'script' with 'executable permission.
#(:
#(: MGR.sh system ( rc.z_MGN.sh, rc.z_E2R.sh, rc.z_CTB.sh, rc.z_S2F.sh, etc. ) 
#(:	CTB Development subdir is '/initrd/mnt/dev_save/MY_/usr-share/My_Dev_' .
#(: ok to rename to "ColdTarBackup.sh" or anything else.
#(: ok to install anywhere, and activated via desktop icon.
#(:
#(: Developed using Geany :
#(: 	with option "Execute" for trace in "BASH Terminal" for Trace/Debug.
#(: 	Using Geany with option "Execute" activates "BASH Terminal" mode . 
#(: 	Using Geany with option "Execute" will allow good debugging in "BASH Terminal"
#(:		Using Geany with option "Execute" in terminal allows monitoring BASH quirks. 
#(:
#(:	Messages to screen : 
#(: 	All of our "echo" lines will show 'B/W' trace in the "BASH Terminal" screen.
#(: 	All of our "Sbr_Str2DevTrm" lines will show 'Color' trace in "BASH Terminal" screen.
#(:
#(: Author's "/Development"  vs.  "/Production" subdirs: 
#(: 	"/Development" is "/initrd/mnt/dev_save/MY_/usr-share/My_Dev_/..."
#(:		"/Production" is "/root/my-applications" backed-up with 'save2flash' in saveDATA . 
#(: 	We maintain separation between "Dev/Edit" and "Production-Final" . 
#(:		OK to rename to "ColdTarBackup.sh" or anything else.
#(:		OK to install anywhere, and 'run' via desktop icon.
#(: 
#(: "Development/Edit" files in "/initrd/mnt/dev_save/MY_/usr-share/My_Dev_/..." .
#(: (1) run "MGR.sh" to activate the utilities located in "Development" subdir .
#(: (2) run "E2R.sh" to copy "Development" versions  into "/root/my-applications" .
#(: (3) store apps/scripts in "/root/my-applications" 
#(:		so they will archive via "Save2Flash" into "saveDATA" user 'layer'. 
#(: (4) this maintains separation: "/DEVELOPMENT" vs "/PRODUCTION" .
#(:

#(: ----------------------------------------------------
#(: gae, Geany  debug method :
#(: [ "Execute" for BASH-Terminal-Trace-Window ]
#(: write "echo" commands for tracing in the Terminal Window.

#(:----------------------------------------------------
#(:	NOTE: 
#(: BASH stacking control quirk, and non-fatal error. 
#(:
#(:		IF user selects "Scan", "Help", "FAQ", "Source" 
#(:			from top of main page. 
#(:		THEN "stack popping" error exists 
#(:		EVIDENCE may show in terminal screen as a succession of "un-pop" messages. 
#(:
#(:		The concept of strict "scope" (isolation of levels of process 'stack') 
#(:       was not implimented in original. 
#(:
#(:		see Note On BASH process stack
#(:		we published in function "Sys_Box_FAQ"  
#(:		

#(: ----------------------------------------------------
#(:  Note : "O.O.P."  [ Object Oriented Programming ] 
#(:  BASH does NOT implement "OOP".
#(:  (gtk)dialog does NOT implement "OOP".
#(:  quoted from "hipersayanx.blogspot.com" › 2012/12 › object-oriented-pr.
#(: 
#(:  BASH is a very common *nix shell, 
#(:  and it's programming language is purely procedural 
#(:  and focused on command execution. 
#(: 
#(:  'O'bject 'O'riented 'P'rogramming (OOP) is a programming paradigm 
#(:  that represents the elements of a problem as entities 
#(:  with a set of properties and actions that it can execute. 
#(:  If you use Bash to write very simple and short scripts, 
#(:  procedural programming is just fine, you don't need more.
#(:  But if your program becomes more and more bigger, 
#(:  a monster BASH system program , 
#(:  then you need a better way to structure your program ...
#(:  Dec 22, 2012
#(:  quoted from "hipersayanx.blogspot.com" › 2012/12 › object-oriented-pr.
#(: 
#(:  These "OOP" Concepts are foreign to Unix Scripting Shell Languages
#(:     Abstraction. 
#(:     Encapsulation. 
#(:     Inheritance. 
#(:     Polymorphism.
#(:
#(:	 The concept of strict "scope" (isolation of levels of process 'stack') is not implimented. 
#(:
#(:  A monster BASH script program ( > 10,000 lines ) 
#(:  requires a modern high-level language like Python.
#(: 
#(:  Note:  LockFile 
#(:  'strict' lockfile method NOT implemented.
#(:  	example:      exit 1   
#(:  'strict' WILL exit from PRG script only at the 'base' stack level.
#(: 
#(:  IF 'strict' block is written into a funxtion() ( which is a "sub-routine" )
#(:		[which by definition is a sublevel in the stack], 
#(:  	THEN exit will only "pop" one level at that funxtion() stack level. 
#(:  	and will not quit the PRG as desired. 
#(:  CTB has 'soft' lock method written into main() stack level. 
#(: 

#(: ----------------------------------------------------

#(:  Note: Problem noted at start of reverse engineering process:
#(:  gae, serious problem with original source . 
#(:  (1) reference   
#(:  ref note: Pupsave_v1 and later
#(:  	contained hard code [ export LOCDEFAULT="/mnt/home" ].
#(:  "export LOCDEFAULT="/mnt/home" was "Hard-Coded" declare/assignbment.  
#(:  	this LOCDEFAULT would not run on author's Puppy Linux OS
#(: 		Author's OS boots from USB with "saveDATA" on SDA1. 
#(: 			(1) has  "/initrd/mnt/dev-save" 
#(: 			(2) not "/mnt/home" 
#(: 
#(:  (2) reference   
#(:  Surprised me !    
#(:  Pupsave_Zipit original , v1 and later,  export LOCDEFAULT="/mnt/home" 
#(:  LOCDEFAULT was 'hard-coded', in original v1 .  
#(:  LOCDEFAULT was NOT calculated from available values, 
#(: 			as per Barry Kauler example (included in this source code). 
#(:  Surprised me !  
#(:  That caused published HotBackup to FAULT on all my Puppy Linux systems. 
#(:  Use of "BK method" to determine the LOCDEFAULT works OK, 
#(:     and has been incorporated in our work (with proper credits to "BK").   
#(:  
#(: 
#(:  Author's Puppy Linux Frugal OS boots via USB flash-drive
#(: 	(1) has Boot drive as "/initrd/mnt/dev_save/sda1" 
#(:  	(2) has Non-Boot drives as "/mnt/home/sd?1" 
#(: 
#(: ===================
#(: 
#(:  > Note about Barry Kauler method for specifying the "System Location" :
#(:  > BK = Barry Kauler calculated "system location" as shown below :  
#(:  > calcs are performed after 
#(: 	(1) system has booted : 
#(: 	(2) 'aufs' is running : 
#(:  > gcSaveFileNameMount : 
#(:  ="`cat /sys/fs/aufs/si_*/br0 | head -1 | cut -f1 -d'='`"
#(:  =cat /sys/fs/aufs/si_*/br0 | head -1 | cut -f1 -d '=' 
#(:  > gcSaveFileNameBaseSrc : 
#(:  ="`cat /sys/fs/aufs/si_*/br1 | head -1 | cut -f1 -d'='`"
#(:  =cat /sys/fs/aufs/si_*/br1 | head -1 | cut -f1 -d '='
#(:  > Author's current UpupJJ, UpupBB, uPupFF, Slacko64 systems ( 6 more )
#(: 		are located on hard-drive  '"/initrd/mnt/dev_save" /sda1' 
#(:  > which changes after system is 'up and running' to '"/mnt/home"'
#(:  > BK = Barry Kauler calculated "system location" (as shown above) 
#(:  is valid code  
#(: 	(1) after system has booted : 
#(: 	(2) after 'aufs' is running : 
#(:  
#(: ===================

#(: ----------------------------------------------------
#(:  2byte wrote the original 'hot' pupsave-backup v.1.2.1, 2011 .
#(:  Sigberg rewrote into the Fuller version, v.1.3,  2013 .
#(:  glene77is rewrote totally into readable "I.T." form, as "rc.z_CTB.sh", 2020 .
#(:  available on website : www.GeoCities.WS/glene77is
#(: 
#(: ----------------------------------------------------
#(: 
#(:  gae developed 'Cold_Tar_Backup', "CTB".  2019-11 <-> 2021-03.
#(:  This project has been merged into our system control utilities 
#(: 		(MGN, E2R, C3C, S2F, CTB)
#(:  CTB : our code was based on the idea behind pupsave-backup 1.2.1
#(:  	see Murga forum at 
#(: 	https://forum.puppylinux.com/viewtopic.php?p=3482&hilit=CTB#p3482
#(: 	
#(:  CTB uses standard gtkdialog -v = 0.8.4 release , Laszlo Pere, Thunor.
#(:  CTB has been tested on Official Puppy Linux distros :  
#(: 		Slacko-7	iso-slacko64-14.0.iso
#(: 		Slacko-64	iso-slacko64-7.0_210420.iso
#(: 		Slacko-6.2	iso-slacko-6.9.9.9-k3.16-4G-FF-ABI-2017.iso
#(: 		Xenial-708, Tahr-606, Quirky-7, LxPup-64, UpupBB+29, UpupFF .
#(: 		Puppy distro UpupBB thru +29
#(: 		UpupFF-D08 .
#(: 		UpupJJ-D08 .
#(: 		UpupSlacko7
#(:  From the Puppy FAQ: 
#(:  "Wheezy Puppy" is NOT a "Puppy Linux Distro" !!!   
#(:		Wheezy is a Debian Distro with Debian dependencies, with an API designed like Puppy. 
#(:  	Q: What is an official Puppy Linux distribution?
#(:  	A: It must meet two conditions. https://github.com/puppylinux-woof-CE/woof-CE
#(: 		1) It must be built using Woof-CE and its build “recipe” should be in woof-distro. 
#(: 		2) It must be endorsed as “official” by the Puppy Master.
#(:  CTB has been tested on Frugal Install "/saveFOLDER" and "/saveFILE.4fs" systems.
#(:  CTB depends on gtkdialog for Progress Dialog, Help-splash and Main-Gui-splash screens.
#(:  CTB depends on Puppy Linux "PUPSTATE" file, required, for system variables.
#(:  CTB has been designed/tested to work with Puppy Linux Frugal installs.
#(:  CTB has been designed/tested to work with Puppy Linux formats Ext2,3,4.
#(:  CTB has been tested to work with Puppy Linux Frugal, saveFOLDER systems.
#(:  CTB has been tested to work with Puppy Linux Frugal, saveFILE.4fs systems.
#(:  CTB has many 'echo' trace messages designed for Geany and ROX "BASH Terminal" mode. 
#(:  CTB has many 'echo' trace messages which only display in the BASH Terminal mode.
#(: 
#(: ----------------------------------------------------
#(: 
#(:  
#(: 
#(:====================================================================
#(: 
#(:   Standard GNU General Public License Header :
#(: 
#(:   2020 root <glen.e77is@Gmail.com>
#(:   website : www.GeoCities.WS/glene77is
#(: 
#(:   This program is free software; you can redistribute it and/or modify
#(:   it under the terms of the GNU General Public License as published by
#(:   the Free Software Foundation; either version 2 of the License, or
#(:   (at your option) any later version.
#(: 
#(:   This program is distributed in the hope that it will be useful,
#(:   but WITHOUT ANY WARRANTY; without even the implied warranty of
#(:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#(:   GNU General Public License for more details.
#(: 
#(:   To received a copy of the GNU General Public License
#(:   write to the Free Software Foundation, Inc.,
#(:   51 Franklin Street, Fifth Floor, Boston,
#(:   MA 02110-1301, USA.
#(:  

#: ==================================================================
#(: 
#(:   tar (GNU tar) 1.29
#(:	  "TAR" tape archive has been around since year zero, gathering datafiles into a single "group". 
#(:   Copyright (C) 2015 Free Software Foundation, Inc.
#(:   License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
#(:   This is free software: you are free to change and redistribute it.
#(:   There is NO WARRANTY, to the extent permitted by law.
#(:   Written by John Gilmore and Jay Fenlason.
#(: 

#(:====================================================================
#(:====================================================================
#(:====================================================================
#(: 
#(:  191113-1116
#(:      gae, first bug killed was the lingering splash banner 
#(:			 /usr/sbin/pupsave-backup    1.2.1 
#(:          which persisted, and was not killed properly at end of orig program.
#(:          and persisted forever on desktop, until Refresh "X" or "Reboot"
#(:      gae, that bug, and other unreadable complexities, 
#(:          led to total re-write from scratch.
#(:		 gae, then to our development of "Cold-Tar-Backup.sh" 
#(:      gae, Design Philosophy : "Simple, Readable, Modular, Modifiable" 
#(: 
#(:====================================================================
#(:  
#(:  Pecuiliar code !    
#(:      /usr/sbin/pupsave-backup    (v.1.2.1)   
#(:  Pupsave_Zipit original , v1 and later,  had "export LOCDEFAULT="/mnt/home"
#(:  LOCDEFAULT was 'hard-coded', in original v1 .  
#(:  LOCDEFAULT was NOT calculated from available values, 
#(:		as per Barry Kauler's example. 
#(:  Surprised me !  
#(:  That caused published HotBackup to fault on my system. 
#(:		which is a USB FlashDrive booting system. 
#(:  Use of Barry Kauler method to determine the LOCDEFAULT works OK.   
#(:  
#(:====================================================================
#(: 
#(: peculiar bug from original Back-2-Tar  (v.1.2.1): now under control :
#(: splash "saving session to savefolder..." was left to linger forever. 
#(: 
#(:====================================================================
#(: 
#(: peculiar bug from original Back-2-Tar  (v.1.2.1): now under control :
#(: On Error, was falling back to original /usr/sbin/   !!!!!!!!!!!!!!!
#(: IF : we are warning only to run on 32bit Frugal save-FOLDER, else failure,
#(: THEN : we do not need to check nor warn-n-exit here !
#(: THEREFORE : this litle block was culled.
#(: lcSF is lcPupSave via "cut -f 3 -d "  above
#(:    if [ ! "$SF" ] ; then   ### gae, then this is a "full install" and B2T will not handle it.
#(:      /usr/lib/gtkdialog/box_ok "Pupsave Backup" error "Currently using a full partition..."
#(:      B2T_cleanup
#(:      exit
#(:    fi
#(: 
#(:====================================================================
#(:====================================================================
#(:===  END of SOURCE CODE ============================================
#(:====================================================================

