#!/bin/bash

LOCKFILE=/var/lock/mirrormanager/update-mirrorlist-server.lock
CACHEDIR=/var/lib/mirrormanager

[ -e ${LOCKFILE} ] && kill -0 $(cat ${LOCKFILE}) && exit 2
mkdir -p $(dirname ${LOCKFILE})
echo $$ > ${LOCKFILE}
trap "rm -f ${LOCKFILE}" QUIT TERM INT HUP EXIT

cd ${MM_DIR}
rm -rf ${CACHEDIR}/old
mkdir -p ${CACHEDIR}/old
cp -ar ${CACHEDIR}/*  ${CACHEDIR}/old/ 2>/dev/null

/usr/local/bin/generate-mirrorlist-cache $@

exit 0
