[Webapps-common-discuss] webapps-common/internal/php4-modconf gd.info,NONE,1.1 ldap.info,NONE,1.1 mcrypt.info,NONE,1.1 mysql.info,NONE,1.1 pgsql.info,NONE,1.1 php4-modconf,NONE,1.1
neilm@haydn.debian.org
neilm@haydn.debian.org
Update of /cvsroot/webapps-common/webapps-common/internal/php4-modconf
In directory haydn:/tmp/cvs-serv7671/php4-modconf
Added Files:
gd.info ldap.info mcrypt.info mysql.info pgsql.info
php4-modconf
Log Message:
--- NEW FILE: gd.info ---
package="gd"
extname="GD"
dsoname="gd"
sapilist="apache apache2 cgi cli fcgi"
depends=""
priority="500"
--- NEW FILE: ldap.info ---
package="ldap"
extname="LDAP"
dsoname="ldap"
sapilist="apache apache2 cgi cli fcgi"
depends=""
priority="500"
--- NEW FILE: mcrypt.info ---
package="mcrypt"
extname="MCrypt"
dsoname="mcrypt"
sapilist="apache apache2 cgi cli fcgi"
depends=""
priority="500"
--- NEW FILE: mysql.info ---
package="mysql"
extname="MySQL"
dsoname="mysql"
sapilist="apache apache2 cgi cli fcgi"
depends=""
priority="500"
--- NEW FILE: pgsql.info ---
package="pgsql"
extname="PostgreSQL"
dsoname="pgsql"
sapilist="apache apache2 cgi cli fcgi"
depends=""
priority="500"
--- NEW FILE: php4-modconf ---
#!/bin/bash
# $Id: php4-modconf,v 1.1 2005/05/28 13:30:50 neilm Exp $
# Piotr Roszatycki <dexter@debian.org>
#
# This program is based on apache-modconf
# by Fabio M. Di Nitto <fabbione@fabbione.net>
set -e
GREP="env -i grep"
PHPEXTDIR="/usr/lib/php4/20020429"
#### global functions ####
go_out() {
case "$1" in
command)
echo "Error: $0 has been called with invalid parameters"
echo "Usage: $0 apache|apache2|cgi|cli|fcgi [enable <module_name>] [quiet]"
echo " $0 apache|apache2|cgi|cli|fcgi [disable <module_name>] [quiet]"
echo " $0 apache|apache2|cgi|cli|fcgi [query <module_name>]"
echo " $0 apache|apache2|cgi|cli|fcgi [list]"
;;
install)
echo "Error: $SAPI appears not to be installed"
;;
esac
exit 1
}
restart() {
FLA="$1"
if [ -x /usr/sbin/invoke-rc.d ]; then
invoke-rc.d $FLA restart > /dev/null 2>&1 3>&1 || true
else
/etc/init.d/$FLA restart > /dev/null 2>&1 3>&1 || true
fi
}
check_info_check_so() {
# this should check if all the .info have an .so file
err=0
cd $phpextdir && \
for i in `ls *.info`; do \
. $i
if [ ! -e "$dsoname.so" ]; then \
echo "Error: $i does not have a valid *.so file."; \
err=1; \
fi; \
done;
if [ "$err" = "1" ]; then
echo "The above errors might cause $SAPI to not work properly or start"
echo "Please reinstall module package to fix it or report it to"
echo "Piotr Roszatycki <dexter@debian.org> if in doubt on how to proceed"
fi
}
available_modules() {
# this implies that ALL the modules MUST have an info file.
# note that is called with LC_COLLATE=C to preserve the list order
available=`\
cd $phpextdir &&\
$GREP -E -l "^sapilist=.*(\"|[[:space:]])$SAPI(\"|[[:space:]])" *.info |\
xargs $GREP -H ^priority= |\
LC_COLLATE=C sort -t: -k2 |\
sed -e 's/\.info.*$/,/g'`
available=`echo $available | sed 's/,$//'`
}
depends_modules() {
MOD=$1
if [ ! "$MOD" ]; then
return
fi
. $MOD.info
echo $depends, $(depends_modules $depends)
}
enabled_modules() {
# we only consider php.ini.
# we should always working ini but enabled_modules is a read only function
# so we just copy the file (modules.conf.dpkg-inst.ini will be regenerated)
cp /etc/php4/$SAPI/php.ini /etc/php4/$SAPI/php.ini.dpkg-inst.old
# importing all the extension= lines
enabled=`\
cat $CONFFILE |\
$GREP '^[[:space:]]*extension[[:space:]]*=[[:space:]]*.*.so' |\
sed -e 's/.*extension=//' -e 's/\.so.*//' |\
sort -u
`
# this creates a map between the .so names found in the configfiles and
# the .info
cd $phpextdir && \
for i in $enabled; do \
mapped="`$GREP -l \"^dsoname=\\\"$i\\\"$\" *.info | sed -e 's/\.info$/,/g'` $mapped";
done
# this enable or disable a module
# note that the enable now checks if the module is already there
# and take more appropriate actions such as not adding it twice
# and goes in quite mode if already there.
# it also checks if module is available.
# disable is safe in all cases
if [ "$CMD" = "enable" ]; then
if [ ! "`echo $mapped | $GREP -E \"(^|[[:space:]])$MOD(,|$)\"`" ] &&\
[ "`echo $available | $GREP -E \"(^|[[:space:]])$MOD(,|$)\"`" ]; then
mapped=`echo $mapped $(depends_modules $MOD) $MOD`
else
QUIET=true
fi
fi
if [ "$CMD" = "disable" ]; then
mapped=`echo $mapped | sed -e 's/^'$MOD'$//g' -e 's/'$MOD,'//g' -e 's/, '$MOD'$//g'`
fi
if [ "$CMD" = "list" ]; then
echo "$mapped" | sed -e 's/,[[:space:]]$//' -e 's/,[[:space:]]/\n/g'
exit 0
fi
if [ "$CMD" = "query" ]; then
if [ "`echo $mapped | $GREP -E \"(^|[[:space:]])$MOD(,|$)\"`" ]; then
echo "$MOD"
fi
exit 0
fi
# the list has a "," at the end that needs to be removed
enabled=`echo $mapped | sed 's/,$//'`
}
enable_config() {
# importing all the extension= lines
enabled=`\
cat $CONFFILE.dpkg-inst.ext |\
$GREP '^[[:space:]]*extension[[:space:]]*=[[:space:]]*.*.so' |\
sed -e 's/.*extension=//' -e 's/\.so.*//' |\
sort -u
`
cp -f $CONFFILE.dpkg-inst.old $CONFFILE.dpkg-inst.tmp
for i in $enabled; do
cat $CONFFILE.dpkg-inst.tmp |\
$GREP -v "^[[:space:]]*extension[[:space:]]*=[[:space:]]*$i.so" \
> $CONFFILE.dpkg-inst.new
mv -f $CONFFILE.dpkg-inst.new $CONFFILE.dpkg-inst.tmp
done
# generating new php.ini based on old php.ini and ext list
if [ "`$GREP '^;;; BEGIN AUTOMAGIC EXTENSIONS LIST' $CONFFILE.dpkg-inst.old`" ]; then
sed "/^;;; BEGIN AUTOMAGIC EXTENSIONS LIST/,/^;;; END AUTOMAGIC EXTENSIONS LIST/{
/^;;; BEGIN AUTOMAGIC EXTENSIONS LIST/ r $CONFFILE.dpkg-inst.ext
d
}" $CONFFILE.dpkg-inst.tmp \
> $CONFFILE.dpkg-inst.new
else
cat $CONFFILE.dpkg-inst.tmp $CONFFILE.dpkg-inst.ext \
> $CONFFILE.dpkg-inst.new
fi
mv -f $CONFFILE.dpkg-inst.new $CONFFILE
rm -f $CONFFILE.dpkg-inst.old $CONFFILE.dpkg-inst.ext $CONFFILE.dpkg-inst.tmp
}
write_config() {
# writing header
echo ";;; BEGIN AUTOMAGIC EXTENSIONS LIST" > $CONFFILE.dpkg-inst.ext
echo "; Autogenerated extensions list - do not edit!" >> $CONFFILE.dpkg-inst.ext
echo "; This file is maintained by the php4-$SAPI package." >> $CONFFILE.dpkg-inst.ext
echo "; To update it, run the command:" >> $CONFFILE.dpkg-inst.ext
echo "; /usr/sbin/php4-modconf $SAPI" >> $CONFFILE.dpkg-inst.ext
echo "" >> $CONFFILE.dpkg-inst.ext
# fullavailable contains <modname>.info and for sure is sorted correctly
# note: it seems like LC_COLLATE=C is enough to avoid resorting in ls.
# The problem seems to be debconf that returns a random sorted $LIST
# so we use a reversed approch starting from something known.
fullavailable=`\
cd $phpextdir &&\
$GREP -E -l "^sapilist=.*(\"|[[:space:]])$SAPI(\"|[[:space:]])" *.info |\
xargs $GREP -H ^priority= |\
LC_COLLATE=C sort -t: -k2 |\
sed -e 's/\.info.*$//g'`
for i in $fullavailable; do \
if [ "`echo $LIST | $GREP -E \"(^|[[:space:]])$i(,|$)\"`" ]; then \
temp=`\
cd $phpextdir &&\
$GREP -l "^dsoname=\"$i\"" $i.info |\
sed -e 's/\.info//'
`; \
if [ -n "$temp" ]; then \
echo "extension=$temp.so" >> $CONFFILE.dpkg-inst.ext; \
fi; \
fi; \
done; \
# writing footer
echo "" >> $CONFFILE.dpkg-inst.ext
echo ";;; END AUTOMAGIC EXTENSIONS LIST" >> $CONFFILE.dpkg-inst.ext
}
set_defaults() {
# these are the defaults that we provide now
# and realligned to be similar
enabled=""
if [ "$rollback" = "false" ]; then
cp /usr/share/ucf/php4-$SAPI$CONFFILE $CONFFILE.dpkg-inst.old
fi
}
#### sanit(ar)y checks ####
SAPI=$1
if [ "$SAPI" != "apache" ] && \
[ "$SAPI" != "apache2" ] && \
[ "$SAPI" != "cgi" ] && \
[ "$SAPI" != "cli" ] && \
[ "$SAPI" != "fcgi" ]; then
go_out command
fi
if [ ! -d /etc/php4/$SAPI ]; then
go_out install
fi
CONFFILE="/etc/php4/$SAPI/php.ini"
phpextdir="$PHPEXTDIR"
CMD=
QUEUECHANGES=false
PRI=low
case "$SAPI" in
apache|apache2)
ASKRESTART=true;;
*)
ASKRESTART=false;;
esac
if [ "$2" ]; then
if [ "$2" != "enable" ] && \
[ "$2" != "disable" ] && \
[ "$2" != "internal" ] && \
[ "$2" != "query" ] && \
[ "$2" != "list" ]; then
go_out command
fi
CMD=$2
case "$CMD" in
internal)
if [ "$3" = "quiet" ]; then
QUIET=true
fi
ASKRESTART=false
QUEUECHANGES=true
;;
list)
;;
*)
if [ ! "$3" ]; then
go_out command
fi
MOD=$3
if [ "$CMD" = "disable" ] || [ "$CMD" = "enable" ]; then
if [ "$4" = "quiet" ]; then
QUIET=true
fi
fi
;;
esac
else
PRI=medium
fi
### time to do some real work ####
check_info_check_so
available_modules
if [ -e $CONFFILE ]; then
enabled_modules
else
rollback=false
set_defaults
fi
. /usr/share/debconf/confmodule
db_version 2.0
db_capb backup
db_subst php5-shared/extensions choices $available
db_subst php5-shared/extensions flavour php4-$SAPI
db_set php5-shared/extensions $enabled
db_subst php5-shared/restart-webserver flavour $SAPI
if [ "$QUIET" = "true" ]; then
db_fset php5-shared/extensions seen true
fi
db_input $PRI php5-shared/extensions || true
if [ "$QUIET" != "true" ]; then
db_go || true
fi
db_get php5-shared/extensions
LIST="$RET"
db_fset php5-shared/extensions seen false
if [ "x$LIST" = "x" ]; then
# if for a mistake the user selects NO modules we need
# at least the defaults to be able to start
rollback=true
set_defaults
LIST=$enabled
fi
write_config
# we enable the config only when we are executed in standalone
if [ "$QUEUECHANGES" = "false" ]; then
enable_config
fi
if [ "$SAPI" = "apache" ]; then
FLAVOURS="apache apache-ssl apache-perl"
else
FLAVOURS="apache2"
fi
for FLA in $FLAVOURS; do
if [ "$ASKRESTART" = "true" ]; then
if [ "`pidof $FLA | awk '{print $0}'`" ]; then
db_subst php5-shared/restart-webserver flavour $FLA
if [ "$QUIET" = "true" ]; then
db_fset php5-shared/restart-webserver seen true
fi
db_input low php5-shared/restart-webserver || true
fi
fi
if [ "$QUIET" != "true" ]; then
db_go || true
fi
if [ "$ASKRESTART" = "true" ]; then
if [ "`pidof $FLA | awk '{print $0}'`" ]; then
db_get php5-shared/restart-webserver
REST="$RET"
db_fset php5-shared/restart-webserver seen false
if [ "$REST" = "true" ]; then
restart "$FLA"
fi
fi
fi
done
exit 0
cat << END
=head1 NAME
php4-modconf - reconfigure the PHP4 extensions list
=head1 SYNOPSIS
B<php4-modconf> apache | apache2 | cgi | cli | fcgi
=head1 DESCRIPTION
This command is meant to be a simple interface between sysadmins and
php4 to administer which modules has to be loaded or not.
It automatically creates extensions list in config file located in
F</etc/php4/{sapi}/php.ini>.
=head1 OPTIONS
A summary of options are included below.
=over 8
=item B<enable> I<module_name> [B<quiet>]
this will automatically enable the module in the selection list and ask if the
web server should be restarted. The quite option will not prompt for any
selection but it will just do the work (usefull only when called by other
scripts).
Example: php4-modconf apache enable mysql
=item B<disable> I<module_name> [B<quiet>]
this will automatically disable the module in the selection list and ask if
the web server should be restarted. The quite option will not prompt for any
selection but it will just do the work (usefull only when called by other
scripts).
Example: php4-modconf cgi disable gd quiet
=item B<query> I<module_name>
this will return a non-empty string if the module is enabled in the configuration.
Example: apache-modconf cli query simplexml
=item B<list>
this will return a list of enabled modules.
=back
=head1 NOTES
In order for php4-modconf to be able to recongnize a module, the latter should
be provided with an .info file installed in F</usr/lib/php4/.../>.
=head1 AUTHORS
(c) 2004-2005 Piotr Roszatycki E<lt>dexter@debian.orgE<gt>
This program and manual page is based on work by Fabio M. Di Nitto
E<lt>fabbione@fabbione.netE<gt>, for the Debian GNU/Linux system (but may be
used by others).