#!/bin/sh

set -e

# Alternatively this check can be disabled by preseeding:
#   echo "wine/setcaps boolean false" | debconf-set-selections

. /usr/share/debconf/confmodule

case "$1" in
    configure)
        if command -v setcap > /dev/null; then
            db_get wine/setcaps

            # Allow dpkg-reconfigure to remove caps
            if test "$RET" = "true"; then
                if ! setcap "cap_net_raw=epi" /opt/wine-staging/bin/wine64-preloader; then
                   echo "Setcap failed on /opt/wine-staging/bin/wine64-preloader, applications that need to send/receive raw IP packets will not work" >&2
                fi
            else
                # setcap -r fails if the xattr is not present
                if getcap /opt/wine-staging/bin/wine64-preloader | grep -qs "/opt/wine-staging/bin/wine64-preloader"; then
                    if ! setcap "-r" /opt/wine-staging/bin/wine64-preloader; then
                       echo "Setcap -r failed on /opt/wine-staging/bin/wine64-preloader, could not remove capabilities" >&2
                    fi
                fi
            fi
        fi
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0