#!/bin/sh
set -e

# If the package is upgraded from a version before 0.0.10,
# move /etc/usbmount.conf to /etc/usbmount/usbmount.conf.
if test "$1" = upgrade || test "$1" = install; then
    if test -n "$2" && dpkg --compare-versions "$2" lt 0.0.10 \
	&& test -f /etc/usbmount.conf \
	&& ! test -e /etc/usbmount/usbmount.conf; then
	test -d /etc/usbmount || mkdir /etc/usbmount
	echo Moving /etc/usbmount.conf to /etc/usbmount/usbmount.conf ...
	mv /etc/usbmount.conf /etc/usbmount/usbmount.conf
    fi
fi

# If the package is installed, try to create the default mountpoints.
# Failure to do so is not considered fatal.
if test "$1" = install; then
    mkdir /media 2> /dev/null || :
    for i in 0 1 2 3 4 5 6 7; do
	mkdir /media/usb$i 2> /dev/null || :
    done
    ln -s usb0 /media/usb 2> /dev/null || :
fi

# If the package is freshly installed or upgraded from a version before
# 0.0.13, create a "flag file" to indicate that a symlink in
# /etc/udev/rules.d must be created.
if test "$1" = upgrade || test "$1" = install; then
    if test -z "$2" || dpkg --compare-versions "$2" lt 0.0.13; then
	test -d /etc/usbmount || mkdir /etc/usbmount
	cat > /etc/usbmount/.create_rules_symlink <<EOF
The presence of this file means that when the usbmount package is
configered, a symbolic link /etc/udev/rules.d/z60_usbmount.rules
pointing to /etc/udev/usbmount.rules is created. If you do not want
this to happen, remove this file.
EOF
    fi
fi

#DEBHELPER#

exit 0
