gluon-core: convert generated upgrade scripts to Lua
This commit is contained in:
parent
d31ea9eba9
commit
b95a4d67e8
@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=gluon-core
|
||||
PKG_VERSION:=2
|
||||
PKG_RELEASE:=1
|
||||
PKG_RELEASE:=$(GLUON_VERSION)
|
||||
|
||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
||||
|
||||
@ -12,7 +12,7 @@ define Package/gluon-core
|
||||
SECTION:=gluon
|
||||
CATEGORY:=Gluon
|
||||
TITLE:=Base files of Gluon
|
||||
DEPENDS:=+gluon-config +odhcp6c
|
||||
DEPENDS:=+gluon-config +luci-lib-core +odhcp6c
|
||||
endef
|
||||
|
||||
define Package/gluon-core/description
|
||||
@ -31,7 +31,6 @@ endef
|
||||
|
||||
define Package/gluon-core/install
|
||||
$(CP) ./files/* $(1)/
|
||||
$(GLUON_GENERATE) ./generate/* $(1)/
|
||||
|
||||
$(INSTALL_DIR) $(1)/lib/gluon
|
||||
echo "$(GLUON_VERSION)" > $(1)/lib/gluon/gluon-version
|
||||
|
14
package/gluon-core/files/lib/gluon/upgrade/core/initial/010-gluon-system
Executable file
14
package/gluon-core/files/lib/gluon/upgrade/core/initial/010-gluon-system
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
local site = require 'gluon.site_config'
|
||||
local sysconfig = require 'gluon.sysconfig'
|
||||
local uci = require 'luci.model.uci'
|
||||
|
||||
local c = uci.cursor()
|
||||
local system = c:get_first('system', 'system')
|
||||
|
||||
c:set('system', system, 'hostname', site.hostname_prefix .. '-' .. string.gsub(sysconfig.primary_mac, ':', ''))
|
||||
c:set('system', system, 'timezone', site.timezone)
|
||||
|
||||
c:save('system')
|
||||
c:commit('system')
|
14
package/gluon-core/files/lib/gluon/upgrade/core/invariant/012-ntp-servers
Executable file
14
package/gluon-core/files/lib/gluon/upgrade/core/invariant/012-ntp-servers
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
local site = require 'gluon.site_config'
|
||||
local uci = require 'luci.model.uci'
|
||||
|
||||
if not site.ntp_servers or #site.ntp_servers == 0 then
|
||||
os.exit(0)
|
||||
end
|
||||
|
||||
local c = uci.cursor()
|
||||
c:delete('system', 'ntp', 'server')
|
||||
c:set_list('system', 'ntp', 'server', site.ntp_servers)
|
||||
c:save('system')
|
||||
c:commit('system')
|
27
package/gluon-core/files/usr/lib/lua/gluon/sysconfig.lua
Normal file
27
package/gluon-core/files/usr/lib/lua/gluon/sysconfig.lua
Normal file
@ -0,0 +1,27 @@
|
||||
local sysconfigdir = '/lib/gluon/core/sysconfig/'
|
||||
|
||||
local function get(_, name)
|
||||
local ret = nil
|
||||
local f = io.open(sysconfigdir .. name)
|
||||
if f then
|
||||
ret = f:read('*line')
|
||||
f:close()
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
local function set(_, name, val)
|
||||
local ret = nil
|
||||
local f = io.open(sysconfigdir .. name, 'w+')
|
||||
f:write(val)
|
||||
f:close()
|
||||
end
|
||||
|
||||
local sysconfig = {}
|
||||
local mt = {
|
||||
__index = get,
|
||||
__newindex = set,
|
||||
}
|
||||
|
||||
setmetatable(sysconfig, mt)
|
||||
return sysconfig
|
@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/gluon/functions/sysconfig.sh
|
||||
|
||||
macaddr=$(sysconfig primary_mac)
|
||||
|
||||
uci_set system '@system[0]' hostname "@hostname_prefix@-${macaddr//:/}"
|
||||
uci_set system '@system[0]' timezone '@timezone@'
|
||||
uci_commit system
|
@ -1,12 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ -n "$(echo @ntp_servers@)" ] || exit 0
|
||||
|
||||
|
||||
uci delete system.ntp.server
|
||||
|
||||
for server in @ntp_servers@; do
|
||||
uci add_list system.ntp.server="$server"
|
||||
done
|
||||
|
||||
uci commit system
|
Loading…
Reference in New Issue
Block a user