#!/bin/sh -e
if test \! -d package || test \! -d debian
then
	echo "You are not in the right directory." 1>&2
	exit 100
fi
if [ $# -lt 2 ]
then
	echo "usage: $0 name staging-dir" 1>&2
	exit 100
fi
name="$1"
dest="$2"

install -d -m 0755 -- "${dest}"/DEBIAN

rm -f -- debian/substvars
if test -d "${dest}"/usr/local/bin || test -d "${dest}"/usr/local/sbin
then
	dpkg-shlibdeps "${dest}"/usr/local/*bin/*
fi
if test -d "${dest}"/usr/bin || test -d "${dest}"/usr/sbin
then
	dpkg-shlibdeps "${dest}"/usr/*bin/*
fi
dpkg-gencontrol -p"${name}" -P"${dest}"

install -d -m 0755 "${dest}"/usr/local/share/doc/"${name}"
cat > "${dest}"/usr/local/share/doc/"${name}"/copyright << EOF
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Name: ${name}

Files: *
Copyright: 2012,2026 Jonathan de Boyne Pollard
License: ISC, BSD-2-clause, FreeBSD, Expat
EOF

true
