From 22130e84e88618b8cfb93fe8fbff859c3e0115fa Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Mon, 26 Oct 2015 20:59:56 +0100
Subject: [PATCH] Merge gluon-radio-config into gluon-core

gluon-radio-config contained only a single file. The code has been adjusted
to allow creating a Gluon configuration without WLAN support by removing
the wifi24 and wifi5 sections from site.conf.
---
 docs/index.rst                                |  8 -----
 docs/package/gluon-radio-config.rst           | 20 ------------
 docs/user/site.rst                            |  8 +++--
 package/gluon-core/check_site.lua             | 10 ++++++
 .../files/lib/gluon/upgrade/200-wireless      | 20 ++++++++++--
 package/gluon-mesh-batman-adv-core/Makefile   |  2 +-
 package/gluon-radio-config/Makefile           | 31 -------------------
 .../lib/gluon/upgrade/250-gluon-radio-config  | 18 -----------
 8 files changed, 34 insertions(+), 83 deletions(-)
 delete mode 100644 docs/package/gluon-radio-config.rst
 delete mode 100644 package/gluon-radio-config/Makefile
 delete mode 100755 package/gluon-radio-config/files/lib/gluon/upgrade/250-gluon-radio-config

diff --git a/docs/index.rst b/docs/index.rst
index 34ab893f4..8af06f4fb 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -43,14 +43,6 @@ Developer Documentation
    dev/wan
    dev/i18n
 
-Packages
---------
-
-.. toctree::
-   :maxdepth: 1
-
-   package/gluon-radio-config
-
 Releases
 --------
 
diff --git a/docs/package/gluon-radio-config.rst b/docs/package/gluon-radio-config.rst
deleted file mode 100644
index b253b1545..000000000
--- a/docs/package/gluon-radio-config.rst
+++ /dev/null
@@ -1,20 +0,0 @@
-gluon-radio-config
-==================
-
-This package takes care of setting basic wireless settings:
-
-- regulatory domain
-- htmode
-- channel
-
-site.conf
----------
-
-regdom
-    regulatory domain (e.g. *de*)
-
-wifi24.channel / wifi5.channel
-    wireless channel for radio
-
-wifi24.htmode / wifi5.htmode
-    desired HT mode (e.g. *HT20*)
diff --git a/docs/user/site.rst b/docs/user/site.rst
index bcffa86c5..bcc811224 100644
--- a/docs/user/site.rst
+++ b/docs/user/site.rst
@@ -72,13 +72,15 @@ opkg : optional
     - ``%GV`` is replaced by the Gluon version
     - ``%GR`` is replaced by the Gluon release (as specified in ``site.mk``)
 
-regdom
+regdom : optional
     The wireless regulatory domain responsible for your area, e.g.:
     ::
 
       regdom = 'DE'
 
-wifi24
+    Setting ``regdom`` in mandatory if ``wifi24`` or ``wifi5`` is defined.
+
+wifi24 : optional
     WLAN configuration for 2.4 GHz devices.
     ``channel`` must be set to a valid wireless channel for your radio.
     ``htmode`` selects the desired htmode (e.g. HT20, HT40- or HT40+).
@@ -121,7 +123,7 @@ wifi24
          },
        },
 
-wifi5
+wifi5 : optional
     Same as `wifi24` but for the 5Ghz radio.
 
 next_node : package
diff --git a/package/gluon-core/check_site.lua b/package/gluon-core/check_site.lua
index 4217b626b..e752dd26f 100644
--- a/package/gluon-core/check_site.lua
+++ b/package/gluon-core/check_site.lua
@@ -21,3 +21,13 @@ need_string_array('ntp_servers', false)
 
 need_string_match('prefix4', '^%d+.%d+.%d+.%d+/%d+$')
 need_string_match('prefix6', '^[%x:]+/%d+$')
+
+
+for _, config in ipairs({'wifi24', 'wifi5'}) do
+  if need_table(config, nil, false) then
+    need_string('regdom') -- regdom is only required when wifi24 or wifi5 is configured
+
+    need_number(config .. '.channel')
+    need_string(config .. '.htmode')
+  end
+end
diff --git a/package/gluon-core/files/lib/gluon/upgrade/200-wireless b/package/gluon-core/files/lib/gluon/upgrade/200-wireless
index 219e505d3..ad47bb01b 100755
--- a/package/gluon-core/files/lib/gluon/upgrade/200-wireless
+++ b/package/gluon-core/files/lib/gluon/upgrade/200-wireless
@@ -1,5 +1,8 @@
 #!/usr/bin/lua
 
+local util = require 'gluon.util'
+local uci = require('luci.model.uci').cursor()
+local site = require 'gluon.site_config'
 local sysconfig = require 'gluon.sysconfig'
 
 -- Initial
@@ -7,6 +10,19 @@ if not sysconfig.gluon_version then
   local uci = require('luci.model.uci').cursor()
 
   uci:delete_all('wireless', 'wifi-iface')
-  uci:save('wireless')
-  uci:commit('wireless')
 end
+
+local function configure_radio(radio, index, config)
+  if config then
+    uci:delete('wireless', radio, 'disabled')
+
+    uci:set('wireless', radio, 'channel', config.channel)
+    uci:set('wireless', radio, 'htmode', config.htmode)
+    uci:set('wireless', radio, 'country', site.regdom)
+  end
+end
+
+util.iterate_radios(configure_radio)
+
+uci:save('wireless')
+uci:commit('wireless')
diff --git a/package/gluon-mesh-batman-adv-core/Makefile b/package/gluon-mesh-batman-adv-core/Makefile
index bb3dc5378..8358089cd 100644
--- a/package/gluon-mesh-batman-adv-core/Makefile
+++ b/package/gluon-mesh-batman-adv-core/Makefile
@@ -11,7 +11,7 @@ define Package/gluon-mesh-batman-adv-core
   SECTION:=gluon
   CATEGORY:=Gluon
   TITLE:=Support for batman-adv meshing (core)
-  DEPENDS:=+gluon-core +gluon-radio-config +firewall +libiwinfo-lua
+  DEPENDS:=+gluon-core +firewall +libiwinfo-lua
 endef
 
 define Build/Prepare
diff --git a/package/gluon-radio-config/Makefile b/package/gluon-radio-config/Makefile
deleted file mode 100644
index 9157e8044..000000000
--- a/package/gluon-radio-config/Makefile
+++ /dev/null
@@ -1,31 +0,0 @@
-include $(TOPDIR)/rules.mk
-
-PKG_NAME:=gluon-radio-config
-PKG_VERSION:=1
-
-PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
-
-include $(GLUONDIR)/include/package.mk
-
-define Package/gluon-radio-config
-  SECTION:=gluon
-  CATEGORY:=Gluon
-  TITLE:=Basic radio config (regdom, channel, htmode)
-  DEPENDS:=+gluon-core
-endef
-
-define Build/Prepare
-	mkdir -p $(PKG_BUILD_DIR)
-endef
-
-define Build/Configure
-endef
-
-define Build/Compile
-endef
-
-define Package/gluon-radio-config/install
-	$(CP) ./files/* $(1)/
-endef
-
-$(eval $(call BuildPackage,gluon-radio-config))
diff --git a/package/gluon-radio-config/files/lib/gluon/upgrade/250-gluon-radio-config b/package/gluon-radio-config/files/lib/gluon/upgrade/250-gluon-radio-config
deleted file mode 100755
index 62e6dcdee..000000000
--- a/package/gluon-radio-config/files/lib/gluon/upgrade/250-gluon-radio-config
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/lua
-
-local util = require 'gluon.util'
-local uci = require('luci.model.uci').cursor()
-local site = require 'gluon.site_config'
-
-local function configure_radio(radio, index, config)
-  uci:delete('wireless', radio, 'disabled')
-
-  uci:set('wireless', radio, 'channel', config.channel)
-  uci:set('wireless', radio, 'htmode', config.htmode)
-  uci:set('wireless', radio, 'country', site.regdom)
-end
-
-util.iterate_radios(configure_radio)
-
-uci:save('wireless')
-uci:commit('wireless')
-- 
GitLab