#!/bin/sh
# postinst script 
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#

# Remove unwanted files or directories.

#if [ -e /etc/gdm ]
#then
#  rm -rf /etc/gdm
#fi

# Remove the kde update app in preference of mint update.
if [ -e /etc/xdg/autostart/update-notifier-kde.desktop ]
then
  rm -f /etc/xdg/autostart/update-notifier-kde.desktop
fi

# Set keyboard clt-alt-backspace to restart X.
#setxkbmap -option terminate:ctrl_alt_bksp

# copy the adjustments to their correct locations.
# Users default .bashrc file.
cp /usr/lib/linuxmint/mintSystem/adjustments/kde/.bashrc /etc/skel/.bashrc
cp /usr/lib/linuxmint/mintSystem/adjustments/kde/bash.bashrc /etc/bash.bashrc

# krestore migrator.
if [ -e /usr/share/kde4/config/kres-migratorrc ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/kres-migratorrc /usr/share/kde4/config/kres-migratorrc
fi

# Mint KDE kde4rc.
if [ -e /etc/kde4rc ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/kde4rc /etc/kde4rc
fi

# CUPS PDF config.
if [ -d /etc/cups ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/cups-pdf.conf /etc/cups/
fi

# Apparmor and cups-pdf.
if [ -d /etc/apparmor.d ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/usr.sbin.cupsd /etc/apparmor.d/
fi

# Reload the apparmor cupsd profile.
# only if it is enforcing.
#service apparmor status | grep enforce > /dev/null
#if [ $? -eq 0 ]
#then
#  apparmor_parser -r /etc/apparmor.d/usr.sbin.cupsd
#fi

# miro.desktop with removed audio/mp3 mime type.
if [ -e /usr/share/applications/miro.desktop ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/miro.desktop /usr/share/applications/
fi

# wine-browsedrive.desktop replaced.
if [ -e /usr/share/applications/wine-browsedrive.desktop ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/wine-browsedrive.desktop /usr/share/applications/wine-browsedrive.desktop
fi

# Hide software-properties-gtk.desktop.
#if [ -e /usr/share/applications/software-properties-gtk.desktop ]
#then
#  cp -f /usr/lib/linuxmint/mintSystem/adjustments/kde/software-properties-gtk.desktop  /usr/share/applications/software-properties-gtk.desktop
#fi

# Users default directories.
if [ -e /etc/xdg/user-dirs.defaults ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/user-dirs.defaults /etc/xdg/user-dirs.defaults
fi

# Linux Mint quassel default chat channels.
if [ -e /usr/share/kde4/apps/quassel/networks.ini ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/networks.ini /usr/share/kde4/apps/quassel/networks.ini
fi

# Copy the newer inxi version into quassel.
if [ -e /usr/bin/inxi ]
then
  cp /usr/bin/inxi /usr/share/kde4/apps/quassel/scripts/inxi
fi

# Mint KDE version of startkde.
if [ -e /usr/bin/startkde ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/startkde /usr/bin/startkde
fi

# This hides sun-java6-javaws menu item.
if [ -e /usr/share/applications/sun-java6-javaws.desktop ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/sun-java6-javaws.desktop /usr/share/applications/sun-java6-javaws.desktop
fi

# Add the gnome default applications list.
mkdir -p /etc/gnome
cp /usr/lib/linuxmint/mintSystem/adjustments/kde/defaults.list /etc/gnome/defaults.list

# Use the mint KDE kdm theme.
if [ -e /etc/kde4/kdm/kdmrc ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/kdmrc /etc/kde4/kdm/kdmrc
fi
# Use mint issue files.
if [ -e /etc/issue ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/issue* /etc/
fi

# Use mint lsb-release file.
if [ -e /etc/lsb-release ]
then
  cp /usr/lib/linuxmint/mintSystem/adjustments/kde/lsb-release /etc/lsb-release
fi

# copy the software-properties icon to hicolor theme.
cp -f /usr/share/icons/Mint-KDE/32x32/apps/software-properties.png /usr/share/icons/hicolor/48x48/apps/
# update the icon cache.
gtk-update-icon-cache /usr/share/icons/hicolor

# Use the mint casper.conf if present.
if [ -e /etc/casper.conf ]
then
  cp -f /usr/lib/linuxmint/mintSystem/adjustments/kde/casper.conf /etc/casper.conf
  # Update initrd with casper.conf.
  update-initramfs -u
fi

# Show grub menu.
if [ -e /etc/default/grub ]
then
  sed -i 's/^GRUB_HIDDEN_TIMEOUT=0/#GRUB_HIDDEN_TIMEOUT=0/' /etc/default/grub
fi

# Set the gconf show_fortunes bool to ture.
if [ -x "/usr/bin/gconftool-2" ]
then
  gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type bool --set /desktop/linuxmint/terminal/show_fortunes false
fi

# root user changes.

if [ -e /etc/skel/.bashrc ]
then
  cp /etc/skel/.bashrc /root/.bashrc
fi

# Make gtk apps use KDE themeing when opened as the root user.

if [ ! -e /root/.gtkrc-2.0 ]
then
  cp /usr/share/mintkde-default-settings/dot-gtkrc-2.0-kde4 /root/.gtkrc-2.0
fi

case "$1" in
    configure)
	update-rc.d mintsystem start 51 S .
    ;;
    abort-upgrade|abort-remove|abort-deconfigure)

    ;;
    triggered)
	/usr/lib/linuxmint/mintSystem/mint-adjust.py
    ;;
    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0


