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 if egrep -q "$php5ext_re" "$ini_file"; then
141 cp_echo "CN: Removing $php5ext extension from file $ini_file"
144 cp_check_and_sed "$php5ext_re" \
146 "$ini_file" && need_restart=1 || true
150 # Check extension configuration in /etc/php5/conf.d/ directory.
151 if [ ! -f "$PHP5CONFD/$php5ext.ini" ]; then
153 cp_echo "CN: Creating configuration file $PHP5CONFD/$php5ext.ini"
155 php5ext_up=`echo $php5ext | tr [:lower:] [:upper:] | sed 's/Y/y/'`
156 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
158 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
160 printf "# configuration for php %s module\nextension=%s.so\n" "${php5ext_up}" "${php5ext}" >> "$INITMP"
161 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
166 if ! grep -q "$php5ext_re" "$PHP5CONFD/$php5ext.ini"; then
168 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
170 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
171 cat "$PHP5CONFD/$php5ext.ini" > "$INITMP"
172 echo "extension=$php5ext.so" >> "$INITMP"
173 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
178 chmod 644 $PHP5CONFD/$php5ext.ini
182 # Enable some PHP5 tweaks for Apache2 web server (/etc/php5/apache2/php.ini).
184 # * upload_max_filesize = 256M
185 # * post_max_size, memory_limit = depends on system memory, we are using
186 # phpmemlimit() function.
188 for SAPI in apache2 cli; do
190 if [ ! -d "$PHP5DIR/$SAPI" ]; then
194 ini_file="$PHP5DIR/$SAPI/php.ini"
195 db_get php5-cn/${SAPI} || true
196 if [ "$RET" = "true" ]; then
198 cp_echo "CN: Checking and enabling some specific parameters in file $ini_file"
200 phplimit="$(phpmemlimit)M"
202 if [ -f "$ini_file" ]; then
204 cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=" \
205 's/^[[:space:]]*upload_max_filesize[[:space:]]*=.*/upload_max_filesize = 256M/' \
206 "$ini_file" && need_restart=1 || true
208 cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=" \
209 "s/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = ${phplimit}/" \
210 "$ini_file" && need_restart=1 || true
212 cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=" \
213 "s/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = ${phplimit}/" \
214 "$ini_file" && need_restart=1 || true
217 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
218 if [ -f "$ini_file" ]; then
219 cat $ini_file > $ini_file_tmp
222 if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then
223 echo "upload_max_filesize = 256M" >> "$ini_file_tmp"
226 if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then
227 echo "post_max_size = ${phplimit}" >> "$ini_file_tmp"
230 if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then
231 echo "memory_limit = ${phplimit}" >> "$ini_file_tmp"
234 cp_mv "$ini_file_tmp" "$ini_file"
235 chmod 644 "$ini_file"
237 if [ -e "$ini_file_tmp" ]; then
238 rm -f "$ini_file_tmp"
242 # Validate php.ini values.
243 if [ -f "$ini_file" ]; then
244 php5_inivalues="$(phpinivalidate "$ini_file")"
245 if [ -n "$php5_inivalues" ]; then
246 db_fset php5-cn/inivalues seen false
247 db_title php5-cn - konfiguracija za $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
248 db_subst php5-cn/inivalues php5_sapi $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
249 db_subst php5-cn/inivalues ini_file "$ini_file"
251 db_subst php5-cn/inivalues php5_inivalues "$(echo -n "$php5_inivalues" | debconf-escape -e)"
252 db_input critical php5-cn/inivalues || true
259 # Compare active PHP5 extensions with PHP4 ones, if PHP4 configuration still exists.
261 if [ -d "${PHP4DIR}" ] && [ -f "${PHP4DIR}/apache2/php.ini" ]; then
263 phpext_re='^[[:space:]]*extension[[:space:]]*=[[:space:]]*["]{0,1}(.*)\.so["]{0,1}'
265 # Get all active PHP4 extensions.
266 php4_ext="$(find ${PHP4DIR} -type f -name *.ini |
267 egrep "\/(conf\.d|apache2|cli)\/" |
268 xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
270 # Get all active PHP5 extensions.
272 if [ -d "${PHP5DIR}" ]; then
273 php5_ext="$(find ${PHP5DIR} -type f -name *.ini |
274 egrep "\/(conf\.d|apache2|cli)\/" |
275 xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
278 # Compare PHP5 <-> PHP4 extensions.
280 for ext in $php4_ext; do
281 if [ "$(echo $php5_ext | egrep $ext)" = "" ]; then
282 php5_ext_mis="\n${ext}${php5_ext_mis}"
286 # Some PHP5 extensions are not active.
287 if [ -n "$php5_ext_mis" ]; then
288 db_fset php5-cn/extensions seen false
289 db_title php5-cn - konfiguracija
291 db_subst php5-cn/extensions php5_extensions "${php5_ext_mis#*\n}"
292 db_input critical php5-cn/extensions || true
301 # Restart Apache2 web server if needed.
303 if [ $need_restart -eq 1 ]; then
305 # Check Apache2 web server configuration.
306 if /usr/sbin/apache2ctl configtest 2>/dev/null; then
308 # Restart Apache2 web server.
309 if [ -x "/etc/init.d/apache2" ]; then
310 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
311 invoke-rc.d apache2 restart || true
313 /etc/init.d/apache2 restart || true
318 # Something is broken.
319 cp_echo "CN: Your Apache2 configuration is broken."
320 cp_echo "CN: Please, check the service after the installation finishes!"