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"
34 PHP70DIR="/etc/php/7.0"
35 PHP70MODADIR="$PHP70DIR/mods-available"
36 PHP70CONFD="/etc/php/7.0/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 PHP5 module and enable Apache2 PHP7 module.
75 if [ -e /etc/apache2/apache2.conf ]; then
76 if [ -e "$A2MODEDIR/php5.load" ]; then
77 cp_echo "CN: Disabling PHP5 module for Apache2 web server"
78 a2dismod php5 >/dev/null || true
81 if [ ! -e "$A2MODEDIR/php7.0.load" ] || [ ! -e "$A2MODEDIR/php7.0.conf" ]; then
82 cp_echo "CN: Enabling PHP7 module for Apache2 web server"
83 a2enmod php7.0 >/dev/null || true
85 if [ -e "$A2MODEDIR/php7.0.conf" ]; then
86 if egrep -qi "^[[:space:]]*php_admin_value engine Off" "$A2MODEDIR/php7.0.conf"; then
87 db_fset php7.0-cn/userdir seen false
88 db_title php7.0-cn - konfiguracija
89 db_subst php7.0-cn/userdir php70_conf "$A2MODEDIR/php5.conf"
90 db_input critical php7.0-cn/userdir || true
100 # Check for PHP7 SAPI directories and configuration files.
102 for SAPI in apache2 cli; do
104 if [ ! -d "$PHP70DIR/$SAPI" ]; then
105 cp_echo "CN: Creating configuration directory $PHP70DIR/$SAPI/"
106 mkdir -p $PHP70DIR/$SAPI/
109 ini_file="$PHP70DIR/$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/lib/php/7.0/php.ini-production.cli" ]; then
118 cat /usr/lib/php/7.0/php.ini-production.cli > $ini_file_tmp
121 if [ -f "/usr/lib/php/7.0/php.ini-production" ]; then
122 cat /usr/lib/php/7.0/php.ini-production > $ini_file_tmp
125 cp_mv $ini_file_tmp $ini_file
132 # Check for /etc/php/7.0/conf.d/ directory.
134 if [ ! -d "$PHP70CONFD" ]; then
135 cp_echo "CN: Creating configuration directory $PHP70CONFD"
136 mkdir -p $PHP70CONFD/
139 # Brisanje obsolete datoteke mysql.ini u $PHP70CONFD
141 if [ -f "$PHP70CONFD/mysql.ini" ]; then
142 # just to make sure mysql is included in _new-style_ configuration
143 if [ -f "$PHP70MODADIR/mysql.ini" ]; then
144 cp_echo "CN: Removing obsolete $PHP70CONFD/mysql.ini"
145 rm -f $PHP70CONFD/mysql.ini
147 cp_echo "CN: WARNING: Obsolete $PHP70CONFD/mysql.ini present, and no $PHP70MODADIR/mysql.ini!"
151 # Check if PHP7 extensions are enabled.
153 for php70ext in $EXTENSIONS; do
155 php70ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php70ext\.so"
157 # Remove extension entry from /etc/php/7.0/(apache2|cli).ini
158 # configuration files.
159 for SAPI in apache2 cli; do
161 ini_file="$PHP70DIR/$SAPI/php.ini"
163 if [ -f "$ini_file" ]; then
165 if egrep -q "$php70ext_re" "$ini_file"; then
166 cp_echo "CN: Removing $php70ext extension from file $ini_file"
169 cp_check_and_sed "$php70ext_re" \
171 "$ini_file" && need_restart=1 || true
175 # Check extension configuration in /etc/php/7.0/conf.d/ directory.
176 if [ ! -f "$PHP70CONFD/$php70ext.ini" ]; then
178 cp_echo "CN: Creating configuration file $PHP70CONFD/$php70ext.ini"
180 php5ext_up=`echo $php70ext | tr [:lower:] [:upper:] | sed 's/Y/y/'`
181 INITMP=`mktemp $PHP70CONFD/$php70ext.ini.tmp.XXXXXX`
183 cp_echo "CN: Adding $php70ext extension to file $PHP70CONFD/$php70ext.ini"
185 printf "# configuration for php %s module\nextension=%s.so\n" "${php70ext_up}" "${php5ext}" >> "$INITMP"
186 cp_mv "$INITMP" "$PHP70CONFD/$php70ext.ini"
191 if ! grep -q "$php70ext_re" "$PHP70CONFD/$php70ext.ini"; then
193 cp_echo "CN: Adding $php70ext extension to file $PHP70CONFD/$php70ext.ini"
195 INITMP=`mktemp $PHP70CONFD/$php70ext.ini.tmp.XXXXXX`
196 cat "$PHP70CONFD/$php70ext.ini" > "$INITMP"
197 echo "extension=$php70ext.so" >> "$INITMP"
198 cp_mv "$INITMP" "$PHP70CONFD/$php70ext.ini"
203 chmod 644 $PHP70CONFD/$php70ext.ini
207 # Enable some PHP7 tweaks for Apache2 web server (/etc/php/7.0/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 "$PHP70DIR/$SAPI" ]; then
220 ini_file="$PHP70DIR/$SAPI/php.ini"
221 db_get php7.0-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 php70_inivalues="$(phpinivalidate "$ini_file")"
279 if [ -n "$php70_inivalues" ]; then
280 db_fset php7.0-cn/inivalues seen false
281 db_title php7.0-cn - konfiguracija za $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
282 db_subst php7.0-cn/inivalues php70_sapi $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
283 db_subst php7.0-cn/inivalues ini_file "$ini_file"
285 db_subst php7.0-cn/inivalues php70_inivalues "$(echo -n "$php70_inivalues" | debconf-escape -e)"
286 db_input critical php7.0-cn/inivalues || true
293 # Compare active PHP7 extensions with PHP5 ones, if PHP5 configuration still exists.
295 if [ -d "${PHP5DIR}" ] && [ -f "${PHP5DIR}/apache2/php.ini" ]; then
297 phpext_re='^[[:space:]]*extension[[:space:]]*=[[:space:]]*["]{0,1}(.*)\.so["]{0,1}'
299 # Get all active PHP5 extensions.
300 php5_ext="$(find ${PHP5DIR} -type f -name *.ini |
301 egrep "\/(conf\.d|apache2|cli)\/" |
302 xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
304 # Get all active PHP7 extensions.
306 if [ -d "${PHP5DIR}" ]; then
307 php70_ext="$(find ${PHP70DIR} -type f -name *.ini |
308 egrep "\/(conf\.d|apache2|cli)\/" |
309 xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
312 # Compare PHP7 <-> PHP5 extensions.
314 for ext in $php5_ext; do
315 if [ "$(echo $php70_ext | egrep $ext)" = "" ]; then
316 php70_ext_mis="\n${ext}${php70_ext_mis}"
320 # Some PHP7 extensions are not active.
321 if [ -n "$php70_ext_mis" ]; then
322 db_fset php7.0-cn/extensions seen false
323 db_title php7.0-cn - konfiguracija
325 db_subst php7.0-cn/extensions php70_extensions "${php70_ext_mis#*\n}"
326 db_input critical php7.0-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!"