#!/bin/bash

# step 0: install dependencies
sudo yum install subversion build-essential autoconf intltool libtool glib2
sudo yum install libc6-dev libglib2.0-dev gtk-doc-tools automake1.9
sudo yum install perl libgtk2.0-dev libexo-0.3-dev intltool libpng12-dev shared-mime-info desktop-file-utils
sudo yum install libhal-dev libdbus-1-dev libdbus-glib-1-dev libhal-storage-dev python-gtk2-dev
sudo yum install libthunar-vfs-1-dev

#bash -e default

# step 1: import the thunar svn code tree
thunar -q
cd $HOME
[ -e $HOME/thunar-dev ] && rm -r -f $HOME/thunar-dev
svn co http://svn.xfce.org/svn/xfce/thunar/trunk/ thunar-dev

# step 2: add our files to code tree #normaly a diff file merge is used
mkdir $HOME/thunar-dev/examples/menuplugin/
cp --verbose $HOME/menuplugin/plugin/menu-plugin.c $HOME/thunar-dev/examples/menuplugin/
cp --verbose $HOME/menuplugin/plugin/menu.c $HOME/thunar-dev/examples/menuplugin/
cp --verbose $HOME/menuplugin/plugin/menu.h $HOME/thunar-dev/examples/menuplugin/
cp --verbose $HOME/menuplugin/plugin/Makefile.am $HOME/thunar-dev/examples/menuplugin/

# step 3: append string "foo-plugin" as sub-dir
patch --strip=4 --directory=$HOME/thunar-dev/ --input=$HOME/menuplugin/patches/Makefile.am.patch

# step 4: onder the line: 'examples/tex-open-terminal/Makefile' append the following: 'examples/foo/Makefile'
patch --strip=4 --directory=$HOME/thunar-dev/ --input=$HOME/menuplugin/patches/configure.in.in.patch

# step 5: compile thunar
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH" # needed in fedora otherwise a libexo error
cd $HOME/thunar-dev
./autogen.sh --prefix=/usr/local
make

# step 6: check for the following files
ls -hal $HOME/thunar-dev/examples/menuplugin/
[ -e $HOME/thunar-dev/examples/menuplugin/menu.la ] && echo exist
[ -e $HOME/thunar-dev/examples/menuplugin/menu_la-foo.lo ] &&  echo exist
[ -e $HOME/thunar-dev/examples/menuplugin/menu_la-foo-plugin.lo ] &&  echo exist
[ -e $HOME/thunar-dev/examples/menuplugin/Makefile.in ]  && echo exist

# step 7: compile the extension
# this is not good can only install as root i need we need to seperate the build enviorment from our working system
cd  $HOME/thunar-dev/examples/menuplugin/
sudo make install-extensionsLTLIBRARIES
thunar -q
# step 8: run thunar and right click a directory and watch the output
bash -e $HOME/thunar-dev/thunar/Thunar
