#!/bin/sh
config() {
  NEW="$1"
  OLD="`dirname $NEW`/`basename $NEW .new`"
  if [ ! -r $OLD ]; then
  # keine alte Datei vhd, neue ueberkopieren
    mv $NEW $OLD
    echo "installiert / installado / installed: " $OLD
  else
   # alte Datei vhd aber gleich neuer, neue irrelevant und loeschen
    if [ "`cat $OLD | md5sum`" = "`cat $NEW | md5sum`" ]; then # toss the redundant copy
      rm $NEW
    else
  # alte und neue Datei lassen, Admin darauf hinweisen Konfigurierung zu machen
      echo "bitte ueberpruefen / favor verificar / pls verify: " $OLD " / ~.new"
    fi 
  fi
}
#libtool --finish /usr/lib/gtk-3.0/modules  > /dev/zero
#libtool --finish /usr/lib/gtk-3.0/3.0.0/immodules  > /dev/zero
#libtool --finish /usr/lib/gtk-3.0/3.0.0/engines  > /dev/zero
#libtool --finish /usr/lib/gtk-3.0/3.0.0/filesystems  > /dev/zero
#libtool --finish /usr/lib/gtk-3.0/3.0.0/loaders  > /dev/zero
#libtool --finish /usr/lib/gtk-3.0/3.0.0/printbackends  > /dev/zero
#libtool --finish /usr/lib/  > /dev/zero
#ldconfig

cp -f  /etc/gtk-3.0/im-multipress.conf /etc/gtk-3.0/im-multipress.conf.old > /dev/zero  # falls alte config retten
config etc/gtk-3.0/im-multipress.conf.new
echo "ggf. Konfiguration in /etc/gtk-3.0 ueberpruefen/aendern"
echo "verifica / adapta a configuracao em  /etc/gtk-3.0"

# Since the use of icon caching is optional, and has to be kept in sync
# somehow (like a "registry" through a cron job, or whatever) I tend to
# think the user should be the one to choose if they really want to set
# this up or not:
#
# Example:
#for dir in /usr/share/icons/* ; do
#  if [ -d $dir ]; then
#    /usr/bin/gtk-update-icon-cache -f -t $dir 1> /dev/null 2> /dev/null
#  fi
#done
mkdir -p etc/gtk-3.0

chroot . rm -f /usr/share/icons/*/icon-theme.cache 1> /dev/null 2> /dev/null

# This has a lot of X deps, so check for the obvious one first:
if [ -e usr/lib/libX11.so.6 ]; then
  chroot . usr/bin/gtk-query-immodules-3.0  > etc/gtk-3.0/gtk.immodules
# chroot . usr/bin/gdk-pixbuf-query-loaders > etc/gtk-3.0/gdk-pixbuf.loaders
fi


#
# Besser das auch nochmal unbedingt zu machen, so wie danach von den Programmen aufgerufen
#if [ -x /usr/bin/gdk-pixbuf-query-loaders ]; then
/usr/bin/gdk-pixbuf-query-loaders > /etc/gtk-3.0/gdk-pixbuf.loaders 
#fi

#if [ -x gtk-query-immodules-3.0 ]; then
#  /usr/bin/gtk-query-immodules-3.0 > /etc/gtk-3.0/gtk.immodules  
#fi

#if [ -x /usr/bin/gtk-update-icon-cache ]; then
#  /usr/bin/gtk-update-icon-cache  -f -q  -t   /usr/share/icons   # /hicolor 
#fi



#
( cd usr/include ; rm -rf gdk-pixbuf )
( cd usr/include ; ln -sf gtk-2.0/gdk-pixbuf gdk-pixbuf )
( cd usr/include ; rm -rf gdk )
( cd usr/include ; ln -sf gtk-3.0/gdk gdk )
( cd usr/include ; rm -rf gdk-pixbuf-xlib )
( cd usr/include ; ln -sf gtk-2.0/gdk-pixbuf-xlib gdk-pixbuf-xlib )
( cd usr/include ; rm -rf gtk )
( cd usr/include ; ln -sf gtk-3.0/gtk gtk )
( cd usr/lib ; rm -rf libgtk-3.0.so )
( cd usr/lib ; ln -sf libgtk-3.0.so.0.9903.0 libgtk-3.0.so )
( cd usr/lib ; rm -rf libgtk-3.0.so.0 )
( cd usr/lib ; ln -sf libgtk-3.0.so.0.9903.0 libgtk-3.0.so.0 )
( cd usr/lib ; rm -rf libgailutil-3.0.so.0 )
( cd usr/lib ; ln -sf libgailutil-3.0.so.0.0.0 libgailutil-3.0.so.0 )
( cd usr/lib ; rm -rf libgdk-3.0.so )
( cd usr/lib ; ln -sf libgdk-3.0.so.0.9903.0 libgdk-3.0.so )
( cd usr/lib/gtk-3.0 ; rm -rf gdk )
( cd usr/lib/gtk-3.0 ; ln -sf .. gdk )
( cd usr/lib/gtk-3.0 ; rm -rf gtk )
( cd usr/lib/gtk-3.0 ; ln -sf .. gtk )
( cd usr/lib ; rm -rf libgdk-3.0.so.0 )
( cd usr/lib ; ln -sf libgdk-3.0.so.0.9903.0 libgdk-3.0.so.0 )
( cd usr/lib ; rm -rf libgailutil-3.0.so )
( cd usr/lib ; ln -sf libgailutil-3.0.so.0.0.0 libgailutil-3.0.so )
