#!/bin/sh 

# Script  : update-kde-ver.sh
# Purpose: Update the KDE version number in all of the 'arm/build' scripts
#          which were using the previous KDE release version number.
#          Not all of KDE packages are in sync with the main release
#          and those will be excluded because their versions are hard coded
#          rather than being able to be overridden by the environment var "VERSION".
# Author : Stuart Winter <mozes@slackware.com>
# Date   : 25-Oct-2009

export PREVKDE=4.5.4
export NEWKDE=4.5.5

rm -rf /tmp/kdebackup
( cd ..
  cp -fav kde /tmp/kdebackup )

#find . -path './*/arm*' -name build -type f -print0 | xargs -0 fgrep -l $PREVKDE | xargs -i sed -i 's?-'"$PREVKDE"'?-'"$NEWKDE"'?g' {}

# Grab the list of core KDE packages from the build script:
eval $( sed -n '/KDEMODS=/{:1;s/\\$//;T2;N;b1;:2;p;q}' KDE.SlackBuild )
for kdepkg in $KDEMODS ; do
 ( cd $kdepkg
   # If we find a version match, update the version & set the build to 1. 
   # Some core KDE apps don't follow the same version as the rest, so there'll always 
   # be a few packages shown as a no match.
   # In those cases, you need to bump the build number by 1.
   grep "VERSION=.*${PREVKDE}.*" arm/build >/dev/null 2>&1 && \
   { sed -i -e 's?-'"$PREVKDE"'?-'"$NEWKDE"'?g' -e 's?BUILD=.*?BUILD=1?g' arm/build
     echo "Updated: $kdepkg" ;} || echo "No version match for: $kdepkg" )
done
  
# Remove the old build logs:
find . -iname '*build.log*' -print0 | xargs -0 rm -f

# So what *is* left to manually work through:
find . -path './*/arm*' -name build -type f -print0 | xargs -0 fgrep  VERSION= | grep -v EXCLUDE | fgrep -v $NEWKDE | sort

# eof

