Prva inacica paketa za Debian squeeze distribuciju.
[php5-cn.git] / debian / postinst
index 14b691b..f9a78dc 100755 (executable)
@@ -5,18 +5,18 @@ set -e
 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
 
 case "$1" in
-       configure)
-       # continue below
-       ;;
-
-       abort-upgrade|abort-remove|abort-deconfigure)
-       exit 0
-       ;;
-
-       *)
-       echo "postinst called with unknown argument \`$1'" >&2
-       exit 0
-       ;;
+    configure)
+    # continue below
+    ;;
+
+    abort-upgrade|abort-remove|abort-deconfigure)
+    exit 0
+    ;;
+
+    *)
+    echo "postinst called with unknown argument \`$1'" >&2
+    exit 0
+    ;;
 esac
 
 
@@ -62,24 +62,24 @@ phpinivalidate () {
     ini_file="$1"
 
     awk -F'[[:space:]]*=[[:space:]]*' \
-       '/^[[:space:]]*[[:alpha:]_]+[[:space:]]*=[[:space:]]*[[:digit:]]+[MGK]B/ {print $1" = "$2}' \
-       "$ini_file"
+        '/^[[:space:]]*[[:alpha:]_]+[[:space:]]*=[[:space:]]*[[:digit:]]+[MGK]B/ {print $1" = "$2}' \
+        "$ini_file"
 }
 
 
 # Disable PHP4 module and enable Apache2 PHP5 module.
 #
 if [ -e /etc/apache2/apache2.conf ]; then
-       if [ -e "$A2MODEDIR/php4.load" ]; then
-               cp_echo "CN: Disabling PHP4 module for Apache2 web server"
-               a2dismod php4 >/dev/null || true
-               need_restart=1
-       fi
-       if [ ! -e "$A2MODEDIR/php5.load" ] || [ ! -e "$A2MODEDIR/php5.conf" ]; then
-               cp_echo "CN: Enabling PHP5 module for Apache2 web server"
-               a2enmod php5 >/dev/null || true
-               need_restart=1
-       fi
+    if [ -e "$A2MODEDIR/php4.load" ]; then
+        cp_echo "CN: Disabling PHP4 module for Apache2 web server"
+        a2dismod php4 >/dev/null || true
+        need_restart=1
+    fi
+    if [ ! -e "$A2MODEDIR/php5.load" ] || [ ! -e "$A2MODEDIR/php5.conf" ]; then
+        cp_echo "CN: Enabling PHP5 module for Apache2 web server"
+        a2enmod php5 >/dev/null || true
+        need_restart=1
+    fi
 fi
 
 
@@ -87,39 +87,39 @@ fi
 #
 for SAPI in apache2 cli; do
 
-        if [ ! -d "$PHP5DIR/$SAPI" ]; then
-                cp_echo "CN: Creating configuration directory $PHP5DIR/$SAPI/"
-                mkdir -p $PHP5DIR/$SAPI/
-        fi
+    if [ ! -d "$PHP5DIR/$SAPI" ]; then
+        cp_echo "CN: Creating configuration directory $PHP5DIR/$SAPI/"
+        mkdir -p $PHP5DIR/$SAPI/
+    fi
 
-        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: 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
+        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
-       chmod 644 $ini_file
+        cp_mv $ini_file_tmp $ini_file
+        need_restart=1
+    fi
+    chmod 644 $ini_file
 done
 
 
 # Check for /etc/php5/conf.d/ directory.
 #
 if [ ! -d "$PHP5CONFD" ]; then
-        cp_echo "CN: Creating configuration directory $PHP5CONFD"
-        mkdir -p $PHP5CONFD/
+    cp_echo "CN: Creating configuration directory $PHP5CONFD"
+    mkdir -p $PHP5CONFD/
 fi
 
 
@@ -127,55 +127,55 @@ fi
 #
 for php5ext in $EXTENSIONS; do
 
-        php5ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php5ext\.so"
-
-       # Remove extension entry from /etc/php5/(apache2|cli).ini
-       # configuration files.
-        for SAPI in apache2 cli; do
-
-               ini_file="$PHP5DIR/$SAPI/php.ini"
-
-               if [ -f "$ini_file" ]; then
-
-                       if egrep -q "$php5ext_re" "$ini_file"; then
-                               cp_echo "CN: Removing $php5ext extension from file $ini_file"
-                       fi
-
-                       cp_check_and_sed "$php5ext_re" \
-                               "/$php5ext_re/d" \
-                               "$ini_file" && need_restart=1 || true
-               fi
-        done
-
-       # Check extension configuration in /etc/php5/conf.d/ directory.
-       if [ ! -f "$PHP5CONFD/$php5ext.ini" ]; then
-
-               cp_echo "CN: Creating configuration file $PHP5CONFD/$php5ext.ini"
-               
-               php5ext_up=`echo $php5ext | tr [:lower:] [:upper:] | sed 's/Y/y/'`
-               INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
-
-               cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
-               
-               printf "# configuration for php %s module\nextension=%s.so\n" "${php5ext_up}" "${php5ext}" >> "$INITMP"
-               cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
-               
-               need_restart=1
-       else
-
-               if ! grep -q "$php5ext_re" "$PHP5CONFD/$php5ext.ini"; then
-
-                       cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
-                       
-                       INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
-                       cat "$PHP5CONFD/$php5ext.ini" > "$INITMP"
-                       echo "extension=$php5ext.so" >> "$INITMP"
-                       cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
-                       
-                       need_restart=1
-               fi
-       fi
-       chmod 644 $PHP5CONFD/$php5ext.ini
+    php5ext_re="^[[:space:]]*extension[[:space:]]*=[[:space:]]*$php5ext\.so"
+
+    # Remove extension entry from /etc/php5/(apache2|cli).ini
+    # configuration files.
+    for SAPI in apache2 cli; do
+
+        ini_file="$PHP5DIR/$SAPI/php.ini"
+
+        if [ -f "$ini_file" ]; then
+
+            if egrep -q "$php5ext_re" "$ini_file"; then
+                cp_echo "CN: Removing $php5ext extension from file $ini_file"
+            fi
+
+            cp_check_and_sed "$php5ext_re" \
+                "/$php5ext_re/d" \
+                "$ini_file" && need_restart=1 || true
+        fi
+    done
+
+    # Check extension configuration in /etc/php5/conf.d/ directory.
+    if [ ! -f "$PHP5CONFD/$php5ext.ini" ]; then
+
+        cp_echo "CN: Creating configuration file $PHP5CONFD/$php5ext.ini"
+
+        php5ext_up=`echo $php5ext | tr [:lower:] [:upper:] | sed 's/Y/y/'`
+        INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
+
+        cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
+
+        printf "# configuration for php %s module\nextension=%s.so\n" "${php5ext_up}" "${php5ext}" >> "$INITMP"
+        cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
+
+        need_restart=1
+    else
+
+        if ! grep -q "$php5ext_re" "$PHP5CONFD/$php5ext.ini"; then
+
+            cp_echo "CN: Adding $php5ext extension to file $PHP5CONFD/$php5ext.ini"
+
+            INITMP=`mktemp $PHP5CONFD/$php5ext.ini.tmp.XXXXXX`
+            cat "$PHP5CONFD/$php5ext.ini" > "$INITMP"
+            echo "extension=$php5ext.so" >> "$INITMP"
+            cp_mv "$INITMP" "$PHP5CONFD/$php5ext.ini"
+
+            need_restart=1
+        fi
+    fi
+    chmod 644 $PHP5CONFD/$php5ext.ini
 done
 
 
@@ -187,111 +187,111 @@ done
 #
 for SAPI in apache2 cli; do
 
-       if [ ! -d "$PHP5DIR/$SAPI" ]; then
-               continue
-       fi
-
-       ini_file="$PHP5DIR/$SAPI/php.ini"
-       db_get php5-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:]]*=" \
-                       '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:]]*=" \
-                       "s/^[[:space:]]*post_max_size[[:space:]]*=.*/post_max_size = ${phplimit}/" \
-                       "$ini_file" && need_restart=1 || true
-
-               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
-
-           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 ! 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
-               php5_inivalues="$(phpinivalidate "$ini_file")"
-               if [ -n "$php5_inivalues" ]; then
-                       db_fset php5-cn/inivalues seen false
-                       db_title php5-cn - konfiguracija za $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
-                       db_subst php5-cn/inivalues php5_sapi $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
-                       db_subst php5-cn/inivalues ini_file "$ini_file"
-                       db_capb escape
-                       db_subst php5-cn/inivalues php5_inivalues "$(echo -n "$php5_inivalues" | debconf-escape -e)"
-                       db_input critical php5-cn/inivalues || true
-                       db_go || true
-               fi
-       fi
-done
+    if [ ! -d "$PHP5DIR/$SAPI" ]; then
+        continue
+    fi
 
+    ini_file="$PHP5DIR/$SAPI/php.ini"
+    db_get php5-cn/${SAPI} || true
+    if [ "$RET" = "true" ]; then
 
-# Compare active PHP5 extensions with PHP4 ones, if PHP4 configuration still exists.
-#
-if [ -d "${PHP4DIR}" ] && [ -f "${PHP4DIR}/apache2/php.ini" ]; then
+        cp_echo "CN: Checking and enabling some specific parameters in file $ini_file"
+
+        phplimit="$(phpmemlimit)M"
 
-        phpext_re='^[[:space:]]*extension[[:space:]]*=[[:space:]]*["]{0,1}(.*)\.so["]{0,1}'
+        if [ -f "$ini_file" ]; then
 
-        # Get all active PHP4 extensions.
-        php4_ext="$(find ${PHP4DIR} -type f -name *.ini | 
-                 egrep "\/(conf\.d|apache2|cli)\/" | 
-                 xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
+            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
 
-        # Get all active PHP5 extensions.
-        php5_ext=""
-        if [ -d "${PHP5DIR}" ]; then
-            php5_ext="$(find ${PHP5DIR} -type f -name *.ini | 
-                     egrep "\/(conf\.d|apache2|cli)\/" | 
-                     xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
+            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:]]*=" \
+                "s/^[[:space:]]*memory_limit[[:space:]]*=.*/memory_limit = ${phplimit}/" \
+                "$ini_file" && need_restart=1 || true
         fi
 
-        # Compare PHP5 <-> PHP4 extensions.
-        php5_ext_mis=""
-        for ext in $php4_ext; do
-            if [ "$(echo $php5_ext | egrep $ext)" = "" ]; then
-                php5_ext_mis="\n${ext}${php5_ext_mis}"
-            fi
-        done
+        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"
+            need_restart=1
+        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"
 
-        # Some PHP5 extensions are not active.
-        if [ -n "$php5_ext_mis" ]; then
-            db_fset php5-cn/extensions seen false
-            db_title php5-cn - konfiguracija
+        if [ -e "$ini_file_tmp" ]; then
+            rm -f "$ini_file_tmp"
+        fi
+    fi
+
+    # Validate php.ini values.
+    if [ -f "$ini_file" ]; then
+        php5_inivalues="$(phpinivalidate "$ini_file")"
+        if [ -n "$php5_inivalues" ]; then
+            db_fset php5-cn/inivalues seen false
+            db_title php5-cn - konfiguracija za $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
+            db_subst php5-cn/inivalues php5_sapi $(echo ${SAPI} | sed 's/a/A/;s/cli/CLI/')
+            db_subst php5-cn/inivalues ini_file "$ini_file"
             db_capb escape
-            db_subst php5-cn/extensions php5_extensions "${php5_ext_mis#*\n}"
-            db_input critical php5-cn/extensions || true
+            db_subst php5-cn/inivalues php5_inivalues "$(echo -n "$php5_inivalues" | debconf-escape -e)"
+            db_input critical php5-cn/inivalues || true
             db_go || true
         fi
+    fi
+done
+
+
+# Compare active PHP5 extensions with PHP4 ones, if PHP4 configuration still exists.
+#
+if [ -d "${PHP4DIR}" ] && [ -f "${PHP4DIR}/apache2/php.ini" ]; then
+
+    phpext_re='^[[:space:]]*extension[[:space:]]*=[[:space:]]*["]{0,1}(.*)\.so["]{0,1}'
+
+    # Get all active PHP4 extensions.
+    php4_ext="$(find ${PHP4DIR} -type f -name *.ini | 
+         egrep "\/(conf\.d|apache2|cli)\/" | 
+         xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
+
+    # Get all active PHP5 extensions.
+    php5_ext=""
+    if [ -d "${PHP5DIR}" ]; then
+        php5_ext="$(find ${PHP5DIR} -type f -name *.ini | 
+             egrep "\/(conf\.d|apache2|cli)\/" | 
+             xargs sed -rn 's/'$phpext_re'/\1/Ip')" || true
+    fi
+
+    # Compare PHP5 <-> PHP4 extensions.
+    php5_ext_mis=""
+    for ext in $php4_ext; do
+        if [ "$(echo $php5_ext | egrep $ext)" = "" ]; then
+            php5_ext_mis="\n${ext}${php5_ext_mis}"
+        fi
+    done
+
+    # Some PHP5 extensions are not active.
+    if [ -n "$php5_ext_mis" ]; then
+        db_fset php5-cn/extensions seen false
+        db_title php5-cn - konfiguracija
+        db_capb escape
+        db_subst php5-cn/extensions php5_extensions "${php5_ext_mis#*\n}"
+        db_input critical php5-cn/extensions || true
+        db_go || true
+    fi
 fi
 
 
@@ -301,24 +301,15 @@ db_stop || true
 # Restart Apache2 web server if needed.
 #
 if [ $need_restart -eq 1 ]; then
-       
-       # Check Apache2 web server configuration.
-       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 || true
-                   else
-                       /etc/init.d/apache2 restart || true
-                   fi
-               fi
-       else
-       
-               # Something is broken.
-               cp_echo "CN: Your Apache2 configuration is broken."
-               cp_echo "CN: Please, check the service after the installation finishes!"
-       fi
+
+    # Check Apache2 web server configuration.
+    if apache2ctl configtest 2>/dev/null; then
+        invoke-rc.d apache2 force-reload || true
+    else
+        # Something is broken.
+        cp_echo "CN: Your Apache2 configuration is broken."
+        cp_echo "CN: Please, check the service after the installation finishes!"
+    fi
 fi
 
 
@@ -326,4 +317,6 @@ fi
 #
 cp_mail "$PKG"
 
+#DEBHELPER#
+
 exit 0