#!/bin/bash
#
# Target dist: Ubuntu bionic
DIST=bionic

rm -rf ${DIST}
cp -r debian ${DIST}

# No dnssec module:
sed -i -e '/libval-dev/d' -e '/^Package: kamailio-dnssec-modules/,/^$/d' \
  ${DIST}/control
sed -i -e '/^PACKAGE_GROUPS += dnssec/d' ${DIST}/rules
sed -i -e '/--EXCLUDED--/i EXTRA_EXCLUDED_MODULES += dnssec' ${DIST}/rules

# No app_java due lack of gcj-jdk
sed -i -e '/gcj-jdk/d' -e '/^Package: kamailio-java-modules/,/^$/d' \
  ${DIST}/control
sed -i -e '/^export JAVA_HOME/d' ${DIST}/rules
sed -i -e '/^PACKAGE_GROUPS += java/d' ${DIST}/rules
sed -i -e '/--EXCLUDED--/i EXTRA_EXCLUDED_MODULES += java' ${DIST}/rules

# No secsipid module
sed -i -e '/libsecsipid-dev/d' -e '/^Package: kamailio-secsipid-modules/,/^$/d' \
	${DIST}/control
sed -i -e '/^PACKAGE_GROUPS += secsipid/d' ${DIST}/rules
sed -i -e '/--EXCLUDED--/i EXTRA_EXCLUDED_MODULES += secsipid' ${DIST}/rules

# libwebsockets >= 3.1
sed -i -e '/libwebsockets-dev/d' -e '/^Package: kamailio-lwsc-modules/,/^$/d' \
	${DIST}/control
sed -i -e '/^PACKAGE_GROUPS += lwsc/d' ${DIST}/rules
sed -i -e '/--EXCLUDED--/i EXTRA_EXCLUDED_MODULES += lwsc' ${DIST}/rules

# no libnats-dev
sed -i -e '/^ libnats-dev,/d' \
  -e '/^Package: kamailio-nats-modules/,/^$/d' \
  ${DIST}/control
sed -i -e '/^PACKAGE_GROUPS += nats/d' ${DIST}/rules
sed -i -e '/--EXCLUDED--/i EXTRA_EXCLUDED_MODULES += nats' ${DIST}/rules

# libmicrohttpd too old
sed -i -e '/^ libmicrohttpd-dev,/d' \
  -e '/^Package: kamailio-microhttpd-modules/,/^$/d' \
  ${DIST}/control
sed -i -e '/^PACKAGE_GROUPS += microhttpd/d' ${DIST}/rules
sed -i -e '/--EXCLUDED--/i EXTRA_EXCLUDED_MODULES += microhttpd' ${DIST}/rules

# libwolfssl-dev < 5.2
sed -i -e '/^ libwolfssl-dev,/d' \
  -e '/^Package: kamailio-wolftls-modules/,/^$/d' \
  ${DIST}/control
sed -i -e '/^PACKAGE_GROUPS += tls_wolfssl/d' ${DIST}/rules
sed -i -e '/--EXCLUDED--/i EXTRA_EXCLUDED_MODULES += tls_wolfssl' ${DIST}/rules

wrap-and-sort -sat -d ${DIST}

# clean backports scripts
rm -rf ${DIST}/backports
exit 0
