post_install() {
    # Install udev rules or hotplug scripts
    if [ -e "/etc/udev/rules.d" ]; then
        ls /dev/bus/usb/*/* > /dev/null 2>&1 && (
            # USB and serial instruments using udev, where udev already creates /dev/bus/usb/00X/00X devices
            if [ ! -e "/etc/udev/rules.d/55-Argyll.rules" ] && [ ! -e "/usr/lib/udev/rules.d/55-Argyll.rules" ] && [ ! -e "/usr/lib/udev/rules.d/69-cd-sensors.rules" ]; then
                ln -s "/usr/share/DisplayCAL/usb/55-Argyll.rules" "/etc/udev/rules.d/55-Argyll.rules"
            fi
        ) || (
            # USB using udev, where there are NOT /dev/bus/usb/00X/00X devices
            if [ ! -e "/etc/udev/rules.d/45-Argyll.rules" ]; then
                ln -s "/usr/share/DisplayCAL/usb/45-Argyll.rules" "/etc/udev/rules.d/45-Argyll.rules"
            fi
        )
        # Reload udev rules
        if [ -e "/sbin/udevadm" ]; then
            /sbin/udevadm control --reload-rules
        fi
    else
        if [ -e "/etc/hotplug" ]; then
            # USB using hotplug and Serial using udev (older versions of Linux)
            if [ ! -e "/etc/hotplug/usb/Argyll" ]; then
                ln -s "/usr/share/DisplayCAL/usb/Argyll" "/etc/hotplug/usb/Argyll"
            fi
            if [ ! -e "/etc/hotplug/usb/Argyll.usermap" ]; then
                ln -s "/usr/share/DisplayCAL/usb/Argyll.usermap" "/etc/hotplug/usb/Argyll.usermap"
            fi
        fi
    fi

    post_upgrade
}

post_upgrade() {
    /bin/touch --no-create /usr/share/icons/hicolor &> /dev/null || true
    xdg-icon-resource forceupdate
    xdg-desktop-menu forceupdate
}

post_remove() {
    # Remove udev rules or hotplug scripts symlinks
    for file in "/etc/udev/rules.d/55-Argyll.rules" "/etc/udev/rules.d/45-Argyll.rules" "/etc/hotplug/usb/Argyll" "/etc/hotplug/usb/Argyll.usermap" ; do
        if [ ! -e $file ]; then
            if [ -L $file ]; then
                rm -f $file
            fi
        fi
    done

    post_upgrade
}

# vim:set ts=2 sw=2 et:
