#!/bin/sh
#
# Quick hack - add extra sources for this arch onto the last *binary* CD
# Initially written for the unofficial amd64 CDs in sarge...
#

set -e

BDIR=$1
ARCH=$2
BASEDIR=$3
CODENAME=$4
MIRROR=$5

SOURCE_LIST=$BASEDIR/data/$CODENAME/$ARCH/extra-sources
DISKNUM=`ls -l $BDIR/?.packages $BDIR/??.packages | wc -l | tr -d " "`
SOURCES=`ls -1 $MIRROR/dists/$CODENAME/*/source/Sources.gz`

echo "dedicated_source: Need to add the following sources to $ARCH CD#$DISKNUM:"

mkdir $BDIR/CD$DISKNUM/extra-sources
for SRC in `grep -v ^# $SOURCE_LIST`
do
	echo "$SRC:"
	FILES=`zcat $SOURCES | awk -v SOURCE=$SRC '
	/^Package:/       {  if ($2 == SOURCE) { found=1 } }
	/^Directory:/     { DIR=$2 }
	/^ /              { if (found) { printf("  %s/%s\n",DIR,$3) }}
	/^$/              {found=0}
'`
	for FILE in $FILES
	do
		echo "  $FILE"
		cp -al $MIRROR/$FILE $BDIR/CD$DISKNUM/extra-sources
	done
done

exit 0

