#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: Mirror localhost repository
## roles-not: [basesystem]
## tags: [basic]
## packages:
##  - apache2 | apache2-mpm-prefork
##  - apt-mirror
## exposure: dangerous

RETVAL=110 # Test fehlgeschlagen
. pool.sh || exit 137

setup_apache "${repoprefix}"

mkpdir "${_version_version}-0" maintained "${ARCH}"
# 0:dists/ucs500/main/binary-amd64/
# 1:dists/errata500/main/binary-amd64/
mkdeb "${pkgname}ua" 1 all "${DIR_POOL}"
mkpkg "${DIRS[0]}" "${DIR_POOL}"
mkdeb "${pkgname}ub" 1 "${ARCH}" "${DIR_POOL}"
mkpkg "${DIRS[0]}" "${DIR_POOL}"
mkdeb "${pkgname}ea" 1 all "${DIR_POOL}"
mkpkg "${DIRS[1]}" "${DIR_POOL}"
mkdeb "${pkgname}eb" 1 "${ARCH}" "${DIR_POOL}"
mkpkg "${DIRS[1]}" "${DIR_POOL}"
mksh "${DIR%/main/binary-*}" preup postup

config_mirror repository/mirror=no

(
	set -e
	grep -v '^#\|^[[:space:]]*$\|^set ' /etc/apt/mirror.list && false
	ucr set repository/mirror=yes
	checkapt --mirror "http://localhost\\(:80\\)\\?/${repoprefix}/" "${DIRS[@]}"
	echo "MARKER START for 09_updater/70mirror" >> /var/log/univention/repository.log
	wait_for_updater_lock
	univention-repository-update net
	echo "MARKER END for 09_updater/70mirror" >> /var/log/univention/repository.log
	checkmirror
)
# shellcheck disable=SC2181
[ $? -eq 0 ] && RETVAL=100 # Test bestanden (Keine Fehler)

exit ${RETVAL}
# vim:set ft=sh:
