From 919a5d162c18f2102c0c24c43d2dc6bf9e6762ee Mon Sep 17 00:00:00 2001 From: bigeagle Date: Mon, 21 Aug 2017 15:09:37 +0800 Subject: [PATCH] docker-ce: integrity checking via file size --- docker-ce.sh | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/docker-ce.sh b/docker-ce.sh index 684e7df..9d57725 100755 --- a/docker-ce.sh +++ b/docker-ce.sh @@ -8,10 +8,7 @@ set -o pipefail _here=`dirname $(realpath $0)` GET_FILELIST="${_here}/helpers/docker-ce-filelist.py" -BASE_URL="${TUNASYNC_UPSTREAM_URL:-"https://download.docker.com/linux/"}" - -TMP_DIR="${TUNASYNC_WORKING_DIR}/.tmp" -mkdir -p $TMP_DIR +BASE_URL="${TUNASYNC_UPSTREAM_URL:-"https://download.docker.com/linux/static/"}" REMOTE_FILELIST="${TUNASYNC_WORKING_DIR}/.filelist.remote" LOCAL_FILELIST="${TUNASYNC_WORKING_DIR}/.filelist.local" @@ -20,9 +17,6 @@ LOCAL_FILELIST="${TUNASYNC_WORKING_DIR}/.filelist.local" function cleanup () { echo "cleaning up" - [[ -d ${TMP_DIR} ]] && { - rm -rf $TMP_DIR - } [[ -f $REMOTE_FILELIST ]] && rm $REMOTE_FILELIST [[ -f $LOCAL_FILELIST ]] && rm $LOCAL_FILELIST } @@ -30,20 +24,28 @@ function cleanup () { trap cleanup EXIT # download -$GET_FILELIST $BASE_URL | while read remote_url; do +while read remote_url; do dst_rel_file=${remote_url#$BASE_URL} dst_file="${TUNASYNC_WORKING_DIR}/${dst_rel_file}" - dst_tmp_file="${TMP_DIR}/$(basename ${dst_file})" + dst_dir=`dirname ${dst_file}` echo "${dst_rel_file}" >> $REMOTE_FILELIST echo "downloading ${remote_url}" - [[ -f ${dst_file} ]] && cp -a ${dst_file} ${dst_tmp_file} || mkdir -p `dirname ${dst_file}` - (cd ${TMP_DIR} && wget -q -N ${remote_url} && mv ${dst_tmp_file} ${dst_file}) -done - -rm -rf $TMP_DIR + if [[ -f ${dst_file} ]]; then + remote_filesize=`curl -sI ${remote_url} | grep -i '^content-length:' | awk '{print $2}' | tr -d '\n\r'` + local_filesize=`stat -c "%s" ${dst_file}` + if (( ${remote_filesize} != ${local_filesize} )); then + rm ${dst_file} + fi + else + mkdir -p $dst_dir + fi + + (cd ${dst_dir} && wget -c -N -q ${remote_url} || rm ${dst_file}) +done < <($GET_FILELIST $BASE_URL) +# remove old files (cd ${TUNASYNC_WORKING_DIR}; find . -type f ) | sed 's+^\./++' > ${LOCAL_FILELIST} comm <(sort $REMOTE_FILELIST) <(sort $LOCAL_FILELIST) -13 | while read file; do file="${TUNASYNC_WORKING_DIR}/$file"