From 5380c7a18d7140fd7c2d8e51d430aa95994b58ab Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 13 Oct 2017 10:34:02 +0100 Subject: [PATCH] update-component-sha: Accept easier to cut-n-paste --image arguments. Signed-off-by: Ian Campbell --- scripts/update-component-sha.sh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/update-component-sha.sh b/scripts/update-component-sha.sh index 2eeda3f49..704ab0a34 100755 --- a/scripts/update-component-sha.sh +++ b/scripts/update-component-sha.sh @@ -23,6 +23,9 @@ Replace by image: $0 --image Example: $0 --image linuxkit/foo abcdef567899 Will tag all instances of linuxkit/foo with abcdef567899 + $0 --image : is accepted as a convenient shortcut for cutting + and pasting e.g.the output of linuxkit pkg show-tag + By default, for convenience, if no mode is given (--image or --hash), the first method (--hash) is assumed. Thus the following are equivalent: $0 @@ -33,28 +36,39 @@ EOF # backwards compatibility -if [ $# -eq 2 ]; then +if [ $# -eq 2 -a -n "${1%--*}" ]; then set -- "--hash" "$1" "$2" fi # sufficient arguments -if [ $# -ne 3 ] ; then +if [ $# -lt 2 -o $# -gt 3 ] ; then usage exit 1 fi - # which mode? case "$1" in --hash) + if [ $# -ne 3 ] ; then + usage + exit 1 + fi old=$2 new=$3 git grep -w -l "\b$old\b" | xargs sed -i.bak -e "s,$old,$new,g" ;; --image) - image=$2 - hash=$3 + case $# in + 2) + image=${2%:*} + hash=${2#*:} + ;; + 3) + image=$2 + hash=$3 + ;; + esac git grep -E -l "\b$image:" | xargs sed -i.bak -e "s,$image:[[:xdigit:]]"'\{40\}'",$image:$hash,g" ;; *)