#!/bin/sh
#
# Create the Tvheadend changelog
#

# Arguments
CHANGELOG=$1
DIST=$2
VER=$3

HISTORY=$(cd "$(dirname "$0")/.."; git log -5 --no-merges --pretty=format:"  * %h %<(50,trunc)%s"; 2> /dev/null)
[ $? -ne 0 ] && HISTORY=""

# Defaults
[ -z "$CHANGELOG"     ] && CHANGELOG=$(dirname "$0")/../debian/changelog
[ -z "$DEBEMAIL"      ] && DEBEMAIL="andreas@tvheadend.org"
[ -z "$DEBFULLNAME"   ] && DEBFULLNAME="Andreas Öman"
[ -z "$VER"           ] && VER=$("$(dirname "$0")"/version)
[ ! -z "$DIST"        ] && VER=${VER}~${DIST}
[ -z "$DIST"          ] && DIST=unstable
[ -z "$HISTORY"       ] && HISTORY=""

# Output
NOW=$(date -R)
echo >"${CHANGELOG}"  "tvheadend (${VER}) ${DIST}; urgency=low"
echo >>"${CHANGELOG}"
[ ! -z "$HISTORY" ] && echo >>"${CHANGELOG}" "${HISTORY}\n"
echo >>"${CHANGELOG}" "  * The full changelog(s) can be found at "
echo >>"${CHANGELOG}" "    https://docs.tvheadend.org/documentation/introduction/release-change-log"
echo >>"${CHANGELOG}" "    https://github.com/tvheadend/tvheadend"
echo >>"${CHANGELOG}"
echo >>"${CHANGELOG}" " -- ${DEBFULLNAME} <${DEBEMAIL}>  ${NOW}"
