Your IP : 18.116.67.43


Current Path : /var/lib/dpkg/info/
Upload File :
Current File : /var/lib/dpkg/info/ispmanager-pkg-roundcube.postinst

#!/bin/bash
# postinst script for coremanager
#
# 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>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

COREDIR=/usr/local/mgr5
CONFNAME=roundcube.conf
. ${COREDIR}/lib/pkgsh/core_pkg_funcs.sh
. ${COREDIR}/lib/pkgsh/ispmgr_pkg_funcs.sh

if [ "$(lsb_release -s -c)" = "xenial" ] || [ -f /usr/sbin/phpenmod ]; then
	PHPENMOD=phpenmod
else
	PHPENMOD=php5enmod
fi

case "$1" in
    configure)
	test -f /etc/nginx/vhosts-includes/roundcube.conf && rm -f /etc/nginx/vhosts-includes/roundcube.conf
	if [[ $(lsb_release -s -c) =~ xenial|stretch ]]; then
		php -m | grep -qi mcrypt || ${PHPENMOD} mcrypt
	fi
	if [ -z "${2}" ]; then
		# debian8
		test -n "$(which a2disconf)" && test -f /etc/apache2/conf-enabled/roundcube.conf && a2disconf -q roundcube || :
	fi
	${COREDIR}/sbin/pkg_configure_roundcube.py $1 $2 || exit 1
	# For autologin
	if [ -f /etc/roundcube/config.inc.php ] && grep -Eq "^\\\$config\['plugins'\] = (\[|array\()\$" /etc/roundcube/config.inc.php ; then
		plugin_ar=$(cat /etc/roundcube/config.inc.php | grep -E -A1 "^\\\$config\['plugins'\] = (\[|array\()\$" | tail -n1)
		if ! echo "${plugin_ar}" | grep -q autologin ; then
			sed -i -r "/^\\\$config\['plugins'\] = (\[|array\()\$/a\    'autologin'," /etc/roundcube/config.inc.php
		fi
	fi
	if [ -f /etc/roundcube/main.inc.php ] && grep -Eq "^\\\$rcmail_config\['plugins'\] = array\(\);\$" /etc/roundcube/main.inc.php ; then
		sed -i -r "s/(^\\\$rcmail_config\['plugins'\] = array\()\);\$/\1 'autologin', );/" /etc/roundcube/main.inc.php
	fi

	RCPASSWD=$(sed -r -n "s/\\\$dbpass='(.*)';/\1/p" /etc/roundcube/debian-db.php)
	if [ -n "${RCPASSWD}" ] ; then
		RCNF=$(mktemp /tmp/.XXXXXX.cnf)
		echo "[client]" > ${RCNF}
		echo "user = roundcube" >> ${RCNF}
		echo "password = ${RCPASSWD}" >> ${RCNF}
		if ! echo "show tables" | mysql --defaults-file=${RCNF} -N roundcube >/dev/null 2>&1 ; then
			if echo "SELECT User FROM mysql.user" | mysql -N | grep -q roundcube ; then
				echo "ALTER USER 'roundcube'@'localhost' IDENTIFIED BY '${RCPASSWD}'" | mysql >/dev/null 2>&1 || echo "SET PASSWORD FOR 'roundcube'@'localhost' = PASSWORD('${RCPASSWD}')" | mysql >/dev/null 2>&1
			else
				echo "CREATE USER 'roundcube'@'localhost' IDENTIFIED BY '${RCPASSWD}'" | mysql >/dev/null 2>&1
				echo "GRANT ALL PRIVILEGES ON roundcube.* To 'roundcube'@'localhost'" | mysql >/dev/null 2>&1
			fi
		fi
		rm -f ${RCNF}
	fi

	if [ -f /usr/share/roundcube/php-cgi.d/php-roundcube.cgi ]; then
		chmod +x /usr/share/roundcube/php-cgi.d/php-roundcube.cgi
	fi

	# This paragraph is needed when updating a package to overwrite old configs
	# for which overwriting is prohibited
	confiles="/etc/nginx/vhosts-includes/roundcube-nginx.conf"
	confiles+=" /etc/apache2/conf.d/roundcube-apache.conf"
	confiles+=" /usr/local/lsws/conf/vhosts-includes/roundcube-openlitespeed.conf"
	for file in $confiles ; do
		if ! grep -qs "# Created by ispmanager 10.10.2024" $file && test -f ${file}.dpkg-dist ; then
			mv -f $file ${file}.dpkg-old
			mv -f ${file}.dpkg-dist $file

			# Nginx check location
			if [ "${file}" == "/etc/nginx/vhosts-includes/roundcube-nginx.conf" ]; then
				old_location="$(awk '/^location \/.*{/ {print $2}' ${file}.dpkg-old | head -n 1 | sed 's|^/||' | sed 's|/$||' | sed 's|/|\\/|g')"
				if [ "$old_location" != "roundcube" ] && [ ! -z $old_location ]; then
					sed -E "s/(^location)( .*\/)(roundcube)/\1\2${old_location}/g" -i ${file}
				fi
			fi

			# Apache check Alias
			if [ "${file}" == "/etc/apache2/conf.d/roundcube-apache.conf" ]; then
				old_alias="$(awk '/^Alias.*/ {print $2}' ${file}.dpkg-old | head -n 1 | sed 's|^/||' | sed 's|/$||' | sed 's|/|\\/|g')"
				if [ "$old_alias" != "roundcube" ] && [ ! -z $old_alias ]; then
					sed -E "s/(^Alias)( \/)(roundcube)/\1\2${old_alias}/g" -i ${file}
				fi
			fi

			# OLS check context
			if [ "${file}" == "/usr/local/lsws/conf/vhosts-includes/roundcube-openlitespeed.conf" ]; then
				old_context="$(awk '/^context.*/ {print $2}' ${file}.dpkg-old | grep -vE '/config|/temp|/logs' | head -n 1 | sed 's|^/||' | sed 's|/$||' | sed 's|/|\\/|g')"
				if [ "$old_context" != "roundcube" ] && [ ! -z $old_context ]; then
					sed -E "s/(^context)( \/)(roundcube)/\1\2${old_context}/g" -i ${file}
				fi
			fi
		fi
	done

	# Enable proxy modules
	test -n "$(which a2enmod)" && a2enmod proxy proxy_fcgi || :

	if [ -f /lib/systemd/system/php-fpm74.service ]; then
		if [ "$(systemctl is-active php-fpm74)" == "active" ]; then
			Service php-fpm74 reload
		elif [ -f /lib/systemd/system/php-fpm74.service ]; then
			Service php-fpm74 enable
			Service php-fpm74 start
		fi
	fi

	GeLswsName() {
		if grep -q ubuntu /etc/os-release ; then
			echo lshttpd
		else
			echo lsws
		fi
	}

	for service in apache2 nginx $(GeLswsName) ; do
		if [ "$(systemctl is-active ${service})" == "active" ]; then
			ReloadService ${service}
		fi
	done

	test -f ${COREDIR}/etc/${ISPMGR}.conf.d/${CONFNAME} || ln -sf ../conf.d/${CONFNAME} ${COREDIR}/etc/${ISPMGR}.conf.d/${CONFNAME}
	ReloadMgr ${ISPMGR}

	if [ -z ${2} ]; then
		if [ -f /etc/roundcube/config.inc.php ]; then
			# For email EAI show utf8 characters
			if ! grep -Eq "^\\\$config\['default_charset'\] = 'utf8';" /etc/roundcube/config.inc.php ; then
				echo "\$config['default_charset'] = 'utf8';" >> /etc/roundcube/config.inc.php
			fi
		fi
		if [ -f /etc/roundcube/main.inc.php ]; then
			# For email EAI show utf8 characters
                	if ! grep -Eq "^\\\$config\['default_charset'\] = 'utf8';" /etc/roundcube/main.inc.php ; then
                        	echo "\$config['default_charset'] = 'utf8';" >> /etc/roundcube/main.inc.php
                	fi
		fi
		ReloadWeb
		# Afterinstall
		AfterinstallModule ${ISPMGR} webmail
	fi
    ;;

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

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

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.



exit 0