source: php5-lliurex-compat/fuentes/debian/postinst @ 1829

Last change on this file since 1829 was 1829, checked in by mabarracus, 3 years ago

Fixes bugs

File size: 5.0 KB
Line 
1#!/bin/sh
2# postinst script for php5-lliurex-compat
3#
4# see: dh_installdeb(1)
5
6set -e
7
8# summary of how this script can be called:
9#        * <postinst> `configure' <most-recently-configured-version>
10#        * <old-postinst> `abort-upgrade' <new version>
11#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
12#          <new-version>
13#        * <postinst> `abort-remove'
14#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
15#          <failed-install-package> <version> `removing'
16#          <conflicting-package> <version>
17# for details, see https://www.debian.org/doc/debian-policy/ or
18# the debian-policy package
19NOW=$(date +'%Y%m%d%h%m')
20setup_apache(){
21    INST="/etc/apache2-lliurex"
22    FILES="ports.conf apache2.conf envvars"
23    IS_DONE=0
24    for file in $FILES; do
25        if [ -f ${INST}/${file} ]; then
26            IS_DONE=1
27        fi
28    done
29    if [ ${IS_DONE} -eq 1 ]; then 
30            echo "Apache2 multi-instance seems already configured, skipping multi-instance configuration"
31            return
32    fi
33   
34    echo "Setting up apache multi-instance"
35    if [ ! -f /usr/share/doc/apache2/examples/setup-instance ]; then
36        echo "ERROR: setup-instance from apache2 not found !!!"
37        exit 1
38    fi
39    if [ -d /etc/apache2-lliurex ]; then
40        mv /etc/apache2-lliurex /etc/apache2-lliurex-${NOW}
41    fi
42    bash /usr/share/doc/apache2/examples/setup-instance lliurex
43}
44change_ports(){
45    echo "Changing default ports from 80 -> 800 & 443 -> 4430 in apache-lliurex"
46    if [ ! -d /etc/apache2-lliurex ]; then
47        echo "ERROR: /etc/apache2-lliurex not found !!!"
48        exit 1
49    fi
50    sed -i -r 's/80( |$)/800/g' /etc/apache2-lliurex/ports.conf
51    sed -i -r 's/443( |$)/4430/g' /etc/apache2-lliurex/ports.conf
52    for site in /etc/apache2-lliurex/sites-available/*.conf; do
53        tst80=$(egrep ':80' ${site}|wc -l)
54        tst443=$(egrep ':443' ${site}|wc -l)
55        if [ ${tst80} -ne 0 ]; then
56            echo "Fixing port 80 in site: " ${site}
57            sed -i -r 's/\*:80/\*:800/g' ${site}
58        fi
59        if [ ${tst443} -ne 0 ]; then
60            echo "Fixing port 443 in site: " ${site}
61            sed -i -r 's/\*:443/\*:4430/g' ${site}
62        fi
63    done;
64}
65fix_mods(){
66    echo "Fixing php modules in apache & apache-lliurex"
67    #which fails into zmd
68    if [ -x /usr/sbin/a2dismod ]; then
69        DISMOD="/usr/sbin/a2dismod"
70    else
71        DISMOD=`/usr/bin/which a2dismod`
72    fi
73    if [ -L /usr/local/sbin/a2dismod-lliurex ]; then
74        DISMOD_LLIUREX=/usr/local/sbin/a2dismod-lliurex
75    else
76        DISMOD_LLIUREX=`/usr/bin/which a2dismod-lliurex`
77        if [ -z ${DISMOD_LLIUREX} ]; then
78            ln -s /usr/sbin/a2dismod /usr/local/sbin/a2dismod-lliurex
79            DISMOD_LLIUREX=/usr/local/sbin/a2dismod-lliurex
80        fi
81       
82    fi
83
84    if [ -L /usr/local/sbin/a2enmod-lliurex ]; then
85        ENMOD_LLIUREX=/usr/local/sbin/a2enmod-lliurex
86    else
87        ENMOD_LLIUREX=`/usr/bin/which a2enmod-lliurex`
88        if [ -z ${ENMOD_LLIUREX} ]; then
89            ln -s /usr/sbin/a2enmod /usr/local/sbin/a2enmod-lliurex
90            ENMOD_LLIUREX=/usr/local/sbin/a2enmod-lliurex
91        fi
92       
93    fi
94   
95    echo "Using: ${DISMOD_LLIUREX} & ${DISMOD} & ${ENMOD_LLIUREX}"
96    if [ -L /etc/apache2-lliurex/mods-enabled/php7.0.load ]; then
97        echo "Disabling php7 into apache2-lliurex instance"
98        ${DISMOD_LLIUREX} php7.0
99    fi
100    if [ -L /etc/apache2/mods-enabled/php5.load ]; then
101        echo "Disabling php5 into apache2 instance"
102        ${DISMOD} php5
103    fi
104    if [ -f /etc/apache2-lliurex/mods-available/php7.0.conf ]; then
105        mv /etc/apache2-lliurex/mods-available/php7.0.conf /etc/apache2-lliurex/mods-available/php7.0.conf.disabled
106    fi
107    if [ -f /etc/apache2-lliurex/mods-available/php7.0.load ]; then
108        mv /etc/apache2-lliurex/mods-available/php7.0.load /etc/apache2-lliurex/mods-available/php7.0.load.disabled
109    fi
110    if [ -f /etc/apache2/mods-available/php5.conf ]; then
111        mv /etc/apache2/mods-available/php5.conf /etc/apache2/mods-available/php5.conf.disabled
112    fi
113    if [ -f /etc/apache2/mods-available/php5.load ]; then
114        mv /etc/apache2/mods-available/php5.load /etc/apache2/mods-available/php5.load.disabled
115    fi
116    TST=""
117    if [ ! -f /etc/apache2/mods-available/php5.conf -o ! -f /etc/apache2/mods-available/php5.load ]; then
118        TST=$(ls /etc/apache2/mods-available|grep php5)
119        if [ ! -z "${TST}" ]; then
120            for x in ${TST}; do 
121                cp ${x%%.disabled} /etc/apache2-lliurex/mods-available/
122            done
123        fi
124    fi
125    if [ -e /etc/apache2-lliurex/mods-available/php5.load -a ! -e /etc/apache2-lliurex/mods-enabled/php5.load ]; then
126        echo "Enabling php5 into apache2-lliurex instance"
127        ${ENMOD_LLIUREX} php5
128    fi
129}
130
131case "$1" in
132    configure)
133        if [ -f /tmp/debug_compat ]; then
134            set -x
135        fi
136        setup_apache
137        change_ports
138        fix_mods
139        echo "Enabling multi-site services"
140        systemctl enable apache2-lliurex
141        systemctl daemon-reload
142        systemctl restart apache2-lliurex
143        systemctl restart apache2
144        if [ -f /tmp/debug_compat ]; then
145            set +x
146        fi
147    ;;
148
149    abort-upgrade|abort-remove|abort-deconfigure)
150    ;;
151
152    *)
153        echo "postinst called with unknown argument \`$1'" >&2
154        exit 1
155    ;;
156esac
157
158# dh_installdeb will replace this with shell code automatically
159# generated by other debhelper scripts.
160
161#DEBHELPER#
162
163exit 0
Note: See TracBrowser for help on using the repository browser.