#!/usr/share/ucs-test/runner bash
# shellcheck shell=bash
## desc: |
##  Update localhost repository one patchlevel
##  1. setup local repository with 2 patchlevels
##  2. check if upgrade of package work
## 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}"

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

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[@]}"
	dpkg-query -W "${pkgname}" | grep -Fqx "${pkgname}	2"
	test "${_version_version}" = "$(ucr get version/version)"
	test 1 = "$(ucr get version/patchlevel)"
	test -n "$(ucr get update/available)"  # make sure update/available has been updated
	checkdeb "${pkgname}" 1 2
# vim:set ft=sh:
