gluon/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/320-gluon-client-bridge-wireless
Matthias Schiffer 293a45456b
gluon-core, gluon-client-bridge: use new gluon.site library in gluon.util
In particular, this affects users of gluon.util.iterate_radios.
2017-08-08 14:07:09 +02:00

52 lines
1.0 KiB
Lua
Executable File

#!/usr/bin/lua
local site = require 'gluon.site_config'
local util = require 'gluon.util'
local uci = require('simple-uci').cursor()
local function is_disabled(config, name)
if uci:get('wireless', name) then
return uci:get_bool('wireless', name, 'disabled')
end
return config.disabled(false)
end
local function configure_client(config, radio, index, suffix)
local name = 'client_' .. radio
local disabled = is_disabled(config, name)
uci:delete('wireless', name)
if not config() then
return
end
local macaddr = util.get_wlan_mac(uci, radio, index, 1)
if not macaddr then
return
end
uci:section('wireless', 'wifi-iface', name, {
device = radio,
network = 'client',
mode = 'ap',
ssid = config.ssid(),
macaddr = macaddr,
ifname = suffix and 'client' .. suffix,
disabled = disabled or false,
})
end
local function configure_radio(radio, index, config)
local suffix = radio:match('^radio(%d+)$')
configure_client(config.ap, radio, index, suffix)
end
util.iterate_radios(uci, configure_radio)
uci:save('wireless')