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"
30 PHP4CONFD="/etc/php4/conf.d"
35 # Disable PHP5 module and enable Apache2 PHP4 module.
37 if [ -e /etc/apache2/apache2.conf ]; then
38 if [ -e "$A2MODEDIR/php5.load" ]; then
39 cp_echo "CN: Disabling PHP5 module for Apache2 web server"
40 a2dismod php5 >/dev/null || true
43 if [ ! -e "$A2MODEDIR/php4.load" ] || [ ! -e "$A2MODEDIR/php4.conf" ]; then
44 cp_echo "CN: Enabling PHP4 module for Apache2 web server"
45 a2enmod php4 >/dev/null || true
51 # Check if PHP4 extensions are enabled.
53 for php4ext in $EXTENSIONS; do
55 php4ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php4ext\.so"
57 # Remove extension entry from /etc/php4/(apache|apache2|cgi|cli).ini
58 # configuration files.
59 for SAPI in apache apache2 cgi cli; do
61 if [ -d "$PHP4DIR/$SAPI" ]; then
63 ini_file="$PHP4DIR/$SAPI/php.ini"
65 if [ -f "$ini_file" ]; then
67 cp_echo "CN: Removing $php4ext extension from file $ini_file"
69 cp_check_and_sed "$php4ext_re" \
71 "$ini_file" && need_restart=1 || true
76 # Check $PHP4CONFD directory.
77 if [ ! -d "$PHP4CONFD" ]; then
78 cp_echo "CN: Creating configuration directory $PHP4CONFD"
82 # Check extension configuration in /etc/php4/conf.d/ directory.
83 if [ ! -f "$PHP4CONFD/$php4ext.ini" ]; then
85 cp_echo "CN: Creating configuration file $PHP4CONFD/$php4ext.ini"
87 php4ext_up=`echo $php4ext | tr [:lower:] [:upper:] | sed 's/Y/y/'`
88 INITMP=`mktemp $PHP4CONFD/$php4ext.ini.tmp.XXXXXX`
90 cp_echo "CN: Adding $php4ext extension to file $PHP4CONFD/$php4ext.ini"
92 echo -e "# configuration for php $php4ext_up module\nextension=$php4ext.so" >> "$INITMP"
93 cp_mv "$INITMP" "$PHP4CONFD/$php4ext.ini"
98 if ! grep -q "$php4ext_re" "$PHP4CONFD/$php4ext.ini"; then
100 cp_echo "CN: Adding $php4ext extension to file $PHP4CONFD/$php4ext.ini"
102 INITMP=`mktemp $PHP4CONFD/$php4ext.ini.tmp.XXXXXX`
103 cat "$PHP4CONFD/$php4ext.ini" > "$INITMP"
104 echo "extension=$php4ext.so" >> "$INITMP"
105 cp_mv "$INITMP" "$PHP4CONFD/$php4ext.ini"
113 # Enable some PHP4 tweaks for Apache2 web server (/etc/php4/apache2/php.ini).
115 # * upload_max_filesize = 256M
116 # * post_max_size = 256M
117 # * memory_limit = 256M
119 for SAPI in apache apache2 cgi cli; do
121 if [ ! -d "$PHP4DIR/$SAPI" ]; then
125 ini_file="$PHP4DIR/$SAPI/php.ini"
127 cp_echo "CN: Checking and enabling some CARNet specific parameters in file $ini_file"
129 if [ -f "$ini_file" ]; then
131 cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=[[:space:]]*2M$" \
132 's/^[[:space:]]*upload_max_filesize[[:space:]]*=.*/upload_max_filesize = 256M/' \
133 "$ini_file" && need_restart=1 || true
135 cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=[[:space:]]*8M$" \
136 's/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = 256M/' \
137 "$ini_file" && need_restart=1 || true
139 cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=[[:space:]]*16M$" \
140 's/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = 256M/' \
141 "$ini_file" && need_restart=1 || true
144 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
145 if [ -f "$ini_file" ]; then
146 cat $ini_file > $ini_file_tmp
149 if ! egrep -q "^[[:space:]]*(upload_max_filesize|post_max_size|memory_limit)[[:space:]]*=" $ini_file_tmp; then
151 if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then
152 echo "upload_max_filesize = 256M" >> "$ini_file_tmp"
154 if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then
155 echo "post_max_size = 256MB" >> "$ini_file_tmp"
157 if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then
158 echo "memory_limit = 256M" >> "$ini_file_tmp"
160 cp_mv "$ini_file_tmp" "$ini_file"
165 if [ -e "$ini_file_tmp" ]; then
166 rm -f "$ini_file_tmp"
171 # Restart Apache2 web server if needed.
173 if [ $need_restart -eq 1 ]; then
175 # Check Apache2 web server configuration.
176 if /usr/sbin/apache2ctl configtest 2>/dev/null; then
178 # Restart Apache2 web server.
179 if [ -x "/etc/init.d/apache2" ]; then
180 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
181 invoke-rc.d apache2 force-reload || true
183 /etc/init.d/apache2 force-reload || true
188 # Something is broken.
189 cp_echo "CN: Your Apache2 configuration is broken."
190 cp_echo "CN: Please, check the service after the installation finishes!"