#!/bin/sh

CWD=`pwd`

MIRROR="ftp.linux.cz/pub/linux/slackware"
RSYNC_CMMND="rsync -avz --delete-after"

echo "****  Creating necessary directories"

mkdir $CWD/kde-3.5.10_source
mkdir $CWD/kde-3.5.10_source/slackware
mkdir $CWD/kde-3.5.10_source/slackware/l

echo "****  Downloading source tree (libraries)"

cd $CWD/kde-3.5.10_source/slackware/l

( $RSYNC_CMMND rsync://${MIRROR}/unsupported/kde-3.5.10-for-slack13.0/source/qt3 . )

if [ -d $CWD/kde-3.5.10_source/slackware/l/qca1 ]; then
    rm -R $CWD/kde-3.5.10_source/slackware/l/qca1
fi

( $RSYNC_CMMND rsync://${MIRROR}/slackware-12.2/source/l/qca . )

mv $CWD/kde-3.5.10_source/slackware/l/qca/qca.SlackBuild $CWD/kde-3.5.10_source/slackware/l/qca/qca1.SlackBuild
mv $CWD/kde-3.5.10_source/slackware/l/qca $CWD/kde-3.5.10_source/slackware/l/qca1

if [ -d $CWD/kde-3.5.10_source/slackware/l/qca-tls1 ]; then
    rm -R $CWD/kde-3.5.10_source/slackware/l/qca-tls1
fi

( $RSYNC_CMMND rsync://${MIRROR}/slackware-12.2/source/l/qca-tls . )

mv $CWD/kde-3.5.10_source/slackware/l/qca-tls/qca-tls.SlackBuild $CWD/kde-3.5.10_source/slackware/l/qca-tls/qca-tls1.SlackBuild
mv $CWD/kde-3.5.10_source/slackware/l/qca-tls $CWD/kde-3.5.10_source/slackware/l/qca-tls1

( $RSYNC_CMMND rsync://${MIRROR}/slackware-13.37/source/l/poppler . )
( $RSYNC_CMMND rsync://${MIRROR}/slackware-12.2/source/l/arts . )
( $RSYNC_CMMND rsync://${MIRROR}/slackware-12.2/source/l/dbus-qt3 . )

cd $CWD/kde-3.5.10_source/slackware

( $RSYNC_CMMND rsync://${MIRROR}/slackware-12.2/source/kde . )

echo "**** Patching sources"

zcat $CWD/kde_source.diff.gz | patch -p1 --verbose || exit 1

echo "**** Leaving"

cd $CWD
