#!/bin/bash

# Check if old recording package are installed

list_packages_with_filter() {
    filter="$1"
    aptitude -q -F '%p' --disable-columns search "$filter"
}

display_xivo_recording_notice() {
	cat <<-EOF
	************************************************************************************************
	*                                      WARNING - Recording                                     *
	* Packages xivo-recording and call-recording-filtering are deprecated.                         *
	*                                                                                              *
	* Please read specific upgrade procedure                                                       *
	* https://documentation.xivo.solutions/en/stable/xivo/upgrade/upgrade.html#specific-procedures *
	* for more details.                                                                            *
	*                                                                                              *
	************************************************************************************************
	EOF
}


is_xivo_recording_installed=$(list_packages_with_filter "?or(?installed?name(\"^xivo-recording$\"),?config-files?name(\"^xivo-recording$\"))")
is_call_filtering_installed=$(list_packages_with_filter "?or(?installed?name(\"^call-recording-filtering$\"),?config-files?name(\"^call-recording-filtering$\"))")

if ! [ -z "$is_xivo_recording_installed" ] || ! [ -z "$is_call_filtering_installed" ]; then
    display_xivo_recording_notice
fi
