summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Yang <yangyang1@zte.com.cn>2017-05-25 15:02:43 +0800
committerAlex Yang <yangyang1@zte.com.cn>2017-05-25 16:34:47 +0800
commit9b3bab184c182f58a5329c1cbb2bd0c4cf3cc66e (patch)
tree0eb5327c5dc131dd986c7fadd23cfe02e5591e66
parentfebeda4a5778f55e9564948c6c326ea0849fef1b (diff)
Remove the incomplete file and re-download it
The kolla file downloaded on the ci node may be incomplete. Change-Id: Id15695504bd29f31178054b5e8cc83d8612543d9 Signed-off-by: Alex Yang <yangyang1@zte.com.cn>
-rwxr-xr-xcode/makefile_patch.sh64
1 files changed, 52 insertions, 12 deletions
diff --git a/code/makefile_patch.sh b/code/makefile_patch.sh
index 23a489b4..7d6c79bc 100755
--- a/code/makefile_patch.sh
+++ b/code/makefile_patch.sh
@@ -25,19 +25,59 @@ cirros_ver="0.3.5"
cirros_filename="cirros-${cirros_ver}-x86_64-disk.img"
cirros_url=${cirros_server}/${cirros_ver}/${cirros_filename}
+function check_or_download_file()
+{
+ file_path=$1
+ file_url=$2
+ file_name=$(basename $2)
+ if [ $# -eq 3 ]; then md5_url=$3; else md5_url=""; fi
+
+ pushd $file_path >/dev/null
+
+ count=0
+ MAX_DOWNLOAD_TIMES=2
+ while [ $count -lt ${MAX_DOWNLOAD_TIMES} ]; do
+ count=$[count + 1]
+
+ if [ ! -f ${file_name} ]; then
+ echo "Begin to download ${file_name}"
+ wget --progress=dot:giga ${file_url}
+ fi
+
+ if [ ! -z ${md5_url} ]; then
+ rm -f $(basename ${md5_url})
+ wget ${md5_url}
+ md5sum -c $(basename ${md5_url})
+ if [ $? -ne 0 ]; then
+ echo "MD5 check failed !"
+ rm -f ${file_name}
+ else
+ echo "MD5 check succeeded !"
+ count=${MAX_DOWNLOAD_TIMES}
+ fi
+ else
+ wget --spider $file_url -o tmp_filesize
+ origin_size=$(cat tmp_filesize | grep Length | awk '{print $2}')
+ rm tmp_filesize
+ local_size=$(stat -c %s ${file_path}/${file_name} | tr -d '\n')
+ if [ ${local_size} -ne ${origin_size} ]; then
+ echo "The local ${file_name} is incomplete."
+ rm -f ${file_name}
+ else
+ echo "File ${file_path}/${file_name} is ok."
+ count=${MAX_DOWNLOAD_TIMES}
+ fi
+ fi
+ done
+
+ popd > /dev/null
+}
+
if [ ! -d $CACHE_PATH ]; then mkdir -p $CACHE_PATH ; fi
-if [ ! -f $CACHE_PATH/${isoname} ]; then
- wget -P $CACHE_PATH $isourl
-fi
-if [ ! -f $CACHE_PATH/$imagename ]; then
- wget -P $CACHE_PATH "$imageserver/$imagename"
-fi
-if [ ! -f $CACHE_PATH/registry-server.tar ]; then
- wget -P $CACHE_PATH "http://daisycloud.org/static/files/registry-server.tar"
-fi
-if [ ! -f $CACHE_PATH/${cirros_filename} ]; then
- wget -P $CACHE_PATH ${cirros_url}
-fi
+check_or_download_file $CACHE_PATH $isourl
+check_or_download_file $CACHE_PATH $imageserver/${imagename} ${imageserver}/${imagename}.md5
+check_or_download_file $CACHE_PATH "http://daisycloud.org/static/files/registry-server.tar"
+check_or_download_file $CACHE_PATH ${cirros_url}
cp $CACHE_PATH/${isoname} $TOOLS_PATH/setup/bin_temp/
cp $CACHE_PATH/$imagename $TOOLS_PATH/setup/bin_temp/