#!/usr/bin/lua

local sysconfig = require 'gluon.sysconfig'
local util = require 'gluon.util'

local uci = require('simple-uci').cursor()


uci:delete('batman-adv', 'bat0')
uci:save('batman-adv')

local gw_mode = uci:get('network_gluon-old', 'gluon_bat0', 'gw_mode') or 'client'
uci:section('network', 'interface', 'gluon_bat0', {
	proto = 'gluon_bat0',
	gw_mode = gw_mode,
})

uci:section('network', 'interface', 'bat0', {
	ifname = 'bat0',
	proto = 'none',
	auto = true,
	macaddr = sysconfig.primary_mac,
	multicast_router = 2,
	learning = true,
})

local interfaces = uci:get_list('network', 'client', 'ifname')
util.add_to_set(interfaces, 'bat0')
uci:set_list('network', 'client', 'ifname', interfaces)

uci:save('network')
