#!/bin/sh
#
# @(#)backup.sh	3.4 99/12/06 Sun Microsystems, Inc.
#
# Build an archive of all the SKIP files and SunScreen configuration data
# and write it all to stdout as a tar file.
#

PATH="/opt/SUNWicg/SunScreen/ssadm:/usr/bin:/usr/sbin/"
export PATH

CONFIGS=/etc/opt/SUNWicg/SunScreen/configs
TMPDIR=/etc/opt/SUNWicg/SunScreen/.backup_temp
SS_LIBDIR=/opt/SUNWicg/SunScreen/lib

set_num=64	# SI18N_CONFIG_BIN_BACKUP_RESTORE
LS()		# localize a string
{
	msg_num=$1; shift
	if [ -x ${SS_LIBDIR}/catgets ]
	then ${SS_LIBDIR}/catgets $set_num $msg_num "$*"
	else echo "$*\c"
	fi
}

usage()
{
    echo>&2 "`LS 1 Usage`: ssadm backup [-v]"
    exit 1;
}

set -e

domain=default
v=
while getopts vD: c
do case $c in
   v) v=-v;;
   D) domain=$OPTARG;;
   *) usage;;
   esac
done

if [ ! -d "$CONFIGS/$domain" ]
then msg=`LS 2 "No such domain"`
     echo>&2 "ssadm backup: $domain: "
     exit 1
fi

# make temp dir
rm -rf $TMPDIR >/dev/null 2>&1
mkdir -m 0700 $TMPDIR
cd $TMPDIR

# This following line is to allow some rudimentary analysis of any
# failure of the backup operation by examining the error output.
#exec 3>&2 2>BackupOutput; set -x

# tar localid(s) & CA(s)
( cd /etc/skip
  exec tar -cf - localid CAs certdb
) >SunScreenSKIPBackup.3.0.tar

# save configurations
( cd $CONFIGS/$domain
  IFS='
'
  exec tar -cf - Registry .ezdb `policy -l $v`
) >SunScreenConfigurationBackup.3.0.tar

# tar up the files and send to stdout
tar -cf - *

# clean up
cd /
rm -rf $TMPDIR
