187 lines
4.4 KiB
Plaintext
187 lines
4.4 KiB
Plaintext
#!/usr/local/bin/tclsh7.4
|
|
|
|
#############################################################################
|
|
### Do we already have this delta ?
|
|
#############################################################################
|
|
|
|
proc find_delta {nbr} {
|
|
global CTMname CTMdest
|
|
if {[file exists [format "%s/$CTMname.%04d" $CTMdest $nbr]]} { return 1 }
|
|
if {[file exists [format "%s/$CTMname.%04d.gz" $CTMdest $nbr]]} { return 1 }
|
|
return 0
|
|
}
|
|
|
|
#############################################################################
|
|
### The top level code...
|
|
#############################################################################
|
|
|
|
set CTMSW /home/ctm/SW
|
|
|
|
cd $CTMSW
|
|
|
|
# Defaults...
|
|
set CTMapply 1
|
|
set CTMignore {^///}
|
|
set CTMbogus {\.core$}
|
|
set CTMmail {}
|
|
set CTMqueue {}
|
|
set CTMqueuemail {}
|
|
set CTMmaxctm 10000000
|
|
set CTMmaxmsg 100000
|
|
set CTMsuff {}
|
|
set CTMdate [exec date -u +%Y%m%d%H%M%SZ]
|
|
set CTMtmp {}
|
|
set CTMcopy {}
|
|
set CTMdest {}
|
|
set CTMprefix .
|
|
set CTMtest 0
|
|
set CTMspecial 0
|
|
set CTMscan .
|
|
set CTMfirst 0
|
|
set max_damage 100
|
|
|
|
set damage 0
|
|
set changes 0
|
|
|
|
source $argv
|
|
exec sh -c "date -u '+%Y%m%d%H%M%S $argv'" >> ${CTMSW}/log
|
|
|
|
if {$CTMtmp == ""} {
|
|
set CTMtmp $CTMSW/../tmp/${CTMname}_${CTMsuff}
|
|
}
|
|
if {$CTMcopy == ""} {
|
|
set CTMcopy $CTMSW/../$CTMname
|
|
}
|
|
if {$CTMdest == ""} {
|
|
set CTMdest $CTMSW/../CTM-pub/$CTMname
|
|
}
|
|
|
|
# Make sure we only run one at a time...
|
|
|
|
set CTMlock Lck.${CTMname}.${CTMdate}.[pid]
|
|
exec rm -f ${CTMlock}
|
|
exec echo starting > ${CTMlock}
|
|
if {[catch "exec ln $CTMlock LCK.$CTMname" a]} {
|
|
puts "Not going, lock exists..."
|
|
exec rm -f $CTMlock
|
|
exit 1
|
|
}
|
|
exec rm -f $CTMlock
|
|
set CTMlock LCK.$CTMname
|
|
|
|
set CTMscratch ${CTMtmp}.tmp
|
|
|
|
while 1 {
|
|
if { ! $CTMspecial} {
|
|
if {$CTMfirst} {
|
|
set CTMnbr 0
|
|
} else {
|
|
set CTMnbr [lindex [exec cat $CTMcopy/.ctm_status] 1]
|
|
}
|
|
|
|
if {$CTMnbr > 0 && ![find_delta $CTMnbr]} {
|
|
puts "$CTMname delta $CTMnbr doesn't exist..."
|
|
exec rm -f $CTMlock
|
|
exit 1
|
|
}
|
|
|
|
incr CTMnbr
|
|
|
|
if {[find_delta $CTMnbr]} {
|
|
puts "$CTMname delta $CTMnbr does already exist..."
|
|
exec rm -f $CTMlock
|
|
exit 1
|
|
}
|
|
|
|
set fo [open $CTMref/.ctm_status w]
|
|
puts $fo "$CTMname $CTMnbr"
|
|
close $fo
|
|
incr changes -1
|
|
|
|
} else {
|
|
set CTMnbr [lindex [exec cat $CTMref/.ctm_status] 1]
|
|
}
|
|
|
|
puts "Doing CTMname $CTMname CTMnbr $CTMnbr$CTMsuff CTMdate $CTMdate"
|
|
flush stdout
|
|
exec sh -c "rm -f ${CTMtmp}.* ${CTMtmp}:*" >&@ stdout
|
|
|
|
set nm [format "%s.%04d%s" $CTMname $CTMnbr $CTMsuff]
|
|
|
|
set x1 $CTMcopy
|
|
if {$x1 == ""} {
|
|
exec mkdir ${CTMtmp}.dir
|
|
set x1 ${CTMtmp}.dir
|
|
}
|
|
set r1 [catch "exec ${CTMSW}/mkctm -I ${CTMignore} -B ${CTMbogus} -l ${CTMtmp}.log -D $max_damage $CTMname $CTMnbr $CTMdate . $x1 $CTMref | md5 -p | gzip -9 > ${CTMtmp}:${nm}.gz 2>@ stderr" r2]
|
|
|
|
if {$r1} {
|
|
if {[lindex $errorCode 2] == 4} {
|
|
puts "No changes, stopping."
|
|
exec rm -f $CTMlock
|
|
exit 0
|
|
}
|
|
puts "problems, stopping now."
|
|
puts "errorCode $errorCode"
|
|
puts "$r2"
|
|
exec rm -f $CTMlock
|
|
exit 1
|
|
}
|
|
|
|
puts "mkctm done"
|
|
|
|
if {$CTMtest} {
|
|
puts "testing, stopping now."
|
|
exec rm -f $CTMlock
|
|
exit 0
|
|
}
|
|
if {$CTMapply} {
|
|
puts "Applying delta"
|
|
flush stdout
|
|
exec echo now applying > $CTMlock
|
|
exec sh -e -c "cd $CTMcopy ; $CTMSW/ctm -v -v -v ${CTMtmp}:${nm}.gz" >& ${CTMtmp}.apply
|
|
exec echo did apply > $CTMlock
|
|
}
|
|
puts "Moving delta"
|
|
flush stdout
|
|
exec mv ${CTMtmp}:${nm}.gz $CTMdest/.CTMtmp_${nm}.gz >&@ stdout
|
|
exec mv $CTMdest/.CTMtmp_${nm}.gz $CTMdest/${nm}.gz >&@ stdout
|
|
exec echo moved > $CTMlock
|
|
|
|
exec sh -c "rm -rf ${CTMtmp}.*" >&@ stdout
|
|
|
|
if {$CTMmail != ""} {
|
|
puts "Mailing delta"
|
|
flush stdout
|
|
exec $CTMSW/ctm_smail -m $CTMmaxmsg -c $CTMmaxctm $CTMdest/${nm}.gz $CTMmail >&@ stdout
|
|
if {$CTMqueue != "" && $CTMqueuemail != ""} {
|
|
puts "Queueing delta"
|
|
flush stdout
|
|
exec $CTMSW/ctm_smail -m $CTMmaxmsg -c $CTMmaxctm -q $CTMqueue $CTMdest/${nm}.gz $CTMqueuemail >&@ stdout
|
|
puts "Sending initial two deltas"
|
|
flush stdout
|
|
exec $CTMSW/ctm_dequeue -n 2 $CTMqueue >&@ stdout
|
|
}
|
|
}
|
|
exec echo mailed > $CTMlock
|
|
|
|
# If we did an absolute delta: stop.
|
|
if {$CTMsuff != ""} break
|
|
|
|
# Make a absolute delta (!) every 100 deltas
|
|
if {$CTMnbr == 0 || ($CTMnbr % 100)} break
|
|
|
|
# Make an absolute delta too...
|
|
set CTMref $CTMcopy
|
|
set CTMsuff A
|
|
set CTMcopy ""
|
|
set CTMmail ""
|
|
set CTMqueue ""
|
|
set CTMqueuemail ""
|
|
set CTMapply 0
|
|
set CTMspecial 1
|
|
exec rm -f $CTMlock
|
|
}
|
|
puts "done."
|
|
exec rm -f $CTMlock
|