Files
linuxkit/scripts/update-component-sha.sh
Chris Irrgang 50025b8840 separate kernel series hashing (#4194)
* separate kernel series hashing

Signed-off-by: Chris Irrgang <chris.irrgang@gmx.de>

* fix issues with the update component sha script

- add bsd/gnu cross compatibility for sed
- also replace in */test.sh files
- replace potentially problematic xargs
- remove potentially problematic word boundary \b

Signed-off-by: Chris Irrgang <chris.irrgang@gmx.de>

* Move common kernel files to dedicated folder

Signed-off-by: Chris Irrgang <chris.irrgang@gmx.de>

* run update-kernel-yamls

Signed-off-by: Chris Irrgang <chris.irrgang@gmx.de>

---------

Signed-off-by: Chris Irrgang <chris.irrgang@gmx.de>
2025-12-11 21:06:47 +02:00

109 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
set -e
##
#
# script to replace hashes in config files
# see usage() for usage and functionality
#
# Detect sed in-place flag (BSD vs GNU)
if sed --version 2>/dev/null | grep -q GNU; then
SED_INPLACE="sed -i"
else
# BSD sed requires an argument for -i
SED_INPLACE="sed -i ''"
fi
usage() {
cat >&2 <<EOF
$0 --<mode> <how-to-find> <new-hash>
Available modes: --hash, --image, --pkg
Replace by hash:
$0 --hash <OLD> <NEW>
Example: $0 --hash 8675309abcdefg abcdef567899
Will replace all instances of 8675309abcdefg with abcdef567899
Replace by image:
$0 --image <IMAGE> <NEW>
Example: $0 --image linuxkit/foo abcdef567899
Will tag all instances of linuxkit/foo with abcdef567899
$0 --image <IMAGE>:<NEW> is accepted as a convenient shortcut for cutting
and pasting e.g.the output of linuxkit pkg show-tag
Replace by pkg directory:
$0 --pkg <PATH/TO/PKG> <NEW>
Example: $0 --pkg ./pkg/xen-tools
Will use linuxkit pkg show-tag on the directory ./pkg/xen-tools, and then
tag all instances with the result
EOF
}
updateImage() {
local image
local hash
case $# in
1)
image=${1%:*}
hash=${1#*:}
;;
2)
image=$1
hash=$2
;;
esac
git grep -E -l "[[:space:]]$image:" -- '*.yml' '*.yaml' '*.yml.in' '*.yaml.in' '*/Dockerfile' '*/Makefile' '*/test.sh' | grep -v /vendor/ | while read -r file; do $SED_INPLACE -E -e "s,([[:space:]])($image):([^[:space:]]+),\1$image:$hash,g" "$file"; done
}
# backwards compatibility
if [ $# -eq 2 -a -n "${1%--*}" ]; then
set -- "--hash" "$1" "$2"
fi
# which mode?
mode=$1
shift
case "${mode}" in
--hash)
if [ $# -ne 2 ] ; then
usage
exit 1
fi
old=$1
new=$2
git grep -E -l "($old)([[:space:]]|$)" -- '*.yml' '*.yaml' '*.yml.in' '*.yaml.in' '*/Dockerfile' '*/Makefile' '*/test.sh' | grep -v /vendor/ | while read -r file; do $SED_INPLACE -E -e "s,($old)([[:space:]]|$),$new\2,g" "$file"; done
;;
--image)
if [ $# -lt 1 ] ; then
usage
exit 1
fi
updateImage $@
;;
--pkg)
if [ $# -ne 1 ]; then
usage
exit 1
fi
if [ ! -d "$1" ]; then
echo "Directory '$1' does not exist"
usage
exit 1
fi
tag=$(linuxkit pkg show-tag $1)
updateImage ${tag}
;;
*)
echo "Unknown mode $1"
usage
exit 1
;;
esac