#!/bin/bash
#
##
# Advanced Policy Firewall (APF) v1.7.5
#             (C) 2002-2014, R-fx Networks <proj@rfxn.com>
#             (C) 2014, Ryan MacDonald <ryan@rfxn.com>
# This program may be freely redistributed under the terms of the GNU GPL v2
##
#
INSTALL_PATH="/etc/apf"
DEF=".ca.def"
DOUT=".conf.apf"

if [ -d "/etc/apf.bk.last" ]; then
# get all the vars from current release
. /etc/apf/conf.apf

# replace with any vars old release had
egrep -v '^\.' /etc/apf.bk.last/conf.apf > nosource.conf.apf
. nosource.conf.apf
rm nosource.conf.apf

old=`cat /etc/apf.bk.last/VERSION | awk '{print$2}' | sed 's/-/ /' | awk '{print$1}'`
if [ "$old" = "0.9.5" ] ; then
DEVEL_MODE="$DEVM"
INSTALL_PATH="$FWPATH"
IFACE_IN="${IF}"
IFACE_OUT="$IF"
IFACE_TRUSTED="$TIF"
SET_VNET="$EN_VNET"
SET_MONOKERN="$MONOKERN"
VF_LGATE="$LGATE_MAC"
TOS_DEF="$DEF_TOS"
ALL_STOP="$DSTOP"
BLK_PORTS="$CDPORTS"
LOG_APF="$IPTLOG"
LOG_LGATE="$LGATE_LOG"
LOG_DROP="$DROP_LOG"
LOG_EXT="$EXLOG"
LOG_RATE="$LRATE"
fi

# generate new conf
. $DEF

cp -f $INSTALL_PATH/conf.apf $INSTALL_PATH/conf.apf.orig

egrep -A 1000 '^\. \$CNFINT$' /etc/apf.bk.last/conf.apf | egrep -v '^\. \$CNFINT$' >> $DOUT

cp -f $DOUT $INSTALL_PATH/conf.apf
cp -f /etc/apf.bk.last/*_hosts.rules /etc/apf/ 2> /dev/null
cp -f /etc/apf.bk.last/vnet/*.rules /etc/apf/vnet/ 2> /dev/null

OV=`cat /etc/apf.bk.last/VERSION | awk '{print$2}'`
NV=`cat /etc/apf/VERSION | awk '{print$2}'`
        echo "  Imported options from $OV to $NV."
fi
