#!/bin/bash

# Script to automate building of r-base and for Debian stable
# This script should be run as root, in one way or another.

# Author: Vincent Goulet <vincent.goulet@act.ulaval.ca>
# Modified for backporting to Debian stable by 
# Johannes Ranke <jranke@uni-bremen.de>

export DEBEMAIL="Johannes Ranke <jranke@uni-bremen.de>"

rm -rf r-base* r-base-core* r-mathlib*

#apt-get update  # needs real root privileges
apt-get source -t unstable r-base
cd r-base-*

# Old version
oldversion=`dpkg-parsechangelog | grep ^Version | cut -f2 -d " "`
cranversion=$oldversion"~lennycran.0"

# Add new version to changelog
dch -v "${cranversion}" -D lenny-cran -b "Backport from Debian unstable to Debian lenny"

# Reverts for lenny:
#

# Build package showing all messages and separating output to build and error logs
(dpkg-buildpackage -tc | tee ../build_log_r-base_i386) 3>&1 1>&2 2>&3 | tee ../build_errors_r-base_i386
if [ $? -ne 0 ]; then
    exit 1
fi

cd ..

# Create diff to Debian unstable
interdiff -z *.diff.gz > interdiff_to_debian_sid

# Sign logs and interdiff
for i in interdiff_to_debian_sid build_log_r-base_i386 build_errors_r-base_i386
do
  gpg --clearsign $i
  mv $i.asc $i
done
