#
# To enable a vdr plugin, its config must be symlinked to /etc/vdr/conf.d.
# This must only be done when installing a plugin package or upgrading
# from an old package, which does not support the conf.d mechanism.
#
# Before installing, we remember if the plugin-config in conf.avail
# does not exist (because this is a new installation or an upgrade
# from an old installation or the config was removed by the admin)
# by creating a /etc/vdr/conf.d/*.dpkg-vdr-plugin-enable "tag"-file.
#
dh_vdrplugin_prepare_enable() {
  local pkgname="$1"
  shift
  while [ $# -gt 0 ] ; do
    local config=$1
    local priority=$2
    shift 2
    local old_md5sum="$(dpkg-query -W -f='${Conffiles}' $pkgname | sed -n -e "\' $config ' { s/ obsolete$//; s/.* //; p }")"
    if [ -z "$old_md5sum" ] ; then
      mkdir -p "/etc/vdr/conf.d"
      touch "/etc/vdr/conf.d/$priority-$config.dpkg-vdrplugin-enable"
    fi
  done
}

dh_vdrplugin_prepare_enable #PKGNAME# #ENABLEDCONFIGS#
