#!/bin/sh # to be periodically run on the master mirror # this requires the master mirror to be on the same drive as the archive master_mirror_root='/srv/http/mirror/mirror.archlinux32.org' archive_root='/srv/http/mirror/archive.archlinux32.org' lock_file='/tmp/archive.lock' # get lock if [ -f "${lock_file}" ] && kill -0 "$(cat "${lock_file}")"; then >&2 echo 'cannot get lock' exit fi echo "$$" >"${lock_file}" # copy the isos find "${master_mirror_root}/archisos" \ -mindepth 1 \ -maxdepth 1 \ -type f \ | while read -r file; do if [ -z "${file##*sums}" ]; then diff -u "${file}" "${archive_root}/iso/${file##*/}" \ | sed ' s/^-\([^-][^-]\)/\1/ t d ' \ | sponge -a "${archive_root}/iso/${file##*/}" fi [ -f "${archive_root}/iso/${file##*/}" ] && continue ln "${file}" "${archive_root}/iso/${file##*/}" done # copy the packages find "${master_mirror_root}/pool" \ -mindepth 1 \ -maxdepth 1 \ -type f \ | sed ' s,.*/\([^/]\)\([^/]*\)$,\0 \1 \1\2, ' \ | while read -r path initial file; do target="${archive_root}/packages/${initial}/${file%-*-*-*}/${file}" [ -f "${target}" ] && continue mkdir -p "${target%/*}" ln "${path}" "${target}" done # copy the repositories todays_path=$(date '+%Y/%m/%d') todays_path="${archive_root}/repos/${todays_path}" if [ ! -d "${todays_path}" ]; then for arch in i486 i686 pentium4; do find "${master_mirror_root}/${arch}" \ -mindepth 1 \ -maxdepth 1 \ -type d \ -printf '%f\n' \ | while read -r repo; do mkdir -p "${todays_path}/${arch}/${repo}" cp -a \ "${master_mirror_root}/${arch}/${repo}/${repo}.db" \ "${master_mirror_root}/${arch}/${repo}/${repo}.db.tar.gz" \ "${master_mirror_root}/${arch}/${repo}/${repo}.files" \ "${master_mirror_root}/${arch}/${repo}/${repo}.files.tar.gz" \ "${todays_path}/${arch}/${repo}/" done done rm -f \ "${archive_root}/repos/last" \ "${archive_root}/repos/week" \ "${archive_root}/repos/month" ln -s \ "${todays_path}" \ "${archive_root}/repos/last" first_of_month=$( find "${archive_root}/repos" -mindepth 3 -maxdepth 3 \ | sed ' s,^.*/\([^/]\+\)/\([^/]\+\)/\([^/]\+\)$,\1/\2 \3, t d ' \ | sort -k1r,1 -k2,2 \ | head -n1 \ | tr ' ' '/' ) ln -s \ "${archive_root}/repos/${first_of_month}" \ "${archive_root}/repos/month" first_of_week=$( find "${archive_root}/repos" -mindepth 3 -maxdepth 3 \ | sed ' s,^.*/\([^/]\+\)/\([^/]\+\)/\([^/]\+\)$,\1-\2-\3, t d ' \ | sort \ | tail -n7 \ | while read -r date; do date '+%Y/%m/%d %G %V' -d "${date}" done \ | sort -k2r,3 -k1,1 \ | head -n1 \ | cut -d' ' -f1 ) ln -s \ "${archive_root}/repos/${first_of_week}" \ "${archive_root}/repos/week" fi # release lock rm -f "${lock_file}"