#!/bin/bash
# $Header: /cvs/WebShield/wsrc/files/mgmt/update_config,v 1.8 2004/06/22 14:19:56 bwhittak Exp $
#
# Copyright (C) 2004 Networks Associates Technology Inc. All rights reserved.
#
# Apply any necessary updates to restored config and update system info from it.

if [ -f $NETAWSS/.profile.vars ]; then
    . $NETAWSS/.profile.vars
else
    . /var/NAIENV/.profile.vars
fi
[[ "$PATH" == "$wsPATH":* || -z "$wsPATH" ]] || PATH=$wsPATH:$PATH

shopt -s extglob

indir=${1:-$XMLCONFDIR}	# input directory with old config files
outdir=${2:-$XMLCONFDIR} # output directory for new config files
[[ $indir == /* ]] || indir=$PWD/$indir
[[ $outdir == /* ]] || outdir=$PWD/$outdir
protodir=$NETAWSS/proto/xmlconfdir
upgxml=$protodir/upgrade.xml
inxml=$indir/WebShield.xml

[[ -s $inxml ]] || exit	# no old config input

update_config_ex "$indir"	# bring pre-2.7 config to 2.7 state

# upgrade rules
cp --no-preserve=all "$protodir/rules.xml" "$outdir"
( cd /opt/NETAeSCM/eplugin &&
    ./xmltool +u +2 "$indir/ContentScanning.xml" +r "$outdir/rules.xml" )

# upgrade everything else
for f in $protodir/!(rules|upgrade).xml; do
    xml-upgrade "$upgxml" "$inxml" "$f" "$outdir/${f##*/}"
done

exit 0
