Skip to content

Commit b9d7f87

Browse files
deitchrvs
authored andcommitted
tool to update components
Signed-off-by: Avi Deitcher <[email protected]>
1 parent 57f55d6 commit b9d7f87

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

tools/update-component-sha.sh

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/sh
2+
set -e
3+
4+
##
5+
#
6+
# script to replace hashes in config files
7+
# see usage() for usage and functionality
8+
#
9+
10+
usage() {
11+
cat >&2 <<EOF
12+
$0 --<mode> <how-to-find> <new-hash>
13+
14+
Available modes: --hash and --image
15+
16+
Replace by hash:
17+
$0 --hash <OLD> <NEW>
18+
Example: $0 --hash 8675309abcdefg abcdef567899
19+
Will replace all instances of 8675309abcdefg with abcdef567899
20+
21+
Replace by image: $0 --image <IMAGE> <NEW>
22+
$0 --image <IMAGE> <NEW>
23+
Example: $0 --image linuxkit/foo abcdef567899
24+
Will tag all instances of linuxkit/foo with abcdef567899
25+
26+
$0 --image <IMAGE>:<NEW> is accepted as a convenient shortcut for cutting
27+
and pasting e.g.the output of linuxkit pkg show-tag
28+
29+
EOF
30+
}
31+
32+
33+
# sufficient arguments
34+
if [ $# -lt 3 ] ; then
35+
usage
36+
exit 1
37+
fi
38+
39+
# which mode?
40+
case "$1" in
41+
--hash)
42+
if [ $# -ne 3 ] ; then
43+
usage
44+
exit 1
45+
fi
46+
old=$2
47+
new=$3
48+
49+
git grep -w -l "\b$old\b" | grep -v /vendor/ | xargs sed -i.bak -e "s,$old,$new,g"
50+
;;
51+
--image)
52+
case $# in
53+
2)
54+
image=${2%:*}
55+
hash=${2#*:}
56+
;;
57+
3)
58+
image=$2
59+
hash=$3
60+
;;
61+
esac
62+
git grep -E -l "[[:space:]]$image:" | grep -v /vendor/ | grep Dockerfile | xargs sed -i.bak -E -e "s,([[:space:]])($image):([^[:space:]]+), $image:$hash,g"
63+
;;
64+
*)
65+
echo "Unknown mode $1"
66+
usage
67+
exit 1
68+
;;
69+
esac
70+
71+
find . -name '*.bak' | xargs rm

0 commit comments

Comments
 (0)