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"
31 ### mysql je vec ukljucen u wheezyu
32 ### EXTENSIONS="mysql"
35 PHP5MODADIR="$PHP5DIR/mods-available"
36 PHP5CONFD="/etc/php5/conf.d"
44 # Calculate memory size for PHP memory_limit option.
48 local memtotal memlimit
49 memtotal=`awk 'tolower($1) == "memtotal:" { printf("%i", $2/1024); }' /proc/meminfo`
51 if [ $memtotal -lt 512 ]; then memlimit=16; fi
52 if [ $memtotal -ge 512 ]; then memlimit=32; fi
53 if [ $memtotal -gt 1024 ]; then memlimit=64; fi
60 # Validate php.ini values.
67 awk -F'[[:space:]]*=[[:space:]]*' \
68 '/^[[:space:]]*[[:alpha:]_]+[[:space:]]*=[[:space:]]*[[:digit:]]+[MGK]B/ {print $1" = "$2}' \
73 # Disable PHP4 module and enable Apache2 PHP5 module.
75 if [ -e /etc/apache2/apache2.conf ]; then
76 if [ -e "$A2MODEDIR/php4.load" ]; then
77 cp_echo "CN: Disabling PHP4 module for Apache2 web server"
78 a2dismod php4 >/dev/null || true
81 if [ ! -e "$A2MODEDIR/php5.load" ] || [ ! -e "$A2MODEDIR/php5.conf" ]; then
82 cp_echo "CN: Enabling PHP5 module for Apache2 web server"
83 a2enmod php5 >/dev/null || true
85 if [ -e "$A2MODEDIR/php5.conf" ]; then
86 if egrep -qi "^[[:space:]]*php_admin_value engine Off" "$A2MODEDIR/php5.conf"; then
87 db_fset php5-cn/userdir seen false
88 db_title php5-cn - konfiguracija
89 db_subst php5-cn/userdir php5_conf "$A2MODEDIR/php5.conf"
90 db_input critical php5-cn/userdir || true
100 # Check for PHP5 SAPI directories and configuration files.
102 for SAPI in apache2 cli; do
104 if [ ! -d "$PHP5DIR/$SAPI" ]; then
105 cp_echo "CN: Creating configuration directory $PHP5DIR/$SAPI/"
106 mkdir -p $PHP5DIR/$SAPI/
109 ini_file="$PHP5DIR/$SAPI/php.ini"
111 if [ ! -f "$ini_file" ]; then
113 cp_echo "CN: Generating configuration file $ini_file"
115 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
116 if [ "$SAPI" = "cli" ]; then
117 if [ -f "/usr/share/php5/php.ini-production.cli" ]; then
118 cat /usr/share/php5/php.ini-production.cli > $ini_file_tmp
121 if [ -f "/usr/share/php5/php.ini-production" ]; then
122 cat /usr/share/php5/php.ini-production > $ini_file_tmp
125 cp_mv $ini_file_tmp $ini_file
132 # Check for /etc/php5/conf.d/ directory.
134 if [ ! -d "$PHP5CONFD" ]; then
135 cp_echo "CN: Creating configuration directory $PHP5CONFD"
139 # Brisanje obsolete datoteke mysql.ini u $PHP5CONFD
141 if [ -f "$PHP5CONFD/mysql.ini" ]; then
142 # just to make sure mysql is included in _new-style_ configuration
143 if [ -f "$PHP5MODADIR/mysql.ini" ]; then
144 cp_echo "CN: Removing obsolete $PHP5CONFD/mysql.ini"
145 rm -f $PHP5CONFD/mysql.ini
147 cp_echo "CN: WARNING: Obsolete $PHP5CONFD/mysql.ini present, and no $PHP5MODADIR/mysql.ini!"
151 # Check if PHP5 extensions are enabled.
153 for php5ext in $EXTENSIONS; do
155 php5ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php5ext\.so"
157 # Remove extension entry from /etc/php5/(apache2|cli).ini
158 # configuration files.
159 for SAPI in apache2 cli; do
161 ini_file="$PHP5DIR/$SAPI/php.ini"
163 if [ -f "$ini_file" ]; then
165 if egrep -q "$php5ext_re" "$ini_file"; then
166 cp_echo "CN: Removing $php5ext extension from file $ini_file"
169 cp_check_and_sed "$php5ext_re" \
171 "$ini_file" && need_restart=1 || true
175 # Check extension configuration in /etc/php5/conf.d/ directory.
176 if [ ! -f "$PHP5CONFD/$php5ext.ini" ]; then
178 cp_echo "CN: Creating configuration file $PHP5CONFD/$php5ext.ini"
180 php5ext_up=`echo $php5ext | tr [:lower:] [:upper:] | sed 's/Y/y/'`
181 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
183 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
185 printf "# configuration for php %s module\nextension=%s.so\n" "${php5ext_up}" "${php5ext}" >> "$INITMP"
186 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
191 if ! grep -q "$php5ext_re" "$PHP5CONFD/$php5ext.ini"; then
193 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
195 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
196 cat "$PHP5CONFD/$php5ext.ini" > "$INITMP"
197 echo "extension=$php5ext.so" >> "$INITMP"
198 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
203 chmod 644 $PHP5CONFD/$php5ext.ini
207 # Enable some PHP5 tweaks for Apache2 web server (/etc/php5/apache2/php.ini).
209 # * upload_max_filesize = 256M
210 # * post_max_size, memory_limit = depends on system memory, we are using
211 # phpmemlimit() function.
212 # * error_reporting = E_ERROR
214 for SAPI in apache2 cli; do
216 if [ ! -d "$PHP5DIR/$SAPI" ]; then
220 ini_file="$PHP5DIR/$SAPI/php.ini"
221 db_get php5-cn/${SAPI} || true
222 if [ "$RET" = "true" ]; then
224 cp_echo "CN: Checking and enabling some specific parameters in file $ini_file"
226 phplimit="$(phpmemlimit)M"
228 if [ -f "$ini_file" ]; then
230 cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=" \
231 's/^[[:space:]]*upload_max_filesize[[:space:]]*=.*/upload_max_filesize = 256M/' \
232 "$ini_file" && need_restart=1 || true
234 cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=" \
235 "s/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = ${phplimit}/" \
236 "$ini_file" && need_restart=1 || true
238 cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=" \
239 "s/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = ${phplimit}/" \
240 "$ini_file" && need_restart=1 || true
242 cp_check_and_sed "^[[:space:]]*error_reporting[[:space:]]*=" \
243 "s/^[[:space:]]*error_reporting[[:space:]]*=.*/error_reporting = E_ERROR/" \
244 "$ini_file" && need_restart=1 || true
247 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
248 if [ -f "$ini_file" ]; then
249 cat $ini_file > $ini_file_tmp
252 if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then
253 echo "upload_max_filesize = 256M" >> "$ini_file_tmp"
256 if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then
257 echo "post_max_size = ${phplimit}" >> "$ini_file_tmp"
260 if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then
261 echo "memory_limit = ${phplimit}" >> "$ini_file_tmp"
264 if ! egrep -q "^[[:space:]]*error_reporting[[:space:]]*=" $ini_file_tmp; then
265 echo "error_reporting = E_ERROR" >> "$ini_file_tmp"
268 cp_mv "$ini_file_tmp" "$ini_file"
269 chmod 644 "$ini_file"
271 if [ -e "$ini_file_tmp" ]; then
272 rm -f "$ini_file_tmp"
276 # Validate php.ini values.
277 if [ -f "$ini_file" ]; then
278 php5_inivalues="$(phpinivalidate "$ini_file")"
279 if [ -n "$php5_inivalues" ]; then
280 db_fset php5-cn/inivalues seen false
281 db_title php5-cn - konfiguracija za $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
282 db_subst php5-cn/inivalues php5_sapi $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
283 db_subst php5-cn/inivalues ini_file "$ini_file"
285 db_subst php5-cn/inivalues php5_inivalues "$(echo -n "$php5_inivalues" | debconf-escape -e)"
286 db_input critical php5-cn/inivalues || true
293 # Compare active PHP5 extensions with PHP4 ones, if PHP4 configuration still exists.
295 if [ -d "${PHP4DIR}" ] && [ -f "${PHP4DIR}/apache2/php.ini" ]; then
297 phpext_re='^[[:space:]]*extension[[:space:]]*=[[:space:]]*["]{0,1}(.*)\.so["]{0,1}'
299 # Get all active PHP4 extensions.
300 php4_ext="$(find ${PHP4DIR} -type f -name *.ini |
301 egrep "\/(conf\.d|apache2|cli)\/" |
302 xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
304 # Get all active PHP5 extensions.
306 if [ -d "${PHP5DIR}" ]; then
307 php5_ext="$(find ${PHP5DIR} -type f -name *.ini |
308 egrep "\/(conf\.d|apache2|cli)\/" |
309 xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
312 # Compare PHP5 <-> PHP4 extensions.
314 for ext in $php4_ext; do
315 if [ "$(echo $php5_ext | egrep $ext)" = "" ]; then
316 php5_ext_mis="\n${ext}${php5_ext_mis}"
320 # Some PHP5 extensions are not active.
321 if [ -n "$php5_ext_mis" ]; then
322 db_fset php5-cn/extensions seen false
323 db_title php5-cn - konfiguracija
325 db_subst php5-cn/extensions php5_extensions "${php5_ext_mis#*\n}"
326 db_input critical php5-cn/extensions || true
335 # Restart Apache2 web server if needed.
337 if [ $need_restart -eq 1 ]; then
339 # Check Apache2 web server configuration.
340 if apache2ctl configtest 2>/dev/null; then
341 invoke-rc.d apache2 force-reload || true
343 # Something is broken.
344 cp_echo "CN: Your Apache2 configuration is broken."
345 cp_echo "CN: Please, check the service after the installation finishes!"