#!/bin/bash

VER='5.40'
SUBVER='.0'
OLDVER='5.39'
OLDSUBVER='.0'

build_a_package()
{
    N=$1
    cd /home/wares/soft/kde/framework
    AD=`ls -d $N-*`
    FW=`echo $AD|sed 's/^'$N'\-//'`
    cd $AD
    #wget -c  http://download.kde.org/stable/frameworks/${VER}/${FW}-${VER}${SUBVER}.tar.xz
    apt-get source ${FW}

    cd ${FW}-${OLDVER}${OLDSUBVER}
    uscan --verbose --download-version ${VER}${SUBVER}
    #uupdate -v ${VER}${SUBVER} ../${FW}-${VER}${SUBVER}.tar.xz
    uupdate ../${FW}_${VER}${SUBVER}.orig.tar.xz
    cd ../${FW}-${VER}${SUBVER}
    #rm -rf ../*${OLDVER}${OLDSUBVER}*
    while quilt push; do quilt refresh; done

    sed -i 's/'${OLDVER}'/'${VER}'/g' debian/control
    sed -i 's/'${OLDVER}'/'${VER}'/g' debian/rules
    #dch -b --newversion=${VER}${SUBVER}-0.1
    sbuild -d sid-amd64-sbuild -A -j7
    #dpkg-buildpackage -j6 --build=full 2>&1|tee ../build.log
    echo =====================================

#cd ..
#sudo dpkg -i `ls *deb|grep -v dbgsym`

    cd /home/wares/soft/kde/
    ./update.sh
#    sudo apt-get update
#    sudo apt-get upgrade
}

if [ $# -gt 0 ]
then
    NN=$@;
else
    NN=`seq -w 49 75`
fi

for N in $NN;
do
    build_a_package $N
done
