#!/bin/bash

SPEC=postgresql*-full.spec.in
VERSION=$(awk '/define packageversion/{print $3}' $SPEC)

cp -a postgresql$VERSION.changes postgresql$VERSION-libs.changes

for f in postgresql$VERSION postgresql$VERSION-libs; do
    sed "s/^\(Name: *\).*/\\1 $f/" $SPEC > $f.spec
done

sed -i \
    -e 's/%define buildmain .*/%define buildmain 1/' \
    -e 's/%define buildlibs .*/%define buildlibs 0/' \
    postgresql$VERSION.spec

sed -i \
    -e 's/%define buildmain .*/%define buildmain 0/' \
    -e 's/%define buildlibs .*/%define buildlibs 1/' \
    postgresql$VERSION-libs.spec
