5 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
7 # Source debconf library.
8 . /usr/share/debconf/confmodule
15 abort-upgrade|abort-remove|abort-deconfigure)
20 echo "postinst called with unknown argument \`$1'" >&2
26 # Include CARNet functions
27 . /usr/share/carnet-tools/functions.sh
30 A2MODEDIR="/etc/apache2/mods-enabled"
31 EXTENSIONS="mysql ldap gd"
33 PHP5CONFD="/etc/php5/conf.d"
38 # Disable PHP4 module and enable Apache2 PHP5 module.
40 if [ -e /etc/apache2/apache2.conf ]; then
41 if [ -e "$A2MODEDIR/php4.load" ]; then
42 cp_echo "CN: Disabling PHP4 module for Apache2 web server"
43 a2dismod php4 >/dev/null || true
46 if [ ! -e "$A2MODEDIR/php5.load" ] || [ ! -e "$A2MODEDIR/php5.conf" ]; then
47 cp_echo "CN: Enabling PHP5 module for Apache2 web server"
48 a2enmod php5 >/dev/null || true
54 # Check if PHP5 extensions (MySQL, LDAP, GD) are enabled.
56 for php5ext in $EXTENSIONS; do
58 php5ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php5ext\.so"
60 # Remove extension entry from /etc/php5/(apache|apache2|cgi|cli).ini
61 # configuration files.
62 for SAPI in apache apache2 cgi cli; do
64 ini_file="$PHP5DIR/$SAPI/php.ini"
66 if [ -f "$ini_file" ]; then
68 cp_echo "CN: Removing $php5ext extension from file $ini_file"
70 cp_check_and_sed "$php5ext_re" \
72 "$ini_file" && need_restart=1 || true
76 # Check extension configuration in /etc/php5/conf.d/ directory.
77 if [ ! -f "$PHP5CONFD/$php5ext.ini" ]; then
79 cp_echo "CN: Creating configuration file $PHP5CONFD/$php5ext.ini"
81 php5ext_up=`echo $php5ext | tr [:lower:] [:upper:] | sed 's/Y/y/'`
82 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
84 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
86 echo -e "# configuration for php $php5ext_up module\nextension=$php5ext.so" >> "$INITMP"
87 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
92 if ! grep -q "$php5ext_re" "$PHP5CONFD/$php5ext.ini"; then
94 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
96 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
97 cat "$PHP5CONFD/$php5ext.ini" > "$INITMP"
98 echo "extension=$php5ext.so" >> "$INITMP"
99 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
107 # Enable some PHP5 tweaks for Apache2 web server (/etc/php5/apache2/php.ini).
109 # * upload_max_filesize = 256M
110 # * post_max_size = 256M
111 # * memory_limit = 256M
113 for SAPI in apache apache2 cgi cli; do
115 if [ ! -d "$PHP5DIR/$SAPI" ]; then
119 ini_file="$PHP5DIR/$SAPI/php.ini"
121 cp_echo "CN: Checking and enabling some CARNet specific parameters in file $ini_file"
123 if [ -f "$ini_file" ]; then
125 cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=[[:space:]]*2M$" \
126 's/^[[:space:]]*upload_max_filesize[[:space:]]*=.*/upload_max_filesize = 256M/' \
127 "$ini_file" && need_restart=1 || true
129 cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=[[:space:]]*8M$" \
130 's/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = 256M/' \
131 "$ini_file" && need_restart=1 || true
133 cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=[[:space:]]*16M$" \
134 's/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = 256M/' \
135 "$ini_file" && need_restart=1 || true
138 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
139 if [ -f "$ini_file" ]; then
140 cat $ini_file > $ini_file_tmp
143 if ! egrep -q "^[[:space:]]*(upload_max_filesize|post_max_size|memory_limit)[[:space:]]*=" $ini_file_tmp; then
145 if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then
146 echo "upload_max_filesize = 256M" >> "$ini_file_tmp"
148 if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then
149 echo "post_max_size = 256MB" >> "$ini_file_tmp"
151 if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then
152 echo "memory_limit = 256M" >> "$ini_file_tmp"
154 cp_mv "$ini_file_tmp" "$ini_file"
159 if [ -e "$ini_file_tmp" ]; then
160 rm -f "$ini_file_tmp"
165 # Restart Apache2 web server if needed.
167 if [ $need_restart -eq 1 ]; then
169 # Check Apache2 web server configuration.
170 if /usr/sbin/apache2ctl configtest 2>/dev/null; then
172 # Restart Apache2 web server.
173 if [ -x "/etc/init.d/apache2" ]; then
174 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
175 invoke-rc.d apache2 force-reload || true
177 /etc/init.d/apache2 force-reload || true
182 # Something is broken.
183 cp_echo "CN: Your Apache2 configuration is broken."
184 cp_echo "CN: Please, check the service after the installation finishes!"