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 <tobetter@gmail.com>
Change-Id: I4581b4ddb990ef975d1c3a0008ed6b596ea627a1
This commit is contained in:
Dongjin Kim
2024-12-04 14:29:53 +09:00
parent fbf58602e1
commit fbe985c5d3

View File

@@ -670,13 +670,36 @@ do_custom_installer() {
url=$(do_url_of_cloudimage ${ARCH} ${DISTRO} ${FLAVOUR})
[ "x${url}" = "x" ] && panic "E: invalid URL - ${url}"
local cloudimage=${download_dir}/$(basename ${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"
local cloudimage=${download_dir}/$(basename ${url})
wget ${url} -O ${cloudimage} \
|| panic "failed to download cloudimage '${url}'"
fi
fi
#
# Extract raw Cloud Image