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

Last change on this file since 5332 was 5332, checked in by hectorgh, 3 years ago

making sure opac and pmb files are the right ones

File size: 5.9 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}
44fix_apache_envvars(){
45    FILE="/etc/apache2-lliurex/envvars"
46    rc=0
47    grep "APACHE_PID_FILE" $FILE | grep "lliurex" || rc=1
48    if [ $rc -eq 1 ]; then
49        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
50    fi
51
52}
53change_ports(){
54    echo "Changing default ports from 80 -> 800 & 443 -> 4430 in apache-lliurex"
55    if [ ! -d /etc/apache2-lliurex ]; then
56        echo "ERROR: /etc/apache2-lliurex not found !!!"
57        exit 1
58    fi
59
60    # MAKING SURE WE HAVE THE RIGHT PMB AND OPAC SITES
61
62    PMB_CONF=$(find /etc/apache2-lliurex* -name pmb.conf | grep available | xargs grep -i directory | cut -d: -f1 | head -n 1)
63    OPAC_CONF=$(find /etc/apache2-lliurex* -name opac.conf | grep available | xargs grep -i directory | cut -d: -f1 | head -n 1)
64
65    if [ -n "$PMB_CONF" -a -n "$OPAC_CONF" ]; then
66   
67        cp $PMB_CONF /etc/apache2-lliurex/sites-available
68        cp $OPAC_CONF /etc/apache2-lliurex/sites-available
69
70    fi
71
72   
73
74
75    sed -i -r 's/80( |$)/800/g' /etc/apache2-lliurex/ports.conf
76    sed -i -r 's/443( |$)/4430/g' /etc/apache2-lliurex/ports.conf
77    for site in /etc/apache2-lliurex/sites-available/*.conf; do
78        tst80=$(egrep ':80' ${site}|wc -l)
79        tst443=$(egrep ':443' ${site}|wc -l)
80        if [ ${tst80} -ne 0 ]; then
81            echo "Fixing port 80 in site: " ${site}
82            sed -i -r 's/\*:80/\*:800/g' ${site}
83        fi
84        if [ ${tst443} -ne 0 ]; then
85            echo "Fixing port 443 in site: " ${site}
86            sed -i -r 's/\*:443/\*:4430/g' ${site}
87        fi
88    done;
89}
90fix_mods(){
91    echo "Fixing php modules in apache & apache-lliurex"
92    #which fails into zmd
93    if [ -x /usr/sbin/a2dismod ]; then
94        DISMOD="/usr/sbin/a2dismod"
95    else
96        DISMOD=`/usr/bin/which a2dismod`
97    fi
98    if [ -L /usr/local/sbin/a2dismod-lliurex ]; then
99        DISMOD_LLIUREX=/usr/local/sbin/a2dismod-lliurex
100    else
101        DISMOD_LLIUREX=`/usr/bin/which a2dismod-lliurex`
102        if [ -z ${DISMOD_LLIUREX} ]; then
103            ln -s /usr/sbin/a2dismod /usr/local/sbin/a2dismod-lliurex
104            DISMOD_LLIUREX=/usr/local/sbin/a2dismod-lliurex
105        fi
106       
107    fi
108
109    if [ -L /usr/local/sbin/a2enmod-lliurex ]; then
110        ENMOD_LLIUREX=/usr/local/sbin/a2enmod-lliurex
111    else
112        ENMOD_LLIUREX=`/usr/bin/which a2enmod-lliurex`
113        if [ -z ${ENMOD_LLIUREX} ]; then
114            ln -s /usr/sbin/a2enmod /usr/local/sbin/a2enmod-lliurex
115            ENMOD_LLIUREX=/usr/local/sbin/a2enmod-lliurex
116        fi
117       
118    fi
119   
120    echo "Using: ${DISMOD_LLIUREX} & ${DISMOD} & ${ENMOD_LLIUREX}"
121    if [ -L /etc/apache2-lliurex/mods-enabled/php7.0.load ]; then
122        echo "Disabling php7 into apache2-lliurex instance"
123        ${DISMOD_LLIUREX} php7.0
124    fi
125    if [ -L /etc/apache2/mods-enabled/php5.load ]; then
126        echo "Disabling php5 into apache2 instance"
127        ${DISMOD} php5
128    fi
129    if [ -f /etc/apache2-lliurex/mods-available/php7.0.conf ]; then
130        mv /etc/apache2-lliurex/mods-available/php7.0.conf /etc/apache2-lliurex/mods-available/php7.0.conf.disabled
131    fi
132    if [ -f /etc/apache2-lliurex/mods-available/php7.0.load ]; then
133        mv /etc/apache2-lliurex/mods-available/php7.0.load /etc/apache2-lliurex/mods-available/php7.0.load.disabled
134    fi
135    if [ -f /etc/apache2/mods-available/php5.conf ]; then
136        mv /etc/apache2/mods-available/php5.conf /etc/apache2/mods-available/php5.conf.disabled
137    fi
138    if [ -f /etc/apache2/mods-available/php5.load ]; then
139        mv /etc/apache2/mods-available/php5.load /etc/apache2/mods-available/php5.load.disabled
140    fi
141    TST=""
142    if [ ! -f /etc/apache2/mods-available/php5.conf -o ! -f /etc/apache2/mods-available/php5.load ]; then
143        TST=$(ls /etc/apache2/mods-available|grep php5)
144        if [ ! -z "${TST}" ]; then
145            for x in ${TST}; do 
146                cp /etc/apache2/mods-available/${x} /etc/apache2-lliurex/mods-available/${x%%.disabled}
147            done
148        fi
149    fi
150    if [ -e /etc/apache2-lliurex/mods-available/php5.load -a ! -e /etc/apache2-lliurex/mods-enabled/php5.load ]; then
151        echo "Enabling php5 into apache2-lliurex instance"
152        ${ENMOD_LLIUREX} php5
153    fi
154}
155
156case "$1" in
157    configure)
158        if [ -f /tmp/debug_compat ]; then
159            set -x
160        fi
161        setup_apache
162        change_ports
163        fix_apache_envvars
164        fix_mods
165        echo "Enabling multi-site services"
166        systemctl enable apache2-lliurex
167        systemctl daemon-reload
168        systemctl restart apache2-lliurex
169        systemctl restart apache2
170        if [ -f /tmp/debug_compat ]; then
171            set +x
172        fi
173    ;;
174
175    abort-upgrade|abort-remove|abort-deconfigure)
176    ;;
177
178    *)
179        echo "postinst called with unknown argument \`$1'" >&2
180        exit 1
181    ;;
182esac
183
184# dh_installdeb will replace this with shell code automatically
185# generated by other debhelper scripts.
186
187#DEBHELPER#
188
189exit 0
Note: See TracBrowser for help on using the repository browser.