description "Notification regarding a crash report"
author "Brian Murray <brian@ubuntu.com>"

start on (
    file FILE=/var/crash/*.crash EVENT=create or
    file FILE=/var/crash/*.crash EVENT=modify
)

env MATCH=NULL
instance $MATCH

script
DATE=$(date)
echo "$DATE crash report $MATCH detected"
if [ -e /var/lib/apport/autoreport ]; then
    echo "$DATE autoreporting enabled exiting"
    exit 0
fi
if [ -O $MATCH ]; then
    /usr/share/apport/apport-gtk
else
    SYSTEMCRASH=0
    /usr/share/apport/apport-checkreports --system || SYSTEMCRASH=$?
    if [ $SYSTEMCRASH -eq 0 ]; then
        # not in admin group return
        ADMIN=0
        groups | grep -qE "sudo|admin" || ADMIN=$?
        if [ $ADMIN -ne 0 ]; then
            exit 1
        fi
        # be nice and always ask first before firing up pkexec
        if [ -x /lib/udev/watershed ]; then
            /lib/udev/watershed sh -c '/usr/lib/update-notifier/system-crash-notification'
        else
            /usr/lib/update-notifier/system-crash-notification
        fi
    fi
fi
end script
