#!/bin/sh
#---------------------------------------------------------------------------
# /etc/rc0.d/sarfile
# (c) copyright 2002 by Reiner Schroeppel <reiner@schroeppel.info>
# see instructions for the licensing terms and conditions
# last modified 2002-11-15
# Version 2.0.1
#----------------------------------------------------------------------------

/usr/local/bin/colecho "Start saving persistant files..." gn

. /etc/sarfile.cfg

idx=1
while [ $idx -le $SARFILE_N ]; do
  eval source='$SARFILE_FILE_'$idx
  eval destination='$SARFILE_SAVETO_'$idx
  for i in $source; do
    if [ -f "$i" ]; then
      if [ ! -d "$destination" ]; then
        /usr/local/bin/colecho "  creating backup directory $destination/..." wh
        mkdir -p $destination
      fi
      /usr/local/bin/colecho "  copying $i to $destination/..." w
      cp $i $destination/
    else
      /usr/local/bin/colecho "  cannot find $i..." rd
    fi
  done
  idx=`expr $idx + 1`
done

/usr/local/bin/colecho "Done saving persistant files..." gn
/usr/local/bin/colecho "" w