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 PHP5CONFD="/etc/php5/conf.d"
41 # Calculate memory size for PHP memory_limit option.
45 local memtotal memlimit
46 memtotal=`awk 'tolower($1) == "memtotal:" { printf("%i", $2/1024); }' /proc/meminfo`
48 if [ $memtotal -lt 512 ]; then memlimit=16; fi
49 if [ $memtotal -ge 512 ]; then memlimit=32; fi
50 if [ $memtotal -gt 1024 ]; then memlimit=64; fi
57 # Validate php.ini values.
64 awk -F'[[:space:]]*=[[:space:]]*' \
65 '/^[[:space:]]*[[:alpha:]_]+[[:space:]]*=[[:space:]]*[[:digit:]]+[MGK]B/ {print $1" = "$2}' \
70 # Disable PHP4 module and enable Apache2 PHP5 module.
72 if [ -e /etc/apache2/apache2.conf ]; then
73 if [ -e "$A2MODEDIR/php4.load" ]; then
74 cp_echo "CN: Disabling PHP4 module for Apache2 web server"
75 a2dismod php4 >/dev/null || true
78 if [ ! -e "$A2MODEDIR/php5.load" ] || [ ! -e "$A2MODEDIR/php5.conf" ]; then
79 cp_echo "CN: Enabling PHP5 module for Apache2 web server"
80 a2enmod php5 >/dev/null || true
86 # Check for PHP5 SAPI directories and configuration files.
88 for SAPI in apache2 cli; do
90 if [ ! -d "$PHP5DIR/$SAPI" ]; then
91 cp_echo "CN: Creating configuration directory $PHP5DIR/$SAPI/"
92 mkdir -p $PHP5DIR/$SAPI/
95 ini_file="$PHP5DIR/$SAPI/php.ini"
97 if [ ! -f "$ini_file" ]; then
99 cp_echo "CN: Generating configuration file $ini_file"
101 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
102 if [ "$SAPI" = "cli" ]; then
103 if [ -f "/usr/share/php5/php.ini-dist.cli" ]; then
104 cat /usr/share/php5/php.ini-dist.cli > $ini_file_tmp
107 if [ -f "/usr/share/php5/php.ini-dist" ]; then
108 cat /usr/share/php5/php.ini-dist > $ini_file_tmp
111 cp_mv $ini_file_tmp $ini_file
118 # Check for /etc/php5/conf.d/ directory.
120 if [ ! -d "$PHP5CONFD" ]; then
121 cp_echo "CN: Creating configuration directory $PHP5CONFD"
126 # Check if PHP5 extensions are enabled.
128 for php5ext in $EXTENSIONS; do
130 php5ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php5ext\.so"
132 # Remove extension entry from /etc/php5/(apache2|cli).ini
133 # configuration files.
134 for SAPI in apache2 cli; do
136 ini_file="$PHP5DIR/$SAPI/php.ini"
138 if [ -f "$ini_file" ]; then
140 cp_echo "CN: Removing $php5ext extension from file $ini_file"
142 cp_check_and_sed "$php5ext_re" \
144 "$ini_file" && need_restart=1 || true
148 # Check extension configuration in /etc/php5/conf.d/ directory.
149 if [ ! -f "$PHP5CONFD/$php5ext.ini" ]; then
151 cp_echo "CN: Creating configuration file $PHP5CONFD/$php5ext.ini"
153 php5ext_up=`echo $php5ext | tr [:lower:] [:upper:] | sed 's/Y/y/'`
154 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
156 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
158 printf "# configuration for php %s module\nextension=%s.so\n" "${php5ext_up}" "${php5ext}" >> "$INITMP"
159 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
164 if ! grep -q "$php5ext_re" "$PHP5CONFD/$php5ext.ini"; then
166 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
168 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
169 cat "$PHP5CONFD/$php5ext.ini" > "$INITMP"
170 echo "extension=$php5ext.so" >> "$INITMP"
171 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
176 chmod 644 $PHP5CONFD/$php5ext.ini
180 # Enable some PHP5 tweaks for Apache2 web server (/etc/php5/apache2/php.ini).
182 # * upload_max_filesize = 256M
183 # * post_max_size, memory_limit = depends on system memory, we are using
184 # phpmemlimit() function.
186 for SAPI in apache2 cli; do
188 if [ ! -d "$PHP5DIR/$SAPI" ]; then
192 ini_file="$PHP5DIR/$SAPI/php.ini"
193 db_get php5-cn/${SAPI} || true
194 if [ "$RET" = "true" ]; then
196 cp_echo "CN: Checking and enabling some specific parameters in file $ini_file"
198 phplimit="$(phpmemlimit)M"
200 if [ -f "$ini_file" ]; then
202 cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=" \
203 's/^[[:space:]]*upload_max_filesize[[:space:]]*=.*/upload_max_filesize = 256M/' \
204 "$ini_file" && need_restart=1 || true
206 cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=" \
207 "s/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = ${phplimit}/" \
208 "$ini_file" && need_restart=1 || true
210 cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=" \
211 "s/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = ${phplimit}/" \
212 "$ini_file" && need_restart=1 || true
215 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
216 if [ -f "$ini_file" ]; then
217 cat $ini_file > $ini_file_tmp
220 if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then
221 echo "upload_max_filesize = 256M" >> "$ini_file_tmp"
224 if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then
225 echo "post_max_size = ${phplimit}" >> "$ini_file_tmp"
228 if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then
229 echo "memory_limit = ${phplimit}" >> "$ini_file_tmp"
232 cp_mv "$ini_file_tmp" "$ini_file"
233 chmod 644 "$ini_file"
235 if [ -e "$ini_file_tmp" ]; then
236 rm -f "$ini_file_tmp"
240 # Validate php.ini values.
241 if [ -f "$ini_file" ]; then
242 php5_inivalues="$(phpinivalidate "$ini_file")"
243 if [ -n "$php5_inivalues" ]; then
244 db_fset php5-cn/inivalues seen false
245 db_title php5-cn - konfiguracija za $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
246 db_subst php5-cn/inivalues php5_sapi $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
247 db_subst php5-cn/inivalues ini_file "$ini_file"
249 db_subst php5-cn/inivalues php5_inivalues "$(echo -n "$php5_inivalues" | debconf-escape -e)"
250 db_input critical php5-cn/inivalues || true
257 # Compare active PHP5 extensions with PHP4 ones, if PHP4 configuration still exists.
259 db_fget php5-cn/extensions seen
260 if [ "$RET" != "true" ]; then
262 if [ -d "${PHP4DIR}" ] && [ -f "${PHP4DIR}/apache2/php.ini" ]; then
264 phpext_re='^[[:space:]]*extension[[:space:]]*=[[:space:]]*["]{0,1}(.*)\.so["]{0,1}'
266 # Get all active PHP4 extensions.
267 php4_ext="$(find ${PHP4DIR} -type f -name *.ini |
268 egrep "\/(conf\.d|apache2|cli)\/" |
269 xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
271 # Get all active PHP5 extensions.
273 if [ -d "${PHP5DIR}" ]; then
274 php5_ext="$(find ${PHP5DIR} -type f -name *.ini |
275 egrep "\/(conf\.d|apache2|cli)\/" |
276 xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
279 # Compare PHP5 <-> PHP4 extensions.
281 for ext in $php4_ext; do
282 if [ "$(echo $php5_ext | egrep $ext)" = "" ]; then
283 php5_ext_mis="\n${ext}${php5_ext_mis}"
287 # Some PHP5 extensions are not active.
288 if [ -n "$php5_ext_mis" ]; then
289 db_fset php5-cn/extensions seen false
290 db_title php5-cn - konfiguracija
292 db_subst php5-cn/extensions php5_extensions "${php5_ext_mis#*\n}"
293 db_input critical php5-cn/extensions || true
303 # Restart Apache2 web server if needed.
305 if [ $need_restart -eq 1 ]; then
307 # Check Apache2 web server configuration.
308 if /usr/sbin/apache2ctl configtest 2>/dev/null; then
310 # Restart Apache2 web server.
311 if [ -x "/etc/init.d/apache2" ]; then
312 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
313 invoke-rc.d apache2 force-reload || true
315 /etc/init.d/apache2 force-reload || true
320 # Something is broken.
321 cp_echo "CN: Your Apache2 configuration is broken."
322 cp_echo "CN: Please, check the service after the installation finishes!"