From 0371b443d3b4562d8d7fdc5322f51e53cf2a8cd2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 23 Jan 2015 05:51:13 +0100 Subject: [PATCH] gluon-legacy: convert the remaining legacy scripts to invariant scripts --- .../invariant/009-legacy-mesh-vpn-fastd | 37 +++++++++++++++++++ .../legacy/010-reset-fastd-config | 35 ------------------ .../invariant/009-legacy-setup-mode | 22 +++++++++++ .../setup-mode/legacy/010-migrate-configured | 20 ---------- .../simple-tc/invariant/009-legacy-simple-tc | 29 +++++++++++++++ .../upgrade/simple-tc/legacy/010-migrate-tc | 27 -------------- 6 files changed, 88 insertions(+), 82 deletions(-) create mode 100755 package/gluon-legacy/files/lib/gluon/upgrade/mesh-vpn-fastd/invariant/009-legacy-mesh-vpn-fastd delete mode 100755 package/gluon-legacy/files/lib/gluon/upgrade/mesh-vpn-fastd/legacy/010-reset-fastd-config create mode 100755 package/gluon-legacy/files/lib/gluon/upgrade/setup-mode/invariant/009-legacy-setup-mode delete mode 100755 package/gluon-legacy/files/lib/gluon/upgrade/setup-mode/legacy/010-migrate-configured create mode 100755 package/gluon-legacy/files/lib/gluon/upgrade/simple-tc/invariant/009-legacy-simple-tc delete mode 100755 package/gluon-legacy/files/lib/gluon/upgrade/simple-tc/legacy/010-migrate-tc diff --git a/package/gluon-legacy/files/lib/gluon/upgrade/mesh-vpn-fastd/invariant/009-legacy-mesh-vpn-fastd b/package/gluon-legacy/files/lib/gluon/upgrade/mesh-vpn-fastd/invariant/009-legacy-mesh-vpn-fastd new file mode 100755 index 00000000..468a35a6 --- /dev/null +++ b/package/gluon-legacy/files/lib/gluon/upgrade/mesh-vpn-fastd/invariant/009-legacy-mesh-vpn-fastd @@ -0,0 +1,37 @@ +#!/usr/bin/lua + +local site = require 'gluon.site_config' +local sysconfig = require 'gluon.sysconfig' + +local uci = require('luci.model.uci').cursor() + + +if sysconfig.gluon_version == 'legacy' then + local secret + local enabled + + + for _, config in ipairs(site.legacy.fastd_configs) do + if not secret then + local s = uci:get_all('fastd', config) + if s then + secret = s.secret + enabled = s.enabled + end + end + + uci:delete('fastd', config) + end + + if secret then + uci:section('fastd', 'fastd', 'mesh_vpn', + { + secret = secret, + enabled = enabled, + } + ) + end + + uci:save('fastd') + uci:commit('fastd') +end diff --git a/package/gluon-legacy/files/lib/gluon/upgrade/mesh-vpn-fastd/legacy/010-reset-fastd-config b/package/gluon-legacy/files/lib/gluon/upgrade/mesh-vpn-fastd/legacy/010-reset-fastd-config deleted file mode 100755 index 730feea0..00000000 --- a/package/gluon-legacy/files/lib/gluon/upgrade/mesh-vpn-fastd/legacy/010-reset-fastd-config +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/lua - -local site = require 'gluon.site_config' -local uci = require 'luci.model.uci' - -local c = uci.cursor() - - -local secret -local enabled - - -for _, config in ipairs(site.legacy.fastd_configs) do - if not secret then - local s = c:get_all('fastd', config) - if s then - secret = s.secret - enabled = s.enabled - end - end - - c:delete('fastd', config) -end - -if secret then - c:section('fastd', 'fastd', 'mesh_vpn', - { - secret = secret, - enabled = enabled, - } - ) -end - -c:save('fastd') -c:commit('fastd') diff --git a/package/gluon-legacy/files/lib/gluon/upgrade/setup-mode/invariant/009-legacy-setup-mode b/package/gluon-legacy/files/lib/gluon/upgrade/setup-mode/invariant/009-legacy-setup-mode new file mode 100755 index 00000000..0b97e120 --- /dev/null +++ b/package/gluon-legacy/files/lib/gluon/upgrade/setup-mode/invariant/009-legacy-setup-mode @@ -0,0 +1,22 @@ +#!/usr/bin/lua + +local site = require 'gluon.site_config' +local sysconfig = require 'gluon.sysconfig' + +local uci = require('luci.model.uci').cursor() + + +if sysconfig.gluon_version == 'legacy' then + for _, config in ipairs(site.legacy.config_mode_configs) do + local old = uci:get_first(config, 'wizard', 'configured') + if old == '1' then + local setup_mode = uci:get_first('gluon-setup-mode', 'setup_mode') + uci:set('gluon-setup-mode', setup_mode, 'configured', '1') + + uci:save('gluon-setup-mode') + uci:commit('gluon-setup-mode') + + break + end + end +end diff --git a/package/gluon-legacy/files/lib/gluon/upgrade/setup-mode/legacy/010-migrate-configured b/package/gluon-legacy/files/lib/gluon/upgrade/setup-mode/legacy/010-migrate-configured deleted file mode 100755 index f4a59570..00000000 --- a/package/gluon-legacy/files/lib/gluon/upgrade/setup-mode/legacy/010-migrate-configured +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/lua - -local site = require 'gluon.site_config' -local uci = require 'luci.model.uci' - -local c = uci.cursor() - - -for _, config in ipairs(site.legacy.config_mode_configs) do - local old = c:get_first(config, 'wizard', 'configured') - if old == '1' then - local setup_mode = c:get_first('gluon-setup-mode', 'setup_mode') - c:set('gluon-setup-mode', setup_mode, 'configured', '1') - - c:save('gluon-setup-mode') - c:commit('gluon-setup-mode') - - break - end -end diff --git a/package/gluon-legacy/files/lib/gluon/upgrade/simple-tc/invariant/009-legacy-simple-tc b/package/gluon-legacy/files/lib/gluon/upgrade/simple-tc/invariant/009-legacy-simple-tc new file mode 100755 index 00000000..c67afe14 --- /dev/null +++ b/package/gluon-legacy/files/lib/gluon/upgrade/simple-tc/invariant/009-legacy-simple-tc @@ -0,0 +1,29 @@ +#!/usr/bin/lua + +local site = require 'gluon.site_config' +local sysconfig = require 'gluon.sysconfig' + +local uci = require('luci.model.uci').cursor() + + +if sysconfig.gluon_version == 'legacy' then + for _, config in ipairs(site.legacy.tc_configs) do + local s = uci:get_first(config, 'bandwidth') + if s then + old = uci:get_all(config, s) + uci:section('gluon-simple-tc', 'interface', 'mesh_vpn', + { + ifname = 'mesh-vpn', + enabled = old.enabled, + limit_ingress = old.downstream, + limit_egress = old.upstream, + } + ) + + uci:save('gluon-simple-tc') + uci:commit('gluon-simple-tc') + + break + end + end +end diff --git a/package/gluon-legacy/files/lib/gluon/upgrade/simple-tc/legacy/010-migrate-tc b/package/gluon-legacy/files/lib/gluon/upgrade/simple-tc/legacy/010-migrate-tc deleted file mode 100755 index 39dd5f5d..00000000 --- a/package/gluon-legacy/files/lib/gluon/upgrade/simple-tc/legacy/010-migrate-tc +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/lua - -local site = require 'gluon.site_config' -local uci = require 'luci.model.uci' - -local c = uci.cursor() - - -for _, config in ipairs(site.legacy.tc_configs) do - local s = c:get_first(config, 'bandwidth') - if s then - old = c:get_all(config, s) - c:section('gluon-simple-tc', 'interface', 'mesh_vpn', - { - ifname = 'mesh-vpn', - enabled = old.enabled, - limit_ingress = old.downstream, - limit_egress = old.upstream, - } - ) - - c:save('gluon-simple-tc') - c:commit('gluon-simple-tc') - - break - end -end