apt-download supports deleting files that does not exist in remote

This commit is contained in:
bigeagle 2016-11-20 16:07:43 +08:00
parent 0117ac0d05
commit 16a462abdd
3 changed files with 57 additions and 2 deletions

View File

@ -56,10 +56,23 @@ if [[ ! -z ${DRY_RUN:-} ]]; then
export APT_DRY_RUN=1 export APT_DRY_RUN=1
fi fi
base_url="https://apt.dockerproject.org/repo" 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 for version in ${APT_VERSIONS[@]}; do
apt-download-binary ${base_url} "$version" "main" "amd64" "${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}" || true apt-download-binary ${base_url} "$version" "main" "i386" "${APT_PATH}" ${remote_filelist} || true
done 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://apt.dockerproject.org/" "${TUNASYNC_WORKING_DIR}/apt"
# sync_docker "http://yum.dockerproject.org/" "${TUNASYNC_WORKING_DIR}/yum" # sync_docker "http://yum.dockerproject.org/" "${TUNASYNC_WORKING_DIR}/yum"

View File

@ -17,6 +17,8 @@ function apt-download-binary() {
local repo=$3 local repo=$3
local arch=$4 local arch=$4
local dest_base_dir=$5 local dest_base_dir=$5
local filelist="${6:-"/dev/null"}"
if [ -z $dest_base_dir ]; then if [ -z $dest_base_dir ]; then
echo "Destination directory is empty, cannot continue" echo "Destination directory is empty, cannot continue"
return 1 return 1
@ -130,6 +132,7 @@ function apt-download-binary() {
# 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
echo ${pkg_filename} >> $filelist
dest_filename="${dest_base_dir}/${pkg_filename}" dest_filename="${dest_base_dir}/${pkg_filename}"
dest_dir=`dirname ${dest_filename}` dest_dir=`dirname ${dest_filename}`
[ ! -d "$dest_dir" ] && mkdir -p "$dest_dir" [ ! -d "$dest_dir" ] && mkdir -p "$dest_dir"

39
test/apt_test.sh Executable file
View File

@ -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}