"gluon-node-info": add section system and option role; add announce script to announce the role as nodeinfo;

add invariant script "001-node-system" to add section "system" if not exist; add invariant script "010-node-role"
to add section "system" if not exist; add invariant script "010-node-role" to set role to default value
(site.roles.default) if not exist; depends on new site.conf section
This commit is contained in:
Kokel 2015-01-11 00:07:00 +01:00
parent 7b81b4a457
commit 547574d7da
6 changed files with 50 additions and 1 deletions

View File

@ -6,7 +6,7 @@ PKG_RELEASE:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
include $(GLUONDIR)/include/package.mk
define Package/gluon-node-info
SECTION:=gluon
@ -33,4 +33,9 @@ define Package/gluon-node-info/install
$(CP) ./files/* $(1)/
endef
define Package/gluon-node-info/postinst
#!/bin/sh
$(call GluonCheckSite,check_site.lua)
endef
$(eval $(call BuildPackage,gluon-node-info))

View File

@ -0,0 +1,8 @@
local function check_role(k, _)
local role = string.format('roles.list[%q]', k)
need_string(role)
end
need_string('roles.default', false)
need_table('roles.list', check_role, false)

View File

@ -2,3 +2,5 @@ config location
option share_location '0'
config owner
config system

View File

@ -0,0 +1,4 @@
local role = uci:get_first('gluon-node-info', 'system', 'role', '')
if role ~= '' then
return role
end

View File

@ -0,0 +1,11 @@
#!/usr/bin/lua
local uci = require('luci.model.uci').cursor()
local config = 'gluon-node-info'
if not uci:get_first(config, 'system') then
uci:section(config, 'system')
uci:save(config)
uci:commit(config)
end

View File

@ -0,0 +1,19 @@
#!/usr/bin/lua
local site = require 'gluon.site_config'
local uci = require('luci.model.uci').cursor()
local config = 'gluon-node-info'
local role = uci:get(config, uci:get_first(config, 'system'), 'role')
if site.roles then
default_role = site.roles.default
else
default_role = ''
end
if not role then
uci:set(config, uci:get_first(config, 'system'), 'role', default_role)
uci:save(config)
uci:commit(config)
end