#!/usr/share/ucs-test/runner bash
## desc: |
##  Mirror localhost minimum
##  1. Create minimum mirror with 101 minor updates, using hard-links
##  2. Check if updater aborts on 99 and 999
## roles-not: [basesystem]
## tags: [basic]
## packages:
##  - apache2 | apache2-mpm-prefork
##  - univention-debmirror
## bugs: [25619]
## versions:
##  3.0-1: fixed
## exposure: dangerous

RETVAL=121 # Bug vorhanden, wie vermutet
. pool.sh || exit 137
FIXED_26249=false # slow univention-repository-update

setup_apache "${repoprefix}"

mkpdir "${major}.0-0" maintained "${ARCH}"
DMASTER="${DIR}"
mkpkg "${DIR}"
declare -a DOKAY=("${DIR}") DBAD=()

echo -n "Creating patchlevel..."
for ((pat=1;pat<=102;pat+=1)) # 0 created by minor
do
	mkpdir "${major}.${minor}-${pat}" maintained "${ARCH}"
	ln -f "${DMASTER:?}/"* "${DIR:?}/"
	[ "$pat" -le 99 ] && DOKAY+=("${DIR}") || DBAD+=("${DIR}")
done
echo -n " minor..."
for ((min=1;min<=102;min+=1)) # 0 is master
do
	mkpdir "${major}.${min}-0" maintained "${ARCH}"
	ln -f "${DMASTER:?}/"* "${DIR:?}/"
	[ "$min" -le 99 ] && DOKAY+=("${DIR}") || DBAD+=("${DIR}")
done
echo -n " major..."
for ((maj=major+1;maj<=102;maj+=1))
do
	mkpdir "${maj}.0-0" maintained "${ARCH}"
	ln -f "${DMASTER:?}/"* "${DIR:?}/"
	[ "$maj" -le 99 ] && DOKAY+=("${DIR}") || DBAD+=("${DIR}")
done
echo " done."

config_mirror \
	repository/mirror/version/start="${major}.0-0" \
	repository/mirror/version/end="102.102-102" \
	version/version="${major}.0" \
	repository/online/unmaintained=no \
	repository/mirror/recreate_packages=no # for speed, otherwise 1308 gzip's

(
	set -e
	echo "Checking /etc/apt/mirror.list for ${#DOKAY[@]} required entries..."
	checkapt --mirror "http://localhost\(:80\)\?/${repoprefix}/" "${DOKAY[@]}"
	echo "Checking /etc/apt/mirror.list for ${#DBAD[@]} forbidden entries..."
	for dir in "${DBAD[@]}"
	do
		checkapt --mirror "http://localhost\(:80\)\?/${repoprefix}/" "${dir}" 2>/dev/null && echo "Failed: $dir" >&2
		test 1 -eq $?
	done
	"${FIXED_26249}" || exit 0
	# every of the 300 patchlevel+minor+major releases are
	# included.  univention-repository-update _interates_ over those 300
	# releases and generates multiple HTTP-HEAD queries for all _previous_
	# releases.  Also for all 300 releases apt-mirror is called which _forks_
	# shells,wgets,g(un)zips for all _previous_ releases.
	echo "Doing mirror..."
	univention-repository-update net
	echo "Checking mirror..."
	checkmirror "${DOKAY[@]}" -- "${DBAD[@]}"
)
[ $? -eq 0 ] && RETVAL=100 # Test bestanden (Keine Fehler)

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