#!/bin/sh

# Mark changes
#-------------

CHECK=`grep "^rule_mark_base[[:space:]]*=[[:space:]]*0x9000$" /etc/netify-fwa.conf`
if [ -n "$CHECK" ]; then
    logger -p local6.notice -t installer "app-netify-fwa-core - updating base mark value"
    sed -i -e 's/^rule_mark_base[[:space:]]*=.*/rule_mark_base = 0x900000/' /etc/netify-fwa.conf
fi

CHECK=`grep "0x9000" /etc/netify-fwa.conf`
if [ -n "$CHECK" ]; then
    logger -p local6.notice -t installer "app-netify-fwa-core - cleaning up protocol mark"
    sed -i -e 's/0x9000,//' /etc/netify-fwa.conf
fi

CHECK=`grep "0x10000" /etc/netify-fwa.conf`
if [ -n "$CHECK" ]; then
    logger -p local6.notice -t installer "app-netify-fwa-core - cleaning up application mark"
    sed -i -e 's/0x10000,//' /etc/netify-fwa.conf
fi

# Restart with an empty state after an upgrade
#---------------------------------------------

if [ -e /var/run/netify-fwa/netify-fwa.pid ]; then
    service netify-fwa stop >/dev/null 2>&1
    rm -f /var/lib/netify-fwa/state.dat
    service netify-fwa start >/dev/null 2>&1
    sleep 1
    service firewall restart >/dev/null 2>&1
fi
