#------------------------------------------------------------------------------
# /etc/rc0.d/tcfromto - copy files on shutdown
#
# Creation:	06.02.2002 Timo Tamm (tita2000@gmx.de)
# Last Update:  06.02.2002 Timo Tamm 
#------------------------------------------------------------------------------

/usr/bin/grep TCFROMTO /etc/rc.cfg > /tmp/tcfromto.sh

. /tmp/tcfromto.sh

if [ "$OPT_TCFROMTO" = "yes" ]
then
  colecho " " gn
  colecho "script TCFROMTO is going to be executed ..." gn
  colecho " " gn
  idx=1
  while [ "$idx" -le "$TCFROMTO_N" ]
  do
    eval source='$TCFROMTO_'$idx'_FROM'
    eval dest='$TCFROMTO_'$idx'_TO'    
    eval file='$TCFROMTO_'$idx'_NAME'
    eval mode='$TCFROMTO_'$idx'_MODE'
    eval back='$TCFROMTO_'$idx'_BACK'

    if [ -d "$source" ]
    then
      if [ -d "$dest" ]
      then
        if [ -f "$source/$file" ]
        then
          if [ -f "$dest/$file" ]
          then
            case $back
            in
            "0"*)
              rm $dest"/"$file
            ;;
            "1"*)
              cp $dest"/"$file $dest"/"$file".bak"
              colecho "backup : $file as $file.bak"
            ;;
            "2"*)
              cp $dest"/"$file $dest"/"$file"."$(date +%y%m%d)$(date +%H%M)
              colecho "backup : $file as $file.$(date +%y%m%d)$(date +%H%M)"
            ;;
            esac
          fi  
          case $mode
          in
          "0"*)
	    cp $source"/"$file $dest
            colecho "file : $file is copied from $source to $dest." gn
          ;;
          "1"*)
          ;;
          "2"*)
	    cp $source"/"$file $dest
            colecho "file : $file is copied from $source to $dest." gn
          ;;
          esac
        else
          colecho "file : $file doesn't exist in $source." rd
        fi
      else
        colecho "destination path : $dest doesn't exist." rd
      fi
    else
      colecho "source path : $source doesn't exist." rd
    fi
    idx=`/usr/bin/expr $idx + 1`
  done
  colecho " " gn
  colecho "finished executing TCFROMTO." gn
  colecho " " gn
fi

