#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: |
##  Update localhost repository one major version
##  1. setup local repository with 1 patchlevel, 1 minor and 1 major update
##  2. check if upgrade of package work
##  3. check if all versions in between are used
##  4. check if only latest major repository is used
## roles-not: [basesystem]
## tags: [basic]
## packages:
##  - apache2 | apache2-mpm-prefork
## exposure: dangerous

. pool.sh || exit 137

setup_apache "${repoprefix}"

mkpdir "${_version_version}-0" maintained "${ARCH}"
mkdeb "${pkgname}" 1 "${ARCH}" "${DIR_POOL}"
mkpkg "${DIR}" "${DIR_POOL}"

mkpdir "${_version_version}-1" maintained "${ARCH}"
mkdeb "${pkgname}" 2 "${ARCH}" "${DIR_POOL}"
mkpkg "${DIR}" "${DIR_POOL}"

minor+=1
minor_update_version="${major}.${minor}-0"
mkpdir "${major}.${minor}-0" maintained "${ARCH}"
mkdeb "${pkgname}" 3 "${ARCH}" "${DIR_POOL}"
mkpkg "${DIR}" "${DIR_POOL}"

major+=1
mkpdir "${major}.0-0" maintained "${ARCH}"
mkdeb "${pkgname}" 4 "${ARCH}" "${DIR_POOL}"
mkpkg "${DIR}" "${DIR_POOL}"

python3 create_releases_json.py "${REPODIR}" "${_version_version}-0" "${_version_version}-1" "${minor_update_version}" "${major}.0-0"

config_repo version/patchlevel=0 version/erratalevel=0

	set -e
	checkapt "http://localhost\\(:80\\)\\?/${repoprefix}/" "${DIRS[0]}"
	apt-get -qq update
	apt-get -qq install "${pkgname}"
	dpkg-query -W "${pkgname}" | grep -Fqx "${pkgname}	1"
	handle_interactive_mode
	/usr/share/univention-updater/univention-updater net
	checkapt "http://localhost\\(:80\\)\\?/${repoprefix}/" "${DIRS[3]}"
	dpkg-query -W "${pkgname}" | grep -Fqx "${pkgname}	4"
	test "${major}.0" = "$(ucr get version/version)"
	test 0 = "$(ucr get version/patchlevel)"
	test -n "$(ucr get update/available)"  # make sure update/available has been updated
	checkdeb "${pkgname}" 1 2 3 4
# vim:set ft=sh:
