#!/bin/sh

. /etc/functions.sh
. /etc/apply_mapping

if   [ -n "$1" ]; then
    changed_conf=$1
else
    changed_conf=`uci fchanges`
    [ -z "$changed_conf" ] && return
fi

ha_enable=`uci get ucarp.general.status`
ha_role=`uci get ucarp.general.role`
[ "$ha_enable" = "enable" -a "$ha_role" = "master" ] && {
    revision=`tail -n 1 /tmp/ucarp/revision`
    revision=$(($revision+1))
    tar -cz -f "/tmp/ucarp/$revision.tar.gz" /tmp/.uci/* 2> /dev/null
    sed -i '3,$d' /tmp/ucarp/revision
    echo "$revision" >> /tmp/ucarp/revision
}

	

for conf in $changed_conf; do
	eval \$$conf
done
