5 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
12 abort-upgrade|abort-remove|abort-deconfigure)
17 echo "postinst called with unknown argument \`$1'" >&2
24 . /usr/share/debconf/confmodule
26 # Include CARNet functions
27 . /usr/share/carnet-tools/functions.sh
30 A2MODEDIR="/etc/apache2/mods-enabled"
33 PHP4CONFD="/etc/php4/conf.d"
40 # Calculate memory size for PHP memory_limit option.
44 local memtotal memlimit
45 memtotal=`awk 'tolower($1) == "memtotal:" { printf("%i", $2/1024); }' /proc/meminfo`
47 if [ $memtotal -lt 512 ]; then memlimit=16; fi
48 if [ $memtotal -ge 512 ]; then memlimit=32; fi
49 if [ $memtotal -gt 1024 ]; then memlimit=64; fi
55 # Disable PHP5 module and enable Apache2 PHP4 module.
57 if [ -e /etc/apache2/apache2.conf ]; then
58 if [ -e "$A2MODEDIR/php5.load" ]; then
59 cp_echo "CN: Disabling PHP5 module for Apache2 web server"
60 a2dismod php5 >/dev/null || true
63 if [ ! -e "$A2MODEDIR/php4.load" ] || [ ! -e "$A2MODEDIR/php4.conf" ]; then
64 cp_echo "CN: Enabling PHP4 module for Apache2 web server"
65 a2enmod php4 >/dev/null || true
71 # Check for PHP4 SAPI directories and configuration files.
73 for SAPI in apache2 cli; do
75 if [ ! -d "$PHP4DIR/$SAPI" ]; then
76 cp_echo "CN: Creating configuration directory $PHP4DIR/$SAPI/"
77 mkdir -p $PHP4DIR/$SAPI/
80 ini_file="$PHP4DIR/$SAPI/php.ini"
82 if [ ! -f "$ini_file" ]; then
84 cp_echo "CN: Generating configuration file $ini_file"
86 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
87 if [ "$SAPI" = "cli" ]; then
88 if [ -f "/usr/share/php4/php.ini-dist.cli" ]; then
89 cat /usr/share/php4/php.ini-dist.cli > $ini_file_tmp
92 if [ -f "/usr/share/php4/php.ini-dist" ]; then
93 cat /usr/share/php4/php.ini-dist > $ini_file_tmp
96 cp_mv $ini_file_tmp $ini_file
103 # Check for /etc/php4/conf.d/ directory.
105 if [ ! -d "$PHP4CONFD" ]; then
106 cp_echo "CN: Creating configuration directory $PHP4CONFD"
111 # Check if PHP4 extensions are enabled.
113 for php4ext in $EXTENSIONS; do
115 php4ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php4ext\.so"
117 # Remove extension entry from /etc/php4/(apache2|cli).ini
118 # configuration files.
119 for SAPI in apache2 cli; do
121 ini_file="$PHP4DIR/$SAPI/php.ini"
123 if [ -f "$ini_file" ]; then
125 cp_echo "CN: Removing $php4ext extension from file $ini_file"
127 cp_check_and_sed "$php4ext_re" \
129 "$ini_file" && need_restart=1 || true
133 # Check extension configuration in /etc/php4/conf.d/ directory.
134 if [ ! -f "$PHP4CONFD/$php4ext.ini" ]; then
136 cp_echo "CN: Creating configuration file $PHP4CONFD/$php4ext.ini"
138 php4ext_up=`echo $php4ext | tr [:lower:] [:upper:] | sed 's/Y/y/'`
139 INITMP=`mktemp $PHP4CONFD/$php4ext.ini.tmp.XXXXXX`
141 cp_echo "CN: Adding $php4ext extension to file $PHP4CONFD/$php4ext.ini"
143 printf "# configuration for php %s module\nextension=%s.so\n" "${php4ext_up}" "${php4ext}" >> "$INITMP"
144 cp_mv "$INITMP" "$PHP4CONFD/$php4ext.ini"
149 if ! grep -q "$php4ext_re" "$PHP4CONFD/$php4ext.ini"; then
151 cp_echo "CN: Adding $php4ext extension to file $PHP4CONFD/$php4ext.ini"
153 INITMP=`mktemp $PHP4CONFD/$php4ext.ini.tmp.XXXXXX`
154 cat "$PHP4CONFD/$php4ext.ini" > "$INITMP"
155 echo "extension=$php4ext.so" >> "$INITMP"
156 cp_mv "$INITMP" "$PHP4CONFD/$php4ext.ini"
161 chmod 644 $PHP4CONFD/$php4ext.ini
165 # Enable some PHP4 tweaks for Apache2 web server (/etc/php4/apache2/php.ini).
167 # * upload_max_filesize = 256M
168 # * post_max_size, memory_limit = depends on system memory, we are using
169 # phpmemlimit() function.
171 for SAPI in apache2 cli; do
173 if [ ! -d "$PHP4DIR/$SAPI" ]; then
177 db_get php4-cn/${SAPI} || true
178 if [ "$RET" = "true" ]; then
180 ini_file="$PHP4DIR/$SAPI/php.ini"
182 cp_echo "CN: Checking and enabling some specific parameters in file $ini_file"
184 phplimit="$(phpmemlimit)M"
186 if [ -f "$ini_file" ]; then
188 cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=" \
189 's/^[[:space:]]*upload_max_filesize[[:space:]]*=.*/upload_max_filesize = 256M/' \
190 "$ini_file" && need_restart=1 || true
192 cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=" \
193 "s/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = ${phplimit}/" \
194 "$ini_file" && need_restart=1 || true
196 cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=" \
197 "s/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = ${phplimit}/" \
198 "$ini_file" && need_restart=1 || true
201 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
202 if [ -f "$ini_file" ]; then
203 cat $ini_file > $ini_file_tmp
206 if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then
207 echo "upload_max_filesize = 256M" >> "$ini_file_tmp"
210 if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then
211 echo "post_max_size = ${phplimit}" >> "$ini_file_tmp"
214 if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then
215 echo "memory_limit = ${phplimit}" >> "$ini_file_tmp"
218 cp_mv "$ini_file_tmp" "$ini_file"
220 if [ -e "$ini_file_tmp" ]; then
221 rm -f "$ini_file_tmp"
230 # Restart Apache2 web server if needed.
232 if [ $need_restart -eq 1 ]; then
234 # Check Apache2 web server configuration.
235 if /usr/sbin/apache2ctl configtest 2>/dev/null; then
237 # Restart Apache2 web server.
238 if [ -x "/etc/init.d/apache2" ]; then
239 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
240 invoke-rc.d apache2 force-reload || true
242 /etc/init.d/apache2 force-reload || true
247 # Something is broken.
248 cp_echo "CN: Your Apache2 configuration is broken."
249 cp_echo "CN: Please, check the service after the installation finishes!"