Skip to content
Snippets Groups Projects
postinst 5.34 KiB
Newer Older
#!/bin/sh
# postinst script for dolibarr
#
# 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 /usr/share/doc/packaging-manual/

. /usr/share/debconf/confmodule
db_version 2.0


echo Run the dolibarr postinst script

case "$1" in
	configure)

		# Copy include for apache.conf
		fileorig="/usr/share/dolibarr/build/deb/apache.conf"
		config="/etc/dolibarr/apache.conf"
		mkdir -p /etc/dolibarr
		cp -p $fileorig $config

		# Create install.forced.php
		fileorig="/usr/share/dolibarr/build/deb/install.forced.php.install"
		config="/usr/share/dolibarr/htdocs/install/install.forced.php"
		superuserlogin=''
		superuserpassword=''
		if [ -f /etc/mysql/debian.cnf ] ; then
			# Load superuser login and pass
			superuserlogin=$(/bin/grep --max-count=1 "user" /etc/mysql/debian.cnf | /bin/sed -e 's/^user[ =]*//g')
			superuserpassword=$(/bin/grep --max-count=1 "password" /etc/mysql/debian.cnf | /bin/sed -e 's/^password[ =]*//g')
		fi
		echo Mysql superuser found to use is $superuserlogin
		if [ -z "$superuserlogin" ] ; then
			cat $fileorig | sed -e 's/__SUPERUSERLOGIN__/root/g' | sed -e 's/__SUPERUSERPASSWORD__//g' > $config
		else
			cat $fileorig | sed -e 's/__SUPERUSERLOGIN__/'$superuserlogin'/g' | sed -e 's/__SUPERUSERPASSWORD__/'$superuserpassword'/g' > $config
		fi
		
		# Create empty conf.php
		if [ ! -f /usr/share/dolibarr/htdocs/conf/conf.php ]
		then 
			echo Create empty file /usr/share/dolibarr/htdocs/conf/conf.php		
			touch /usr/share/dolibarr/htdocs/conf/conf.php
			chown -R www-data.www-data /usr/share/dolibarr/htdocs/conf/conf.php;
	    	chmod -R 750 /usr/share/dolibarr/htdocs/conf/conf.php;
		fi

		#db_reset "dolibarr/webserver"

		# Get the web server type (use db_get for interactive mode).
#		db_get "dolibarr/webserver"		# Read value for webserver.
#		webserver="$RET"
		case $webserver in
			Apache)		webservers="apache2" ;;
			Apache-SSL)	webservers="apache2-ssl" ;;
			Both)		webservers="apache2 apache2-ssl" ;;
			*)		    webservers="apache2 apache2-ssl" ;;
		esac

		# Set up web server.
		for server in $webservers ; do
			echo Complete config of server $server
			# Add info for PHP (obsolete)
			#typestr='application/x-httpd-php'
			#extension='.php'
			#. /usr/share/wwwconfig-common/apache-addtype_all.sh
			# Enable PHP module (obsolete)
			#. /usr/share/wwwconfig-common/apache-php.sh
			#echo Result of enabling PHP modules: $status
			
			# Detect webuser and webgroup
			webuser=
			webgroup=

			# Search in httpd.conf (obsolete)
			#. /usr/share/wwwconfig-common/apache-run.get
			#echo Web user.group found is $webuser.$webgroup

			if [ -z "$webuser" ] ; then
				webuser=www-data
			fi
			if [ -z "$webgroup" ] ; then
				webgroup=www-data
			fi

			echo Web user.group used is $webuser.$webgroup

			#
			# That may lead to problems if apache & apache-ssl do
			# not have the same user/group.
			#
			chown -R $webuser.$webgroup /usr/share/dolibarr

			includefile="/etc/dolibarr/apache.conf"
			#echo "$includefile $server" 
			. /usr/share/dolibarr/build/deb/apache-include_all.sh
			test "$status" = "uncomment" -o "$status" = "include" && restart="$server $restart"
			
			# (useless)
			#for index in index.php; do
			#	. /usr/share/wwwconfig-common/apache-index_all.sh
			#	test "$status" = "added" && restart="$server $restart"
			#done
Laurent Destailleur's avatar
Laurent Destailleur committed
		#echo "Copy icon file"
		#fileorig="/usr/share/dolibarr/doc/images/dolibarr.xpm"
		#target="/usr/share/pixmaps/"
		#cp -f $fileorig $target
Laurent Destailleur's avatar
Laurent Destailleur committed
		#echo "Install menu entry"
Laurent Destailleur's avatar
Laurent Destailleur committed
		#fileorig="/usr/share/dolibarr/build/deb/dolibarr.desktop"
		#target="/usr/share/applications/"
		#cp -f $fileorig $target
		# Not sure this is usefull
		if test -x /usr/bin/update-menus; then 
			echo "update-menus"
			update-menus;
		fi
		# TODO Create the file to force parameters in Web installer
		#if grep DBHOST /usr/share/dolibarr/htdocs/conf/conf.php > /dev/null
		#then
		#    perl -pi -e "s/DBHOST/$dbserver/" /usr/share/dolibarr/htdocs/conf/conf.php
		#    perl -pi -e "s/DBNAME/$dbname/" /usr/share/dolibarr/htdocs/conf/conf.php
		#    perl -pi -e "s/DBUSER/$dbuser/" /usr/share/dolibarr/htdocs/conf/conf.php
		#    perl -pi -e "s/DBPASS/$dbpass/" /usr/share/dolibarr/htdocs/conf/conf.php
		#fi

		# Restart servers
		servers="apache2-ssl apache2 mysql"
		if [ -f /usr/share/wwwconfig-common/restart.sh ] ;
		then
			. /usr/share/wwwconfig-common/restart.sh
		else
			# Another way to restart
			for server in $servers ; do
        		if [ -x /usr/sbin/invoke-rc.d ]; then
        		    # This on works with Debian (5.05,...) and Ubuntu (9.10,10.04,...)
        	    	invoke-rc.d $server reload || true
        		else
        	    	/etc/init.d/$server reload || true
        		fi
			done
		fi
		
		echo "Launch Dolibarr on page http://localhost/dolibarr/ to complete the installation and use Dolibarr."
	;;

	abort-upgrade|abort-remove|abort-deconfigure)
	;;

	*)
		echo "postinst called with unknown argument \`$1'" >&2
		exit 0
	;;
esac

db_stop

#DEBHELPER#