#!/bin/sh
#
#NAME
#	Save - save files to a backup directory
#
#SYNOPSIS
#	Save [dir [savedir]]
#
#DESCRIPTION
#  Save all the files in the .savelist file.  The default directories
#  are /etc/ and /etc/.save/.
#
#  If there is a .savelist file, we scan it to get the list of  files
#  that  are  to  be  saved.  If not, we build the .savelist file and
#  populate it with a standard set of file names.
#
#  This is part of an on-disk backup package. It is typically run via
#  cron(1)  to  make  sure  that  valuable files are replicated.  The
#  Restore command exists to quickly restore all the files  to  their
#  backed-up states.
#
#SEE ALSO
#  Restore
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>

if	[ $# -lt 1 ];then set /etc/ /etc/.save;fi
if	[ $# -lt 2 ];then set  $*   /etc/.save;fi
if	[ !  -d $1 ];then echo $1 is not a directory; exit 1; fi
if	[ !  -d $2 ];then mkdir -p $2;fi
if	[ ! -f $1/.savelist ];then
	echo  >$1/.savelist .savelist
	if [ -f $1/getty    ];then echo>>$1/.savelist getty   ;fi
	if [ -f $1/group    ];then echo>>$1/.savelist group   ;fi
	if [ -f $1/hosts    ];then echo>>$1/.savelist hosts   ;fi
	if [ -f $1/passwd   ];then echo>>$1/.savelist passwd  ;fi
	if [ -f $1/rc       ];then echo>>$1/.savelist rc      ;fi
	if [ -f $1/rc.local ];then echo>>$1/.savelist rc.local;fi
	if [ -f $1/svc.conf ];then echo>>$1/.savelist svc.conf;fi
	if [ -f $1/ttys     ];then echo>>$1/.savelist ttys    ;fi
	if [ -f $1/uutty    ];then echo>>$1/.savelist uutty   ;fi
fi
for f in `cat $1/.savelist`
do	newer $2/$f $1/$f ||  cp $1/$f $2/$f
done
