X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=debian%2Fpostinst;h=25b98041b0ee9d30f9fe42e3fe80ebe52a7ee212;hb=0afc3c15999bbb2ef281abf83c95649645b7e97c;hp=1f6771e8d2c116d5aa2a1e90e3e2c1bb71533239;hpb=77da50f4913fa24efe0e061cca00093b7e09991e;p=php5-cn.git diff --git a/debian/postinst b/debian/postinst index 1f6771e..25b9804 100755 --- a/debian/postinst +++ b/debian/postinst @@ -20,18 +20,38 @@ case "$1" in esac +# Load debconf +. /usr/share/debconf/confmodule + # Include CARNet functions . /usr/share/carnet-tools/functions.sh PKG="php5-cn" A2MODEDIR="/etc/apache2/mods-enabled" -EXTENSIONS="mysql ldap gd" +EXTENSIONS="mysql" PHP5DIR="/etc/php5" PHP5CONFD="/etc/php5/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 +} + + # Disable PHP4 module and enable Apache2 PHP5 module. # if [ -e /etc/apache2/apache2.conf ]; then @@ -48,26 +68,65 @@ if [ -e /etc/apache2/apache2.conf ]; then fi -# Check if PHP5 extensions (MySQL, LDAP, GD) are enabled. +# Check for PHP5 SAPI directories and configuration files. +# +for SAPI in apache2 cli; do + + if [ ! -d "$PHP5DIR/$SAPI" ]; then + cp_echo "CN: Creating configuration directory $PHP5DIR/$SAPI/" + mkdir -p $PHP5DIR/$SAPI/ + fi + + ini_file="$PHP5DIR/$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/php5/php.ini-dist.cli" ]; then + cat /usr/share/php5/php.ini-dist.cli > $ini_file_tmp + fi + else + if [ -f "/usr/share/php5/php.ini-dist" ]; then + cat /usr/share/php5/php.ini-dist > $ini_file_tmp + fi + fi + cp_mv $ini_file_tmp $ini_file + need_restart=1 + fi +done + + +# Check for /etc/php5/conf.d/ directory. +# +if [ ! -d "$PHP5CONFD" ]; then + cp_echo "CN: Creating configuration directory $PHP5CONFD" + mkdir -p $PHP5CONFD/ +fi + + +# Check if PHP5 extensions are enabled. # for php5ext in $EXTENSIONS; do php5ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php5ext\.so" - # Remove extension entry from /etc/php5/(apache|apache2|cgi|cli).ini + # Remove extension entry from /etc/php5/(apache2|cli).ini # configuration files. - for SAPI in apache apache2 cgi cli; do + for SAPI in apache2 cli; do - ini_file="$PHP5DIR/$SAPI/php.ini" + ini_file="$PHP5DIR/$SAPI/php.ini" - if [ -f "$ini_file" ]; then + if [ -f "$ini_file" ]; then cp_echo "CN: Removing $php5ext extension from file $ini_file" cp_check_and_sed "$php5ext_re" \ "/$php5ext_re/d" \ "$ini_file" && need_restart=1 || true - fi + fi done # Check extension configuration in /etc/php5/conf.d/ directory. @@ -80,7 +139,7 @@ for php5ext in $EXTENSIONS; do cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini" - echo -e "# configuration for php $php5ext_up module\nextension=$php5ext.so" >> "$INITMP" + printf "# configuration for php %s module\nextension=%s\n" "${php5ext_up}" "${php5ext}" >> "$INITMP" cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini" need_restart=1 @@ -104,61 +163,69 @@ done # Enable some PHP5 tweaks for Apache2 web server (/etc/php5/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 +for SAPI in apache2 cli; do if [ ! -d "$PHP5DIR/$SAPI" ]; then continue fi + + db_get php5-cn/${SAPI} || true + if [ "$RET" = "true" ]; then - ini_file="$PHP5DIR/$SAPI/php.ini" + ini_file="$PHP5DIR/$SAPI/php.ini" - cp_echo "CN: Checking and enabling some CARNet specific parameters in file $ini_file" + cp_echo "CN: Checking and enabling some specific parameters in file $ini_file" + + phplimit="$(phpmemlimit)M" - if [ -f "$ini_file" ]; then + 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 + fi - ini_file_tmp=`mktemp $ini_file.tmp.XXXXXX` - if [ -f "$ini_file" ]; then + 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 - - 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 + 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" + - if [ -e "$ini_file_tmp" ]; then + if [ -e "$ini_file_tmp" ]; then rm -f "$ini_file_tmp" + fi fi done +db_stop || true + + # Restart Apache2 web server if needed. # if [ $need_restart -eq 1 ]; then