#!/bin/bash

source /usr/bin/xivo-upgrade-functions

# Keep in sync with pre-stop.d/02-save-dird-services-conf
lookup_by_label_version="2026.10.00"

backup_file="/var/tmp/xivo-upgrade-lookup-by-label/dird-services.yml"

if ! dpkg --compare-versions "$XIVO_VERSION_INSTALLED" "<<" "$lookup_by_label_version"; then
    exit 0
fi

cmn_echo_important "The per context directory search has been replaced by the search by label."
cmn_echo_important "The menu 'CTI Server -> Directories -> Direct directories' is now 'CTI Server -> Directories -> Search by label'."

if [ -s "${backup_file}" ]; then
    cmn_echo_important "Your previous per context directory configuration was saved in:"
    cmn_echo_important "  ${backup_file}"
    cmn_echo_important "Refer to it to configure the search by label accordingly."
else
    cmn_echo_important "WARNING: your previous per context directory configuration could not be saved,"
    cmn_echo_important "         please review the search by label configuration in the web interface."
fi
