#!/bin/sh
### nope.sh  -*- Sh -*-
## Create a dummy Provides: ${package} .deb package.

### Ivan Shmakov, 2019

## To the extent possible under law, the author(s) have dedicated
## all copyright and related and neighboring rights to this software
## to the public domain worldwide.  This software is distributed
## without any warranty.

## You should have received a copy of the CC0 Public Domain Dedication
## along with this software.  If not, see
## <http://creativecommons.org/publicdomain/zero/1.0/>.

### History:

## 0.1  2019-04-27
##      Initial revision.

### Code:

set -e
set -C

case "$#" in
    (1 | 2) ;;
    (*) printf %s\\n "Usage: sh ${0##*/}  PACKAGE [VERSION]" >&2
        ## .
        exit 1 ;;
esac

: "${NOPE_EMAIL:=${LOGNAME}@example.invalid}"
: "${NOPE_REALNAME:=$(getent -- passwd "$LOGNAME" | cut -d: -f5)}"
: "${NOPE_SUITE:=workarounds}"

w=0.1
p=${1}
v=${2}
no=no-${p}
prov=${p}${v:+ (= ${v})}
d=$(mktemp -d -- "$no".XXXXXXXX)

## FIXME: do cleanup on exit
# trap cleanup EXIT

doc="${d}/usr/share/doc/${no}"

mkdir -- "$d"/DEBIAN \
    "$d"/usr "$d"/usr/share "$d"/usr/share/doc "$doc"

cat > "$d"/DEBIAN/control <<EOF
Package: ${no}
Version: ${w}
Architecture: all
Provides: ${prov}
Maintainer: ${NOPE_REALNAME} <${NOPE_EMAIL}>
Priority: extra
Description: dummy package to work-around unwarranted dependencies on ${p}
 This dummy package exists solely for its Provides: ${p} magic.
EOF

cat > "$doc"/changelog <<EOF
${no} (${w}) ${NOPE_SUITE}; urgency=medium

  * Created a dummy Provides: ${prov} package to work-around
    unwarranted dependencies on ${p}.

 -- ${NOPE_REALNAME} <${NOPE_EMAIL}>  $(date --rfc-822)
EOF

case "$d" in
    (*/*) cd "${d%/*}" ;;
esac

## .
${NOPE_DPKG_DEB:-dpkg-deb} --build -- "${d##*/}" .

### nope.sh ends here
