Remove all remaining uses of sysconfig.sh

This commit is contained in:
Matthias Schiffer 2014-07-10 23:44:06 +02:00
parent 7773afdc18
commit f73d727ae6
10 changed files with 145 additions and 130 deletions

View File

@ -11,7 +11,7 @@ include $(GLUONDIR)/include/package.mk
define Package/gluon-autoupdater
SECTION:=gluon
CATEGORY:=Gluon
DEPENDS:=+gluon-core +gluon-cron +lua-platform-info +opkg +ecdsautils +!BUSYBOX_CONFIG_SHA512SUM:coreutils-sha512sum
DEPENDS:=+gluon-core +gluon-cron +opkg +ecdsautils +!BUSYBOX_CONFIG_SHA512SUM:coreutils-sha512sum
TITLE:=Automatically update firmware
endef

View File

@ -12,7 +12,7 @@ define Package/gluon-core
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Base files of Gluon
DEPENDS:=+gluon-config +luci-lib-core +odhcp6c
DEPENDS:=+gluon-config +lua-platform-info +luci-lib-core +odhcp6c
endef
define Package/gluon-core/description

View File

@ -1,42 +1,42 @@
#!/bin/sh
#!/usr/bin/lua
. /lib/gluon/functions/sysconfig.sh
. /lib/ar71xx.sh
local sysconfig = require 'gluon.sysconfig'
local gluon_util = require 'gluon.util'
local fs = require 'luci.fs'
local uci = require('luci.model.uci').cursor()
local util = require 'luci.util'
local platform_info = require 'platform_info'
get_primary_mac() {
case "$(ar71xx_board_name)" in
tl-wdr3600|tl-wdr4300)
cat /sys/class/ieee80211/phy1/macaddress
;;
*)
cat /sys/class/ieee80211/phy0/macaddress
;;
esac
}
local board_name = platform_info.get_board_name()
iface_exists() {
local name="$1"
ip link show dev "${name//.*/}" >/dev/null 2>&1
}
case "$(ar71xx_board_name)" in
nanostation-m)
# It's more convenient to swap the ports for these devices so WAN is the PoE port
lan_ifname="$(uci get network.wan.ifname)"
wan_ifname="$(uci get network.lan.ifname)"
;;
*)
lan_ifname="$(uci get network.lan.ifname)"
wan_ifname="$(uci get network.wan.ifname)"
;;
esac
if [ -n "$wan_ifname" ] && iface_exists "$wan_ifname"; then
[ -z "$lan_ifname" ] || sysconfig_set lan_ifname "$lan_ifname"
sysconfig_set wan_ifname "$wan_ifname"
if board_name == 'tl-wdr3600' or board_name == 'tl-wdr4300' then
sysconfig.primary_mac = util.trim(fs.readfile('/sys/class/ieee80211/phy1/macaddress'))
else
sysconfig_set wan_ifname "$lan_ifname"
fi
sysconfig.primary_mac = util.trim(fs.readfile('/sys/class/ieee80211/phy0/macaddress'))
end
sysconfig_set primary_mac "$(get_primary_mac)"
local function iface_exists(name)
return (gluon_util.exec('ip', 'link', 'show', 'dev', (name:gsub('%..*$', ''))) == 0)
end
local lan_ifname = uci:get('network', 'lan', 'ifname')
local wan_ifname = uci:get('network', 'wan', 'ifname')
if board_name == 'nanostation-m' then
lan_ifname, wan_ifname = wan_ifname, lan_ifname
end
if wan_ifname and iface_exists(wan_ifname) then
sysconfig.wan_ifname = wan_ifname
sysconfig.lan_ifname = lan_ifname
else
sysconfig.wan_ifname = lan_ifname
end

View File

@ -1,32 +1,36 @@
#!/bin/sh
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
local uci = require('luci.model.uci').cursor()
local util = require 'luci.util'
local nixio = require 'nixio'
local platform_info = require 'platform_info'
. /lib/functions.sh
. /lib/gluon/functions/sysconfig.sh
. /lib/ar71xx.sh
uci:delete('network', 'lan')
uci:delete('network', 'wan')
uci:section('network', 'interface', 'wan',
{
ifname = sysconfig.wan_ifname,
type = 'bridge',
proto = 'dhcp',
}
)
uci_remove network lan
uci_remove network wan
if util.contains({'tl-wr1043nd', 'tl-wdr3600', 'tl-wdr4300'}, platform_info.get_board_name()) then
-- fix up duplicate mac addresses
local m1, m2, m3, m4, m5, m6 = string.match(sysconfig.primary_mac, '(%x%x):(%x%x):(%x%x):(%x%x):(%x%x):(%x%x)')
m1 = nixio.bit.bor(tonumber(m1, 16), 0x02)
m4 = (tonumber(m4, 16)+1) % 0x100
m6 = (tonumber(m6, 16)+1) % 0x100
local wanaddr = string.format('%02x:%s:%s:%02x:%s:%02x', m1, m2, m3, m4, m5, m6)
uci_add network interface wan
uci_set network wan ifname "$(sysconfig wan_ifname)"
uci_set network wan type 'bridge'
uci_set network wan proto 'dhcp'
uci:set('network', 'wan', 'macaddr', wanaddr)
end
case "$(ar71xx_board_name)" in
tl-wr1043nd|\
tl-wdr3600|\
tl-wdr4300) # fix up duplicate mac addresses
local mainaddr=$(sysconfig primary_mac)
local oIFS="$IFS"; IFS=":"; set -- $mainaddr; IFS="$oIFS"
local b2mask=0x02
local wanaddr=$(printf "%02x:%s:%s:%02x:%s:%02x" $(( 0x$1 | $b2mask )) $2 $3 $(( (0x$4 + 1) % 0x100 )) $5 $(( (0x$6 + 1) % 0x100 )) )
uci_set network wan macaddr "$wanaddr"
;;
esac
uci_commit network
uci:save('network')
uci:commit('network')

View File

@ -1,39 +1,42 @@
#!/bin/sh
#!/usr/bin/lua
. /lib/gluon/functions/sysconfig.sh
. /lib/ar71xx.sh
local sysconfig = require 'gluon.sysconfig'
local gluon_util = require 'gluon.util'
local site = require 'gluon.site_config'
local fs = require 'luci.fs'
local uci = require('luci.model.uci').cursor()
local util = require 'luci.util'
local platform_info = require 'platform_info'
get_primary_mac() {
case "$(ar71xx_board_name)" in
tl-wdr3600|tl-wdr4300)
cat /sys/class/ieee80211/phy1/macaddress
;;
*)
cat /sys/class/ieee80211/phy0/macaddress
;;
esac
}
iface_exists() {
local name="$1"
ip link show dev "${name//.*/}" >/dev/null 2>&1
}
remove_bat0() {
sed -r -e 's/(^| )bat0( |$)/ /g' -e 's/^ | $//g'
}
local board_name = platform_info.get_board_name()
mesh_section="$(lua -e 'print(require("gluon.site_config").legacy.mesh_ifname)')"
mesh_ifname="$(uci get "network.${mesh_section}.ifname" | remove_bat0)"
wan_ifname="$(uci get network.wan.ifname)"
if [ -n "$wan_ifname" ] && iface_exists "$wan_ifname"; then
[ -z "$mesh_ifname" ] || sysconfig_set lan_ifname "$mesh_ifname"
sysconfig_set wan_ifname "$wan_ifname"
if board_name == 'tl-wdr3600' or board_name == 'tl-wdr4300' then
sysconfig.primary_mac = util.trim(fs.readfile('/sys/class/ieee80211/phy1/macaddress'))
else
sysconfig_set wan_ifname "$mesh_ifname"
fi
sysconfig.primary_mac = util.trim(fs.readfile('/sys/class/ieee80211/phy0/macaddress'))
end
sysconfig_set primary_mac "$(get_primary_mac)"
local function iface_exists(name)
return (gluon_util.exec('ip', 'link', 'show', 'dev', (name:gsub('%..*$', ''))) == 0)
end
local function remove_bat0(iface)
return util.trim(string.gsub(' ' .. iface .. ' ', ' bat0 ', ' '))
end
local lan_ifname = remove_bat0(uci:get('network', site.legacy.mesh_ifname, 'ifname'))
local wan_ifname = uci:get('network', 'wan', 'ifname')
if wan_ifname and iface_exists(wan_ifname) then
sysconfig.wan_ifname = wan_ifname
sysconfig.lan_ifname = lan_ifname
else
sysconfig.wan_ifname = lan_ifname
end

View File

@ -1,22 +1,24 @@
#!/bin/sh
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
local uci = require('luci.model.uci').cursor()
local util = require 'luci.util'
local nixio = require 'nixio'
local platform_info = require 'platform_info'
. /lib/functions.sh
. /lib/gluon/functions/sysconfig.sh
if util.contains({'tl-wr1043nd', 'tl-wdr3600', 'tl-wdr4300'}, platform_info.get_board_name()) then
-- fix up duplicate mac addresses
local m1, m2, m3, m4, m5, m6 = string.match(sysconfig.primary_mac, '(%x%x):(%x%x):(%x%x):(%x%x):(%x%x):(%x%x)')
m1 = nixio.bit.bor(tonumber(m1, 16), 0x02)
m4 = (tonumber(m4, 16)+1) % 0x100
m6 = (tonumber(m6, 16)+1) % 0x100
local wanaddr = string.format('%02x:%s:%s:%02x:%s:%02x', m1, m2, m3, m4, m5, m6)
uci:set('network', 'wan', 'macaddr', wanaddr)
end
case "$(ar71xx_board_name)" in
tl-wr1043nd|\
tl-wdr3600|\
tl-wdr4300) # fix up duplicate mac addresses
local mainaddr=$(sysconfig primary_mac)
local oIFS="$IFS"; IFS=":"; set -- $mainaddr; IFS="$oIFS"
local b2mask=0x02
local wanaddr=$(printf "%02x:%s:%s:%02x:%s:%02x" $(( 0x$1 | $b2mask )) $2 $3 $(( (0x$4 + 1) % 0x100 )) $5 $(( (0x$6 + 1) % 0x100 )) )
uci_set network wan macaddr "$wanaddr"
;;
esac
uci_commit network
uci:save('network')
uci:commit('network')

View File

@ -1,18 +1,26 @@
#!/bin/sh
#!/usr/bin/lua
. /lib/functions.sh
. /lib/gluon/functions/sysconfig.sh
local sysconfig = require 'gluon.sysconfig'
local uci = require('luci.model.uci').cursor()
lan_ifname="$(sysconfig lan_ifname)"
uci_add network interface client
local ifname
if [ -n "$lan_ifname" ]; then
uci_set network client ifname "$lan_ifname bat0"
if sysconfig.lan_ifname then
ifname = sysconfig.lan_ifname .. ' bat0'
else
uci_set network client ifname "bat0"
fi
ifname = 'bat0'
end
uci_set network client type 'bridge'
uci_set network client proto 'dhcpv6'
uci_set network client reqprefix 'no'
uci:section('network', 'interface', 'client',
{
ifname = ifname,
type = 'bridge',
proto = 'dhcpv6',
reqprefix = 'no',
}
)
uci:save('network')
uci:commit('network')

View File

@ -14,7 +14,7 @@ define Package/gluon-setup-mode
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Setup mode
DEPENDS:=+gluon-core +lua-platform-info +uhttpd +dnsmasq +ip
DEPENDS:=+gluon-core +uhttpd +dnsmasq +ip
endef
define Package/gluon-setup-mode/description

View File

@ -35,7 +35,7 @@ setup_network() {
config_foreach delete_interface interface
uci_add network interface setup
uci_set network setup ifname "$(sysconfig setup_ifname)"
uci_set network setup ifname "$(lua -e 'print(require("gluon.sysconfig").setup_ifname)')"
uci_set network setup type 'bridge'
uci_set network setup proto 'static'
uci_set network setup ipaddr "$SETUP_MODE_ADDR"
@ -55,8 +55,6 @@ setup_network() {
}
start() {
. /lib/gluon/functions/sysconfig.sh
enable=0
config_load gluon-setup-mode
config_foreach check_enable setup_mode

View File

@ -12,7 +12,7 @@ define Package/gluon-status-page
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Adds a status page showing information about the node.
DEPENDS:=+gluon-core +lua-platform-info +uhttpd
DEPENDS:=+gluon-core +uhttpd
endef
define Package/gluon-status-page/description