cvs: pearweb /public_html go-pear
| From: | Stig Bakken | Date: | Fri, 14 Jun 2002 09:26:38 +0000 |
| Subject: | cvs: pearweb /public_html go-pear | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-4609@lists.php.net to get a copy of this message | ||
ssb Fri Jun 14 05:26:38 2002 EDT
Modified files:
/pearweb/public_html go-pear
Log:
* PHP rewrite
Index: pearweb/public_html/go-pear diff -u pearweb/public_html/go-pear:1.10 pearweb/public_html/go-pear:1.11 --- pearweb/public_html/go-pear:1.10 Wed Jun 12 20:28:30 2002 +++ pearweb/public_html/go-pear Fri Jun 14 05:26:38 2002 @@ -1,4 +1,5 @@ -#!/bin/sh +<?php // -*- PHP -*- +//; echo; echo "YOU NEED TO RUN THIS SCRIPT WITH PHP NOW!"; echo; echo "Try this: lynx -source http://pear.php.net/go-pear | php -q"; echo; exit # +----------------------------------------------------------------------+ # | PHP Version 4 | # +----------------------------------------------------------------------+ @@ -13,19 +14,17 @@ # | license@php.net so we can mail you a copy immediately. | # +----------------------------------------------------------------------+ # | Authors: Tomas V.V.Cox <cox@idecnet.com> | +# | Stig Sæther Bakken <stig@php.net> | # +----------------------------------------------------------------------+ # -# $Id: go-pear,v 1.10 2002/06/13 00:28:30 cox Exp $ +# $Id: go-pear,v 1.11 2002/06/14 09:26:38 ssb Exp $ # # Automatically download all the files needed to run the "pear" command # (the PEAR package installer) # # Usage: This script could be directly launched or can be passed # via lynx so: -# $ lynx -source http://pear.php.net/go-pear | sh -# -# TODO: -# -rewrite in PHP +# $ lynx -source http://pear.php.net/go-pear | php # # From Rev5 please see the pearweb CVS module at cvs.php.net # @@ -51,145 +50,509 @@ # # Rev1 2002-03-24: Initial -echo -echo "This script will install the PEAR Installer command 'pear' and" -echo "all the files needed by it. The 'pear' command is the tool" -echo "that can manage PEAR packages downloaded both from the PEAR website" -echo "(http://pear.php.net) or from the 'pear/' CVS module of cvs.php.net." -echo -echo "With this script you can also download and install" -echo "the common PEAR files from CVS that also come with any PHP distribution" -echo "(located at php4/pear in CVS). The common PEAR files means classes like" -echo "PEAR DB, XML_Parser, IT template engine or Mail. Please read the" -echo "FAQ at http://pear.php.net/faq.php for more information." -echo -echo "For an explanation on how to use the PEAR Installer or what PEAR" -echo "packages are, visit:" -echo " http://cvs.php.net/co.php/pearweb/doc/pear_package_manager.txt" -echo - -php=`which php` -if [ -z "$php" ]; then - echo "No php cgi binary found in PATH" - exit 1 -fi -prefix=`echo $php | perl -pe 's/\/bin\/php//'` -TARGET="${prefix}/bin/pear" +if (!function_exists("version_compare")) { + die( +"Sorry! Your PHP version is too old. PEAR and this script requires at +least PHP 4.1.0 for stable operation. + +It may be that you have a newer version of PHP installed in your web +server, but an older version installed as the 'php' command. In this +case, you need to rebuilt PHP from source. + +If your source is 4.1.x, you need to run 'configure' without any SAPI +options such as --with-apache. After rebuilding you will find the +'php' binary in the top-level directory. + +If your source is 4.2.x, you need to run 'configure' with the +--enable-cli option, rebuild and copy sapi/cli/php somewhere. + +If your source is 4.3.x or newer, just make sure you don't run +'configure' with --disable-cli, rebuilt and copy sapi/cli/php. + +Please upgrade PHP to a newer version, and try again. See you then. + +"); +} + +define('WINDOWS', (substr(PHP_OS, 0, 3) == 'WIN')); + +if (WINDOWS) { + $tty = fopen("php://stdin", "r"); +} else { + // this allows for a stdin that is not the terminal, as you + // get with "lynx -source .../go-pear | php" + $tty = fopen("/dev/tty", "r"); +} + +print "Welcome to go-pear! + +Go-pear will install the 'pear' command and all the files needed by +it. This command is your tool for PEAR installation and maintenance. + +Go-pear also lets you download and install the PEAR packages bundled +with PHP, such as DB, Mail_Mime, XML_Parser and others. + +If you wish to abort, press Control-C now, or press Enter to continue: "; + +fgets($tty, 1024); + +print "\n"; + +if (isset($_ENV['HTTP_PROXY'])) { + $http_proxy = $_ENV['HTTP_PROXY']; +} elseif (isset($_ENV['http_proxy'])) { + $http_proxy = $_ENV['http_proxy']; +} else { + $http_proxy = ''; +} +$prefix = dirname(PHP_BINDIR); +$bin_dir = '$prefix/bin'; +$php_dir = '$prefix/share/pear'; +$doc_dir = '$prefix/share/pear/docs'; +$data_dir = '$prefix/share/pear/data'; +$tests_dir = '$prefix/share/pear/tests'; + +register_shutdown_function('bail'); + +if (isset($_ENV['_'])) { + $php = $_ENV['_']; +} else { + $php = which('php'); +} +if (empty($php)) { + bail("No php cgi binary found in PATH\n"); +} #### # User configurable options #### -echo "Which filename do you want to use for the 'pear' executable?" -echo -n "[$TARGET] : " -read destpearin < /dev/tty -if [ ! -z "$destpearin" ]; then - TARGET=$destpearin -fi -touch $TARGET > /dev/null -if [ $? -ne 0 ]; then - echo "Could not create file '$TARGET'" - exit 1 -fi - -echo "Some files need to be installed in your system" -echo "In what directory do you want to install them?" -echo "(note that the path has to be in the include_path of your php.ini)" -echo -n "[$prefix/lib/php] : " -read destdir < /dev/tty -if [ -z "$destdir" ]; then - destdir="$prefix/lib/php" -fi -if [ ! -d $destdir ]; then - echo "Directory '$destdir' does not exist or is not a directory" - exit 1 -fi - -echo -n "Do you also want to install the common PEAR files? [Y/n] : " -read installall < /dev/tty -files="/" -if [ `echo $installall | grep -i 'n'` ]; then - files="/scripts/pear.in /Archive/Tar.php /Console/Getopt.php /PEAR.php \ - /System.php /PEAR /OS /package-Archive_Tar.xml \ - /package-Console_Getopt.xml /package-PEAR.xml \ - /packages/XML_RPC-1.0.3.tar /package.dtd" - installall="n" -fi +print "HTTP proxy (host:port), or Enter for none"; +if (!empty($http_proxy)) { + print " [$http_proxy]"; +} +print ": "; +$tmp = trim(fgets($tty, 1024)); +if (!empty($tmp)) { + $http_proxy = $tmp; +} + +$config_desc = array( + 'prefix' => 'Installation prefix', + 'bin_dir' => 'Binaries directory', + 'php_dir' => 'PHP code directory', + 'doc_dir' => 'Documentation base directory', + 'data_dir' => 'Data base directory', + 'tests_dir' => 'Tests base directory', +); +$config_vars = array_keys($config_desc); +// make indices run from 1... +array_unshift($config_vars, ""); +unset($config_vars[0]); +reset($config_vars); +$desclen = max(array_map('strlen', $config_desc)); +$descfmt = "%-{$desclen}s"; +$first = key($config_vars); +end($config_vars); +$last = key($config_vars); + +while (true) { + print " +Below is a suggested file layout for your new PEAR installation. To +change individual locations, type the number in front of the +directory. Type 'all' to change all of them or simply press Enter to +accept these locations. + +"; + foreach ($config_vars as $n => $var) { + printf("%2d. $descfmt : %s\n", $n, $config_desc[$var], $$var); + } + print "\n$first-$last, 'all' or Enter to continue: "; + $tmp = trim(fgets($tty, 1024)); + if (empty($tmp)) { + break; + } + if (isset($config_vars[(int)$tmp])) { + $var = $config_vars[(int)$tmp]; + $desc = $config_desc[$var]; + $current = $$var; + print "$desc [$current] : "; + $tmp = trim(fgets($tty, 1024)); + if (!empty($tmp)) { + $$var = $tmp; + } + } elseif ($tmp == 'all') { + foreach ($config_vars as $n => $var) { + $desc = $config_desc[$var]; + $current = $$var; + print "$desc [$current] : "; + $tmp = trim(fgets($tty, 1024)); + if (!empty($tmp)) { + $$var = $tmp; + } + } + } +} + +foreach ($config_vars as $n => $var) { + $$var = str_replace('$prefix', $prefix, $$var); +} + +foreach ($config_vars as $var) { + $dir = $$var; + if (!@is_dir($dir)) { + if (!mkdir_p($dir)) { + $root = WINDOWS ? 'administrator' : 'root'; + bail("Unable to create {$config_desc[$var]} $dir. +Run this script as $root or pick another location.\n"); + } + } +} + +print " +Do you want to install the PEAR packages bundled with PHP? [Y/n] : "; +$install_pfc = !stristr(fgets($tty, 1024), "n"); +print "\n"; #### # Temp stuff #### -if [ -z "$TMPDIR" ]; then - TMPDIR=/tmp -fi -PTMP=`date +%s` -PTMP="${TMPDIR}/${PTMP}" -/bin/rm -rf $PTMP && mkdir -m 0700 -p $PTMP -origpwd=`pwd` -cd $PTMP - -TMPPASS="$PTMP/cvspass" -echo ":pserver:cvsread@cvs.php.net:/repository phpfi" > $TMPPASS -export CVSPASS=$TMPPASS +if (isset($_ENV['TMPDIR'])) { + $tmp_dir = $_ENV['TMPDIR']; +} else { + $tmp_dir = '/tmp'; +} + +$ptmp = $tmp_dir . '/go-pear-' . $_ENV['USER'] . '-' . time(); + +rm_rf($ptmp); +mkdir_p($ptmp, 0700); +$origpwd = getcwd(); +chdir($ptmp); #### # Download #### -echo "Downloading files..." - -for i in $files; do - cvs -q -d :pserver:cvsread@cvs.php.net:/repository \ - export -D "now" "php4/pear$i" -done -pearin=php4/pear/scripts/pear.in -if [ ! -f $pearin ]; then - echo "Could not download the files from CVS" - exit 1 -fi -echo "done!" - -#### -# Copy files -#### - -/bin/cp -fR php4/pear/* $destdir < /dev/tty - -#### -# Set the right interpreter for the pear cmd -#### - -prefix=`echo $prefix | perl -pe 's#\/#\x5c\/#g;'` -cat $pearin | perl -pe "s#\@prefix@#$prefix#" > $TARGET -chmod +x $TARGET - -#### -# Install needed packages and finish the registration -#### - -PEAR="php -C -d include_path=$PTMP/php4/pear -f $TARGET -- " -$PEAR -D php_dir=$destdir -S -$PEAR install -r php4/pear/package-Archive_Tar.xml -$PEAR install -r php4/pear/package-Console_Getopt.xml -$PEAR install -r php4/pear/package-PEAR.xml -$PEAR install -s php4/pear/packages/XML_RPC-1.0.3.tar -if [ "$installall" != "n" ]; then - for i in "php4/pear/packages/*"; do - $PEAR install -s $i - done -fi - -#### -# Clean up and finish -#### - -cd $origpwd -rm -rf $PTMP +ini_set("include_path", $ptmp); -echo -echo "The 'pear' command has been successfully installed under $TARGET" -echo "try it by typing '$TARGET' for help" -echo +print 'Bootstrapping: PEAR...................'; +$url = 'http://cvs.php.net/co.php/php4/pear/PEAR.php?p=1'; +download_url($url, 'PEAR.php', $http_proxy); +include_once 'PEAR.php'; +print "ok\n"; + +print 'Bootstrapping: Archive_Tar............'; +$url = 'http://cvs.php.net/co.php/pear/Archive_Tar/Archive/Tar.php?p=1'; +mkdir('Archive', 0700); +download_url($url, 'Archive/Tar.php', $http_proxy); +print "ok\n"; + +print 'Bootstrapping: Console_Getopt.........'; +$url = 'http://cvs.php.net/co.php/php4/pear/Console/Getopt.php?p=1'; +mkdir('Console', 0700); +download_url($url, 'Console/Getopt.php', $http_proxy); +print "ok\n"; + +if (!extension_loaded('zlib')) { + if (WINDOWS) { + @dl('php_zlib.dll'); + } elseif (PHP_OS == 'HP-UX') { + @dl('zlib.sl'); + } elseif (PHP_OS == 'AIX') { + @dl('zlib.a'); + } else { + @dl('zlib.so'); + } +} +if (!extension_loaded('zlib')) { + $urltemplate = 'http://pear.php.net/get/%s?uncompress=yes'; + $have_gzip = false; +} else { + $urltemplate = 'http://pear.php.net/get/%s'; + $have_gzip = true; +} + +$installer_packages = array( + 'PEAR', + 'Archive_Tar', + 'Console_Getopt', + 'XML_RPC' + ); +$pfc_packages = array( + 'DB', + 'Mail_Mime', + 'XML_Parser', + ); +if ($install_pfc) { + $to_install = array_merge($installer_packages, $pfc_packages); +} else { + $to_install = $installer_packages; +} + +foreach ($to_install as $pkg) { + $msg = str_pad("Downloading package: $pkg", 38, '.'); + print $msg; + $url = sprintf($urltemplate, $pkg); + $tarball[$pkg] = download_url($url, null, $http_proxy); + print "ok\n"; +} + +PEAR::setErrorHandling(PEAR_ERROR_DIE, "\n%s\n"); +print 'Extracting installer..................'; +$dot = strrpos($tarball['PEAR'], '.'); +$pkg = substr($tarball['PEAR'], 0, $dot); +$ext = substr($tarball['PEAR'], $dot+1); + +include_once 'Archive/Tar.php'; +$tar = &new Archive_Tar($tarball['PEAR'], $have_gzip); +if (!$tar->extractModify($ptmp, $pkg)) { + bail("failed!\n"); +} +print "ok\n"; +$tarball['PEAR'] = 'package.xml'; // :-) + +include_once "./PEAR.php"; +include_once "./PEAR/Config.php"; +include_once "./PEAR/Command.php"; +include_once "./PEAR/Registry.php"; + +$config = &PEAR_Config::singleton(); +foreach ($config_vars as $var) { + $config->set($var, $$var); +} +$config->store(); + +$registry = new PEAR_Registry($php_dir); +PEAR_Command::setFrontendType('CLI'); +$install = &PEAR_Command::factory('install', $config); +$install_options = array( + 'nodeps' => true, + 'force' => true, + ); +foreach ($tarball as $pkg => $src) { + $options = $install_options; + if ($registry->packageExists($pkg)) { + $options['upgrade'] = true; + } + $install->run('install', $options, array($src)); +} + +ini_restore("include_path"); +$sep = WINDOWS ? ';' : ':'; +$include_path = explode($sep, ini_get('include_path')); +if (!in_array($php_dir, $include_path)) { + print " +****************************************************************************** +WARNING! The include_path defined in the currently used php.ini does not +contain the PEAR PHP directory you just configured. + +Current include path: ".ini_get('include_path')." +Configured directory: $php_dir +"; + if (WINDOWS) { + print " +Please look over your php.ini file to make sure +$php_dir is in your include_path."; + } else { + print " +I will add a workaround for this in the 'pear' command to make sure +the installer works, but please look over your php.ini or Apache +configuration to make sure $php_dir is in your include_path. +"; + } + print "\nPress Enter to continue: "; + fgets($tty, 1024); + if (!WINDOWS) { + print 'Fixing installer include_path.........'; + $pear_cmd = "$bin_dir/pear"; + $tmpfile = "$bin_dir/.tmp.pear"; + $fp = @fopen($pear_cmd, "r"); + $wp = @fopen($tmpfile, "w"); + if ($fp && $wp) { + $hashbang = rtrim(fgets($fp, 1024)) . + "d include_path=$php_dir\n"; + fwrite($wp, $hashbang); + while ($data = fread($fp, 2048)) { + fwrite($wp, $data); + } + fclose($fp); + fclose($wp); + $perms = fileperms($pear_cmd); + rename($tmpfile, $pear_cmd); + chmod($pear_cmd, $perms); + print "ok\n"; + } else { + print "failed\n"; + print "Make sure you update your php.ini!\n\n"; + } + } +} + +print " +The 'pear' command is now at your service. Try 'pear list' to see +what packages are installed, or 'pear help' for help. + +For more information about PEAR, please check these out: + + http://pear.php.net/faq.php + http://cvs.php.net/co.php/pearweb/doc/pear_package_manager.txt?p=1 + http://pear.php.net/manual/ + +Thanks for using go-pear! + +"; + +// {{{ download_url() + +function download_url($url, $destfile = null, $proxy = null) +{ + $use_suggested_filename = ($destfile === null); + if ($use_suggested_filename) { + $destfile = basename($url); + } + $tmp = parse_url($url); + if (empty($tmp['port'])) { + $tmp['port'] = 80; + } + if (empty($proxy)) { + $fp = fsockopen($tmp['host'], $tmp['port'], $errno, $errstr); + //print "\nconnecting to $tmp[host]:$tmp[port]\n"; + } else { + list($phost, $pport) = explode(":", $proxy); + $fp = fsockopen($phost, $pport, $errno, $errstr); + //print "\nconnecting to $phost:$pport\n"; + } + if (!$fp) { + bail("download of $url failed: $errstr ($errno)\n"); + } + if (empty($proxy)) { + $path = $tmp['path']; + } else { + $path = "http://$tmp[host]:$tmp[port]$tmp[path]"; + } + if (isset($tmp['query'])) { + $path .= "?$tmp[query]"; + } + if (isset($tmp['fragment'])) { + $path .= "#$tmp[fragment]"; + } + $request = "GET $path HTTP/1.0\r\nHost: $tmp[host]:$tmp[port]\r\n". + "User-Agent: go-pear\r\n\r\n"; + fwrite($fp, $request); + $cdh = "content-disposition:"; + $cdhl = strlen($cdh); + while ($line = fgets($fp, 2048)) { + if (trim($line) == '') { + break; + } + if ($use_suggested_filename && !strncasecmp($line, $cdh, $cdhl)) { + if (eregi('filename="([^"]+)"', $line, $matches)) { + $destfile = basename($matches[1]); + } + } + } + $wp = fopen($destfile, "w"); + if (!$wp) { + bail("could not open $destfile for writing\n"); + } + while ($data = fread($fp, 2048)) { + fwrite($wp, $data); + } + fclose($fp); + fclose($wp); + return $destfile; +} + +// }}} +// {{{ which() + +function which($program) +{ + $sep = WINDOWS ? ';' : ':'; + $dirs = explode($sep, $_ENV['PATH']); + if (WINDOWS) { + foreach ($dirs as $dir) { + $tmp = "$dir/$program"; + if (file_exists($ret = "$tmp.exe") || + file_exists($ret = "$tmp.com") || + file_exists($ret = "$tmp.bat") || + file_exists($ret = "$tmp.cmd")) { + return $ret; + } + } + } else { + foreach ($dirs as $dir) { + if (is_executable("$dir/$program")) { + return "$dir/$program"; + } + } + } + return null; +} + +// }}} +// {{{ bail() + +function bail($msg = '') +{ + global $ptmp; + if ($ptmp && is_dir($ptmp)) { + chdir('/'); + system("rm -rf $ptmp"); + } + if ($msg) { + die($msg); + } +} + +// }}} +// {{{ mkdir_p() + +function mkdir_p($dir, $mode = 0777) +{ + $lastdir = ''; + if (@is_dir($dir)) { + return true; + } + $parent = dirname($dir); + $parent_exists = (int)@is_dir($parent); + $ok = true; + if (!@is_dir($parent) && $parent != $dir) { + $ok = mkdir_p(dirname($dir), $mode); + } + if ($ok) { + $ok = @mkdir($dir, $mode); + if (!$ok) { + print "mkdir failed: $dir\n"; + } + } + return $ok; +} + +// }}} +// {{{ rm_rf() + +function rm_rf($path) +{ + if (@is_dir($path)) { + $dp = opendir($path); + while ($ent = readdir($dp)) { + if ($ent == '.' || $ent == '..') { + continue; + } + $file = $path . DIRECTORY_SEPARATOR . $ent; + if (@is_dir($file)) { + rm_rf($file); + } else { + unlink($file); + } + } + return rmdir($path); + } else { + return @unlink($path); + } +} -exit +// }}}
Index: pearweb/public_html/go-pear diff -u pearweb/public_html/go-pear:1.10 pearweb/public_html/go-pear:1.11 --- pearweb/public_html/go-pear:1.10 Wed Jun 12 20:28:30 2002 +++ pearweb/public_html/go-pear Fri Jun 14 05:26:38 2002 @@ -1,4 +1,5 @@ -#!/bin/sh +<?php // -*- PHP -*- +//; echo; echo "YOU NEED TO RUN THIS SCRIPT WITH PHP NOW!"; echo; echo "Try this: lynx -source http://pear.php.net/go-pear | php -q"; echo; exit # +----------------------------------------------------------------------+ # | PHP Version 4 | # +----------------------------------------------------------------------+ @@ -13,19 +14,17 @@ # | license@php.net so we can mail you a copy immediately. | # +----------------------------------------------------------------------+ # | Authors: Tomas V.V.Cox <cox@idecnet.com> | +# | Stig Sæther Bakken <stig@php.net> | # +----------------------------------------------------------------------+ # -# $Id: go-pear,v 1.10 2002/06/13 00:28:30 cox Exp $ +# $Id: go-pear,v 1.11 2002/06/14 09:26:38 ssb Exp $ # # Automatically download all the files needed to run the "pear" command # (the PEAR package installer) # # Usage: This script could be directly launched or can be passed # via lynx so: -# $ lynx -source http://pear.php.net/go-pear | sh -# -# TODO: -# -rewrite in PHP +# $ lynx -source http://pear.php.net/go-pear | php # # From Rev5 please see the pearweb CVS module at cvs.php.net # @@ -51,145 +50,509 @@ # # Rev1 2002-03-24: Initial -echo -echo "This script will install the PEAR Installer command 'pear' and" -echo "all the files needed by it. The 'pear' command is the tool" -echo "that can manage PEAR packages downloaded both from the PEAR website" -echo "(http://pear.php.net) or from the 'pear/' CVS module of cvs.php.net." -echo -echo "With this script you can also download and install" -echo "the common PEAR files from CVS that also come with any PHP distribution" -echo "(located at php4/pear in CVS). The common PEAR files means classes like" -echo "PEAR DB, XML_Parser, IT template engine or Mail. Please read the" -echo "FAQ at http://pear.php.net/faq.php for more information." -echo -echo "For an explanation on how to use the PEAR Installer or what PEAR" -echo "packages are, visit:" -echo " http://cvs.php.net/co.php/pearweb/doc/pear_package_manager.txt" -echo - -php=`which php` -if [ -z "$php" ]; then - echo "No php cgi binary found in PATH" - exit 1 -fi -prefix=`echo $php | perl -pe 's/\/bin\/php//'` -TARGET="${prefix}/bin/pear" +if (!function_exists("version_compare")) { + die( +"Sorry! Your PHP version is too old. PEAR and this script requires at +least PHP 4.1.0 for stable operation. + +It may be that you have a newer version of PHP installed in your web +server, but an older version installed as the 'php' command. In this +case, you need to rebuilt PHP from source. + +If your source is 4.1.x, you need to run 'configure' without any SAPI +options such as --with-apache. After rebuilding you will find the +'php' binary in the top-level directory. + +If your source is 4.2.x, you need to run 'configure' with the +--enable-cli option, rebuild and copy sapi/cli/php somewhere. + +If your source is 4.3.x or newer, just make sure you don't run +'configure' with --disable-cli, rebuilt and copy sapi/cli/php. + +Please upgrade PHP to a newer version, and try again. See you then. + +"); +} + +define('WINDOWS', (substr(PHP_OS, 0, 3) == 'WIN')); + +if (WINDOWS) { + $tty = fopen("php://stdin", "r"); +} else { + // this allows for a stdin that is not the terminal, as you + // get with "lynx -source .../go-pear | php" + $tty = fopen("/dev/tty", "r"); +} + +print "Welcome to go-pear! + +Go-pear will install the 'pear' command and all the files needed by +it. This command is your tool for PEAR installation and maintenance. + +Go-pear also lets you download and install the PEAR packages bundled +with PHP, such as DB, Mail_Mime, XML_Parser and others. + +If you wish to abort, press Control-C now, or press Enter to continue: "; + +fgets($tty, 1024); + +print "\n"; + +if (isset($_ENV['HTTP_PROXY'])) { + $http_proxy = $_ENV['HTTP_PROXY']; +} elseif (isset($_ENV['http_proxy'])) { + $http_proxy = $_ENV['http_proxy']; +} else { + $http_proxy = ''; +} +$prefix = dirname(PHP_BINDIR); +$bin_dir = '$prefix/bin'; +$php_dir = '$prefix/share/pear'; +$doc_dir = '$prefix/share/pear/docs'; +$data_dir = '$prefix/share/pear/data'; +$tests_dir = '$prefix/share/pear/tests'; + +register_shutdown_function('bail'); + +if (isset($_ENV['_'])) { + $php = $_ENV['_']; +} else { + $php = which('php'); +} +if (empty($php)) { + bail("No php cgi binary found in PATH\n"); +} #### # User configurable options #### -echo "Which filename do you want to use for the 'pear' executable?" -echo -n "[$TARGET] : " -read destpearin < /dev/tty -if [ ! -z "$destpearin" ]; then - TARGET=$destpearin -fi -touch $TARGET > /dev/null -if [ $? -ne 0 ]; then - echo "Could not create file '$TARGET'" - exit 1 -fi - -echo "Some files need to be installed in your system" -echo "In what directory do you want to install them?" -echo "(note that the path has to be in the include_path of your php.ini)" -echo -n "[$prefix/lib/php] : " -read destdir < /dev/tty -if [ -z "$destdir" ]; then - destdir="$prefix/lib/php" -fi -if [ ! -d $destdir ]; then - echo "Directory '$destdir' does not exist or is not a directory" - exit 1 -fi - -echo -n "Do you also want to install the common PEAR files? [Y/n] : " -read installall < /dev/tty -files="/" -if [ `echo $installall | grep -i 'n'` ]; then - files="/scripts/pear.in /Archive/Tar.php /Console/Getopt.php /PEAR.php \ - /System.php /PEAR /OS /package-Archive_Tar.xml \ - /package-Console_Getopt.xml /package-PEAR.xml \ - /packages/XML_RPC-1.0.3.tar /package.dtd" - installall="n" -fi +print "HTTP proxy (host:port), or Enter for none"; +if (!empty($http_proxy)) { + print " [$http_proxy]"; +} +print ": "; +$tmp = trim(fgets($tty, 1024)); +if (!empty($tmp)) { + $http_proxy = $tmp; +} + +$config_desc = array( + 'prefix' => 'Installation prefix', + 'bin_dir' => 'Binaries directory', + 'php_dir' => 'PHP code directory', + 'doc_dir' => 'Documentation base directory', + 'data_dir' => 'Data base directory', + 'tests_dir' => 'Tests base directory', +); +$config_vars = array_keys($config_desc); +// make indices run from 1... +array_unshift($config_vars, ""); +unset($config_vars[0]); +reset($config_vars); +$desclen = max(array_map('strlen', $config_desc)); +$descfmt = "%-{$desclen}s"; +$first = key($config_vars); +end($config_vars); +$last = key($config_vars); + +while (true) { + print " +Below is a suggested file layout for your new PEAR installation. To +change individual locations, type the number in front of the +directory. Type 'all' to change all of them or simply press Enter to +accept these locations. + +"; + foreach ($config_vars as $n => $var) { + printf("%2d. $descfmt : %s\n", $n, $config_desc[$var], $$var); + } + print "\n$first-$last, 'all' or Enter to continue: "; + $tmp = trim(fgets($tty, 1024)); + if (empty($tmp)) { + break; + } + if (isset($config_vars[(int)$tmp])) { + $var = $config_vars[(int)$tmp]; + $desc = $config_desc[$var]; + $current = $$var; + print "$desc [$current] : "; + $tmp = trim(fgets($tty, 1024)); + if (!empty($tmp)) { + $$var = $tmp; + } + } elseif ($tmp == 'all') { + foreach ($config_vars as $n => $var) { + $desc = $config_desc[$var]; + $current = $$var; + print "$desc [$current] : "; + $tmp = trim(fgets($tty, 1024)); + if (!empty($tmp)) { + $$var = $tmp; + } + } + } +} + +foreach ($config_vars as $n => $var) { + $$var = str_replace('$prefix', $prefix, $$var); +} + +foreach ($config_vars as $var) { + $dir = $$var; + if (!@is_dir($dir)) { + if (!mkdir_p($dir)) { + $root = WINDOWS ? 'administrator' : 'root'; + bail("Unable to create {$config_desc[$var]} $dir. +Run this script as $root or pick another location.\n"); + } + } +} + +print " +Do you want to install the PEAR packages bundled with PHP? [Y/n] : "; +$install_pfc = !stristr(fgets($tty, 1024), "n"); +print "\n"; #### # Temp stuff #### -if [ -z "$TMPDIR" ]; then - TMPDIR=/tmp -fi -PTMP=`date +%s` -PTMP="${TMPDIR}/${PTMP}" -/bin/rm -rf $PTMP && mkdir -m 0700 -p $PTMP -origpwd=`pwd` -cd $PTMP - -TMPPASS="$PTMP/cvspass" -echo ":pserver:cvsread@cvs.php.net:/repository phpfi" > $TMPPASS -export CVSPASS=$TMPPASS +if (isset($_ENV['TMPDIR'])) { + $tmp_dir = $_ENV['TMPDIR']; +} else { + $tmp_dir = '/tmp'; +} + +$ptmp = $tmp_dir . '/go-pear-' . $_ENV['USER'] . '-' . time(); + +rm_rf($ptmp); +mkdir_p($ptmp, 0700); +$origpwd = getcwd(); +chdir($ptmp); #### # Download #### -echo "Downloading files..." - -for i in $files; do - cvs -q -d :pserver:cvsread@cvs.php.net:/repository \ - export -D "now" "php4/pear$i" -done -pearin=php4/pear/scripts/pear.in -if [ ! -f $pearin ]; then - echo "Could not download the files from CVS" - exit 1 -fi -echo "done!" - -#### -# Copy files -#### - -/bin/cp -fR php4/pear/* $destdir < /dev/tty - -#### -# Set the right interpreter for the pear cmd -#### - -prefix=`echo $prefix | perl -pe 's#\/#\x5c\/#g;'` -cat $pearin | perl -pe "s#\@prefix@#$prefix#" > $TARGET -chmod +x $TARGET - -#### -# Install needed packages and finish the registration -#### - -PEAR="php -C -d include_path=$PTMP/php4/pear -f $TARGET -- " -$PEAR -D php_dir=$destdir -S -$PEAR install -r php4/pear/package-Archive_Tar.xml -$PEAR install -r php4/pear/package-Console_Getopt.xml -$PEAR install -r php4/pear/package-PEAR.xml -$PEAR install -s php4/pear/packages/XML_RPC-1.0.3.tar -if [ "$installall" != "n" ]; then - for i in "php4/pear/packages/*"; do - $PEAR install -s $i - done -fi - -#### -# Clean up and finish -#### - -cd $origpwd -rm -rf $PTMP +ini_set("include_path", $ptmp); -echo -echo "The 'pear' command has been successfully installed under $TARGET" -echo "try it by typing '$TARGET' for help" -echo +print 'Bootstrapping: PEAR...................'; +$url = 'http://cvs.php.net/co.php/php4/pear/PEAR.php?p=1'; +download_url($url, 'PEAR.php', $http_proxy); +include_once 'PEAR.php'; +print "ok\n"; + +print 'Bootstrapping: Archive_Tar............'; +$url = 'http://cvs.php.net/co.php/pear/Archive_Tar/Archive/Tar.php?p=1'; +mkdir('Archive', 0700); +download_url($url, 'Archive/Tar.php', $http_proxy); +print "ok\n"; + +print 'Bootstrapping: Console_Getopt.........'; +$url = 'http://cvs.php.net/co.php/php4/pear/Console/Getopt.php?p=1'; +mkdir('Console', 0700); +download_url($url, 'Console/Getopt.php', $http_proxy); +print "ok\n"; + +if (!extension_loaded('zlib')) { + if (WINDOWS) { + @dl('php_zlib.dll'); + } elseif (PHP_OS == 'HP-UX') { + @dl('zlib.sl'); + } elseif (PHP_OS == 'AIX') { + @dl('zlib.a'); + } else { + @dl('zlib.so'); + } +} +if (!extension_loaded('zlib')) { + $urltemplate = 'http://pear.php.net/get/%s?uncompress=yes'; + $have_gzip = false; +} else { + $urltemplate = 'http://pear.php.net/get/%s'; + $have_gzip = true; +} + +$installer_packages = array( + 'PEAR', + 'Archive_Tar', + 'Console_Getopt', + 'XML_RPC' + ); +$pfc_packages = array( + 'DB', + 'Mail_Mime', + 'XML_Parser', + ); +if ($install_pfc) { + $to_install = array_merge($installer_packages, $pfc_packages); +} else { + $to_install = $installer_packages; +} + +foreach ($to_install as $pkg) { + $msg = str_pad("Downloading package: $pkg", 38, '.'); + print $msg; + $url = sprintf($urltemplate, $pkg); + $tarball[$pkg] = download_url($url, null, $http_proxy); + print "ok\n"; +} + +PEAR::setErrorHandling(PEAR_ERROR_DIE, "\n%s\n"); +print 'Extracting installer..................'; +$dot = strrpos($tarball['PEAR'], '.'); +$pkg = substr($tarball['PEAR'], 0, $dot); +$ext = substr($tarball['PEAR'], $dot+1); + +include_once 'Archive/Tar.php'; +$tar = &new Archive_Tar($tarball['PEAR'], $have_gzip); +if (!$tar->extractModify($ptmp, $pkg)) { + bail("failed!\n"); +} +print "ok\n"; +$tarball['PEAR'] = 'package.xml'; // :-) + +include_once "./PEAR.php"; +include_once "./PEAR/Config.php"; +include_once "./PEAR/Command.php"; +include_once "./PEAR/Registry.php"; + +$config = &PEAR_Config::singleton(); +foreach ($config_vars as $var) { + $config->set($var, $$var); +} +$config->store(); + +$registry = new PEAR_Registry($php_dir); +PEAR_Command::setFrontendType('CLI'); +$install = &PEAR_Command::factory('install', $config); +$install_options = array( + 'nodeps' => true, + 'force' => true, + ); +foreach ($tarball as $pkg => $src) { + $options = $install_options; + if ($registry->packageExists($pkg)) { + $options['upgrade'] = true; + } + $install->run('install', $options, array($src)); +} + +ini_restore("include_path"); +$sep = WINDOWS ? ';' : ':'; +$include_path = explode($sep, ini_get('include_path')); +if (!in_array($php_dir, $include_path)) { + print " +****************************************************************************** +WARNING! The include_path defined in the currently used php.ini does not +contain the PEAR PHP directory you just configured. + +Current include path: ".ini_get('include_path')." +Configured directory: $php_dir +"; + if (WINDOWS) { + print " +Please look over your php.ini file to make sure +$php_dir is in your include_path."; + } else { + print " +I will add a workaround for this in the 'pear' command to make sure +the installer works, but please look over your php.ini or Apache +configuration to make sure $php_dir is in your include_path. +"; + } + print "\nPress Enter to continue: "; + fgets($tty, 1024); + if (!WINDOWS) { + print 'Fixing installer include_path.........'; + $pear_cmd = "$bin_dir/pear"; + $tmpfile = "$bin_dir/.tmp.pear"; + $fp = @fopen($pear_cmd, "r"); + $wp = @fopen($tmpfile, "w"); + if ($fp && $wp) { + $hashbang = rtrim(fgets($fp, 1024)) . + "d include_path=$php_dir\n"; + fwrite($wp, $hashbang); + while ($data = fread($fp, 2048)) { + fwrite($wp, $data); + } + fclose($fp); + fclose($wp); + $perms = fileperms($pear_cmd); + rename($tmpfile, $pear_cmd); + chmod($pear_cmd, $perms); + print "ok\n"; + } else { + print "failed\n"; + print "Make sure you update your php.ini!\n\n"; + } + } +} + +print " +The 'pear' command is now at your service. Try 'pear list' to see +what packages are installed, or 'pear help' for help. + +For more information about PEAR, please check these out: + + http://pear.php.net/faq.php + http://cvs.php.net/co.php/pearweb/doc/pear_package_manager.txt?p=1 + http://pear.php.net/manual/ + +Thanks for using go-pear! + +"; + +// {{{ download_url() + +function download_url($url, $destfile = null, $proxy = null) +{ + $use_suggested_filename = ($destfile === null); + if ($use_suggested_filename) { + $destfile = basename($url); + } + $tmp = parse_url($url); + if (empty($tmp['port'])) { + $tmp['port'] = 80; + } + if (empty($proxy)) { + $fp = fsockopen($tmp['host'], $tmp['port'], $errno, $errstr); + //print "\nconnecting to $tmp[host]:$tmp[port]\n"; + } else { + list($phost, $pport) = explode(":", $proxy); + $fp = fsockopen($phost, $pport, $errno, $errstr); + //print "\nconnecting to $phost:$pport\n"; + } + if (!$fp) { + bail("download of $url failed: $errstr ($errno)\n"); + } + if (empty($proxy)) { + $path = $tmp['path']; + } else { + $path = "http://$tmp[host]:$tmp[port]$tmp[path]"; + } + if (isset($tmp['query'])) { + $path .= "?$tmp[query]"; + } + if (isset($tmp['fragment'])) { + $path .= "#$tmp[fragment]"; + } + $request = "GET $path HTTP/1.0\r\nHost: $tmp[host]:$tmp[port]\r\n". + "User-Agent: go-pear\r\n\r\n"; + fwrite($fp, $request); + $cdh = "content-disposition:"; + $cdhl = strlen($cdh); + while ($line = fgets($fp, 2048)) { + if (trim($line) == '') { + break; + } + if ($use_suggested_filename && !strncasecmp($line, $cdh, $cdhl)) { + if (eregi('filename="([^"]+)"', $line, $matches)) { + $destfile = basename($matches[1]); + } + } + } + $wp = fopen($destfile, "w"); + if (!$wp) { + bail("could not open $destfile for writing\n"); + } + while ($data = fread($fp, 2048)) { + fwrite($wp, $data); + } + fclose($fp); + fclose($wp); + return $destfile; +} + +// }}} +// {{{ which() + +function which($program) +{ + $sep = WINDOWS ? ';' : ':'; + $dirs = explode($sep, $_ENV['PATH']); + if (WINDOWS) { + foreach ($dirs as $dir) { + $tmp = "$dir/$program"; + if (file_exists($ret = "$tmp.exe") || + file_exists($ret = "$tmp.com") || + file_exists($ret = "$tmp.bat") || + file_exists($ret = "$tmp.cmd")) { + return $ret; + } + } + } else { + foreach ($dirs as $dir) { + if (is_executable("$dir/$program")) { + return "$dir/$program"; + } + } + } + return null; +} + +// }}} +// {{{ bail() + +function bail($msg = '') +{ + global $ptmp; + if ($ptmp && is_dir($ptmp)) { + chdir('/'); + system("rm -rf $ptmp"); + } + if ($msg) { + die($msg); + } +} + +// }}} +// {{{ mkdir_p() + +function mkdir_p($dir, $mode = 0777) +{ + $lastdir = ''; + if (@is_dir($dir)) { + return true; + } + $parent = dirname($dir); + $parent_exists = (int)@is_dir($parent); + $ok = true; + if (!@is_dir($parent) && $parent != $dir) { + $ok = mkdir_p(dirname($dir), $mode); + } + if ($ok) { + $ok = @mkdir($dir, $mode); + if (!$ok) { + print "mkdir failed: $dir\n"; + } + } + return $ok; +} + +// }}} +// {{{ rm_rf() + +function rm_rf($path) +{ + if (@is_dir($path)) { + $dp = opendir($path); + while ($ent = readdir($dp)) { + if ($ent == '.' || $ent == '..') { + continue; + } + $file = $path . DIRECTORY_SEPARATOR . $ent; + if (@is_dir($file)) { + rm_rf($file); + } else { + unlink($file); + } + } + return rmdir($path); + } else { + return @unlink($path); + } +} -exit +// }}}