From f73d727ae6d5bc6503a0d6cf7a7c5105af47299c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 10 Jul 2014 23:44:06 +0200 Subject: [PATCH] Remove all remaining uses of sysconfig.sh --- package/gluon-autoupdater/Makefile | 2 +- package/gluon-core/Makefile | 2 +- .../gluon/upgrade/core/initial/001-sysconfig | 70 +++++++++---------- .../upgrade/core/initial/011-gluon-network | 56 ++++++++------- .../gluon/upgrade/core/legacy/001-sysconfig | 67 +++++++++--------- .../upgrade/core/legacy/011-gluon-network | 38 +++++----- .../upgrade/mesh-batman-adv/initial/010-mesh | 32 +++++---- package/gluon-setup-mode/Makefile | 2 +- .../files/etc/init.d/gluon-setup-mode | 4 +- package/gluon-status-page/Makefile | 2 +- 10 files changed, 145 insertions(+), 130 deletions(-) diff --git a/package/gluon-autoupdater/Makefile b/package/gluon-autoupdater/Makefile index 3e555a0b..a885a0d0 100644 --- a/package/gluon-autoupdater/Makefile +++ b/package/gluon-autoupdater/Makefile @@ -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 diff --git a/package/gluon-core/Makefile b/package/gluon-core/Makefile index 5dbaee00..27babd75 100644 --- a/package/gluon-core/Makefile +++ b/package/gluon-core/Makefile @@ -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 diff --git a/package/gluon-core/files/lib/gluon/upgrade/core/initial/001-sysconfig b/package/gluon-core/files/lib/gluon/upgrade/core/initial/001-sysconfig index afabb2df..1e6c56d8 100755 --- a/package/gluon-core/files/lib/gluon/upgrade/core/initial/001-sysconfig +++ b/package/gluon-core/files/lib/gluon/upgrade/core/initial/001-sysconfig @@ -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 diff --git a/package/gluon-core/files/lib/gluon/upgrade/core/initial/011-gluon-network b/package/gluon-core/files/lib/gluon/upgrade/core/initial/011-gluon-network index 17ca50ee..1bc3514f 100755 --- a/package/gluon-core/files/lib/gluon/upgrade/core/initial/011-gluon-network +++ b/package/gluon-core/files/lib/gluon/upgrade/core/initial/011-gluon-network @@ -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') diff --git a/package/gluon-legacy/files/lib/gluon/upgrade/core/legacy/001-sysconfig b/package/gluon-legacy/files/lib/gluon/upgrade/core/legacy/001-sysconfig index 4fb4a39a..52e91a3b 100755 --- a/package/gluon-legacy/files/lib/gluon/upgrade/core/legacy/001-sysconfig +++ b/package/gluon-legacy/files/lib/gluon/upgrade/core/legacy/001-sysconfig @@ -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 diff --git a/package/gluon-legacy/files/lib/gluon/upgrade/core/legacy/011-gluon-network b/package/gluon-legacy/files/lib/gluon/upgrade/core/legacy/011-gluon-network index dd9c6ca5..79b63996 100755 --- a/package/gluon-legacy/files/lib/gluon/upgrade/core/legacy/011-gluon-network +++ b/package/gluon-legacy/files/lib/gluon/upgrade/core/legacy/011-gluon-network @@ -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') diff --git a/package/gluon-mesh-batman-adv/files/lib/gluon/upgrade/mesh-batman-adv/initial/010-mesh b/package/gluon-mesh-batman-adv/files/lib/gluon/upgrade/mesh-batman-adv/initial/010-mesh index 42206d00..5b275099 100755 --- a/package/gluon-mesh-batman-adv/files/lib/gluon/upgrade/mesh-batman-adv/initial/010-mesh +++ b/package/gluon-mesh-batman-adv/files/lib/gluon/upgrade/mesh-batman-adv/initial/010-mesh @@ -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') diff --git a/package/gluon-setup-mode/Makefile b/package/gluon-setup-mode/Makefile index 9fda3d9a..39952ddd 100644 --- a/package/gluon-setup-mode/Makefile +++ b/package/gluon-setup-mode/Makefile @@ -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 diff --git a/package/gluon-setup-mode/files/etc/init.d/gluon-setup-mode b/package/gluon-setup-mode/files/etc/init.d/gluon-setup-mode index 6abff8eb..53f18360 100755 --- a/package/gluon-setup-mode/files/etc/init.d/gluon-setup-mode +++ b/package/gluon-setup-mode/files/etc/init.d/gluon-setup-mode @@ -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 diff --git a/package/gluon-status-page/Makefile b/package/gluon-status-page/Makefile index db7cc7bd..d0e9d488 100644 --- a/package/gluon-status-page/Makefile +++ b/package/gluon-status-page/Makefile @@ -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