# -*- shell-script -*-

if [ "$1" = 'purge' ] ; then
    # If runscript was never invoked, there will be no files
    # in this directory, and `dpkg' will remove it. In this case,
    # we have nothing to do.
    supervise_dir="/var/lib/runit/supervise/#NAME#"
    if [ -d "$supervise_dir" ] ; then

        # Actually only `down' may be absent, but it does not
        # matter.

        for file in control lock ok pid stat status down ; do
            rm -f "$supervise_dir/$file"
        done

        # It should be empty now. If it is not, it means that system administrator put
        # something there. It is very stupid, but will of user is sacred, and directory
        # is left as-is in such case.
        #
        # NOTE: Non-POSIX option is used. The day coreutils will no longer be essential,
        # it will require a fix.
        rmdir --ignore-fail-on-nonempty "$supervise_dir"
    fi
    unset supervise_dir
fi

# Local Variables:
# eval: (sh-set-shell "sh" t nil)
# End:
