diff --git a/docker.sh b/docker.sh index 3f5eef3..84c4f21 100755 --- a/docker.sh +++ b/docker.sh @@ -56,10 +56,23 @@ if [[ ! -z ${DRY_RUN:-} ]]; then export APT_DRY_RUN=1 fi base_url="https://apt.dockerproject.org/repo" +remote_filelist="${APT_PATH}/filelist.remote" +local_filelist="${APT_PATH}/filelist.local" + for version in ${APT_VERSIONS[@]}; do - apt-download-binary ${base_url} "$version" "main" "amd64" "${APT_PATH}" || true - apt-download-binary ${base_url} "$version" "main" "i386" "${APT_PATH}" || true + apt-download-binary ${base_url} "$version" "main" "amd64" "${APT_PATH}" ${remote_filelist} || true + apt-download-binary ${base_url} "$version" "main" "i386" "${APT_PATH}" ${remote_filelist} || true done +APT_BACKUP_PATH="${BASE_PATH}/backup/apt" +mkdir -p ${APT_BACKUP_PATH} +(cd ${APT_PATH}; find . -type f -iname "*.deb") | sed 's+^\./++' > ${local_filelist} +comm <(sort $remote_filelist) <(sort $local_filelist) -13 | while read file; do + echo "deleting ${file}" + mv $file ${APT_BACKUP_PATH} +done + +rm ${remote_filelist} ${local_filelist} + # sync_docker "http://apt.dockerproject.org/" "${TUNASYNC_WORKING_DIR}/apt" # sync_docker "http://yum.dockerproject.org/" "${TUNASYNC_WORKING_DIR}/yum" diff --git a/helpers/apt-download b/helpers/apt-download index d12927f..5cd02f5 100644 --- a/helpers/apt-download +++ b/helpers/apt-download @@ -17,6 +17,8 @@ function apt-download-binary() { local repo=$3 local arch=$4 local dest_base_dir=$5 + local filelist="${6:-"/dev/null"}" + if [ -z $dest_base_dir ]; then echo "Destination directory is empty, cannot continue" return 1 @@ -130,6 +132,7 @@ function apt-download-binary() { # Download packages (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 + echo ${pkg_filename} >> $filelist dest_filename="${dest_base_dir}/${pkg_filename}" dest_dir=`dirname ${dest_filename}` [ ! -d "$dest_dir" ] && mkdir -p "$dest_dir" diff --git a/test/apt_test.sh b/test/apt_test.sh new file mode 100755 index 0000000..7d842f4 --- /dev/null +++ b/test/apt_test.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# reqires: wget, yum-utils + +set -e +set -o pipefail + +_here=`dirname $(realpath $0)` +_here=`dirname ${_here}` + +. ${_here}/helpers/apt-download +APT_VERSIONS=("debian-jessie" "debian-stretch" "ubuntu-xenial") + +BASE_PATH="${TUNASYNC_WORKING_DIR}" +APT_PATH="${BASE_PATH}/apt/repo" + +mkdir -p ${APT_PATH} + +# APT mirror +if [[ ! -z ${DRY_RUN:-} ]]; then + export APT_DRY_RUN=1 +fi +base_url="https://apt.dockerproject.org/repo" +remote_filelist="${APT_PATH}/filelist.remote" +local_filelist="${APT_PATH}/filelist.local" + +for version in ${APT_VERSIONS[@]}; do + apt-download-binary ${base_url} "$version" "main" "amd64" "${APT_PATH}" ${remote_filelist} || true + apt-download-binary ${base_url} "$version" "main" "i386" "${APT_PATH}" ${remote_filelist} || true +done + +APT_BACKUP_PATH="${BASE_PATH}/backup/apt" +mkdir -p ${APT_BACKUP_PATH} +(cd ${APT_PATH}; find . -type f -iname "*.deb") | sed 's+^\./++' > ${local_filelist} +comm <(sort $remote_filelist) <(sort $local_filelist) -13 | while read file; do + echo "deleting ${file}" + mv $file ${APT_BACKUP_PATH} +done + +rm ${remote_filelist} ${local_filelist}