From 8710615589c3a9202f8eaff12ec7372692f1d49c Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Tue, 3 Nov 2020 11:38:06 +0800 Subject: [PATCH] base-files: upgrade: add get_image_dd() This is mainly to handle stderr message "Broken pipe", "F+P records in/out" by common pattern "xcat | dd .." Ref: https://bugs.openwrt.org/index.php?do=details&task_id=3140 Reported-by: Philip Prindeville Signed-off-by: Yousong Zhou Reviewed-By: Philip Prindeville (cherry picked from commit 50b870ee3c7a000a6f1a6c5b5e927f3af1b124c0) --- package/base-files/files/lib/upgrade/common.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh index e2b3ff9664..d3938b9996 100755 --- a/package/base-files/files/lib/upgrade/common.sh +++ b/package/base-files/files/lib/upgrade/common.sh @@ -90,6 +90,17 @@ get_image() { # [ ] cat "$from" 2>/dev/null | $cmd } +get_image_dd() { + local from="$1"; shift + + ( + exec 3>&2 + ( exec 3>&2; get_image "$from" 2>&1 1>&3 | grep -v -F ' Broken pipe' ) 2>&1 1>&3 \ + | ( exec 3>&2; dd "$@" 2>&1 1>&3 | grep -v -E ' records (in|out)') 2>&1 1>&3 + exec 3>&- + ) +} + get_magic_word() { (get_image "$@" | dd bs=2 count=1 | hexdump -v -n 2 -e '1/1 "%02x"') 2>/dev/null }