From 5559247df3d16eb48051aad99b9e7be85362a2cf Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 22 Aug 2017 09:59:26 +0200 Subject: bin/build-packages: try to download sources by hash --- bin/build-packages | 10 ++++++++ bin/common-functions | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) (limited to 'bin') diff --git a/bin/build-packages b/bin/build-packages index fc3a205..c207966 100755 --- a/bin/build-packages +++ b/bin/build-packages @@ -187,6 +187,16 @@ while [ ${count} -ne 0 ]; do tar -xz --overwrite -f "${source_name}" --exclude PKGBUILD --strip-components=1 || true fi + if echo "${straw}" | \ + grep -qF ':mirrored_source_by_hash:'; then + # maybe a missing source is/was the problem? + # download it from sources.archlinux32.org by its hash + if ! download_sources_by_hash "${package}" "${repository}" "${git_revision}" "${mod_git_revision}"; then + # we can't improve anything, if no source was downloadable + continue + fi + fi + if echo "${straw}" | \ grep -qF ':with_build_support:'; then build_command='staging-with-build-support-i686-build' diff --git a/bin/common-functions b/bin/common-functions index f721614..1f2d108 100755 --- a/bin/common-functions +++ b/bin/common-functions @@ -680,3 +680,69 @@ find_dependencies_on_build_list() { uniq -d } + +# download_sources_by_hash $package $repository $git_revision $git_mod_revision +# try to download all sources by their hash into the current directory +# returns 0 if any source was downloaded and 1 otherwise + +download_sources_by_hash() { + + local package="$1" + local repository="$2" + local git_revision="$3" + local git_mod_revision="$4" + + local return_value=1 + local tmp_dir=$(mktemp -d) + local sum_type + local arch_suffix + + if ! make_source_info "${package}" "${repository}" "${git_revision}" "${git_mod_revision}" "${tmp_dir}/.SRCINFO"; then + >&2 echo 'download_sources_by_hash: make_source_info failed.' + rm -rf --one-file-system "${tmp_dir}" + return 1 + fi + + if ! [ -s "${tmp_dir}/.SRCINFO" ]; then + >&2 echo 'download_sources_by_hash: ".SRCINFO" has not been created by make_source_info.' + rm -rf --one-file-system "${tmp_dir}" + return 1 + fi + + for arch_suffix in '' '_i686'; do + for sum_type in 'sha256sum' 'sha512sum'; do + grep "^\s*${sum_type}s${arch_suffix} = " "${tmp_dir}/.SRCINFO" | \ + sed 's|^.* = ||' | \ + cat -n > \ + "${tmp_dir}/sums" + grep "^\s*source${arch_suffix} = " "${tmp_dir}/.SRCINFO" | \ + sed ' + s|^.* = || + s|::.*$|| + s|.*/|| + ' | \ + cat -n > \ + "${tmp_dir}/urls" + if [ $(wc -l < "${tmp_dir}/sums") -eq $(wc -l < "${tmp_dir}/urls") ]; then + join -1 1 -2 1 -o 1.2,2.2 "${tmp_dir}/sums" "${tmp_dir}/urls" > \ + "${tmp_dir}/joined" + while read -r sum file; do + if echo "${sum} ${file}" | \ + ${sum_type} -c > /dev/null 2>&1; then + # the correct source is already there + continue + fi + if wget -O "${tmp_dir}/transfer" "${source_by_hash_mirror}${sum}"; then + mv "${tmp_dir}/transfer" "${file}" + return_value=0 + fi + done < \ + "${tmp_dir}/joined" + fi + done + done + + rm -rf --one-file-system "${tmp_dir}" + return ${return_value} + +} -- cgit v1.2.3-54-g00ecf