#!/bin/bash
#
# script to help doing a release
#
# debian/patches/release
#   is harmless, it can be reverted
#
# debian/patches/release unpatch
#   reverts the "release" changes
#
# debian/patches/release 4.3.2-1
#   sets the version number and deletes the original files
#

function regular_release_changes
{
 mv debian/changelog debian/changelog.orig
 sed -e '1s/UNRELEASED/unstable/' \
     -e '3s/expecting //' debian/changelog.orig > debian/changelog

 mv debian/control debian/control.orig
 sed -e '/Package: conglomerate-dbg/,$d' debian/control.orig | \
 sed -e '/architecture independent/,$ { /^$/d }' > debian/control

 mv debian/rules debian/rules.orig
 sed -e '/enable-debug/d' \
     -e 's/dh_strip -a --exclude.*/dh_strip -a/' \
     -e '/conglomerate-dbg/d' debian/rules.orig > debian/rules
 chmod +x debian/rules

 echo Don\'t forgot to update the NEWS file.
}

if [ "x" == "x${1}" ]
then
 regular_release_changes
else
 case "${1}" in
  unpatch)
   test -f debian/changelog.orig && mv debian/changelog.orig debian/changelog
   test -f debian/control.orig && mv debian/control.orig debian/control
   test -f debian/rules.orig && mv debian/rules.orig debian/rules
  ;;
  *\.*\.*-*)
   regular_release_changes
   # set version and current date
   VERSION=${1}
   RFC2822DATE=$(date -R)
   mv debian/changelog debian/changelog.orig
   sed -e "1s/\(.*\) (\(.*\)) \(.*\)/\1 ($VERSION) \3/" \
       -e "1,/ -- /s/>  .*/>  $RFC2822DATE/" \
       debian/changelog.orig > debian/changelog
   # plus a clean up
   rm debian/changelog.orig
   rm debian/control.orig
   rm debian/rules.orig
  ;;
  *)
   echo \'${1}\' is an unsupported subcommand
   echo "Supported subcommands are: unpatch & *.*.*-*"
   echo " Where * are digits for the version"
  ;;
 esac
fi

# end of script ( happy hacking/testing the package )
