#!/bin/sh

set -e

## Remove obsolete symlink which is in the way of dh_apache2:
ol="/etc/apache2/conf-available/zoneminder.conf"
if [ -h "${ol}" ]; then
    [ "$(readlink ${ol})" = "/etc/zm/apache.conf" ] && rm -f "${ol}"
fi

abort=false
if [ -h /usr/share/zoneminder/www/events ]; then
    l=$(readlink /usr/share/zoneminder/www/events)
    if [ "$l" != "/var/cache/zoneminder/events" ]; then
        abort=true
    fi
fi
if [ -h /usr/share/zoneminder/www/images ]; then
    l=$(readlink /usr/share/zoneminder/www/images )
    if [ "$l" != "/var/cache/zoneminder/images" ]; then
        abort=true
    fi
fi

if [ "$abort" = "true" ]; then
    cat >&2 << EOF
Aborting installation of zoneminder due to non-default symlinks in
/usr/share/zoneminder for the images and/or events directory, which could
result in loss of data. Please move your data in each of these directories to
/var/cache/zoneminder before installing zoneminder from the package.
EOF
    exit 1

fi

#DEBHELPER#
