Skip to content

Commit 395eb32

Browse files
committed
autoupdate: backport changes from 23.05
1 parent faeffa5 commit 395eb32

File tree

6 files changed

+750
-19
lines changed

6 files changed

+750
-19
lines changed

packages/falter-berlin-autoupdate/LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

packages/falter-berlin-autoupdate/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
include $(TOPDIR)/rules.mk
22

33
PKG_NAME:=falter-berlin-autoupdate
4-
PKG_VERSION:=0.1
4+
PKG_VERSION:=2022.08.29
5+
6+
PKG_LICENSE:=GPL-3.0-or-later
7+
PKG_LICENSE_FILES:=LICENSE
58

69
include $(INCLUDE_DIR)/package.mk
710

@@ -10,12 +13,14 @@ define Package/falter-berlin-autoupdate/default
1013
CATEGORY:=falter-berlin
1114
URL:=https://github.com/freifunk-berlin/falter-packages
1215
PKGARCH:=all
16+
# falter-berlin-migration holds the semver-library needed by the autoupdater
17+
EXTRA_DEPENDS:=uci, jshn, falter-berlin-migration
1318
endef
1419

1520
define Package/falter-berlin-autoupdate
1621
$(call Package/falter-berlin-autoupdate/default)
1722
TITLE:=Freifunk Berlin Autoupdater
18-
EXTRA_DEPENDS:=falter-berlin-autoupdate-keys uci usign
23+
EXTRA_DEPENDS:=falter-berlin-autoupdate-keys, uci, usign
1924
endef
2025

2126
define Package/falter-berlin-autoupdate-keys

packages/falter-berlin-autoupdate/files/autoupdate.sh

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
#! /bin/sh
1+
#!/bin/sh
2+
3+
# This software originates from Freifunk Berlin and implements a basic autoupdate mechanism
4+
# by using OpenWrts built-in sysupgrade.
5+
# It is licensed under GNU General Public License v3.0 or later
6+
# Copyright (C) 2022 Martin Hübner and Tobias Schwarz
7+
8+
# shellcheck shell=dash
29

310
# except than noted, this script is not posix-compliant in one way: we use "local"
411
# variables definition. As nearly all shells out there implement local, this should
512
# work anyway. This is a little reminder to you, if you use some rare shell without
613
# a builtin "local" statement.
714

15+
# We don't need the return values and check the correct execution in other ways.
16+
# shellcheck disable=SC2155
17+
18+
# we can't check those dependencies at the CI
19+
# shellcheck source=/dev/null
820
. /lib/functions.sh
921
. /lib/config/uci.sh
1022
. /etc/freifunk_release
@@ -54,14 +66,14 @@ Example call:
5466
# Load Configuration #
5567
##########################
5668

57-
SELECTOR_URL=$(uci_get autoupdate cfg selector_fqdn)
69+
export SELECTOR_URL=$(uci_get autoupdate cfg selector_fqdn)
5870
FW_SERVER_URL=$(uci_get autoupdate cfg fw_server_fqdn)
5971
MIN_CERTS=$(uci_get autoupdate cfg minimum_certs)
6072
DISABLED=$(uci_get autoupdate cfg disabled)
6173

6274
PATH_DIR="/tmp/autoupdate"
6375
PATH_BIN="$PATH_DIR/freifunk_syupgrade.bin"
64-
KEY_DIR="/etc/autoupdate/keys/"
76+
export KEY_DIR="/etc/autoupdate/keys/"
6577

6678
MIN_RAM_FREE=1536 # amount of kiB that must be free in RAM after firmware-download
6779

@@ -107,19 +119,19 @@ log "starting autoupdate..."
107119
# Checks and Checks again
108120

109121
is_stable_release=$(echo "$FREIFUNK_RELEASE" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$')
110-
if [ -z $OPT_FORCE ] && [ -z "$is_stable_release" ]; then
122+
if [ -z "$OPT_FORCE" ] && [ -z "$is_stable_release" ]; then
111123
log "automatic updates aren't supported for development-firmwares. Please update manually or use the force update option '-f' or new-install option '-n'."
112124
exit 2
113125
fi
114126

115-
if [ -z $OPT_FORCE ] && { [ "$DISABLED" = "1" ] || [ "$DISABLED" = "yes" ] || [ "$DISABLED" = "true" ]; }; then
127+
if [ -z "$OPT_FORCE" ] && { [ "$DISABLED" = "1" ] || [ "$DISABLED" = "yes" ] || [ "$DISABLED" = "true" ]; }; then
116128
log "autoupdate is disabled. Change the configs at /et/config/autoupdate to enable it."
117129
exit 2
118130
fi
119131

120132
UPTIME=$(cut -d'.' -f1 </proc/uptime)
121133
# only update, if router runs for at least two hours (so the update probably won't get disrupted)
122-
if [ -z $OPT_FORCE ] && [ "$UPTIME" -lt 7200 ]; then
134+
if [ -z "$OPT_FORCE" ] && [ "$UPTIME" -lt 7200 ]; then
123135
log "Router didn't run for two hours. It might be just plugged in for testing. Aborting..."
124136
exit 2
125137
fi
@@ -129,15 +141,14 @@ rm -rf "$PATH_DIR"
129141
mkdir -p "$PATH_DIR"
130142

131143
log "fetch autoupdate.json from $FW_SERVER_URL ..."
132-
load_overview_and_certs "$FW_SERVER_URL"
133-
if [ $? != 0 ]; then
144+
if load_overview_and_certs "$FW_SERVER_URL"; then
134145
log "fetching autoupdate.json failed. Probably no internet connection."
135146
exit 2
136147
fi
137148
log "done."
138149

139150
# prove to be signed by minimum amount of certs
140-
if [ -z $OPT_IGNORE_CERTS ]; then
151+
if [ -z "$OPT_IGNORE_CERTS" ]; then
141152
log "Verifying image-signatures..."
142153
min_valid_certificates "$PATH_DIR/autoupdate.json" "$MIN_CERTS"
143154
ret_code=$?
@@ -151,8 +162,7 @@ else
151162
log "ignoring certificates as requested."
152163
fi
153164

154-
latest_release=$(read_latest_stable "$PATH_DIR/autoupdate.json")
155-
if [ $? != 0 ]; then
165+
if latest_release=$(read_latest_stable "$PATH_DIR/autoupdate.json"); then
156166
log "wasn't able to read latest stable version from autoupdate.json"
157167
exit 2
158168
else
@@ -182,7 +192,7 @@ if semverLT "$FREIFUNK_RELEASE" "$latest_release"; then
182192
log "download link is: $link."
183193

184194
# delete json and signatures to save space in RAM
185-
if [ -z $OPT_TESTRUN ]; then
195+
if [ -z "$OPT_TESTRUN" ]; then
186196
json_sig_files=$(find "$PATH_DIR" -name "autoupdate.json*")
187197
for f in $json_sig_files; do
188198
rm "$f"
@@ -222,12 +232,18 @@ if semverLT "$FREIFUNK_RELEASE" "$latest_release"; then
222232
fi
223233

224234
# flash image
225-
if [ -z $OPT_TESTRUN ]; then
235+
if [ -z "$OPT_TESTRUN" ]; then
226236
log "start flashing the image..."
227237
if [ -n "$OPT_N" ]; then
228238
sysupgrade -n "$PATH_BIN"
229239
else
230-
sysupgrade "$PATH_BIN"
240+
check_ignore_minor_compat
241+
ret_code=$?
242+
if [ $ret_code = 0 ]; then
243+
sysupgrade --ignore-minor-compat-version "$PATH_BIN"
244+
else
245+
sysupgrade "$PATH_BIN"
246+
fi
231247
fi
232248
log "done."
233249
fi

packages/falter-berlin-autoupdate/files/lib_autoupdate.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
#!/bin/sh
22

3+
# This software originates from Freifunk Berlin and implements a basic autoupdate mechanism
4+
# by using OpenWrts built-in sysupgrade.
5+
# It is licensed under GNU General Public License v3.0 or later
6+
# Copyright (C) 2022 Martin Hübner and Tobias Schwarz
7+
8+
# shellcheck shell=dash
9+
10+
# jshn assigns the variables for us, but shellcheck doesn't get it.
11+
# shellcheck disable=SC2154
12+
# We don't need the return values and check the correct execution in other ways.
13+
# shellcheck disable=SC2155
14+
# using printf with variables and nc didn't work correctly. Thus this hack
15+
# shellcheck disable=SC2059
16+
# FW_SERVER_URL isn't mispelled, but a global variable defined in autoupdate.sh
17+
# shellcheck disable=SC2153
18+
19+
# Those dependencies aren't available for CI checking.
20+
# shellcheck source=/dev/null
321
. /lib/functions.sh
422
. /lib/functions/semver.sh
523
. /lib/config/uci.sh
@@ -142,6 +160,11 @@ get_download_link_and_hash() {
142160
# load board-specific json with image-name from selector
143161
board_json=$(wget -qO - "https://${SELECTOR_URL}/${version}/${flavour}/${curr_target}/${BOARD}.json")
144162

163+
if [ -z "$board_json" ]; then
164+
log "Failed to download board-specific JSON-File from firmware selector. Exiting..."
165+
exit 2
166+
fi
167+
145168
json_init
146169
json_load "$board_json"
147170
json_for_each_item "iter_images" "images"
@@ -215,11 +238,22 @@ min_valid_certificates() {
215238
#pop key from list. Thus one key cannot validate multiple certs.
216239
key_list=$(pop_element "$key_list" "$key")
217240
fi
218-
if [ $cert_cnt = $min_cnt ]; then
241+
if [ $cert_cnt = "$min_cnt" ]; then
219242
return 255
220243
fi
221244
done
222245
done
223246

224247
return $cert_cnt
225248
}
249+
250+
check_ignore_minor_compat() {
251+
# checks if the installed sysupgrade tool supports the option
252+
# --ignore-minor-compat-version already.
253+
# returns 0 if option is available, 1 otherwise
254+
if sysupgrade -h | grep -q 'ignore-minor-compat-version'; then
255+
return 0
256+
else
257+
return 1
258+
fi
259+
}

packages/falter-berlin-autoupdate/files/post-inst.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/sh
22

3+
# I can remember, that this script was fairly horrible to get it working as
4+
# intended. You better shouldn't touch anything here.
5+
# shellcheck disable=all
6+
37
[ -z $IPKG_INSTROOT ] || exit 0
48

59
# if autoupdate is not present in crontab, include it.

packages/falter-berlin-autoupdate/keys/alex.pub

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)