Skip to content

Commit

Permalink
Fix debian bullseye x86_64 sysroot [CLARM-39] (#20)
Browse files Browse the repository at this point in the history
The fix makes the script retry 4 times if the checksum of the
downloaded package is wrong. The issue is caused by a server
that sometimes breaks the connection without delivering all the data.
curl: (18) transfer closed with 8605775 bytes remaining to read
  • Loading branch information
krisukox authored Jun 16, 2023
1 parent 5e4d51b commit 42031f2
Showing 1 changed file with 58 additions and 12 deletions.
70 changes: 58 additions & 12 deletions sysroot/sysroot-creator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,21 @@ DownloadOrCopyNonUniqueFilename() {
# does not.
local url="$1"
local dest="$2"
local force="${3:-0}"

local hash="$(echo "$url" | sha256sum | cut -d' ' -f1)"

DownloadOrCopy "${url}" "${dest}.${hash}"
DownloadOrCopy "${url}" "${dest}.${hash}" "${force}"
# cp the file to prevent having to redownload it, but mv it to the
# final location so that it's atomic.
cp "${dest}.${hash}" "${dest}.$$"
mv "${dest}.$$" "${dest}"
}

DownloadOrCopy() {
if [ -f "$2" ] ; then
local force="${3:-0}"

if [ $force -eq 0 ] && [ -f "$2" ] ; then
echo "$2 already in place"
return
fi
Expand Down Expand Up @@ -296,7 +299,21 @@ GeneratePackageListDistRepo() {
local package_list_arch="${repo_basedir}/${package_file_arch}"

DownloadOrCopyNonUniqueFilename "${package_list_arch}" "${package_list}"
VerifyPackageListing "${package_file_arch}" "${package_list}" ${repo} ${dist}

for i in {1..5}; do
if VerifyPackageListing "${package_file_arch}" "${package_list}" ${repo} ${dist}; then
break
fi

if [ $i -eq 5 ]; then
echo "sha256sum: ERROR: computed checksum did NOT match, exceeded max number of attempts"
exit 1
fi

echo "sha256sum: WARNING: computed checksum did NOT match, retrying..."
DownloadOrCopyNonUniqueFilename "${package_list_arch}" "${package_list}" 1
done

ExtractPackageXz "${package_list}" "${tmp_package_list}" ${repo}
cat "${tmp_package_list}" | ./merge-package-lists.py "${list_base}"
}
Expand Down Expand Up @@ -401,14 +418,33 @@ InstallIntoSysroot() {
exit 1
fi

Banner "Installing $(basename ${file})"
DownloadOrCopy ${file} ${package}
if [ ! -s "${package}" ] ; then
echo
echo "ERROR: bad package ${package}"
exit 1
fi
echo "${sha256sum} ${package}" | sha256sum --quiet -c
for i in {1..5}; do
Banner "Installing $(basename ${file})"
DownloadOrCopy ${file} ${package}
if [ ! -s "${package}" ] ; then
echo
echo "ERROR: bad package ${package}"
exit 1
fi

sha256sum_comp=($(sha256sum ${package}))

if [ "$sha256sum_comp" = "$sha256sum" ]; then
break
fi

echo ${output_file}
echo expected: ${sha256sum}
echo computed: ${sha256sum_comp}

if [ $i -eq 5 ]; then
echo "sha256sum: ERROR: computed checksum did NOT match, exceeded max number of attempts"
exit 1
fi

echo "sha256sum: WARNING: computed checksum did NOT match, retrying..."
rm ${package}
done

SubBanner "Extracting to ${INSTALL_ROOT}"
dpkg-deb -x ${package} ${INSTALL_ROOT}
Expand Down Expand Up @@ -551,7 +587,17 @@ VerifyPackageListing() {
exit 1
fi

echo "${sha256sum} ${output_file}" | sha256sum --quiet -c
sha256sum_comp=($(sha256sum ${output_file}))

if [ "$sha256sum_comp" = "$sha256sum" ]; then
return 0
fi

echo ${output_file}
echo expected: ${sha256sum}
echo computed: ${sha256sum_comp}

return 1
}

#
Expand Down

0 comments on commit 42031f2

Please sign in to comment.