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

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

repoprefix="univention-repository-$$-${RANDOM}"

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

# shellcheck disable=SC2119
config_mirror

if ! "${FIXED_18225}"
then
	mkdir -p "${BASEDIR}/mirror/mirror"
	ln -s . "${BASEDIR}/mirror/mirror/${repoprefix}"
fi

(
	set -e
	checkapt --mirror "http://localhost\\(:80\\)\\?/${repoprefix}/" "${DIRS[@]}"
	wait_for_updater_lock
	univention-repository-update net
	checkmirror
)
# shellcheck disable=SC2181
[ $? -eq 0 ] && RETVAL=100 # Test bestanden (Keine Fehler)

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