#######################################################################
#  $RCSfile$
#
#  Copyright (C) 2004 Novell, Inc.
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public
#  License as published by the Free Software Foundation; either
#  version 2 of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public
#  License along with this program; if not, write to the Free
#  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#  Author: Paul Thomas <pthomas@novell.com>
#
#######################################################################

%define prefix /opt/novell/ifolder3
%define MONO_MACHINECONF /etc/mono/1.0/machine.config

Summary      : iFolder 3
Name         : ifolder3
Version      : 3.5.6088.1
Release      : 1
License    : GPL
Group        : Applications/Productivity
Source       : %{name}-%{version}.tar.gz
URL          : http://forge.novell.com/modules/xfmod/project/?ifolder
#Distribution : 
Vendor       : www.ifolder.com
Packager     : <unknown>
BuildRoot    : %{_tmppath}/%{name}-%{version}

Requires     : simias >= 1.2.5347.1 
Requires     : gtk-sharp >= 1.0.9
Requires     : libgdiplus >= 1.1.7
Obsoletes    : %{name} <= %{version}

#=============================================================================
%Description
iFolder 3 supports file sharing and collaboration across an enterprise.


#=============================================================================
%ChangeLog


#=============================================================================
%Prep
%setup -n %{name}-%{version}

#=============================================================================
%Build
./configure --prefix=%{prefix}
make

#=============================================================================
%Install
%{__rm} -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install

#=============================================================================
%Clean
%{__rm} -rf $RPM_BUILD_ROOT

#=============================================================================
%Post
INSTANCES_AFTER_INSTALL=$1
if [ "$INSTANCES_AFTER_INSTALL" = "1" ]; then

# These two fixes are for defect 74635 as a workaround to a mono defect 71219
    if [ -d /etc/mono ]; then
	chmod -R 755 /etc/mono
    fi

    if [ -d /usr/lib/mono ]; then
	chmod -R 755 /usr/lib/mono
    fi


    #
    # If path is not already in ld.so.conf, append it
    #
#    if ! grep -q "^%{prefix}/lib$" /etc/ld.so.conf ; then
#        echo "%{prefix}/lib" >> /etc/ld.so.conf
#        /sbin/ldconfig
#    fi
    
    #
    # Configure tray app to start on user login for each desktop user
    #
    #HOME_DIRS=`sed 's;[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*;\1;' /etc/passwd`
    #for path in $HOME_DIRS
    #do
	#%{prefix}/lib/setup-autostart $path
    #done 2>/dev/null

    #
    # Create ifolder.sh in /etc/profile.d to set PKG_CONFIG_PATH
    #
#    cat<<HERE > /etc/profile.d/ifolder.sh
#if test -z "\$PKG_CONFIG_PATH" ; then
#    export PKG_CONFIG_PATH="%{prefix}/lib/pkgconfig"
#else
#    export PKG_CONFIG_PATH="\$PKG_CONFIG_PATH:%{prefix}/lib/pkgconfig"
#fi
#HERE
    #
    # Install assemblies into the gac
    #
#    %{prefix}/bin/install-ifolder-to-gac -i


	#
	# Set up iFolder in the menu for Gnome
	#
    if test "%{prefix}" != "/usr"; then
        cp -f %{prefix}/share/applications/ifolder.desktop /usr/share/applications
    fi

	#
	# Set up a sym link to /usr/bin so iFolder will run
	#
	ln -s %{prefix}/bin/ifolder /usr/bin/ifolder

    #
    # Set up iFolder file associations for Gnome
    #
    #if test -d "$GNOMEDIR" -a \( "%{prefix}" != "$GNOMEDIR" \); then
    #    cp -f %{prefix}/share/mime-info/ifolder.mime $GNOMEDIR/share/mime-info
    #    cp -f %{prefix}/share/mime-info/ifolder.keys $GNOMEDIR/share/mime-info
    #    cp -f %{prefix}/share/application-registry/ifolder.applications $GNOMEDIR/share/application-registry
    #fi

    INSTANCES_AFTER_INSTALL=$1
    if [ "$INSTANCES_AFTER_INSTALL" = "1" ]; then
        echo "Editing %{MONO_MACHINECONF} to allow for more connections"
        if [ -w %{MONO_MACHINECONF} ]; then
                cp %{MONO_MACHINECONF} %{MONO_MACHINECONF}.backup
                cat %{MONO_MACHINECONF}.backup | sed "s/maxconnection=\"2\"/maxconnection=\"10\" /" > %{MONO_MACHINECONF}
                rm -f %{MONO_MACHINECONF}.backup
        else
                echo "WARNING: %{MONO_MACHINECONF} not writable"
                                                                                                                                             
        fi
    fi



fi

#=============================================================================
%Preun
INSTANCES_AFTER_UNINSTALL=$1
if [ "$INSTANCES_AFTER_UNINSTALL" = "0" ]; then
    #
    # Unconfigure tray app to start on user login for each desktop user
    #
    #HOME_DIRS=`sed 's;[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*;\1;' /etc/passwd`
    #for path in $HOME_DIRS
    #do
    #    %{prefix}/lib/setup-autostart -e $path
    #done 2>/dev/null

    #
    # Remove assemblies from the gac
    #
#    %{prefix}/bin/install-ifolder-to-gac -u

	#
	# Set up iFolder in the menu for Gnome
	#
    if test "%{prefix}" != "/usr"; then
		rm -f /usr/share/applications/ifolder.desktop
    fi

	#
	# Remove sym link to ifolder from /usr/bin/ifolder
	#
	rm -f /usr/bin/ifolder

    #
    # Remove iFolder file associations for Gnome
    #
    #if test -d "$GNOMEDIR" -a \( "%{prefix}" != "$GNOMEDIR" \); then
    #    rm -f $GNOMEDIR/share/mime-info/ifolder.mime
    #    rm -f $GNOMEDIR/share/mime-info/ifolder.keys
    #    rm -f $GNOMEDIR/share/application-registry/ifolder.applications
    #fi

fi
    
#=============================================================================
%Postun
INSTANCES_AFTER_UNINSTALL=$1
if [ "$INSTANCES_AFTER_UNINSTALL" = "0" ]; then
        #Remove the ~/.local/simias folder recursively for all users
        echo "Removing simias information for all users"
        if [ -e /root/.local/share/simias ]
        then
                rm -rf /root/.local/share/simias
        fi
        rm -rf /home/*/.local/share/simias
                                                                                                                                  
    #
    # Remove ifolder.sh from /etc/profile.d
    #
#    %{__rm} -f /etc/profile.d/ifolder.sh
fi

#=============================================================================
%Files
%defattr(755,root,root)
%{prefix}/*