#!/bin/sh
. /lib/functions.sh

CONFIG_PATH="${UCI_CONFIG_DIR:-"/etc/config"}"

add_role() {
	uci_set "port_security" "$1" "role" "server"
	enabled=$(uci_get "port_security" "$1" "dot1x_enable")
	uci_set "port_security" "$1" "dot1x_enable" ""
	uci_set "port_security" "$1" "enabled" "$enabled"
}

if [ ! -s "$CONFIG_PATH/dot1x" ]; then
	config_load "port_security"
	config_foreach "add_role" "port"
	uci_commit port_security
	mv "$CONFIG_PATH/port_security" "$CONFIG_PATH/dot1x"
fi
