#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

#### meta start
#### project Whonix
#### category networking
#### workstation_only yes
#### description
## Compiles <code>/usr/lib/bindp.c</code> to <code>/usr/lib/libindp.so</code>
## during package installation using <code>gcc</code>.
#### meta end

if [ -f /usr/libexec/helper-scripts/pre.bsh ]; then
   source /usr/libexec/helper-scripts/pre.bsh
fi

set -e

true "
#####################################################################
## INFO: BEGIN: $DPKG_MAINTSCRIPT_PACKAGE $DPKG_MAINTSCRIPT_NAME $@
#####################################################################
"

case "$1" in
    configure)
        if ! cd /usr/src/bindp ; then
            printf '%s\n' "Cannot cd to '/usr/src/bindp'!" >&2
            exit 1
        fi
        if ! make ; then
            printf '%s\n' "Error building bindp!" >&2
            exit 1
        fi
        if ! rm -f /usr/lib/libindp.so ; then
            printf '%s\n' "Cannot remove old libindp.so!" >&2
            exit 1
        fi
        if ! mv libindp.so /usr/lib/libindp.so ; then
            printf '%s\n' "Cannot move libindp.so to '/usr/lib'!" >&2
            exit 1
        fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "$DPKG_MAINTSCRIPT_NAME called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

true "INFO: debhelper beginning here."

#DEBHELPER#

true "INFO: Done with debhelper."

true "
#####################################################################
## INFO: END  : $DPKG_MAINTSCRIPT_PACKAGE $DPKG_MAINTSCRIPT_NAME $@
#####################################################################
"

## Explicitly "exit 0", so eventually trapped errors can be ignored.
exit 0
