X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=debian%2Fpostinst;h=bd93964ba60f2e6fb4a7670f92b17f74fdd258d1;hb=e206da1fdeb7945986319d4f8338c9b8b3dbec4b;hp=5a3279c7958e8b799fdcfbf5cc5541745b91646c;hpb=b3a467537d3200a343868f8d57b25c1d8d11e8ff;p=php4-cn.git diff --git a/debian/postinst b/debian/postinst index 5a3279c..bd93964 100755 --- a/debian/postinst +++ b/debian/postinst @@ -4,9 +4,6 @@ set -e [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx -# Source debconf library. -. /usr/share/debconf/confmodule - case "$1" in configure) # continue below @@ -23,54 +20,128 @@ case "$1" in esac +# Load debconf +. /usr/share/debconf/confmodule + # Include CARNet functions . /usr/share/carnet-tools/functions.sh PKG="php4-cn" A2MODEDIR="/etc/apache2/mods-enabled" -EXTENSIONS="mysql ldap gd" +EXTENSIONS="mysql" PHP4DIR="/etc/php4" PHP4CONFD="/etc/php4/conf.d" need_restart=0 +# phpmemlimit () +# +# Calculate memory size for PHP memory_limit option. +# +phpmemlimit () { + + local memtotal memlimit + memtotal=`awk 'tolower($1) == "memtotal:" { printf("%i", $2/1024); }' /proc/meminfo` + + if [ $memtotal -lt 512 ]; then memlimit=16; fi + if [ $memtotal -ge 512 ]; then memlimit=32; fi + if [ $memtotal -gt 1024 ]; then memlimit=64; fi + + echo $memlimit +} + +# phpinivalidate () +# +# Validate php.ini values. +# +phpinivalidate () { + + local ini_file + ini_file="$1" + + awk -F'[[:space:]]*=[[:space:]]*' \ + '/^[[:space:]]*[[:alpha:]_]+[[:space:]]*=[[:space:]]*[[:digit:]]+[MGK]B/ {print $1" = "$2}' \ + "$ini_file" +} + + # Disable PHP5 module and enable Apache2 PHP4 module. # if [ -e /etc/apache2/apache2.conf ]; then - if [ -e "$A2MODEDIR/php5.load" ]; then - cp_echo "CN: Disabling PHP5 module for Apache2 web server" - a2dismod php5 >/dev/null || true - need_restart=1 + if [ -e "$A2MODEDIR/php5.load" ]; then + cp_echo "CN: Disabling PHP5 module for Apache2 web server" + a2dismod php5 >/dev/null || true + need_restart=1 + fi + if [ ! -e "$A2MODEDIR/php4.load" ] || [ ! -e "$A2MODEDIR/php4.conf" ]; then + cp_echo "CN: Enabling PHP4 module for Apache2 web server" + a2enmod php4 >/dev/null || true + need_restart=1 + fi +fi + + +# Check for PHP4 SAPI directories and configuration files. +# +for SAPI in apache2 cli; do + + if [ ! -d "$PHP4DIR/$SAPI" ]; then + cp_echo "CN: Creating configuration directory $PHP4DIR/$SAPI/" + mkdir -p $PHP4DIR/$SAPI/ fi - if [ ! -e "$A2MODEDIR/php4.load" ] || [ ! -e "$A2MODEDIR/php4.conf" ]; then - cp_echo "CN: Enabling PHP4 module for Apache2 web server" - a2enmod php4 >/dev/null || true + + ini_file="$PHP4DIR/$SAPI/php.ini" + + if [ ! -f "$ini_file" ]; then + + cp_echo "CN: Generating configuration file $ini_file" + + ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX` + if [ "$SAPI" = "cli" ]; then + if [ -f "/usr/share/php4/php.ini-dist.cli" ]; then + cat /usr/share/php4/php.ini-dist.cli > $ini_file_tmp + fi + else + if [ -f "/usr/share/php4/php.ini-dist" ]; then + cat /usr/share/php4/php.ini-dist > $ini_file_tmp + fi + fi + cp_mv $ini_file_tmp $ini_file need_restart=1 fi + chmod 644 $ini_file +done + + +# Check for /etc/php4/conf.d/ directory. +# +if [ ! -d "$PHP4CONFD" ]; then + cp_echo "CN: Creating configuration directory $PHP4CONFD" + mkdir -p $PHP4CONFD/ fi -# Check if PHP4 extensions (MySQL, LDAP, GD) are enabled. +# Check if PHP4 extensions are enabled. # for php4ext in $EXTENSIONS; do php4ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php4ext\.so" - # Remove extension entry from /etc/php4/(apache|apache2|cgi|cli).ini + # Remove extension entry from /etc/php4/(apache2|cli).ini # configuration files. - for SAPI in apache apache2 cgi cli; do + for SAPI in apache2 cli; do - ini_file="$PHP4DIR/$SAPI/php.ini" + ini_file="$PHP4DIR/$SAPI/php.ini" - if [ -f "$ini_file" ]; then + if [ -f "$ini_file" ]; then cp_echo "CN: Removing $php4ext extension from file $ini_file" cp_check_and_sed "$php4ext_re" \ "/$php4ext_re/d" \ "$ini_file" && need_restart=1 || true - fi + fi done # Check extension configuration in /etc/php4/conf.d/ directory. @@ -83,7 +154,7 @@ for php4ext in $EXTENSIONS; do cp_echo "CN: Adding $php4ext extension to file $PHP4CONFD/$php4ext.ini" - echo -e "# configuration for php $php4ext_up module\nextension=$php4ext.so" >> "$INITMP" + printf "# configuration for php %s module\nextension=%s.so\n" "${php4ext_up}" "${php4ext}" >> "$INITMP" cp_mv "$INITMP" "$PHP4CONFD/$php4ext.ini" need_restart=1 @@ -101,76 +172,103 @@ for php4ext in $EXTENSIONS; do need_restart=1 fi fi + chmod 644 $PHP4CONFD/$php4ext.ini done # Enable some PHP4 tweaks for Apache2 web server (/etc/php4/apache2/php.ini). # # * upload_max_filesize = 256M -# * post_max_size = 256M -# * memory_limit = 256M +# * post_max_size, memory_limit = depends on system memory, we are using +# phpmemlimit() function. # -for SAPI in apache apache2 cgi cli; do - - ini_file="$PHP4DIR/$SAPI/php.ini" +for SAPI in apache2 cli; do - cp_echo "CN: Checking and enabling some CARNet specific parameters in file $ini_file" + if [ ! -d "$PHP4DIR/$SAPI" ]; then + continue + fi - if [ -f "$ini_file" ]; then + ini_file="$PHP4DIR/$SAPI/php.ini" + db_get php4-cn/${SAPI} || true + if [ "$RET" = "true" ]; then + + cp_echo "CN: Checking and enabling some specific parameters in file $ini_file" + + phplimit="$(phpmemlimit)M" + + if [ -f "$ini_file" ]; then - cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=[[:space:]]*2M$" \ + cp_check_and_sed "^[[:space:]]*upload_max_filesize[[:space:]]*=" \ 's/^[[:space:]]*upload_max_filesize[[:space:]]*=.*/upload_max_filesize = 256M/' \ "$ini_file" && need_restart=1 || true - cp_check_and_sed "^[[:space:]]*post_max_size[[:space]]*=[[:space:]]*8M$" \ - 's/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = 256M/' \ + cp_check_and_sed "^[[:space:]]*post_max_size[[:space:]]*=" \ + "s/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = ${phplimit}/" \ "$ini_file" && need_restart=1 || true - cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=[[:space:]]*16M$" \ - 's/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = 256M/' \ + cp_check_and_sed "^[[:space:]]*memory_limit[[:space:]]*=" \ + "s/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = ${phplimit}/" \ "$ini_file" && need_restart=1 || true - fi - - ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX` - if [ -f "$ini_file" ]; then - cat $ini_file > $ini_file_tmp - fi + fi - if ! egrep -q "^[[:space:]]*(upload_max_filesize|post_max_size|memory_limit)[[:space:]]*=" $ini_file_tmp; then + ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX` + if [ -f "$ini_file" ]; then + cat $ini_file > $ini_file_tmp + fi - if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then - echo "upload_max_filesize = 256M" >> "$ini_file_tmp" - fi - if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then - echo "post_max_size = 256MB" >> "$ini_file_tmp" - fi - if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then - echo "memory_limit = 256M" >> "$ini_file_tmp" - fi - cp_mv "$ini_file_tmp" "$ini_file" - + if ! egrep -q "^[[:space:]]*upload_max_filesize[[:space:]]*=" $ini_file_tmp; then + echo "upload_max_filesize = 256M" >> "$ini_file_tmp" need_restart=1 - fi - - if [ -e "$ini_file_tmp" ]; then + fi + if ! egrep -q "^[[:space:]]*post_max_size[[:space:]]*=" $ini_file_tmp; then + echo "post_max_size = ${phplimit}" >> "$ini_file_tmp" + need_restart=1 + fi + if ! egrep -q "^[[:space:]]*memory_limit[[:space:]]*=" $ini_file_tmp; then + echo "memory_limit = ${phplimit}" >> "$ini_file_tmp" + need_restart=1 + fi + cp_mv "$ini_file_tmp" "$ini_file" + chmod 644 "$ini_file" + + if [ -e "$ini_file_tmp" ]; then rm -f "$ini_file_tmp" + fi + fi + + # Validate php.ini values. + if [ -f "$ini_file" ]; then + php4_inivalues="$(phpinivalidate "$ini_file")" + if [ -n "$php4_inivalues" ]; then + db_fset php4-cn/inivalues seen false + db_title php4-cn - konfiguracija za $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/') + db_subst php4-cn/inivalues php4_sapi $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/') + db_subst php4-cn/inivalues ini_file "$ini_file" + db_capb escape + db_subst php4-cn/inivalues php4_inivalues "$(echo -n "$php4_inivalues" | debconf-escape -e)" + db_input critical php4-cn/inivalues || true + db_go || true + fi fi done +db_stop || true + + # Restart Apache2 web server if needed. # if [ $need_restart -eq 1 ]; then # Check Apache2 web server configuration. - if apache2ctl configtest 2>/dev/null; then + if /usr/sbin/apache2ctl configtest 2>/dev/null; then # Restart Apache2 web server. if [ -x "/etc/init.d/apache2" ]; then if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then - invoke-rc.d apache2 restart || exit $? + invoke-rc.d apache2 force-reload || true else - /etc/init.d/apache2 restart || exit $? + /etc/init.d/apache2 force-reload || true fi fi else