mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 17:26:28 +00:00
Merge pull request #2275 from deitch/util-replace-all-tags-by-image
Add script to update tag for all image matches
This commit is contained in:
commit
dedd690b69
@ -1,10 +1,67 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
if [ $# -ne 2 ] ; then
|
||||
echo "Need <OLD> and <NEW> as arguments" >&2
|
||||
|
||||
##
|
||||
#
|
||||
# script to replace hashes in config files
|
||||
# see usage() for usage and functionality
|
||||
#
|
||||
|
||||
function usage() {
|
||||
cat >&2 <<EOF
|
||||
$0 --<mode> <how-to-find> <new-hash>
|
||||
|
||||
Available modes: --hash and --image
|
||||
|
||||
Replace by hash:
|
||||
$0 --hash <OLD> <NEW>
|
||||
Example: $0 8675309abcdefg abcdef567899
|
||||
Will replace all instances of 8675309abcdefg with abcdef567899
|
||||
|
||||
Replace by image: $0 --image <IMAGE> <NEW>
|
||||
$0 --image <IMAGE> <NEW>
|
||||
Example: $0 linuxkit/foo abcdef567899
|
||||
Will tag all instances of linuxkit/foo with abcdef567899
|
||||
|
||||
By default, for convenience, if no mode is given (--image or --hash), the first method (--hash) is assumed.
|
||||
Thus the following are equivalent:
|
||||
$0 <OLD> <NEW>
|
||||
$0 --hash <OLD> <NEW>
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
# backwards compatibility
|
||||
if [ $# -eq 2 ]; then
|
||||
set -- "--hash" "$1" "$2"
|
||||
fi
|
||||
|
||||
# sufficient arguments
|
||||
if [ $# -ne 3 ] ; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
old=$1
|
||||
new=$2
|
||||
|
||||
git grep -l "$old" | xargs sed -i -e "s,$old,$new,g"
|
||||
|
||||
# which mode?
|
||||
case "$1" in
|
||||
--hash)
|
||||
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
|
||||
git grep -E -l "\b$image:" | xargs sed -i.bak -e "s,$image:[[:xdigit:]]"'\{40\}'",$image:$hash,g"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown mode $1"
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
find . -name '*.bak' | xargs rm
|
||||
|
Loading…
Reference in New Issue
Block a user