From 21b3dd32592241301a80d6ce748d04242fa2fd9b Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Thu, 28 Dec 2017 22:50:31 +0100
Subject: [PATCH] build: add file size field to manifest lines

We would like to check the file size instead of downloading indefinitely.
The file size is added in another copy of the manifest lines, which is
ignored by older autoupdater implementations.
---
 scripts/filesize.sh          | 16 ++++++++++++++++
 scripts/generate_manifest.sh | 18 ++++++++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100755 scripts/filesize.sh

diff --git a/scripts/filesize.sh b/scripts/filesize.sh
new file mode 100755
index 000000000..1a6ea4dd9
--- /dev/null
+++ b/scripts/filesize.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+check_command() {
+	which "$1" >/dev/null 2>&1
+}
+
+if check_command gnustat; then
+	gnustat -c%s "$@"
+elif check_command gstat; then
+	gstat -c%s "$@"
+elif check_command stat; then
+	stat -c%s "$@"
+else
+	echo "$0: no suitable stat implementation was found" >&2
+	exit 1
+fi
diff --git a/scripts/generate_manifest.sh b/scripts/generate_manifest.sh
index a9dfca3c4..d0f1ce4e1 100755
--- a/scripts/generate_manifest.sh
+++ b/scripts/generate_manifest.sh
@@ -21,8 +21,22 @@ generate_line() {
 	local model="$1"
 	local file="$2"
 
-	[ ! -e "${GLUON_IMAGEDIR}/sysupgrade/$file" ] || echo "$model" "$GLUON_RELEASE" "$(scripts/sha256sum.sh "${GLUON_IMAGEDIR}/sysupgrade/$file")" "$file"
-	[ ! -e "${GLUON_IMAGEDIR}/sysupgrade/$file" ] || echo "$model" "$GLUON_RELEASE" "$(scripts/sha512sum.sh "${GLUON_IMAGEDIR}/sysupgrade/$file")" "$file"
+	[ ! -e "${GLUON_IMAGEDIR}/sysupgrade/$file" ] || echo \
+		"$model" \
+		"$GLUON_RELEASE" \
+		"$(scripts/sha256sum.sh "${GLUON_IMAGEDIR}/sysupgrade/$file")" \
+		"$(scripts/filesize.sh "${GLUON_IMAGEDIR}/sysupgrade/$file")" \
+		"$file"
+	[ ! -e "${GLUON_IMAGEDIR}/sysupgrade/$file" ] || echo \
+		"$model" \
+		"$GLUON_RELEASE" \
+		"$(scripts/sha256sum.sh "${GLUON_IMAGEDIR}/sysupgrade/$file")" \
+		"$file"
+	[ ! -e "${GLUON_IMAGEDIR}/sysupgrade/$file" ] || echo \
+		"$model" \
+		"$GLUON_RELEASE" \
+		"$(scripts/sha512sum.sh "${GLUON_IMAGEDIR}/sysupgrade/$file")" \
+		"$file"
 }
 
 generate() {
-- 
GitLab