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
82 if [ -e "$A2MODEDIR/php5.conf" ]; then
83 if egrep -qi "^[[:space:]]*php_admin_value engine Off" "$A2MODEDIR/php5.conf"; then
84 db_fset php5-cn/userdir seen false
85 db_title php5-cn - konfiguracija
86 db_subst php5-cn/userdir php5_conf "$A2MODEDIR/php5.conf"
87 db_input critical php5-cn/userdir || true
97 # Check for PHP5 SAPI directories and configuration files.
99 for SAPI in apache2 cli; do
101 if [ ! -d "$PHP5DIR/$SAPI" ]; then
102 cp_echo "CN: Creating configuration directory $PHP5DIR/$SAPI/"
103 mkdir -p $PHP5DIR/$SAPI/
106 ini_file="$PHP5DIR/$SAPI/php.ini"
108 if [ ! -f "$ini_file" ]; then
110 cp_echo "CN: Generating configuration file $ini_file"
112 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
113 if [ "$SAPI" = "cli" ]; then
114 if [ -f "/usr/share/php5/php.ini-production.cli" ]; then
115 cat /usr/share/php5/php.ini-production.cli > $ini_file_tmp
118 if [ -f "/usr/share/php5/php.ini-production" ]; then
119 cat /usr/share/php5/php.ini-production > $ini_file_tmp
122 cp_mv $ini_file_tmp $ini_file
129 # Check for /etc/php5/conf.d/ directory.
131 if [ ! -d "$PHP5CONFD" ]; then
132 cp_echo "CN: Creating configuration directory $PHP5CONFD"
137 # Check if PHP5 extensions are enabled.
139 for php5ext in $EXTENSIONS; do
141 php5ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php5ext\.so"
143 # Remove extension entry from /etc/php5/(apache2|cli).ini
144 # configuration files.
145 for SAPI in apache2 cli; do
147 ini_file="$PHP5DIR/$SAPI/php.ini"
149 if [ -f "$ini_file" ]; then
151 if egrep -q "$php5ext_re" "$ini_file"; then
152 cp_echo "CN: Removing $php5ext extension from file $ini_file"
155 cp_check_and_sed "$php5ext_re" \
157 "$ini_file" && need_restart=1 || true
161 # Check extension configuration in /etc/php5/conf.d/ directory.
162 if [ ! -f "$PHP5CONFD/$php5ext.ini" ]; then
164 cp_echo "CN: Creating configuration file $PHP5CONFD/$php5ext.ini"
166 php5ext_up=`echo $php5ext | tr [:lower:] [:upper:] | sed 's/Y/y/'`
167 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
169 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
171 printf "# configuration for php %s module\nextension=%s.so\n" "${php5ext_up}" "${php5ext}" >> "$INITMP"
172 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
177 if ! grep -q "$php5ext_re" "$PHP5CONFD/$php5ext.ini"; then
179 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
181 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
182 cat "$PHP5CONFD/$php5ext.ini" > "$INITMP"
183 echo "extension=$php5ext.so" >> "$INITMP"
184 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
189 chmod 644 $PHP5CONFD/$php5ext.ini
193 # Enable some PHP5 tweaks for Apache2 web server (/etc/php5/apache2/php.ini).
195 # * upload_max_filesize = 256M
196 # * post_max_size, memory_limit = depends on system memory, we are using
197 # phpmemlimit() function.
198 # * error_reporting = E_ERROR
200 for SAPI in apache2 cli; do
202 if [ ! -d "$PHP5DIR/$SAPI" ]; then
206 ini_file="$PHP5DIR/$SAPI/php.ini"
207 db_get php5-cn/${SAPI} || true
208 if [ "$RET" = "true" ]; then
210 cp_echo "CN: Checking and enabling some specific parameters in file $ini_file"
212 phplimit="$(phpmemlimit)M"
214 if [ -f "$ini_file" ]; then
216 cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=" \
217 's/^[[:space:]]*upload_max_filesize[[:space:]]*=.*/upload_max_filesize = 256M/' \
218 "$ini_file" && need_restart=1 || true
220 cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=" \
221 "s/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = ${phplimit}/" \
222 "$ini_file" && need_restart=1 || true
224 cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=" \
225 "s/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = ${phplimit}/" \
226 "$ini_file" && need_restart=1 || true
228 cp_check_and_sed "^[[:space:]]*error_reporting[[:space:]]*=" \
229 "s/^[[:space:]]*error_reporting[[:space:]]*=.*/error_reporting = E_ERROR/" \
230 "$ini_file" && need_restart=1 || true
233 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
234 if [ -f "$ini_file" ]; then
235 cat $ini_file > $ini_file_tmp
238 if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then
239 echo "upload_max_filesize = 256M" >> "$ini_file_tmp"
242 if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then
243 echo "post_max_size = ${phplimit}" >> "$ini_file_tmp"
246 if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then
247 echo "memory_limit = ${phplimit}" >> "$ini_file_tmp"
250 if ! egrep -q "^[[:space:]]*error_reporting[[:space:]]*=" $ini_file_tmp; then
251 echo "error_reporting = E_ERROR" >> "$ini_file_tmp"
254 cp_mv "$ini_file_tmp" "$ini_file"
255 chmod 644 "$ini_file"
257 if [ -e "$ini_file_tmp" ]; then
258 rm -f "$ini_file_tmp"
262 # Validate php.ini values.
263 if [ -f "$ini_file" ]; then
264 php5_inivalues="$(phpinivalidate "$ini_file")"
265 if [ -n "$php5_inivalues" ]; then
266 db_fset php5-cn/inivalues seen false
267 db_title php5-cn - konfiguracija za $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
268 db_subst php5-cn/inivalues php5_sapi $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
269 db_subst php5-cn/inivalues ini_file "$ini_file"
271 db_subst php5-cn/inivalues php5_inivalues "$(echo -n "$php5_inivalues" | debconf-escape -e)"
272 db_input critical php5-cn/inivalues || true
279 # Compare active PHP5 extensions with PHP4 ones, if PHP4 configuration still exists.
281 if [ -d "${PHP4DIR}" ] && [ -f "${PHP4DIR}/apache2/php.ini" ]; then
283 phpext_re='^[[:space:]]*extension[[:space:]]*=[[:space:]]*["]{0,1}(.*)\.so["]{0,1}'
285 # Get all active PHP4 extensions.
286 php4_ext="$(find ${PHP4DIR} -type f -name *.ini |
287 egrep "\/(conf\.d|apache2|cli)\/" |
288 xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
290 # Get all active PHP5 extensions.
292 if [ -d "${PHP5DIR}" ]; then
293 php5_ext="$(find ${PHP5DIR} -type f -name *.ini |
294 egrep "\/(conf\.d|apache2|cli)\/" |
295 xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
298 # Compare PHP5 <-> PHP4 extensions.
300 for ext in $php4_ext; do
301 if [ "$(echo $php5_ext | egrep $ext)" = "" ]; then
302 php5_ext_mis="\n${ext}${php5_ext_mis}"
306 # Some PHP5 extensions are not active.
307 if [ -n "$php5_ext_mis" ]; then
308 db_fset php5-cn/extensions seen false
309 db_title php5-cn - konfiguracija
311 db_subst php5-cn/extensions php5_extensions "${php5_ext_mis#*\n}"
312 db_input critical php5-cn/extensions || true
321 # Restart Apache2 web server if needed.
323 if [ $need_restart -eq 1 ]; then
325 # Check Apache2 web server configuration.
326 if apache2ctl configtest 2>/dev/null; then
327 invoke-rc.d apache2 force-reload || true
329 # Something is broken.
330 cp_echo "CN: Your Apache2 configuration is broken."
331 cp_echo "CN: Please, check the service after the installation finishes!"