Skip to content

Commit 6649972

Browse files
committed
autoupdate: backport changes from 23.05
1 parent a3677e3 commit 6649972

File tree

6 files changed

+732
-20
lines changed

6 files changed

+732
-20
lines changed

packages/falter-berlin-autoupdate/LICENSE

+674
Large diffs are not rendered by default.

packages/falter-berlin-autoupdate/Makefile

+6-1
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,6 +13,8 @@ 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

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

+25-15
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,12 @@ 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
228-
sysupgrade -n --ignore-minor-compat-version "$PATH_BIN"
238+
sysupgrade -n "$PATH_BIN"
229239
else
230-
sysupgrade --ignore-minor-compat-version "$PATH_BIN"
240+
sysupgrade "$PATH_BIN"
231241
fi
232242
log "done."
233243
fi

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

+24-1
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,7 +238,7 @@ 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

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

3-
[ -z $IPKG_INSTROOT ] || exit 0
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
46

57
# if autoupdate is not present in crontab, include it.
68
crontab -l | grep /usr/bin/autoupdate >>/dev/null

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

-2
This file was deleted.

0 commit comments

Comments
 (0)