gluon-autoupdater: replace config script generator with Lua script

This commit is contained in:
Matthias Schiffer 2014-05-14 20:46:31 +02:00
parent 7111337bad
commit e16bfbe309
3 changed files with 48 additions and 51 deletions

View File

@ -1,8 +1,8 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-autoupdater
PKG_VERSION:=0.1
PKG_RELEASE:=1.$(GLUON_CONFIG_VERSION)$(if $(GLUON_BRANCH),.$(GLUON_BRANCH))
PKG_VERSION:=2
PKG_RELEASE:=$(GLUON_BRANCH)
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
@ -28,9 +28,10 @@ endef
define Package/gluon-autoupdater/install
$(CP) ./files/* $(1)/
$(INSTALL_DIR) $(1)/lib/gluon/upgrade/autoupdater/invariant
GLUON_BRANCH='$(GLUON_BRANCH)' $(GLUON_CONFIGURE) invariant.pl > $(1)/lib/gluon/upgrade/autoupdater/invariant/010-autoupdater
chmod +x $(1)/lib/gluon/upgrade/autoupdater/invariant/010-autoupdater
if [ '$(GLUON_BRANCH)' ]; then \
$(INSTALL_DIR) $(1)/lib/gluon/autoupdater; \
echo '$(GLUON_BRANCH)' > $(1)/lib/gluon/autoupdater/default_branch; \
fi
endef
$(eval $(call BuildPackage,gluon-autoupdater))

View File

@ -0,0 +1,42 @@
#!/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.autoupdater.branches) do
c:delete('autoupdater', name)
c:section('autoupdater', 'branch', name,
{
name = config.name,
mirror = config.mirrors,
probability = config.probability,
good_signatures = config.good_signatures,
pubkey = config.pubkeys,
}
)
end
if not c:get('autoupdater', 'settings') then
local enabled = 0
local branch = site.autoupdater.branch
local f = io.open('/lib/gluon/autoupdater/default_branch')
if f then
enabled = 1
branch = f:read('*line')
f:close()
end
c:section('autoupdater', 'autoupdater', 'settings',
{
enabled = enabled,
branch = branch,
}
)
end
c:save('autoupdater')
c:commit('autoupdater')

View File

@ -1,46 +0,0 @@
my $cfg = $CONFIG->{autoupdater};
my $branch = $ENV{GLUON_BRANCH} || $cfg->{branch};
my $enabled = $ENV{GLUON_BRANCH} ? 1 : 0;
print <<END;
#/bin/sh
uci -q get autoupdater.settings || {
uci -q batch <<EOF
set autoupdater.settings=autoupdater
set autoupdater.settings.branch=$branch
set autoupdater.settings.enabled=$enabled
EOF
}
uci -q batch <<EOF
END
foreach my $name (sort keys $cfg->{branches}) {
my $branch = $cfg->{branches}->{$name};
print <<END;
delete autoupdater.$name
set autoupdater.$name=branch
END
for (qw(name probability good_signatures)) {
print "set autoupdater.$name.$_=$branch->{$_}\n";
}
for (@{$branch->{mirrors}}) {
print "add_list autoupdater.$name.mirror=$_\n";
}
for (@{$branch->{pubkeys}}) {
print "add_list autoupdater.$name.pubkey=$_\n";
}
}
print <<END;
commit autoupdater
EOF
END