5 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
12 abort-upgrade|abort-remove|abort-deconfigure)
17 echo "postinst called with unknown argument \`$1'" >&2
23 # Include CARNet functions
24 . /usr/share/carnet-tools/functions.sh
27 A2MODEDIR="/etc/apache2/mods-enabled"
28 EXTENSIONS="mysql ldap gd"
30 PHP5CONFD="/etc/php5/conf.d"
35 # Disable PHP4 module and enable Apache2 PHP5 module.
37 if [ -e /etc/apache2/apache2.conf ]; then
38 if [ -e "$A2MODEDIR/php4.load" ]; then
39 cp_echo "CN: Disabling PHP4 module for Apache2 web server"
40 a2dismod php4 >/dev/null || true
43 if [ ! -e "$A2MODEDIR/php5.load" ] || [ ! -e "$A2MODEDIR/php5.conf" ]; then
44 cp_echo "CN: Enabling PHP5 module for Apache2 web server"
45 a2enmod php5 >/dev/null || true
51 # Check if PHP5 extensions (MySQL, LDAP, GD) are enabled.
53 for php5ext in $EXTENSIONS; do
55 php5ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php5ext\.so"
57 # Remove extension entry from /etc/php5/(apache|apache2|cgi|cli).ini
58 # configuration files.
59 for SAPI in apache apache2 cgi cli; do
61 ini_file="$PHP5DIR/$SAPI/php.ini"
63 if [ -f "$ini_file" ]; then
65 cp_echo "CN: Removing $php5ext extension from file $ini_file"
67 cp_check_and_sed "$php5ext_re" \
69 "$ini_file" && need_restart=1 || true
73 # Check extension configuration in /etc/php5/conf.d/ directory.
74 if [ ! -f "$PHP5CONFD/$php5ext.ini" ]; then
76 cp_echo "CN: Creating configuration file $PHP5CONFD/$php5ext.ini"
78 php5ext_up=`echo $php5ext | tr [:lower:] [:upper:] | sed 's/Y/y/'`
79 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
81 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
83 echo -e "# configuration for php $php5ext_up module\nextension=$php5ext.so" >> "$INITMP"
84 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
89 if ! grep -q "$php5ext_re" "$PHP5CONFD/$php5ext.ini"; then
91 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
93 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
94 cat "$PHP5CONFD/$php5ext.ini" > "$INITMP"
95 echo "extension=$php5ext.so" >> "$INITMP"
96 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
104 # Enable some PHP5 tweaks for Apache2 web server (/etc/php5/apache2/php.ini).
106 # * upload_max_filesize = 256M
107 # * post_max_size = 256M
108 # * memory_limit = 256M
110 for SAPI in apache apache2 cgi cli; do
112 if [ ! -d "$PHP5DIR/$SAPI" ]; then
116 ini_file="$PHP5DIR/$SAPI/php.ini"
118 cp_echo "CN: Checking and enabling some CARNet specific parameters in file $ini_file"
120 if [ -f "$ini_file" ]; then
122 cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=[[:space:]]*2M$" \
123 's/^[[:space:]]*upload_max_filesize[[:space:]]*=.*/upload_max_filesize = 256M/' \
124 "$ini_file" && need_restart=1 || true
126 cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=[[:space:]]*8M$" \
127 's/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = 256M/' \
128 "$ini_file" && need_restart=1 || true
130 cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=[[:space:]]*16M$" \
131 's/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = 256M/' \
132 "$ini_file" && need_restart=1 || true
135 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
136 if [ -f "$ini_file" ]; then
137 cat $ini_file > $ini_file_tmp
140 if ! egrep -q "^[[:space:]]*(upload_max_filesize|post_max_size|memory_limit)[[:space:]]*=" $ini_file_tmp; then
142 if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then
143 echo "upload_max_filesize = 256M" >> "$ini_file_tmp"
145 if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then
146 echo "post_max_size = 256MB" >> "$ini_file_tmp"
148 if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then
149 echo "memory_limit = 256M" >> "$ini_file_tmp"
151 cp_mv "$ini_file_tmp" "$ini_file"
156 if [ -e "$ini_file_tmp" ]; then
157 rm -f "$ini_file_tmp"
162 # Restart Apache2 web server if needed.
164 if [ $need_restart -eq 1 ]; then
166 # Check Apache2 web server configuration.
167 if /usr/sbin/apache2ctl configtest 2>/dev/null; then
169 # Restart Apache2 web server.
170 if [ -x "/etc/init.d/apache2" ]; then
171 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
172 invoke-rc.d apache2 force-reload || true
174 /etc/init.d/apache2 force-reload || true
179 # Something is broken.
180 cp_echo "CN: Your Apache2 configuration is broken."
181 cp_echo "CN: Please, check the service after the installation finishes!"