From 43e47f1912ce07e65181355d4f5c52298a8fba28 Mon Sep 17 00:00:00 2001 From: Maksim Malchuk Date: Sun, 23 Apr 2023 22:37:33 +0300 Subject: [PATCH] Extend the checksum files generation procedure The usage of the DIB_CHECKSUM variable is extended to have an ability generate the only one checksum file, for example only 'sha256' (by setting an environment variable DIB_CHECKSUM='sha256'), and to retain the backward compatibility (DIB_CHECKSUM=1 will generate both 'sha256' and 'md5' supported at this moment). As an additional feature we have the simple way to completely deprecate 'md5' later, and add new methods, for example, 'sha512' etc. Change-Id: I2dd1c60e3bfd9c823a7382b1390b1d40c52a5c97 Signed-off-by: Maksim Malchuk --- diskimage_builder/lib/common-functions | 7 ++++--- releasenotes/notes/dib-checksum-3d0d9af8778176be.yaml | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/dib-checksum-3d0d9af8778176be.yaml diff --git a/diskimage_builder/lib/common-functions b/diskimage_builder/lib/common-functions index b8b8b383..262094f7 100644 --- a/diskimage_builder/lib/common-functions +++ b/diskimage_builder/lib/common-functions @@ -65,7 +65,7 @@ function finish_image () { fi mv $OUT_IMAGE_PATH $1 - if [ "$DIB_CHECKSUM" == "1" ]; then + if [[ -n "$DIB_CHECKSUM" && "$DIB_CHECKSUM" != "0" ]]; then # NOTE(pabelanger): Read image into memory once and generate # both checksum files. @@ -74,8 +74,9 @@ function finish_image () { # no tty). Waiting for just these processes is a bit of hacky # workaround ... declare -a wait_for - md5sum $1 > $1.md5 & wait_for+=($!) - sha256sum $1 > $1.sha256 & wait_for+=($!) + [[ "$DIB_CHECKSUM" == "1" ]] && DIB_CHECKSUM="md5,sha256" + [[ "$DIB_CHECKSUM" == *md5* ]] && md5sum $1 > $1.md5 & wait_for+=($!) + [[ "$DIB_CHECKSUM" == *sha256* ]] && sha256sum $1 > $1.sha256 & wait_for+=($!) wait "${wait_for[@]}" fi echo "Image file $1 created..." diff --git a/releasenotes/notes/dib-checksum-3d0d9af8778176be.yaml b/releasenotes/notes/dib-checksum-3d0d9af8778176be.yaml new file mode 100644 index 00000000..1214b7f1 --- /dev/null +++ b/releasenotes/notes/dib-checksum-3d0d9af8778176be.yaml @@ -0,0 +1,10 @@ +--- +features: + - | + The usage of the ``DIB_CHECKSUM`` variable is extended. Now to be more + specific the variable can be set to the ``sha256`` or ``md5`` value to + generate only one checksum file. There also can be provided a + comma-separated list of the values, but only ``sha256`` and ``md5`` + supported. For backward compatibility using ``DIB_CHECKSUM=1`` or option + ``--checksum`` in the command line still can be used to generate all + supported checksums.