#!/bin/tcsh -f
# JLdL 25Sep10.
#
# Get the current sizes of the various mirrors,
# _ then format and and write out the result.
#
# Define a variable with the tab character.
set tab = "`echo -n '\t'`"
#
# Set a file-exclusion egrep target, in order to
# _ exclude everything but the actual mirrors.
set excl = "${tab}lost\+found"'$'
set excl = "$excl|${tab}backports"'$'
set excl = "$excl|${tab}backports.org"'$'
set excl = "$excl|${tab}debian-backport"'$'
set excl = "$excl|${tab}debian-ubuntu"'$'
set excl = "$excl|${tab}debian-marillat"'$'
set excl = "$excl|${tab}dev"'$'
set excl = "$excl|${tab}doc"'$'
set excl = "$excl|${tab}doit-get-sizes"'$'
set excl = "$excl|${tab}gnupg"'$'
set excl = "$excl|${tab}kernel"'$'
set excl = "$excl|${tab}linux"'$'
set excl = "$excl|${tab}lock"'$'
set excl = "$excl|${tab}log"'$'
set excl = "$excl|${tab}README.ACCESS"'$'
set excl = "$excl|${tab}README.CONTACT"'$'
set excl = "$excl|${tab}README.CONTENT"'$'
set excl = "$excl|${tab}README.lost-data"'$'
set excl = "$excl|${tab}releases"'$'
set excl = "$excl|${tab}robots.txt"'$'
set excl = "$excl|${tab}sbin"'$'
set excl = "$excl|${tab}software"'$'
set excl = "$excl|${tab}tmp"'$'
set excl = "$excl|${tab}trash"'$'
set excl = "$excl|${tab}ubuntu-releases"'$'
set excl = "$excl|${tab}welcome.msg"'$'
set excl = "$excl|${tab}welcome.msg.ORIG"'$'
#
# Set a file-inclusion egrep target, in order to
# _ include only the actual mirrors.
set incl = "${tab}debian"'$'
set incl = "$incl|${tab}debian-backports"'$'
set incl = "$incl|${tab}debian-cd"'$'
set incl = "$incl|${tab}debian-cluster"'$'
set incl = "$incl|${tab}debian-eeepc"'$'
set incl = "$incl|${tab}debian-knoppix"'$'
set incl = "$incl|${tab}debian-multimedia"'$'
set incl = "$incl|${tab}debian-security"'$'
set incl = "$incl|${tab}debian-volatile"'$'
set incl = "$incl|${tab}pub"'$'
set incl = "$incl|${tab}ubuntu"'$'
set incl = "$incl|${tab}ubuntu-cd"'$'
#
# Define a time-stamped file name.
set file = /sft/log/`date +%y-%m-%d_%H:%M`
#
# Get the data and put it into a temporary file;
# _ this may take a long time.
#du -sk * | sort -n | egrep -v "$excl" >! $file.tmp
cd /sft
du -sk * | sort -n | egrep "$incl" >! $file.tmp
cd -
#
# Acquire all the data into a single array.
set data = `cat $file.tmp`
#
# Remove the temporary file.
rm -f $file.tmp
#
# Initialize the final file.
df -h . >! $file.log
#
# Start an array-element counter.
set icnt = 0
#
# Loop over the array elements, two at a time.
while ( $icnt < $#data )
    #
    # Increment the array-element counter.
    @ icnt = $icnt + 1
    #
    # Get the size datum.
    set size = $data[$icnt]
    #
    # Increment the array-element counter.
    @ icnt = $icnt + 1
    #
    # Get the mirror datum.
    set mirr = $data[$icnt]
    #
    # Calculate the size of the blank space to
    # _ be inserted in front of the line.
    @ nchr = 10 - `echo -n $size | wc -c`
    #
    # Start a character counter.
    set ichr = 0
    #
    # Start the blank space.
    set spcs = ""
    #
    # Loop over the blank spaces.
    while ( $ichr < $nchr )
	#
	# Increment the character counter.
	@ ichr = $ichr + 1
	#
	# Increase the blank space.
	set spcs = "$spcs "
	#
    end
    #
    # Write out the formatted line to the final file.
    echo "$spcs$size\t$mirr" >> $file.log
    #
end
