#!/bin/sh
set -e

case "$1" in
    configure)
        if [ -f /etc/default/zfs-fuse ]; then
            . /etc/default/zfs-fuse
        fi
        if [ -x /etc/init.d/zfs-fuse ]; then
            if start-stop-daemon --stop --test --quiet --pidfile /var/run/zfs-fuse.pid \
                --exec /usr/sbin/zfs-fuse >/dev/null 2>&1; then
                if [ "x${RESTART_ON_UPGRADE:-no}" = "xno" ]; then
                    echo "Not restarting zfs-fuse; \$RESTART_ON_UPGRADE is set to 'no'" >&2
                    echo "Administrative binaries (zfs, zpool) may not work until" >&2
                    echo "zfs-fuse is restarted." >&2
                elif [ -f /run/openrc/softlevel ] && command -v rc-service >/dev/null 2>&1; then
                    rc-service zfs-fuse restart || {
                        echo "Proceeding with upgrade anyway. Please note that administrative binaries" >&2
                        echo "such as zfs or zpool may not work properly until the zfs-fuse daemon is" >&2
                        echo "restarted." >&2
                    }
                else
                    invoke-rc.d zfs-fuse restart || {
                        echo "Proceeding with upgrade anyway. Please note that administrative binaries" >&2
                        echo "such as zfs or zpool may not work properly until the zfs-fuse daemon is" >&2
                        echo "restarted." >&2
                    }
                fi
            fi
        fi
        ;;
esac

#DEBHELPER#
