#! /bin/sh
# $Id: checkpoint,v 1.1.1.1 2004/12/14 12:47:31 root Exp $
########################################################################

die () {
  echo "$0: FATAL" "$@" 1>&2
  exit -1
}

error () {
  echo "$0: ERROR" "$@" 1>&2
}

shadow () {
  file=$1
  dir=`dirname $1`
  rm -f shadow$file
  [ -d shadow$dir ] || mkdir -p shadow$dir
  cp -dp $file shadow$file
}

########################################################################

cd /home/CONFIGURATION || die "can't cd /home/CONFIGURATION"
dpkg --get-selections > dpkg-selection

grep '^/' files | while read file; do
  if [ -r $file ]; then
    if [ $file -nt shadow$file ]; then
      shadow $file
    elif diff -a -I '\$[I][d]:.*\$' $file shadow$file; then
      :
    else
      shadow $file
    fi
  else
    shadow $file
  fi
done

if [ X"$1" = Xtest ]; then
  cvs update
else
  cvs commit -m "checkpoint `date`"
fi
