Skip to content
Snippets Groups Projects
postinst 5.12 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

#
# Description:	Verifies that the env module is loaded in the apache config file.
# Needs:	$server the apache server to use,
#			anything that matches /etc/$server/*.conf
#
env_enable()
{
    envverm="env_module"
    if grep -e "^[[:space:]]*#[[:space:]]*LoadModule[[:space:]]\+$envverm" /etc/$server/httpd.conf > /dev/null 2>&1; then
		# Uncommenting
	sed -e "s#\([[:space:]]*\)\#[[:space:]]\+\(LoadModule $envverm\)#\1\2#" /etc/$server/httpd.conf > /etc/$server/httpd.conf.tmp
	status=uncomment
	if grep -e "^[[:space:]]*LoadModule[[:space:]]\+$envverm" /etc/$server/httpd.conf.tmp >/dev/null 2>&1; then
			# Uncomment successful.
	    cp /etc/$server/httpd.conf /etc/$server/httpd.conf.back >/dev/null 2>&1
	    mv /etc/$server/httpd.conf.tmp /etc/$server/httpd.conf
	else
			# Uncomment unsuccessful.
	    status=error
	    rm /etc/$server/httpd.conf.tmp
	fi
    fi
}

echo Run the 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

		# Copy install.forced.php
		fileorig="/usr/share/dolibarr/build/deb/install.forced.php"
		config="/usr/share/dolibarr/htdocs/install/install.forced.php"
		cp -p $fileorig $config

		# 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" ;;
		# Define variable phpver and phpini
		. /usr/share/wwwconfig-common/php.get

		# Set up web server.
		for server in $webservers ; do
			echo Complete config of server $server
			env_enable
			
			# Add info for PHP (might be obsolete)
			typestr='application/x-httpd-php'
			extension='.php'
			. /usr/share/wwwconfig-common/apache-addtype_all.sh
			
			# Enable PHP module (might be obsolete)
			#. /usr/share/wwwconfig-common/apache-php.sh
			#echo Result of enabling PHP modules: $status
			
			# Detect webuser and webgroup
			webuser=
			webgroup=
			. /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/wwwconfig-common/apache-include_all.sh
			test "$status" = "uncomment" -o "$status" = "include" && restart="$server $restart"
			for index in index.php; do
				. /usr/share/wwwconfig-common/apache-index_all.sh
				test "$status" = "added" && restart="$server $restart"
			done
		done

		# Copy icon file
		echo "Copy icon file"
		fileorig="/usr/share/dolibarr/doc/images/dolibarr.xpm"
		target="/usr/share/pixmaps/"
		cp -p $fileorig $target

		echo "Install menu entry"
		# This one is for Gnome ubuntu
		fileorig="/usr/share/dolibarr/build/deb/dolibarr.desktop"
		target="/usr/share/applications/"
		cp -p $fileorig $target
		# Not sure this one is usefulle
		if test -x /usr/bin/update-menus; then 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

		servers="apache2-ssl apache2 mysql"
		. /usr/share/wwwconfig-common/restart.sh

		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#