#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: |
##  Update multiple localhost components with current version
##  1. setup local repository for maintained component with current version
##  2. check if the component is installable
##  3. newer version is blocked by release version
## roles-not: [basesystem]
## tags: [basic]
## packages:
##  - apache2 | apache2-mpm-prefork
## exposure: dangerous

. pool.sh || exit 137

compname1="test1${RANDOM}"
compname2="test2${RANDOM}"

setup_apache "${repoprefix}"

version1="${major}.${minor}-${_version_patchlevel}"
mkpdir "${major}.${minor}-${_version_patchlevel}" maintained "${ARCH}"  # 0 1
mkpkg "${DIR}" "${DIR_POOL}"

mkpdir "${major}.${minor}--component/${compname1}" maintained all "${ARCH}"  # 2 3
mkdeb "${pkgname}" 1 "${ARCH}" "${DIR}"
mkpkg "${DIR}" "${DIR}"

mkpdir "${major}.${minor}--component/${compname2}" maintained all "${ARCH}"  # 4 5
mkdeb "${pkgname}" 2 "${ARCH}" "${DIR}"
mkpkg "${DIR}" "${DIR}"

declare -a BDIR=("${DIRS[@]}")

minor+=1
version2="${major}.${minor}-${_version_patchlevel}"
mkpdir "${major}.${minor}-${_version_patchlevel}" maintained "${ARCH}"  # 6 7
mkpkg "${DIR}" "${DIR_POOL}"

python3 create_releases_json.py "${REPODIR}" "$version1" "$version2"

comp1="repository/online/component/${compname1}"
comp2="repository/online/component/${compname2}"
config_repo \
	"${comp1}=yes" "${comp1}/version=current" \
	"${comp2}=yes" "${comp2}/version=current"
UP_LOG="${BASEDIR}/up.log"

	set -e
	checkapt "http://localhost\\(:80\\)\\?/${repoprefix}/" "${BDIR[@]}"
	apt-get -qq update
	apt-get -qq install "${pkgname}"
	dpkg-query -W "${pkgname}" | grep -Fqx "${pkgname}	2"
	checkdeb "${pkgname}" 2
	/usr/share/univention-updater/univention-updater net </dev/null 2>&1 >"$UP_LOG"
	grep " is blocked because the components .*\\<$compname1\\>.* are marked as required" "$UP_LOG"
	grep " is blocked because the components .*\\<$compname2\\>.* are marked as required" "$UP_LOG"
	univention-upgrade --disable-app-updates </dev/null >"$UP_LOG" 2>&1 || :
	grep " is blocked because the components .*\\<$compname1\\>.* are marked as required" "$UP_LOG"
	grep " is blocked because the components .*\\<$compname2\\>.* are marked as required" "$UP_LOG"
# vim:set ft=sh:
