#!/bin/sh

. /lib/functions.sh

index="0"

config_cb() {
	[ "${1}" = "ipsec" ] && uci_rename "ipsec" "$2" "global"
	[ "${1}" != "secret" ] && return
	[ "${2:0:3}" != "cfg" ] && return
	index=$((index + 1))

	#There are situations when names can be duplicated.
	#Get a unique section name here
	while uci_get "ipsec" "$index" >/dev/null 2>&1; do
		index=$((index + 1))
	done

	uci_rename "ipsec" "$2" "$index"
}

config_load "ipsec"
uci_commit "ipsec"

exit 0
