[PATCH v2 04/10] base-files: upgrade: fwtool.sh: use v for log lines

Adrian Schmutzler mail at adrianschmutzler.de
Tue Nov 10 06:54:16 EST 2020


Hi,

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces at lists.openwrt.org]
> On Behalf Of Yousong Zhou
> Sent: Dienstag, 10. November 2020 03:22
> To: Adrian Schmutzler <mail at adrianschmutzler.de>; Philip Prindeville
> <philipp at redfish-solutions.com>
> Cc: Yousong Zhou <yszhou4tech at gmail.com>; OpenWrt Development List
> <openwrt-devel at lists.openwrt.org>
> Subject: [PATCH v2 04/10] base-files: upgrade: fwtool.sh: use v for log lines
> 
> This will have at least the following effects
> 
>  - Log lines will have common prefix
>  - They will be output to stderr instead of stdout
> 
> Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
> ---
>  .../base-files/files/lib/upgrade/fwtool.sh    | 24 +++++++++----------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/package/base-files/files/lib/upgrade/fwtool.sh b/package/base-
> files/files/lib/upgrade/fwtool.sh
> index 3a74c72bba..d30b37c4f0 100644
> --- a/package/base-files/files/lib/upgrade/fwtool.sh
> +++ b/package/base-files/files/lib/upgrade/fwtool.sh
> @@ -10,9 +10,9 @@ fwtool_check_signature() {
>  	}
> 
>  	if ! fwtool -q -s /tmp/sysupgrade.ucert "$1"; then
> -		echo "Image signature not found"
> +		v "Image signature not found"
>  		[ "$REQUIRE_IMAGE_SIGNATURE" = 1 -a "$FORCE" != 1 ] && {
> -			echo "Use sysupgrade -F to override this check when
> downgrading or flashing to vendor firmware"
> +			v "Use sysupgrade -F to override this check when
> downgrading or flashing to vendor firmware"
>  		}
>  		[ "$REQUIRE_IMAGE_SIGNATURE" = 1 ] && return 1
>  		return 0
> @@ -30,16 +30,16 @@ fwtool_check_image() {
>  	. /usr/share/libubox/jshn.sh
> 
>  	if ! fwtool -q -i /tmp/sysupgrade.meta "$1"; then
> -		echo "Image metadata not found"
> +		v "Image metadata not found"
>  		[ "$REQUIRE_IMAGE_METADATA" = 1 -a "$FORCE" != 1 ] && {
> -			echo "Use sysupgrade -F to override this check when
> downgrading or flashing to vendor firmware"
> +			v "Use sysupgrade -F to override this check when
> downgrading or flashing to vendor firmware"
>  		}
>  		[ "$REQUIRE_IMAGE_METADATA" = 1 ] && return 1
>  		return 0
>  	fi
> 
>  	json_load "$(cat /tmp/sysupgrade.meta)" || {
> -		echo "Invalid image metadata"
> +		v "Invalid image metadata"
>  		return 1
>  	}
> 
> @@ -64,15 +64,15 @@ fwtool_check_image() {
>  		if [ "$dev" = "$device" ]; then
>  			# major compat version -> no sysupgrade
>  			if [ "${devicecompat%.*}" != "${imagecompat%.*}" ];
> then
> -				echo "The device is supported, but this image
> is incompatible for sysupgrade based on the image version ($devicecompat-
> >$imagecompat)."
> -				[ -n "$compatmessage" ] && echo
> "$compatmessage"
> +				v "The device is supported, but this image is
> incompatible for sysupgrade based on the image version ($devicecompat-
> >$imagecompat)."
> +				[ -n "$compatmessage" ] && v
> "$compatmessage"
>  				return 1
>  			fi
> 
>  			# minor compat version -> sysupgrade with -n
> required
>  			if [ "${devicecompat#.*}" != "${imagecompat#.*}" ]
> && [ "$SAVE_CONFIG" = "1" ]; then
> -				echo "The device is supported, but the config
> is incompatible to the new image ($devicecompat->$imagecompat). Please
> upgrade without keeping config (sysupgrade -n)."
> -				[ -n "$compatmessage" ] && echo
> "$compatmessage"
> +				v "The device is supported, but the config is
> incompatible to the new image ($devicecompat->$imagecompat). Please
> upgrade without keeping config (sysupgrade -n)."
> +				[ -n "$compatmessage" ] && v
> "$compatmessage"
>  				return 1
>  			fi
> 
> @@ -80,11 +80,11 @@ fwtool_check_image() {
>  		fi
>  	done
> 
> -	echo "Device $device not supported by this image"
> -	echo -n "Supported devices:"
> +	v "Device $device not supported by this image"
> +	echo -n "Supported devices:" >&2

This might give us a little trouble, since echo -n will suppress the \n at the _end_ of the line, so the "Supported devices: ..." line will then have no prefix. Probably the easiest way to address this would be to introduce a "vn" function that does the same as "v" but without adding a newline at the end. Or we just say it's okay that "Supported devices: ..." is not prefixed like the rest of the upgrade output ...

Best

Adrian

>  	for k in $dev_keys; do
>  		json_get_var dev "$k"
> -		echo -n " $dev"
> +		echo -n " $dev" >&2
>  	done
>  	echo
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: openpgp-digital-signature.asc
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20201110/9e59ac6e/attachment-0001.sig>


More information about the openwrt-devel mailing list