From 156813b34f9484c9ed22e9cfcffb381b944fd05f Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Wed, 14 May 2014 18:51:32 +0200
Subject: [PATCH] gluon-simple-tc: replace config script generator with Lua
 script

---
 package/gluon-simple-tc/Makefile               |  7 +------
 .../simple-tc/invariant/010-site-defaults      | 16 ++++++++++++++++
 package/gluon-simple-tc/invariant.pl           | 18 ------------------
 3 files changed, 17 insertions(+), 24 deletions(-)
 create mode 100755 package/gluon-simple-tc/files/lib/gluon/upgrade/simple-tc/invariant/010-site-defaults
 delete mode 100644 package/gluon-simple-tc/invariant.pl

diff --git a/package/gluon-simple-tc/Makefile b/package/gluon-simple-tc/Makefile
index 1c8ae9b14..1c9fd1479 100644
--- a/package/gluon-simple-tc/Makefile
+++ b/package/gluon-simple-tc/Makefile
@@ -1,8 +1,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=gluon-simple-tc
-PKG_VERSION:=1
-PKG_RELEASE:=1.$(GLUON_CONFIG_VERSION)
+PKG_VERSION:=2
 
 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
 
@@ -31,10 +30,6 @@ endef
 
 define Package/gluon-simple-tc/install
 	$(CP) ./files/* $(1)/
-
-	$(INSTALL_DIR) $(1)/lib/gluon/upgrade/simple-tc/invariant
-	$(GLUON_CONFIGURE) invariant.pl > $(1)/lib/gluon/upgrade/simple-tc/invariant/010-site-defaults
-	chmod +x $(1)/lib/gluon/upgrade/simple-tc/invariant/010-site-defaults
 endef
 
 $(eval $(call BuildPackage,gluon-simple-tc))
diff --git a/package/gluon-simple-tc/files/lib/gluon/upgrade/simple-tc/invariant/010-site-defaults b/package/gluon-simple-tc/files/lib/gluon/upgrade/simple-tc/invariant/010-site-defaults
new file mode 100755
index 000000000..d99a51baa
--- /dev/null
+++ b/package/gluon-simple-tc/files/lib/gluon/upgrade/simple-tc/invariant/010-site-defaults
@@ -0,0 +1,16 @@
+#!/usr/bin/lua
+
+local site = require 'gluon.site_config'
+local uci = require 'luci.model.uci'
+
+local c = uci.cursor()
+
+
+for name, config in pairs(site.simple_tc) do
+	if not c:get('gluon-simple-tc', name) then
+		c:section('gluon-simple-tc', 'interface', name, config)
+	end
+end
+
+c:save('gluon-simple-tc')
+c:commit('gluon-simple-tc')
diff --git a/package/gluon-simple-tc/invariant.pl b/package/gluon-simple-tc/invariant.pl
deleted file mode 100644
index 6b91a9511..000000000
--- a/package/gluon-simple-tc/invariant.pl
+++ /dev/null
@@ -1,18 +0,0 @@
-my $cfg = $CONFIG->{simple_tc};
-
-print "#/bin/sh\n\n";
-
-foreach my $name (sort keys %{$cfg}) {
-  my $interface = $cfg->{$name};
-
-  print "uci -q get gluon-simple-tc.$name >/dev/null || uci -q batch <<EOF\n";
-  print "set gluon-simple-tc.$name=interface\n";
-
-  for (qw(enabled ifname limit_egress limit_ingress)) {
-    print "set gluon-simple-tc.$name.$_=$interface->{$_}\n";
-  }
-
-  print "EOF\n\n";
-}
-
-print "uci commit gluon-simple-tc\n";
-- 
GitLab