#!/bin/bash

# This program is part of the tbackup package,
# (c) 1993,1994 Koen Holtman.
#
# The tbackup package is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
# No warranty. See the GNU General Public License for more details.

#Lists the configured directory sets in a machine readable form.

#output format: for each existing set, the following lines are printed:

#-set name

#-commment in set file describing set

#if a full backup was made:
# -a line containing the string "lastfull"
# -date of last full in human readable form
# -approx. days past since then

#if an incremental backup was made after the last full backup:
# -a line containing the string "lastinc"
# -date of last inc in human readable form
# -approx. days past since then

#-a line containing the string "[END]"


cd /tmp

export now2=`expr \`date +%j\` + 365 \* \`date +%Y\``

for met in /etc/tbackup/*.set ; do 

  setname=`basename $met .set`
  echo $setname
  head -1 $met

  if [ -e /etc/tbackup/$setname.log ]; then
   grep "^f " /etc/tbackup/$setname.log | tail -1 >listsets.$$tmp
   if [ -s listsets.$$tmp ]; then
    nowyy=`gawk "{ print \\\$3; }" listsets.$$tmp`
    echo lastfull
    gawk -F/ '{ print substr($2,2); }' listsets.$$tmp
    expr $now2 - $nowyy
   fi
  
   gawk -f- /etc/tbackup/$setname.log >listsets.$$tmp <<-WUXTA
BEGIN { i=""; }
\$1 == "f" { i=""; }
\$1 == "if" { i=\$0; }
\$1 == "ii" { i=\$0; }
END { if(i!="") print i; }
WUXTA
   if [ -s listsets.$$tmp ]; then
    nowzz=`gawk "{ print \\\$3; }" listsets.$$tmp`
    echo lastinc
    gawk -F/ '{ print substr($2,2); }' listsets.$$tmp
    expr $now2 - $nowzz
   fi
  
  fi

  echo "[END]"

done

rm listsets.$$tmp