#!/bin/sh -e

. /usr/share/debconf/confmodule
db_get wireshark-common/install-setuid
PROGRAM=/usr/bin/dumpcap
GROUP=wireshark

if [ -e "$PROGRAM" ]; then
    if [ "$RET" = "false" ] ; then
         if [ -x /usr/sbin/dpkg-statoverride ] && \
             ! /usr/sbin/dpkg-statoverride --list $PROGRAM >/dev/null; then
             chown root:root $PROGRAM
             chmod u=rwx,go=rx $PROGRAM
         fi
    else
        if [ -x /usr/sbin/dpkg-statoverride ] && \
            ! /usr/sbin/dpkg-statoverride --list $PROGRAM >/dev/null; then
            addgroup --quiet --system $GROUP
            chown root:$GROUP $PROGRAM
            if which setcap > /dev/null ; then
                chmod u=rwx,g=rx,o=r $PROGRAM
                if ! setcap cap_net_raw,cap_net_admin=eip $PROGRAM; then
                    echo "Setting capabilities for dumpcap using Linux Capabilities failed."
                    echo "Falling back to setting set-user-id bit."
                    chmod u=rwxs,g=rx,o=r $PROGRAM
                fi
            else
                chmod u=rwxs,g=rx,o=r $PROGRAM
            fi
        fi
    fi
fi

#DEBHELPER#
