gluon-autoupdater: new branch specification

It is now possible to specific multiple branches like this:

config branch stable
  option url ...
  list pubkey ...
  ...

config branch testing
  ...

and select one in autoupdater.settings:

config autoupdater settings
  option branch "stable"
This commit is contained in:
Nils Schneider 2013-10-02 13:33:47 +02:00
parent 09855e0c80
commit f637e923f5
8 changed files with 87 additions and 51 deletions

View File

@ -1,8 +1,8 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-autoupdater
PKG_VERSION:=0.3.2.99
PKG_RELEASE:=0.1
PKG_VERSION:=0.1
PKG_RELEASE:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
@ -11,7 +11,7 @@ include $(INCLUDE_DIR)/package.mk
define Package/gluon-autoupdater
SECTION:=gluon
CATEGORY:=Gluon
DEPENDS:=+ecdsautils +gluon-cron +gluon-release
DEPENDS:=+ecdsautils +gluon-cron +gluon-release +gluon-location
TITLE:=Automatically update firmware
endef
@ -23,13 +23,13 @@ define Build/Configure
endef
define Build/Compile
$(GLUON_CONFIGURE) autoupdater.pl > $(PKG_BUILD_DIR)/autoupdater.sh
$(GLUON_CONFIGURE) invariant.pl > $(PKG_BUILD_DIR)/invariant.sh
endef
define Package/gluon-autoupdater/install
$(CP) ./files/* $(1)/
$(INSTALL_DIR) $(1)/lib/gluon/upgrade/autoupdater/initial
$(INSTALL_BIN) $(PKG_BUILD_DIR)/autoupdater.sh $(1)/lib/gluon/upgrade/autoupdater/initial/010-autoupdater
$(INSTALL_DIR) $(1)/lib/gluon/upgrade/autoupdater/invariant
$(INSTALL_BIN) $(PKG_BUILD_DIR)/invariant.sh $(1)/lib/gluon/upgrade/autoupdater/invariant/010-autoupdater
endef
$(eval $(call BuildPackage,gluon-autoupdater))

View File

@ -1,23 +0,0 @@
my $cfg = $CONFIG->{autoupdater};
print <<'END';
#/bin/sh
uci -q batch <<EOF
delete autoupdater.default
set autoupdater.default=autoupdater
END
for (qw(enabled branch url probability good_signatures)) {
print 'set autoupdater.default.' . $_ . '=' . $cfg->{$_} . "\n";
}
for (@{$cfg->{pubkeys}}) {
print 'add_list autoupdater.default.pubkey=' . $_ . "\n";
}
print <<END;
commit autoupdater
EOF
END

View File

@ -1,19 +1,21 @@
config autoupdater default
option enabled 1
option branch "stable"
option url 'http://[fdef:ffc0:3dd7::8]/~freifunk/firmware/autoupdate'
config autoupdater settings
option enabled 1
option branch "stable"
# The updater will run once per hour and perform an update with a certain
# probability.
# 1.0 - perform an update every hour
# 0.5 - on average, perform an update every two hours
# 0.0 - inhibit any automatic updates
option probability 0.5
config branch stable
option url 'http://[fdef:ffc0:3dd7::8]/~freifunk/firmware/autoupdate'
# Minimum valid signatures required to perform the update
option good_signatures 2
# The updater will run once per hour and perform an update with a certain
# probability.
# 1.0 - perform an update every hour
# 0.5 - on average, perform an update every two hours
# 0.0 - inhibit any automatic updates
option probability 0.5
# List of public keys
list pubkey 'beea7da92ed0c19563b6c259162b4cb471aa2fdf9d3939d05fea2cf498ea7642'
list pubkey 'c75c9390cf5d7cc49a388d35f831ca379060cf7bca8c6e3d2d1ea31604597c42'
list pubkey '03e9514f137f0467c0f0ac108892c0da2b71f1039b30f863331cbd5701abd042'
# Minimum valid signatures required to perform the update
option good_signatures 2
# List of public keys
list pubkey 'beea7da92ed0c19563b6c259162b4cb471aa2fdf9d3939d05fea2cf498ea7642'
list pubkey 'c75c9390cf5d7cc49a388d35f831ca379060cf7bca8c6e3d2d1ea31604597c42'
list pubkey '03e9514f137f0467c0f0ac108892c0da2b71f1039b30f863331cbd5701abd042'

View File

@ -0,0 +1,3 @@
#/bin/sh
uci -q delete autoupdater.settings

View File

@ -0,0 +1,3 @@
#/bin/sh
uci -q delete autoupdater.settings

View File

@ -1,11 +1,13 @@
#!/bin/sh
if test $(uci get autoupdater.default.enabled) != 1; then
if test $(uci get autoupdater.settings.enabled) != 1; then
echo "autoupdater is disabled"
exit 0
fi
PROBABILITY=$(uci get autoupdater.default.probability)
BRANCH=$(uci get autoupdater.settings.branch)
PROBABILITY=$(uci get autoupdater.${BRANCH}.probability)
if test "a$1" != "a-f"; then
echo | awk "END{srand();exit rand() > $PROBABILITY}"
@ -15,10 +17,9 @@ if test "a$1" != "a-f"; then
fi
fi
BASE=$(uci get autoupdater.default.url)
PUBKEYS=$(uci get autoupdater.default.pubkey)
GOOD_SIGNATURES=$(uci get autoupdater.default.good_signatures)
BRANCH=$(uci get autoupdater.default.branch)
BASE=$(uci get autoupdater.${BRANCH}.url)
PUBKEYS=$(uci get autoupdater.${BRANCH}.pubkey)
GOOD_SIGNATURES=$(uci get autoupdater.${BRANCH}.good_signatures)
VERSION_FILE=/lib/gluon/release

View File

@ -0,0 +1,44 @@
my $cfg = $CONFIG->{autoupdater};
print <<'END';
#/bin/sh
uci -q get autoupdater.settings || {
uci -q batch <<EOF
set autoupdater.settings=autoupdater
END
for (qw(enabled branch)) {
print "set autoupdater.settings.$_=$cfg->{$_}\n";
}
print <<'END';
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(url probability good_signatures)) {
print "set autoupdater.$name.$_=$branch->{$_}\n";
}
for (@{$branch->{pubkeys}}) {
print "add_list autoupdater.$name.pubkey=$_\n";
}
}
print <<END;
commit autoupdater
EOF
END

View File

@ -0,0 +1,6 @@
#!/bin/sh
OLD_CFG=/etc/config/config_mode
NEW_CFG=/etc/config/configmode
[ -f $OLD_CFG ] && mv $OLD_CFG $NEW_CFG