limit apt-download max_retry

This commit is contained in:
bigeagle 2016-08-22 00:35:27 +08:00
parent 0328080802
commit 147414f1e9

View File

@ -3,6 +3,7 @@ set -e
set -u set -u
set -o pipefail set -o pipefail
LOADED_APT_DOWNLOAD="yes" LOADED_APT_DOWNLOAD="yes"
MAX_RETRY=${MAX_RETRY:-"3"}
function check-and-download() { function check-and-download() {
remote_file=$1 remote_file=$1
@ -120,6 +121,8 @@ function apt-download-binary() {
checksum_cmd="md5sum"; checksum_regex="^MD5sum" checksum_cmd="md5sum"; checksum_regex="^MD5sum"
fi fi
ERROR=0
# Download packages # Download packages
(echo -e "${pkgidx_content}" | grep -e '^Filename' -e '^Size' -e ${checksum_regex} | cut -d' ' -f 2) | \ (echo -e "${pkgidx_content}" | grep -e '^Filename' -e '^Size' -e ${checksum_regex} | cut -d' ' -f 2) | \
while read pkg_filename; read pkg_size; read pkg_checksum; do while read pkg_filename; read pkg_size; read pkg_checksum; do
@ -135,7 +138,7 @@ function apt-download-binary() {
echo "Skipping ${pkg_filename}, size ${pkg_size}" echo "Skipping ${pkg_filename}, size ${pkg_size}"
fi fi
fi fi
while [ $downloaded != true ]; do for retry in `seq ${MAX_RETRY}`; do
echo "downloading ${pkg_url} to ${dest_filename}" echo "downloading ${pkg_url} to ${dest_filename}"
if [[ -z ${APT_DRY_RUN:-} ]]; then if [[ -z ${APT_DRY_RUN:-} ]]; then
wget ${WGET_OPTIONS:-} -q -O ${dest_filename} ${pkg_url} && { wget ${WGET_OPTIONS:-} -q -O ${dest_filename} ${pkg_url} && {
@ -144,7 +147,9 @@ function apt-download-binary() {
else else
downloaded=true downloaded=true
fi fi
[[ $downloaded == true ]] && break
done done
[[ $downloaded == false ]] && ERROR=1
done done
mv ${pkgidx_tmp_dir}/* ${pkgidx_dir} mv ${pkgidx_tmp_dir}/* ${pkgidx_dir}
@ -154,6 +159,7 @@ function apt-download-binary() {
echo "Mirroring ${base_url} ${dist}, ${repo}, ${arch} done!" echo "Mirroring ${base_url} ${dist}, ${repo}, ${arch} done!"
return $ERROR
} }
# vim: ts=4 sts=4 sw=4 # vim: ts=4 sts=4 sw=4