#!/bin/sh
# The upstream Debian packaging in tools/debian/ applies to all supported
# Debian/Ubuntu release targets of Cockpit. In some of them, some
# features or build dependendencies might not be available or are deliberately
# disabled.
# This script can modify (in-place) the debian/* packaging for a particular
# release (first CLI argument). It gets called by
# https://github.com/cockpit-project/cockpituous/blob/master/release/release-dsc
# for building Debian/Ubuntu packages for a new Cockpit release.

set -eu
if [ -z "${1:-}" ] || [ -n "${2:-}" ]; then
    echo "Usage: $0 <release>" >&2
    exit 1
fi
release="$1"

debian_dir=$(dirname $(readlink -f "$0"))

set -x
# Remove PCP build dependencies, binary package, and Suggests: while pcp is not in testing
# (https://tracker.debian.org/pcp)
case "$release" in
    unstable|testing|stable|stretch|buster)
        sed -i '/libpcp.*-dev/d; /^Package: cockpit-pcp/,/^$/ d; /cockpit-pcp/d' $debian_dir/control
        # also remove the files, otherwise --fail-missing breaks the build
        sed -i 's/for m in /&pcp /' $debian_dir/rules
        ;;
esac
