#!/bin/sh

set -e

VERSION="$1"

for r in ghc testsuite nofib `grep . ../ghc/libraries/core-packages | sed "s#^#packages/#"`
do
    MOTD="$r"/_darcs/prefs/motd
    DEFAULTS="$r"/_darcs/prefs/defaults
    EMAIL="$r"/_darcs/prefs/email
    if [ -e ../"$MOTD" ]
    then
        sed "s/HEAD/$VERSION STABLE/" ../"$MOTD" > "$MOTD"
    fi
    if [ -e ../"$DEFAULTS" ]
    then
        cp ../"$DEFAULTS" "$DEFAULTS"
    fi
    if [ -e ../"$EMAIL" ]
    then
        cp ../"$EMAIL" "$EMAIL"
    fi
    ( cd "$r"; darcs changes --last 1 --xml-output | grep "hash='" | sed "s/^.*hash='\([^']*\)'.*$/\1/" > .current-hash; )
done

