#!/bin/bash

phase="$1"
version="$2"

if [ "x$phase" = "xpost" ] && [ "x$version" = "x5.0-0" ]; then
	[ -f /etc/apt/preferences.d/99kopanotest.pref ] ||
	cat >/etc/apt/preferences.d/99kopanotest.pref <<__PREF__
Package: *kopano* python3-mapi *z-push*
Pin: origin appcenter-test.software-univention.de
Pin-Priority: 1001
__PREF__
	
	[ -f /etc/apt/preferences.d/99kopano.pref ] ||
	cat >/etc/apt/preferences.d/99kopano.pref <<__PREF__
Package: *kopano* python3-mapi *z-push*
Pin: origin appcenter.software-univention.de
Pin-Priority: 1001
__PREF__

[ -f /etc/apt/preferences.d/99kopano-externalrepo.pref ] ||
	cat >/etc/apt/preferences.d/99kopano-externalrepo.pref <<__PREF__
Package: *kopano* python3-mapi *z-push*
Pin: origin download.kopano.io
Pin-Priority: 1001
__PREF__

set -x
cp /etc/apt/sources.list.d/kopano-core.list /etc/apt/sources.list.d/00-updateucs5-kopano-core.list
cp /etc/apt/sources.list.d/kopano-webapp.list /etc/apt/sources.list.d/00-updateucs5-kopano-webapp.list
cp /etc/apt/sources.list.d/z-push.list /etc/apt/sources.list.d/00-updateucs5-kopano-z-push.list

sed -i 's/Univention_4.3/Univention_5.0/g' /etc/apt/sources.list.d/00-updateucs5-kopano*list
set +x

fi

exit 0
