#!/bin/sh

set -e

#
# Skip, if we are upgrading
#
if [ "$1" = "upgrade" ]; then
        exit 0
fi


package=symbiosis-httpd-logger
bin=/usr/sbin/symbiosis-httpd-logger
theirbin="$bin.dpkg-symbiosis.orig"

#
# Add the diversion if the file has not been generated by Symbiosis, and if the
# diversion doesn't exist.
#
if dpkg-divert --list "$package" | grep -xFq "diversion of $bin to $theirbin by $package"; then

  if [ -e "$theirbin" ] ; then
    # Remove and rename back again
    dpkg-divert --remove --rename --package "$package" "$bin" || true
  else
    # Otherwise just remove the diversion
    dpkg-divert --remove --package "$package" "$bin" || true
  fi
fi

#DEBHELPER#
