Sriram Natarajan wrote:
>  Kindly find the webrev for PHP5 More Features
> 
> http://cr.opensolaris.org/~sn123202/PHP5_ARC_CASE_2007_656/
[snip]

Here comes a 5min race through the patch (patch code is quoted with ">
"):
> --- old/usr/src/cmd/php5/install-php5 Mon Nov 26 12:45:39 2007
> +++ new/usr/src/cmd/php5/install-php5 Mon Nov 26 12:45:38 2007
> @@ -1,4 +1,4 @@
> -#!/bin/sh
> +#!/bin/ksh

Please use either "#!/usr/bin/ksh -p" or "#!/usr/bin/ksh93" (e.g.
/usr/bin/ instead of /bin and "-p" if you use the old ksh).

> --- old/usr/src/cmd/php5/install-php5 Mon Nov 26 12:45:39 2007
> +++ new/usr/src/cmd/php5/install-php5 Mon Nov 26 12:45:38 2007
> @@ -23,12 +23,13 @@
>  # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
>  # Use is subject to license terms.
>  #
> -#pragma ident        "@(#)install-php5       1.2     07/11/12 SMI"
> +#pragma ident        "@(#)install-php5       1.3     07/11/26 SMI"

General note for this type of script: Please add a $ set -o errexit # at
the beginning that the script - the "errexit" flag causes the shell to
immediately abort the script when it hits a command which returns a
failure instead of continuing operation (and maybe running amok (or
worse) ...)

>  . ${SRC}/tools/install.subr

If you use ksh93 (see above) replace the "." with "source".

>  VERS=`grep "^PHP_VERSION=" Makefile.sfw | sed s/PHP_VERSION=//`
>  PHPDIR=php-${VERS}
> +PHPCGI=${PHPDIR}-cgi

Please put quotes around the variable expansion, e.g.
-- snip --
PHPCGI="${PHPDIR}-cgi"
-- snip --

>  PHP_ROOT=/usr/php5/${VERS}
>  PHP_ROOT_BIN=${PHP_ROOT}/bin
> @@ -45,16 +46,52 @@
>  EXTDIR=${TOPDIR}/modules
>  MAN1DIR=${TOPDIR}/man/man1
>  
> +APACHE2_CONFDIR="${ROOT}/etc/apache2/2.2/conf.d"
> +APACHE2_MODDIR="${ROOT}/usr/apache2/2.2/libexec"
> +
>  CWD=`pwd`

Please replace this with...
-- snip --
CWD="$PWD"
-- snip --
... (ksh88/ksh93 both have a special variable "PWD" which always points
to the current working directory
(the variable name "CWD" somehow sounds weired... AFAIK "INSTBASEDIR"
("installation base dir") may be better)).

>  # ----- Common Utility Functions -----
>  
> +# Handle the glue to Apache 2 HTTP Server.
> +#
> +add_apache2_module_support() {

Uhm... please use ksh-style functions (when you switch from Bourne shell
(=/sbin/sh&&/bin/sh) to /usr/bin/ksh (=ksh88) you get functions with own
scope for both Bourne-style and ksh-style functions while ksh93 uses
Bourne-style behaviour for Bourne-style functions (e.g. no seperate
scope) and ksh-style behaviour for ksh-style functions (e.g. seperate
scope) - to get consistent behaviour for all ksh vesions (and clones)
it's recommended to use the ksh-style functions (and see
http://www.opensolaris.org/os/project/shell/shellstyle/#use_ksh_style_function_syntax)).

> +    # Load the PHP5 module within modules-32.load 
> +echo "
> +# Load the PHP5 module
> +<Ifmodule prefork.c>
> +LoadModule php5_module libexec/mod_php5.so
> +</IfModule>
> +" >> ${APACHE2_CONFDIR}/modules-32.load
> +
> +    _install N ${CWD}/Solaris/php5.conf ${APACHE2_CONFDIR}/php5.conf 644
> +}
> +
>  # handle all configuration related manipulations.
>  #
>  fix_config_files() {

Please use ksh-style functions...

> +    cd ${CWD}
> +
>      # Ship a default php.ini to simplify ease of use. 
> -    cd ${PHPDIR}
> -    _install N php.ini-recommended ${CONFDIR}/php.ini 644
> +    gpatch -p 0 -o php.ini-patched \
> +     ${PHPDIR}/php.ini-recommended ${CWD}/patches/php_ini.patch
> +
> +    cat php.ini-patched | \
> +       sed -e "s#<<VERSION>>#${VERS}#" \
> +       > php.ini

Please remove the extra "cat" ...

> +    _install N php.ini ${CONFDIR}/php.ini 644
> + 
> +    # Prepare configuration files for each extension
> +    for module in ${EXTDIR}/*.so; do
> +        module=${module%.so}
> +        ext=${module##*/}
> +        echo ";Comment out next line to disable $ext extension in php" \
> +            > $ext.ini

If the variable name is followed by a dot ('.') but curly brackets
around the variable name, e.g. ...
-- snip --
    > ${ext}.ini
-- snip --

> +        echo "extension=$ext.so" >> $ext.ini

1. Please combine both redirections into one, e.g.
-- snip --
{
  echo ";Comment out next line to disable $ext extension in php"
  echo "extension=$ext.so"
} > "$ext.ini"
-- snip --
2. Please use "print" and not "echo" in ksh scripts. The statement in
[1] then becomes
-- snip --
{
  print ";Comment out next line to disable $ext extension in php"
  print "extension=$ext.so"
}  > "${ext}.ini"
-- snip --

> +        _install N $ext.ini ${CONFDIR}/conf.d/$ext.ini 644
> +        rm ${ext}.ini

Please put quotes around variable expansions (important when running
potentionally dangerous commands like "rm") and if the variable name is
followed by a dot ('.') put curly brackets around the variable name,
e.g. ...
-- snip --
 rm "${ext}.ini"
-- snip --

> +    done
>  }
>  
>  # scripts in the bin directory have paths to the build environment
> @@ -87,13 +124,9 @@
>      # Ensure basic file permissions.
>      cd $PHPDIR
>      _install E sapi/cli/php ${BINDIR}/php  555
> -    # _install E sapi/cgi/php-cgi ${BINDIR}/php-cgi  555
> -}
>  
> -# symlinks for shared libraries
> -fix_so_symlinks() {

Please use ksh-style functions...

> -    cd ${LIBDIR}
> -    _install L libphp5-${VERS}.so libphp5.so
> +    cd ../$PHPCGI
> +    _install E sapi/cgi/php-cgi ${BINDIR}/php-cgi  555
>  }
>  
>  # doc related
> @@ -105,6 +138,17 @@
>      cat ${CWD}/Solaris/htmldocs.tar.gz | gunzip | tar xf -
>  }
>  
> +# Create symbolic links
> +create_symlinks() {

Please use ksh-style functions...

> +    cd ${ROOT}/usr/php5;
> +    _install L ./${VERS}/bin bin;
> +    _install L ./${VERS}/lib lib;
> +    _install L ./${VERS}/include include;
> +    _install L ./${VERS}/modules modules;
> +    _install L ./${VERS}/doc doc;
> +    _install L ./${VERS}/man man;

Please use quotes around "${VERS}" ...

> +}
> +
>  # ----- START HERE - actual script processing starts here -----
>  
>  # Even though this is called "install-php5", it doesn't really
> @@ -114,10 +158,11 @@
>  # Each install task is a function, so it's relatively easy to add new
>  # stuff.
>  #
> +add_apache2_module_support
>  fix_config_files
>  fix_bin_scripts
> -fix_so_symlinks
>  install_docs
> +create_symlinks
>  
>  
>  exit 0

> --- old/usr/src/cmd/php5/Makefile.sfw Mon Nov 26 12:45:39 2007
> +++ new/usr/src/cmd/php5/Makefile.sfw Mon Nov 26 12:45:39 2007
[snip]
> +install_xdebug: build_xdebug
> +     /usr/ucb/install $(XDEBUG_DIR)/modules/xdebug.so \
> +             $(ROOT)/$(PREFIX)/modules/

Erm... is it really allowed to use commands from /usr/ucb/ here ?

[snip]
>  clean:
>       -rm -rf $(PHP_DIR)
> +     -rm -rf $(PHP_CGI)
>       -rm -rf $(SUHOSIN_DIR)
>       -rm -rf $(TCPWRAP_DIR)
>       -rm -rf $(IDN_DIR)
>       -rm -rf $(DTRACE_DIR)
>       -rm -rf $(APC_DIR)
> -     -rm -f php-config-proto phpize-proto package.xml phpize php-config
> +     -rm -rf $(XDEBUG_DIR)
> +     -rm -f php-config-proto phpize-proto package.xml package2.xml \
> +             phpize php-config php.ini-patched

Two nits:
1. Please put quotes around directory names when "rm -rf" is used (which
limits damage if any variable contains garbage)
2. Please bundle multiple "rm" calls
For example:
-- snip --
 clean:
        -rm -rf \
           "$(PHP_DIR)" \
           "$(PHP_CGI)" \
           "$(SUHOSIN_DIR)" \
           "$(TCPWRAP_DIR)" \
           "$(IDN_DIR)" \
           "$(DTRACE_DIR)" \
           "$(APC_DIR)" \
           "$(XDEBUG_DIR)"
        -rm -f php-config-proto phpize-proto package.xml package2.xml \
                phpize php-config php.ini-patched
 
-- snip --


BTW: I've attached an updated version of the script as
"install-php5_20071126.txt" ...

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) roland.mainz at nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 7950090
 (;O/ \/ \O;)
-------------- next part --------------
#!/usr/bin/ksh93
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#pragma ident   "@(#)install-php5       1.3     07/11/26 SMI"

# stop at the first error
set -o errexit

# load builtin commands
builtin cat

source "${SRC}/tools/install.subr"

typeset VERS="$(grep '^PHP_VERSION=' Makefile.sfw | sed s/PHP_VERSION=//)"
typeset PHPDIR="php-${VERS}"
typeset PHPCGI="${PHPDIR}-cgi"

typeset PHP_ROOT="/usr/php5/${VERS}"
typeset PHP_ROOT_BIN="${PHP_ROOT}/bin"
typeset PHP_ROOT_LIB="${PHP_ROOT}/lib"
typeset PHP_ROOT_INC="${PHP_ROOT}/include/php"
typeset PHP_ROOT_EXT="${PHP_ROOT}/modules"

typeset CONFDIR="${ROOT}/etc/php5/${VERS}"
typeset TOPDIR="${ROOT}/usr/php5/${VERS}"
typeset BINDIR="${TOPDIR}/bin"
typeset LIBDIR="${TOPDIR}/lib"
typeset DOCDIR="${TOPDIR}/doc"
typeset INCDIR="${TOPDIR}/include/php"
typeset EXTDIR="${TOPDIR}/modules"
typeset MAN1DIR="${TOPDIR}/man/man1"

typeset APACHE2_CONFDIR="${ROOT}/etc/apache2/2.2/conf.d"
typeset APACHE2_MODDIR="${ROOT}/usr/apache2/2.2/libexec"

typeset CWD="$PWD"

# ----- Common Utility Functions -----

# Handle the glue to Apache 2 HTTP Server.
#
function add_apache2_module_support
{
    # stop at the first error
    set -o errexit # stop at the first error

    # Load the PHP5 module within modules-32.load 
print -r "
# Load the PHP5 module
<Ifmodule prefork.c>
LoadModule php5_module libexec/mod_php5.so
</IfModule>
" >> "${APACHE2_CONFDIR}/modules-32.load"

    _install N "${CWD}/Solaris/php5.conf" "${APACHE2_CONFDIR}/php5.conf" 644
}

# handle all configuration related manipulations.
#
function fix_config_files
{
    set -o errexit # stop at the first error

    # local vars
    typeset module ext

    cd ${CWD}

    # Ship a default php.ini to simplify ease of use. 
    gpatch -p0 -o php.ini-patched \
        "${PHPDIR}/php.ini-recommended" "${CWD}/patches/php_ini.patch"

    sed -e "s#<<VERSION>>#${VERS}#" < "php.ini-patched" > php.ini
    _install N php.ini "${CONFDIR}/php.ini" 644
 
    # Prepare configuration files for each extension
    for module in ${EXTDIR}/*.so; do
        module="${module%.so}"
        ext="${module##*/}"

        {
            print -r ";Comment out next line to disable ${ext} extension in php"
            print -r "extension=${ext}.so"
        } > "${ext}.ini"

        _install N "${ext}.ini" "${CONFDIR}/conf.d/${ext}.ini" 644
        rm "${ext}.ini"
    done
}

# scripts in the bin directory have paths to the build environment
# wired into them - need to fix these
#
function fix_bin_scripts
{
    set -o errexit # stop at the first error

    # Adjust scripts for building extensions
    cd "${CWD}"
    cat "${PHPDIR}/scripts/phpize" | \
          sed -e "s#^prefix=.*#prefix=${PHP_ROOT}#" | \
          sed -e "s#^exec_prefix=.*#exec_prefix=${PHP_ROOT}#" | \
          sed -e "s#^includedir=.*#includedir=${PHP_ROOT_INC}#" | \
          sed -e "s#^phpdir=.*#phpdir=${PHP_ROOT_LIB}/build#" | \
          sed -e "s#^php_binary=.*#php_binary=${PHP_ROOT_BIN}/php#" | \
          sed -e "s#^extension_dir=.*#extension_dir=${PHP_ROOT_EXT}#" \
          > phpize

    cat "${PHPDIR}/scripts/php-config" | \
          sed -e "s#^prefix=.*#prefix=${PHP_ROOT}#" | \
          sed -e "s#^exec_prefix=.*#exec_prefix=${PHP_ROOT}#" | \
          sed -e "s#^includedir=.*#includedir=${PHP_ROOT_INC}#" | \
          sed -e "s#^phpdir=.*#phpdir=${PHP_ROOT}#" | \
          sed -e "s#^php_binary=.*#php_binary=${PHP_ROOT_BIN}/php#" | \
          sed -e "s#^extension_dir=.*#extension_dir=${PHP_ROOT_EXT}#" \
          > php-config

    _install S php-config "${BINDIR}/php-config" 555
    _install S phpize "${BINDIR}/phpize" 555

    # Ensure basic file permissions.
    cd "$PHPDIR"
    _install E sapi/cli/php "${BINDIR}/php" 555

    cd "../$PHPCGI"
    _install E sapi/cgi/php-cgi "${BINDIR}/php-cgi" 555
}

# doc related
function install_docs
{
    set -o errexit # stop at the first error

    cd "${CWD}"
    _install N Solaris/php.1.sunman \
        "${ROOT}/usr/share/man/man1/php.1" 644
    cd "${DOCDIR}"
    gunzip <"${CWD}/Solaris/htmldocs.tar.gz" | tar -xf -
}

# Create symbolic links
function create_symlinks
{
    set -o errexit # stop at the first error

    cd "${ROOT}/usr/php5"
    _install L "./${VERS}/bin" bin;
    _install L "./${VERS}/lib" lib;
    _install L "./${VERS}/include" include;
    _install L "./${VERS}/modules" modules;
    _install L "./${VERS}/doc" doc;
    _install L "./${VERS}/man" man;
}

# ----- START HERE - actual script processing starts here -----

# Even though this is called "install-php5", it doesn't really
# install the whole thing.  Much of php itself is installed by
# make install - we need to fix only permissions.  What we install here
# are stuffs that php won't install as part of its normal build.
# Each install task is a function, so it's relatively easy to add new
# stuff.
#
add_apache2_module_support
fix_config_files
fix_bin_scripts
install_docs
create_symlinks

exit 0

Reply via email to