#!/bin/sh # postinst script for php5-lliurex-compat # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * `configure' # * `abort-upgrade' # * `abort-remove' `in-favour' # # * `abort-remove' # * `abort-deconfigure' `in-favour' # `removing' # # for details, see https://www.debian.org/doc/debian-policy/ or # the debian-policy package NOW=$(date +'%Y%m%d%h%m') setup_apache(){ INST="/etc/apache2-lliurex" FILES="ports.conf apache2.conf envvars" IS_DONE=0 for file in $FILES; do if [ -f ${INST}/${file} ]; then IS_DONE=1 fi done if [ ${IS_DONE} -eq 1 ]; then echo "Apache2 multi-instance seems already configured, skipping multi-instance configuration" return fi echo "Setting up apache multi-instance" if [ ! -f /usr/share/doc/apache2/examples/setup-instance ]; then echo "ERROR: setup-instance from apache2 not found !!!" exit 1 fi if [ -d /etc/apache2-lliurex ]; then mv /etc/apache2-lliurex /etc/apache2-lliurex-${NOW} fi bash /usr/share/doc/apache2/examples/setup-instance lliurex } fix_apache_envvars(){ FILE="/etc/apache2-lliurex/envvars" rc=0 grep "APACHE_PID_FILE" $FILE | grep "lliurex" || rc=1 if [ $rc -eq 1 ]; then sed -i "s/export APACHE_PID_FILE=\/var\/run\/apache2\/apache2\$SUFFIX.pid/export APACHE_PID_FILE=\/var\/run\/apache2-lliurex\/apache2\$SUFFIX.pid/g" $FILE fi } change_ports(){ echo "Changing default ports from 80 -> 800 & 443 -> 4430 in apache-lliurex" if [ ! -d /etc/apache2-lliurex ]; then echo "ERROR: /etc/apache2-lliurex not found !!!" exit 1 fi sed -i -r 's/80( |$)/800/g' /etc/apache2-lliurex/ports.conf sed -i -r 's/443( |$)/4430/g' /etc/apache2-lliurex/ports.conf for site in /etc/apache2-lliurex/sites-available/*.conf; do tst80=$(egrep ':80' ${site}|wc -l) tst443=$(egrep ':443' ${site}|wc -l) if [ ${tst80} -ne 0 ]; then echo "Fixing port 80 in site: " ${site} sed -i -r 's/\*:80/\*:800/g' ${site} fi if [ ${tst443} -ne 0 ]; then echo "Fixing port 443 in site: " ${site} sed -i -r 's/\*:443/\*:4430/g' ${site} fi done; } fix_mods(){ echo "Fixing php modules in apache & apache-lliurex" #which fails into zmd if [ -x /usr/sbin/a2dismod ]; then DISMOD="/usr/sbin/a2dismod" else DISMOD=`/usr/bin/which a2dismod` fi if [ -L /usr/local/sbin/a2dismod-lliurex ]; then DISMOD_LLIUREX=/usr/local/sbin/a2dismod-lliurex else DISMOD_LLIUREX=`/usr/bin/which a2dismod-lliurex` if [ -z ${DISMOD_LLIUREX} ]; then ln -s /usr/sbin/a2dismod /usr/local/sbin/a2dismod-lliurex DISMOD_LLIUREX=/usr/local/sbin/a2dismod-lliurex fi fi if [ -L /usr/local/sbin/a2enmod-lliurex ]; then ENMOD_LLIUREX=/usr/local/sbin/a2enmod-lliurex else ENMOD_LLIUREX=`/usr/bin/which a2enmod-lliurex` if [ -z ${ENMOD_LLIUREX} ]; then ln -s /usr/sbin/a2enmod /usr/local/sbin/a2enmod-lliurex ENMOD_LLIUREX=/usr/local/sbin/a2enmod-lliurex fi fi echo "Using: ${DISMOD_LLIUREX} & ${DISMOD} & ${ENMOD_LLIUREX}" if [ -L /etc/apache2-lliurex/mods-enabled/php7.0.load ]; then echo "Disabling php7 into apache2-lliurex instance" ${DISMOD_LLIUREX} php7.0 fi if [ -L /etc/apache2/mods-enabled/php5.load ]; then echo "Disabling php5 into apache2 instance" ${DISMOD} php5 fi if [ -f /etc/apache2-lliurex/mods-available/php7.0.conf ]; then mv /etc/apache2-lliurex/mods-available/php7.0.conf /etc/apache2-lliurex/mods-available/php7.0.conf.disabled fi if [ -f /etc/apache2-lliurex/mods-available/php7.0.load ]; then mv /etc/apache2-lliurex/mods-available/php7.0.load /etc/apache2-lliurex/mods-available/php7.0.load.disabled fi if [ -f /etc/apache2/mods-available/php5.conf ]; then mv /etc/apache2/mods-available/php5.conf /etc/apache2/mods-available/php5.conf.disabled fi if [ -f /etc/apache2/mods-available/php5.load ]; then mv /etc/apache2/mods-available/php5.load /etc/apache2/mods-available/php5.load.disabled fi TST="" if [ ! -f /etc/apache2/mods-available/php5.conf -o ! -f /etc/apache2/mods-available/php5.load ]; then TST=$(ls /etc/apache2/mods-available|grep php5) if [ ! -z "${TST}" ]; then for x in ${TST}; do cp /etc/apache2/mods-available/${x} /etc/apache2-lliurex/mods-available/${x%%.disabled} done fi fi if [ -e /etc/apache2-lliurex/mods-available/php5.load -a ! -e /etc/apache2-lliurex/mods-enabled/php5.load ]; then echo "Enabling php5 into apache2-lliurex instance" ${ENMOD_LLIUREX} php5 fi } case "$1" in configure) if [ -f /tmp/debug_compat ]; then set -x fi if [ ! -e /etc/init.d/apache2-lliurex ]; then setup_apache change_ports fix_apache_envvars fix_mods echo "Enabling multi-site services" systemctl enable apache2-lliurex systemctl daemon-reload systemctl restart apache2-lliurex systemctl restart apache2 fi if dpkg --compare-versions "$2" lt 0.7; then FILE="/etc/apache2-lliurex/envvars" if [ -e $FILE ]; then rc=0 grep "APACHE_PID_FILE" $FILE | grep "lliurex" || rc=1 if [ $rc -eq 1 ]; then sed -i "s/export APACHE_PID_FILE=\/var\/run\/apache2\/apache2\$SUFFIX.pid/export APACHE_PID_FILE=\/var\/run\/apache2-lliurex\/apache2\$SUFFIX.pid/g" $FILE systemctl restart apache2-lliurex || true fi fi fi if [ -f /tmp/debug_compat ]; then set +x 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. #DEBHELPER# exit 0