#!/bin/sh set -e [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx case "$1" in configure) # continue below ;; abort-upgrade|abort-remove|abort-deconfigure) exit 0 ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 0 ;; esac # Include CARNet functions . /usr/share/carnet-tools/functions.sh PKG="php4-cn" A2MODEDIR="/etc/apache2/mods-enabled" EXTENSIONS="mysql" PHP4DIR="/etc/php4" PHP4CONFD="/etc/php4/conf.d" need_restart=0 # Disable PHP5 module and enable Apache2 PHP4 module. # if [ -e /etc/apache2/apache2.conf ]; then if [ -e "$A2MODEDIR/php5.load" ]; then cp_echo "CN: Disabling PHP5 module for Apache2 web server" a2dismod php5 >/dev/null || true need_restart=1 fi if [ ! -e "$A2MODEDIR/php4.load" ] || [ ! -e "$A2MODEDIR/php4.conf" ]; then cp_echo "CN: Enabling PHP4 module for Apache2 web server" a2enmod php4 >/dev/null || true need_restart=1 fi fi # Check if PHP4 extensions are enabled. # for php4ext in $EXTENSIONS; do php4ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php4ext\.so" # Remove extension entry from /etc/php4/(apache|apache2|cgi|cli).ini # configuration files. for SAPI in apache apache2 cgi cli; do if [ -d "$PHP4DIR/$SAPI" ]; then ini_file="$PHP4DIR/$SAPI/php.ini" if [ -f "$ini_file" ]; then cp_echo "CN: Removing $php4ext extension from file $ini_file" cp_check_and_sed "$php4ext_re" \ "/$php4ext_re/d" \ "$ini_file" && need_restart=1 || true fi fi done # Check $PHP4CONFD directory. if [ ! -d "$PHP4CONFD" ]; then cp_echo "CN: Creating configuration directory $PHP4CONFD" mkdir $PHP4CONFD fi # Check extension configuration in /etc/php4/conf.d/ directory. if [ ! -f "$PHP4CONFD/$php4ext.ini" ]; then cp_echo "CN: Creating configuration file $PHP4CONFD/$php4ext.ini" php4ext_up=`echo $php4ext | tr [:lower:] [:upper:] | sed 's/Y/y/'` INITMP=`mktemp $PHP4CONFD/$php4ext.ini.tmp.XXXXXX` cp_echo "CN: Adding $php4ext extension to file $PHP4CONFD/$php4ext.ini" echo -e "# configuration for php $php4ext_up module\nextension=$php4ext.so" >> "$INITMP" cp_mv "$INITMP" "$PHP4CONFD/$php4ext.ini" need_restart=1 else if ! grep -q "$php4ext_re" "$PHP4CONFD/$php4ext.ini"; then cp_echo "CN: Adding $php4ext extension to file $PHP4CONFD/$php4ext.ini" INITMP=`mktemp $PHP4CONFD/$php4ext.ini.tmp.XXXXXX` cat "$PHP4CONFD/$php4ext.ini" > "$INITMP" echo "extension=$php4ext.so" >> "$INITMP" cp_mv "$INITMP" "$PHP4CONFD/$php4ext.ini" need_restart=1 fi fi done # Enable some PHP4 tweaks for Apache2 web server (/etc/php4/apache2/php.ini). # # * upload_max_filesize = 256M # * post_max_size = 256M # * memory_limit = 256M # for SAPI in apache apache2 cgi cli; do if [ ! -d "$PHP4DIR/$SAPI" ]; then continue fi ini_file="$PHP4DIR/$SAPI/php.ini" cp_echo "CN: Checking and enabling some CARNet specific parameters in file $ini_file" if [ -f "$ini_file" ]; then cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=[[:space:]]*2M$" \ 's/^[[:space:]]*upload_max_filesize[[:space:]]*=.*/upload_max_filesize = 256M/' \ "$ini_file" && need_restart=1 || true cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=[[:space:]]*8M$" \ 's/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = 256M/' \ "$ini_file" && need_restart=1 || true cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=[[:space:]]*16M$" \ 's/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = 256M/' \ "$ini_file" && need_restart=1 || true fi ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX` if [ -f "$ini_file" ]; then cat $ini_file > $ini_file_tmp fi if ! egrep -q "^[[:space:]]*(upload_max_filesize|post_max_size|memory_limit)[[:space:]]*=" $ini_file_tmp; then if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then echo "upload_max_filesize = 256M" >> "$ini_file_tmp" fi if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then echo "post_max_size = 256MB" >> "$ini_file_tmp" fi if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then echo "memory_limit = 256M" >> "$ini_file_tmp" fi cp_mv "$ini_file_tmp" "$ini_file" need_restart=1 fi if [ -e "$ini_file_tmp" ]; then rm -f "$ini_file_tmp" fi done # Restart Apache2 web server if needed. # if [ $need_restart -eq 1 ]; then # Check Apache2 web server configuration. if /usr/sbin/apache2ctl configtest 2>/dev/null; then # Restart Apache2 web server. if [ -x "/etc/init.d/apache2" ]; then if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then invoke-rc.d apache2 force-reload || true else /etc/init.d/apache2 force-reload || true fi fi else # Something is broken. cp_echo "CN: Your Apache2 configuration is broken." cp_echo "CN: Please, check the service after the installation finishes!" fi fi # Mail root # cp_mail "$PKG" exit 0