From ba81359c602d7177e3167d3002454cc6021ab524 Mon Sep 17 00:00:00 2001 From: Kokel Date: Sun, 11 Jan 2015 00:07:00 +0100 Subject: [PATCH] "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 --- package/gluon-node-info/Makefile | 7 ++++++- package/gluon-node-info/check_site.lua | 8 ++++++++ .../files/etc/config/gluon-node-info | 2 ++ .../lib/gluon/announce/nodeinfo.d/system/role | 4 ++++ .../node-info/invariant/001-node-system | 11 +++++++++++ .../upgrade/node-info/invariant/010-node-role | 19 +++++++++++++++++++ 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 package/gluon-node-info/check_site.lua create mode 100644 package/gluon-node-info/files/lib/gluon/announce/nodeinfo.d/system/role create mode 100755 package/gluon-node-info/files/lib/gluon/upgrade/node-info/invariant/001-node-system create mode 100755 package/gluon-node-info/files/lib/gluon/upgrade/node-info/invariant/010-node-role diff --git a/package/gluon-node-info/Makefile b/package/gluon-node-info/Makefile index b509e992..0fe8a8dd 100644 --- a/package/gluon-node-info/Makefile +++ b/package/gluon-node-info/Makefile @@ -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)) diff --git a/package/gluon-node-info/check_site.lua b/package/gluon-node-info/check_site.lua new file mode 100644 index 00000000..d8d46408 --- /dev/null +++ b/package/gluon-node-info/check_site.lua @@ -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) diff --git a/package/gluon-node-info/files/etc/config/gluon-node-info b/package/gluon-node-info/files/etc/config/gluon-node-info index 9ac6ec55..8f6f472f 100644 --- a/package/gluon-node-info/files/etc/config/gluon-node-info +++ b/package/gluon-node-info/files/etc/config/gluon-node-info @@ -2,3 +2,5 @@ config location option share_location '0' config owner + +config system diff --git a/package/gluon-node-info/files/lib/gluon/announce/nodeinfo.d/system/role b/package/gluon-node-info/files/lib/gluon/announce/nodeinfo.d/system/role new file mode 100644 index 00000000..38de47d7 --- /dev/null +++ b/package/gluon-node-info/files/lib/gluon/announce/nodeinfo.d/system/role @@ -0,0 +1,4 @@ +local role = uci:get_first('gluon-node-info', 'system', 'role', '') +if role ~= '' then + return role +end diff --git a/package/gluon-node-info/files/lib/gluon/upgrade/node-info/invariant/001-node-system b/package/gluon-node-info/files/lib/gluon/upgrade/node-info/invariant/001-node-system new file mode 100755 index 00000000..a17b9461 --- /dev/null +++ b/package/gluon-node-info/files/lib/gluon/upgrade/node-info/invariant/001-node-system @@ -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 diff --git a/package/gluon-node-info/files/lib/gluon/upgrade/node-info/invariant/010-node-role b/package/gluon-node-info/files/lib/gluon/upgrade/node-info/invariant/010-node-role new file mode 100755 index 00000000..6e54a234 --- /dev/null +++ b/package/gluon-node-info/files/lib/gluon/upgrade/node-info/invariant/010-node-role @@ -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