#!/bin/bash

test -f update-desktop-files.spec || { "cwd must contain update-desktop-files.spec"; exit 1; }

rm -rf po
svn export http://svn.suse.de/svn/lcn/trunk/update-desktop-files po
rm -f desktop-translations.tar.bz2
tar cfj desktop-translations.tar.bz2 po
rm -rf po
exit

rm -rf kappfinder
svn export svn://anonsvn.kde.org/home/kde/branches/KDE/3.5/kdebase/kappfinder/apps kappfinder
cd kappfinder/
# make sure we only have one desktop file of each.
if test $(find -type f -printf '%f\n' 2>/dev/null | grep -v Makefile.am | sort | uniq -c | sort -n | awk '{print $1}' | grep -v 1 | wc -l) -ne 0; then
  echo "There is some duplicate desktop file!!!!"
  echo " FIX ME!"
  exit 1
fi
rm -f ../kappfinder.tar.bz2
tar cfj ../kappfinder.tar.bz2 *
cd -
rm -rf kappfinder-icons
mkdir -p kappfinder-icons
BASEDIR=/mounts/dist/unpacked/i386.full/opt/kde3
find  kappfinder/ -name \*.desktop | while read f; do 
  oicon=`sed -n 's,Icon=\(.*\),\1,p' $f`
  icon=`find $BASEDIR/share/icons/default.kde/32x32 -name $oicon -o -name $oicon.png -o -name $oicon.xpm | head -n 1`
  if [ ! -r "$icon" ] ; then
    icon=`find $BASEDIR/share/icons/*/32x32/apps -name $oicon -o -name $oicon.png -o -name $oicon.xpm | head -n 1`
  fi
  if [ -r "$icon" ] ; then
     cp $icon kappfinder-icons/ 
  else
    echo "can't find icon $oicon from file $f"
    # grep -v ^Icon= $f > ${f}_ && mv ${f}_ $f
  fi
done
rm -f kappfinder-icons.tar.bz2
tar cfj kappfinder-icons.tar.bz2 kappfinder-icons
rm -rf kappfinder-icons
rm -rf kappfinder
