gluon-core: convert generated upgrade scripts to Lua

This commit is contained in:
Matthias Schiffer 2014-05-14 08:47:26 +02:00
parent d31ea9eba9
commit b95a4d67e8
7 changed files with 57 additions and 25 deletions

View File

@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-core PKG_NAME:=gluon-core
PKG_VERSION:=2 PKG_VERSION:=2
PKG_RELEASE:=1 PKG_RELEASE:=$(GLUON_VERSION)
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
@ -12,7 +12,7 @@ define Package/gluon-core
SECTION:=gluon SECTION:=gluon
CATEGORY:=Gluon CATEGORY:=Gluon
TITLE:=Base files of Gluon TITLE:=Base files of Gluon
DEPENDS:=+gluon-config +odhcp6c DEPENDS:=+gluon-config +luci-lib-core +odhcp6c
endef endef
define Package/gluon-core/description define Package/gluon-core/description
@ -31,7 +31,6 @@ endef
define Package/gluon-core/install define Package/gluon-core/install
$(CP) ./files/* $(1)/ $(CP) ./files/* $(1)/
$(GLUON_GENERATE) ./generate/* $(1)/
$(INSTALL_DIR) $(1)/lib/gluon $(INSTALL_DIR) $(1)/lib/gluon
echo "$(GLUON_VERSION)" > $(1)/lib/gluon/gluon-version echo "$(GLUON_VERSION)" > $(1)/lib/gluon/gluon-version

View 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')

View 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')

View 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

View File

@ -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

View File

@ -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