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"
40 # Calculate memory size for PHP memory_limit option.
44 local memtotal memlimit
45 memtotal=`awk 'tolower($1) == "memtotal:" { printf("%i", $2/1024); }' /proc/meminfo`
47 if [ $memtotal -lt 512 ]; then memlimit=16; fi
48 if [ $memtotal -ge 512 ]; then memlimit=32; fi
49 if [ $memtotal -gt 1024 ]; then memlimit=64; fi
56 # Validate php.ini values.
63 awk -F'[[:space:]]*=[[:space:]]*' \
64 '/^[[:space:]]*[[:alpha:]_]+[[:space:]]*=[[:space:]]*[[:digit:]]+[MGK]B/ {print $1" = "$2}' \
69 # Disable PHP4 module and enable Apache2 PHP5 module.
71 if [ -e /etc/apache2/apache2.conf ]; then
72 if [ -e "$A2MODEDIR/php4.load" ]; then
73 cp_echo "CN: Disabling PHP4 module for Apache2 web server"
74 a2dismod php4 >/dev/null || true
77 if [ ! -e "$A2MODEDIR/php5.load" ] || [ ! -e "$A2MODEDIR/php5.conf" ]; then
78 cp_echo "CN: Enabling PHP5 module for Apache2 web server"
79 a2enmod php5 >/dev/null || true
85 # Check for PHP5 SAPI directories and configuration files.
87 for SAPI in apache2 cli; do
89 if [ ! -d "$PHP5DIR/$SAPI" ]; then
90 cp_echo "CN: Creating configuration directory $PHP5DIR/$SAPI/"
91 mkdir -p $PHP5DIR/$SAPI/
94 ini_file="$PHP5DIR/$SAPI/php.ini"
96 if [ ! -f "$ini_file" ]; then
98 cp_echo "CN: Generating configuration file $ini_file"
100 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
101 if [ "$SAPI" = "cli" ]; then
102 if [ -f "/usr/share/php5/php.ini-dist.cli" ]; then
103 cat /usr/share/php5/php.ini-dist.cli > $ini_file_tmp
106 if [ -f "/usr/share/php5/php.ini-dist" ]; then
107 cat /usr/share/php5/php.ini-dist > $ini_file_tmp
110 cp_mv $ini_file_tmp $ini_file
117 # Check for /etc/php5/conf.d/ directory.
119 if [ ! -d "$PHP5CONFD" ]; then
120 cp_echo "CN: Creating configuration directory $PHP5CONFD"
125 # Check if PHP5 extensions are enabled.
127 for php5ext in $EXTENSIONS; do
129 php5ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php5ext\.so"
131 # Remove extension entry from /etc/php5/(apache2|cli).ini
132 # configuration files.
133 for SAPI in apache2 cli; do
135 ini_file="$PHP5DIR/$SAPI/php.ini"
137 if [ -f "$ini_file" ]; then
139 cp_echo "CN: Removing $php5ext extension from file $ini_file"
141 cp_check_and_sed "$php5ext_re" \
143 "$ini_file" && need_restart=1 || true
147 # Check extension configuration in /etc/php5/conf.d/ directory.
148 if [ ! -f "$PHP5CONFD/$php5ext.ini" ]; then
150 cp_echo "CN: Creating configuration file $PHP5CONFD/$php5ext.ini"
152 php5ext_up=`echo $php5ext | tr [:lower:] [:upper:] | sed 's/Y/y/'`
153 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
155 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
157 printf "# configuration for php %s module\nextension=%s.so\n" "${php5ext_up}" "${php5ext}" >> "$INITMP"
158 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
163 if ! grep -q "$php5ext_re" "$PHP5CONFD/$php5ext.ini"; then
165 cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
167 INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
168 cat "$PHP5CONFD/$php5ext.ini" > "$INITMP"
169 echo "extension=$php5ext.so" >> "$INITMP"
170 cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
175 chmod 644 $PHP5CONFD/$php5ext.ini
179 # Enable some PHP5 tweaks for Apache2 web server (/etc/php5/apache2/php.ini).
181 # * upload_max_filesize = 256M
182 # * post_max_size, memory_limit = depends on system memory, we are using
183 # phpmemlimit() function.
185 for SAPI in apache2 cli; do
187 if [ ! -d "$PHP5DIR/$SAPI" ]; then
191 ini_file="$PHP5DIR/$SAPI/php.ini"
192 db_get php5-cn/${SAPI} || true
193 if [ "$RET" = "true" ]; then
195 cp_echo "CN: Checking and enabling some specific parameters in file $ini_file"
197 phplimit="$(phpmemlimit)M"
199 if [ -f "$ini_file" ]; then
201 cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=" \
202 's/^[[:space:]]*upload_max_filesize[[:space:]]*=.*/upload_max_filesize = 256M/' \
203 "$ini_file" && need_restart=1 || true
205 cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=" \
206 "s/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = ${phplimit}/" \
207 "$ini_file" && need_restart=1 || true
209 cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=" \
210 "s/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = ${phplimit}/" \
211 "$ini_file" && need_restart=1 || true
214 ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX`
215 if [ -f "$ini_file" ]; then
216 cat $ini_file > $ini_file_tmp
219 if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then
220 echo "upload_max_filesize = 256M" >> "$ini_file_tmp"
223 if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then
224 echo "post_max_size = ${phplimit}" >> "$ini_file_tmp"
227 if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then
228 echo "memory_limit = ${phplimit}" >> "$ini_file_tmp"
231 cp_mv "$ini_file_tmp" "$ini_file"
232 chmod 644 "$ini_file"
234 if [ -e "$ini_file_tmp" ]; then
235 rm -f "$ini_file_tmp"
239 # Validate php.ini values.
240 if [ -f "$ini_file" ]; then
241 php5_inivalues="$(phpinivalidate "$ini_file")"
242 if [ -n "$php5_inivalues" ]; then
243 db_fset php5-cn/inivalues seen false
244 db_title php5-cn - konfiguracija za $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
245 db_subst php5-cn/inivalues php5_sapi $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
246 db_subst php5-cn/inivalues ini_file "$ini_file"
248 db_subst php5-cn/inivalues php5_inivalues "$(echo -n "$php5_inivalues" | debconf-escape -e)"
249 db_input critical php5-cn/inivalues || true
259 # Restart Apache2 web server if needed.
261 if [ $need_restart -eq 1 ]; then
263 # Check Apache2 web server configuration.
264 if /usr/sbin/apache2ctl configtest 2>/dev/null; then
266 # Restart Apache2 web server.
267 if [ -x "/etc/init.d/apache2" ]; then
268 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
269 invoke-rc.d apache2 force-reload || true
271 /etc/init.d/apache2 force-reload || true
276 # Something is broken.
277 cp_echo "CN: Your Apache2 configuration is broken."
278 cp_echo "CN: Please, check the service after the installation finishes!"