From fbe985c5d3b4e01478d07b134e1b88a284070f6d Mon Sep 17 00:00:00 2001 From: Dongjin Kim Date: Wed, 4 Dec 2024 14:29:53 +0900 Subject: [PATCH] functions: fix keep downloading original image file Currently the base image is downloaded everytime even if the same file is already downloaded and exist in the output directory. So this patch will check the SHA value of the file before downloading when the same file is required to build an OS image. Signed-off-by: Dongjin Kim Change-Id: I4581b4ddb990ef975d1c3a0008ed6b596ea627a1 --- functions | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/functions b/functions index c29d936..38db65f 100644 --- a/functions +++ b/functions @@ -670,13 +670,36 @@ do_custom_installer() { url=$(do_url_of_cloudimage ${ARCH} ${DISTRO} ${FLAVOUR}) [ "x${url}" = "x" ] && panic "E: invalid URL - ${url}" - # - # Download official Cloud Image - # - echo "I: download official Cloud Image" local cloudimage=${download_dir}/$(basename ${url}) - wget ${url} -O ${cloudimage} \ - || panic "failed to download cloudimage '${url}'" + + if [ -f ${cloudimage} ]; then + local hash_bits=256 + + case $(basename ${cloudimage}) in + debian-*.tar.xz) + hash_bits=512 + esac + + local hashurl=$(dirname ${url})/SHA${hash_bits}SUMS + local hash2=$(sha${hash_bits}sum ${cloudimage} | awk '{print $1}') + + local hashfile=${download_dir}/hash + + echo "I: Checking HASH value before downloading $(basename ${cloudimage})..." + wget --quiet ${hashurl} -O ${hashfile} \ + || panic "failed to download hash file '${hashurl}'" + + local hash1=$(cat ${hashfile} | grep $(basename ${url})$ | awk '{print $1}') + + if [ ${hash1} != ${hash2} ]; then + # + # Download official Cloud Image + # + echo "I: download official Cloud Image" + wget ${url} -O ${cloudimage} \ + || panic "failed to download cloudimage '${url}'" + fi + fi # # Extract raw Cloud Image