From f32bc24285a37ba5f99654018b001726a7951c3c Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Wed, 24 Jul 2013 13:49:40 +0200
Subject: [PATCH] Fix: Upgrade of package break install

Conflicts:
	build/rpm/dolibarr_fedora.spec
	build/rpm/dolibarr_generic.spec
---
 build/rpm/dolibarr_fedora.spec   |  49 +++++++-------
 build/rpm/dolibarr_generic.spec  | 106 +++++++++++++++++--------------
 build/rpm/dolibarr_mandriva.spec |  53 +++++++++-------
 build/rpm/dolibarr_opensuse.spec |  54 +++++++++-------
 4 files changed, 147 insertions(+), 115 deletions(-)

diff --git a/build/rpm/dolibarr_fedora.spec b/build/rpm/dolibarr_fedora.spec
index a72b4955342..69553f983b1 100755
--- a/build/rpm/dolibarr_fedora.spec
+++ b/build/rpm/dolibarr_fedora.spec
@@ -302,34 +302,37 @@ echo "-------------------------------------------------------"
 echo
 
 
-#---- postun (after uninstall)
+#---- postun (after upgrade or uninstall)
 %postun
 
-# Define vars
-export apachelink="%{_sysconfdir}/httpd/conf.d/dolibarr.conf"
-
-# Remove apache link
-if [ -L $apachelink ] ;
+if [ "x$1" = "x0" ] ;
 then
-    echo "Delete apache config link for Dolibarr ($apachelink)"
-    %{__rm} -f $apachelink
-    status=purge
+	# Remove
+	echo "Removed package"
+
+	# Define vars
+	export apachelink="%{_sysconfdir}/httpd/conf.d/dolibarr.conf"
+	
+	# Remove apache link
+	if [ -L $apachelink ] ;
+	then
+	    echo "Delete apache config link for Dolibarr ($apachelink)"
+	    %{__rm} -f $apachelink
+	    status=purge
+	fi
+	
+	# Restart web servers if required
+	if [ "x$status" = "xpurge" ] ;
+	then
+	    # Restart web server
+	    echo Restart web server
+	    /sbin/service httpd restart
+	fi
+else
+	# Upgrade
+	echo "No remove ation done (this is an upgrade)"
 fi
 
-# Restart web servers if required
-if [ "x$status" = "xpurge" ] ;
-then
-    # Restart web server
-    echo Restart web server
-    if [ -f %{_sysconfdir}/init.d/httpd ]; then
-        %{_sysconfdir}/init.d/httpd restart
-    fi
-    if [ -f %{_sysconfdir}/init.d/apache2 ]; then
-        %{_sysconfdir}/init.d/apache2 restart
-    fi
-fi
-
-
 
 %changelog
 * Mon Apr 22 2013 Laurent Destailleur 3.3.3-0.3
diff --git a/build/rpm/dolibarr_generic.spec b/build/rpm/dolibarr_generic.spec
index fbdb1d9bf06..7e0c426a53d 100755
--- a/build/rpm/dolibarr_generic.spec
+++ b/build/rpm/dolibarr_generic.spec
@@ -478,59 +478,71 @@ echo
 
 
 
-#---- postun (after uninstall)
+#---- postun (after upgrade or uninstall)
 %postun
 
-# Define vars
-os='unknown';
-%if 0%{?fedora} || 0%{?rhel_version} || 0%{?centos_version} || 0%{?mdkversion}
-export apachelink="%{_sysconfdir}/httpd/conf.d/dolibarr.conf"
-%else
-%if 0%{?suse_version}
-export apachelink="%{_sysconfdir}/apache2/conf.d/dolibarr.conf"
-%else
-if [ -d %{_sysconfdir}/httpd/conf.d ]; then
-    export os='fedora-redhat';
-    export apachelink="%{_sysconfdir}/httpd/conf.d/dolibarr.conf"
-fi
-if [ -d %{_sysconfdir}/apache2/conf.d -a `grep ^wwwrun /etc/passwd | wc -l` -ge 1 ]; then
-    export os='opensuse';
-    export apachelink="%{_sysconfdir}/apache2/conf.d/dolibarr.conf"
-fi
-if [ -d %{_sysconfdir}/httpd/conf.d -a `grep -i "^mageia\|mandriva" /etc/issue | wc -l` -ge 1 ]; then
-    export os='mageia-mandriva';
-    export apachelink="%{_sysconfdir}/httpd/conf.d/dolibarr.conf"
-fi
-if [ -d %{_sysconfdir}/apache2/conf.d -a `grep ^www-data /etc/passwd | wc -l` -ge 1 ]; then
-    export os='ubuntu-debian';
-    export apachelink="%{_sysconfdir}/apache2/conf.d/dolibarr.conf"
-fi
-%endif
-%endif
-
-# Remove apache link
-if [ -L $apachelink ] ;
-then
-    echo "Delete apache config link for Dolibarr ($apachelink)"
-    %{__rm} -f $apachelink
-    status=purge
-fi
-
-# Restart web servers if required
-if [ "x$status" = "xpurge" ] ;
+if [ "x$1" = "x0" ] ;
 then
-    # Restart web server
-    echo Restart web server
-    if [ -f %{_sysconfdir}/init.d/httpd ]; then
-        %{_sysconfdir}/init.d/httpd restart
-    fi
-    if [ -f %{_sysconfdir}/init.d/apache2 ]; then
-        %{_sysconfdir}/init.d/apache2 restart
-    fi
+	# Remove
+	echo "Removed package"
+
+	# Define vars
+	os='unknown';
+	%if 0%{?fedora} || 0%{?rhel_version} || 0%{?centos_version} || 0%{?mdkversion}
+	export apachelink="%{_sysconfdir}/httpd/conf.d/dolibarr.conf"
+	%else
+	%if 0%{?suse_version}
+	export apachelink="%{_sysconfdir}/apache2/conf.d/dolibarr.conf"
+	%else
+	if [ -d %{_sysconfdir}/httpd/conf.d ]; then
+	    export os='fedora-redhat';
+	    export apachelink="%{_sysconfdir}/httpd/conf.d/dolibarr.conf"
+	fi
+	if [ -d %{_sysconfdir}/apache2/conf.d -a `grep ^wwwrun /etc/passwd | wc -l` -ge 1 ]; then
+	    export os='opensuse';
+	    export apachelink="%{_sysconfdir}/apache2/conf.d/dolibarr.conf"
+	fi
+	if [ -d %{_sysconfdir}/httpd/conf.d -a `grep -i "^mageia\|mandriva" /etc/issue | wc -l` -ge 1 ]; then
+	    export os='mageia-mandriva';
+	    export apachelink="%{_sysconfdir}/httpd/conf.d/dolibarr.conf"
+	fi
+	if [ -d %{_sysconfdir}/apache2/conf.d -a `grep ^www-data /etc/passwd | wc -l` -ge 1 ]; then
+	    export os='ubuntu-debian';
+	    export apachelink="%{_sysconfdir}/apache2/conf.d/dolibarr.conf"
+	fi
+	%endif
+	%endif
+	
+	# Remove apache link
+	if [ -L $apachelink ] ;
+	then
+	    echo "Delete apache config link for Dolibarr ($apachelink)"
+	    %{__rm} -f $apachelink
+	    status=purge
+	fi
+	
+	# Restart web servers if required
+	if [ "x$status" = "xpurge" ] ;
+	then
+	    # Restart web server
+	    echo Restart web server
+		%if 0%{?fedora} || 0%{?rhel_version} || 0%{?centos_version} || 0%{?mdkversion}
+	    /sbin/service httpd restart
+		%else
+	    if [ -f %{_sysconfdir}/init.d/httpd ]; then
+	        %{_sysconfdir}/init.d/httpd restart
+	    fi
+	    if [ -f %{_sysconfdir}/init.d/apache2 ]; then
+	        %{_sysconfdir}/init.d/apache2 restart
+	    fi
+	    %endif
+	fi
+else
+	# Upgrade
+	echo "No remove ation done (this is an upgrade)"
 fi
 
 
-
 %changelog
 * Mon Apr 22 2013 Laurent Destailleur 3.3.3-0.3
 - Initial version (#723326)
diff --git a/build/rpm/dolibarr_mandriva.spec b/build/rpm/dolibarr_mandriva.spec
index ab4f32080e7..04ce7640657 100755
--- a/build/rpm/dolibarr_mandriva.spec
+++ b/build/rpm/dolibarr_mandriva.spec
@@ -294,31 +294,40 @@ echo "-------------------------------------------------------"
 echo
 
 
-#---- postun (after uninstall)
+#---- postun (after upgrade or uninstall)
 %postun
 
-# Define vars
-export apachelink="%{_sysconfdir}/httpd/conf.d/dolibarr.conf"
-
-# Remove apache link
-if [ -L $apachelink ] ;
-then
-    echo "Delete apache config link for Dolibarr ($apachelink)"
-    %{__rm} -f $apachelink
-    status=purge
-fi
-
-# Restart web servers if required
-if [ "x$status" = "xpurge" ] ;
+if [ "x$1" = "x0" ] ;
 then
-    # Restart web server
-    echo Restart web server
-    if [ -f %{_sysconfdir}/init.d/httpd ]; then
-        %{_sysconfdir}/init.d/httpd restart
-    fi
-    if [ -f %{_sysconfdir}/init.d/apache2 ]; then
-        %{_sysconfdir}/init.d/apache2 restart
-    fi
+	# Remove
+	echo "Removed package"
+
+	# Define vars
+	export apachelink="%{_sysconfdir}/httpd/conf.d/dolibarr.conf"
+	
+	# Remove apache link
+	if [ -L $apachelink ] ;
+	then
+	    echo "Delete apache config link for Dolibarr ($apachelink)"
+	    %{__rm} -f $apachelink
+	    status=purge
+	fi
+	
+	# Restart web servers if required
+	if [ "x$status" = "xpurge" ] ;
+	then
+	    # Restart web server
+	    echo Restart web server
+	    if [ -f %{_sysconfdir}/init.d/httpd ]; then
+	        %{_sysconfdir}/init.d/httpd restart
+	    fi
+	    if [ -f %{_sysconfdir}/init.d/apache2 ]; then
+	        %{_sysconfdir}/init.d/apache2 restart
+	    fi
+	fi
+else
+	# Upgrade
+	echo "No remove ation done (this is an upgrade)"
 fi
 
 
diff --git a/build/rpm/dolibarr_opensuse.spec b/build/rpm/dolibarr_opensuse.spec
index 35d05de2c53..3a35aaa9bc6 100755
--- a/build/rpm/dolibarr_opensuse.spec
+++ b/build/rpm/dolibarr_opensuse.spec
@@ -300,34 +300,42 @@ echo "-------------------------------------------------------"
 echo
 
 
-#---- postun (after uninstall)
+#---- postun (after upgrade or uninstall)
 %postun
 
-# Define vars
-export apachelink="%{_sysconfdir}/apache2/conf.d/dolibarr.conf"
-
-# Remove apache link
-if [ -L $apachelink ] ;
+if [ "x$1" = "x0" ] ;
 then
-    echo "Delete apache config link for Dolibarr ($apachelink)"
-    %{__rm} -f $apachelink
-    status=purge
+	# Remove
+	echo "Removed package"
+	
+	# Define vars
+	export apachelink="%{_sysconfdir}/apache2/conf.d/dolibarr.conf"
+	
+	# Remove apache link
+	if [ -L $apachelink ] ;
+	then
+	    echo "Delete apache config link for Dolibarr ($apachelink)"
+	    %{__rm} -f $apachelink
+	    status=purge
+	fi
+	
+	# Restart web servers if required
+	if [ "x$status" = "xpurge" ] ;
+	then
+	    # Restart web server
+	    echo Restart web server
+	    if [ -f %{_sysconfdir}/init.d/httpd ]; then
+	        %{_sysconfdir}/init.d/httpd restart
+	    fi
+	    if [ -f %{_sysconfdir}/init.d/apache2 ]; then
+	        %{_sysconfdir}/init.d/apache2 restart
+	    fi
+	fi
+else
+	# Upgrade
+	echo "No remove ation done (this is an upgrade)"
 fi
 
-# Restart web servers if required
-if [ "x$status" = "xpurge" ] ;
-then
-    # Restart web server
-    echo Restart web server
-    if [ -f %{_sysconfdir}/init.d/httpd ]; then
-        %{_sysconfdir}/init.d/httpd restart
-    fi
-    if [ -f %{_sysconfdir}/init.d/apache2 ]; then
-        %{_sysconfdir}/init.d/apache2 restart
-    fi
-fi
-
-
 
 %changelog
 * Mon Apr 22 2013 Laurent Destailleur 3.3.3-0.3
-- 
GitLab