#!/bin/bash
#
# Remove old kde and install kde-4.1.3
#
# URL to packages
URL="http://rra.etc.br/linux/Slamd64/kde4/4.1.3"

# Check Slamd64
if [ "`cat /etc/slamd64-version`" != "Slamd64 12.1.0" ]; then
  echo "This is not a Slamd64 12.1.0"
  exit 1
fi

# remove kde3
LIST_KDE="amarok kdeaccessibility kdeaddons kdeadmin kdeartwork
          kdebase kdebindings kdeedu kdegames kdegraphics kdelibs
          kdemultimedia kdenetwork kdepim kdesdk kdetoys kdeutils
          kdevelop kdewebdev knemo koffice ktorrent"

for pkg in $LIST_KDE; do
  removepkg $pkg 2>/dev/null
done

# Next, remove arts, Qt3, and Qt3 related dependencies.
LIST_OTHERS="arts qca qca-tls qt loudmouth libmtp libmp4v2 poppler mysql cmake"

for pkg in $LIST_OTHERS; do
  removepkg $pkg 2>/dev/null
done

# Finally, try to remove any KDE language packs:
( cd /var/log/packages ; removepkg kde-i18n-* 2>/dev/null )

# Download packages
[ ! -e install_list ] && wget $URL/install_list
[ ! -e MD5SUM.txt ] && wget $URL/MD5SUM.txt

for pkg in `cat install_list`; do
  [ ! -e $pkg.tgz ] && wget $URL/$pkg.tgz
done

# Remove all packages in install_list
cat install_list | sed 's/\(.*\)\-.*\-.*\-.*$/\1/' | xargs removepkg

# Check md5sum
if ! md5sum -c MD5SUM.txt; then
  echo "Check md5sum fail..."
  echo "Reload error file and rerun this script" 
  exit 1
fi

rm /etc/profile.d/kde.*

# install packages
for pkg in `cat install_list`; do
  installpkg $pkg
done

chmod +x /etc/profile.d/kde.*
ln -sf /etc/X11/xinit/xinitrc.kde /etc/X11/xinit/xinitrc

echo "Restart you system..."

