Skip to content
Snippets Groups Projects
postinst 4.96 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 apache.conf file into target directory
		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 into Dolibarr install directory
		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=$(grep --max-count=1 "user" /etc/mysql/debian.cnf | /bin/sed -e 's/^user[ =]*//g')
			superuserpassword=$(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 document directory
        #docdir='/var/lib/dolibarr/documents'
        docdir='/usr/share/dolibarr/documents'
        mkdir -p $docdir
        chown -R www-data:www-data $docdir
        chmod -R 775 $docdir
        chmod -R g+s $docdir
		# Create an empty conf.php with permission to web server
		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
Laurent Destailleur's avatar
Laurent Destailleur committed
			chown -R root:www-data /usr/share/dolibarr/htdocs/conf/conf.php
	    	chmod -R 660 /usr/share/dolibarr/htdocs/conf/conf.php

		#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
			
			# Detect webuser and webgroup
			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
            chown -R root:$webgroup /usr/share/dolibarr/htdocs/conf/conf.php
			# Add link to config file
            echo Setup web server $server to add dolibarr config file
			ln -fs /etc/dolibarr/apache.conf /etc/apache2/conf.d/dolibarr.conf
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"
		# Another way to restart
		for server in $servers ; do
    		if [ -x /usr/sbin/invoke-rc.d ]; then
                echo Restart web server $server using invoke-rc.d
    		    # This works with Debian (5.05,...) and Ubuntu (9.10,10.04,...)
    	    	invoke-rc.d $server reload || true
    		else
                echo Restart web server $server using $server reload
    	    	/etc/init.d/$server reload || true
    		fi
		done
		echo ----------
		echo "Call Dolibarr page http://localhost/dolibarr/ to complete the installation and use Dolibarr."
		echo ----------
	;;

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

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

db_stop

#DEBHELPER#