cvs: pearweb /public_html go-pear
| From: | Tomas V.V.Cox | Date: | Fri, 14 Jun 2002 13:56:31 +0000 |
| Subject: | cvs: pearweb /public_html go-pear | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-4616@lists.php.net to get a copy of this message | ||
cox Fri Jun 14 09:56:31 2002 EDT
Modified files:
/pearweb/public_html go-pear
Log:
- List the bundled packages in the cmd messages
- Added function my_env() which uses $_ENV or getenv() (in my system
PHP 4.2.1 both cgi/cli $_ENV is empty)
- Make the tmpdir creation OS independant
- Clean up tmpdir on successful end
Index: pearweb/public_html/go-pear
diff -u pearweb/public_html/go-pear:1.11 pearweb/public_html/go-pear:1.12
--- pearweb/public_html/go-pear:1.11 Fri Jun 14 05:26:38 2002
+++ pearweb/public_html/go-pear Fri Jun 14 09:56:31 2002
@@ -17,7 +17,7 @@
# | Stig Sæther Bakken <stig@php.net> |
# +----------------------------------------------------------------------+
#
-# $Id: go-pear,v 1.11 2002/06/14 09:26:38 ssb Exp $
+# $Id: go-pear,v 1.12 2002/06/14 13:56:31 cox Exp $
#
# Automatically download all the files needed to run the "pear" command
# (the PEAR package installer)
@@ -84,13 +84,25 @@
$tty = fopen("/dev/tty", "r");
}
+$installer_packages = array(
+ 'PEAR',
+ 'Archive_Tar',
+ 'Console_Getopt',
+ 'XML_RPC'
+ );
+$pfc_packages = array(
+ 'DB',
+ 'Mail',
+ 'XML_Parser',
+ );
+
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.
+with PHP: " . implode(', ', $pfc_packages) . ".
If you wish to abort, press Control-C now, or press Enter to continue: ";
@@ -98,24 +110,26 @@
print "\n";
-if (isset($_ENV['HTTP_PROXY'])) {
- $http_proxy = $_ENV['HTTP_PROXY'];
-} elseif (isset($_ENV['http_proxy'])) {
- $http_proxy = $_ENV['http_proxy'];
+if (my_env('HTTP_PROXY')) {
+ $http_proxy = my_env('HTTP_PROXY');
+} elseif (my_env('http_proxy')) {
+ $http_proxy = my_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';
+$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';
+$origpwd = getcwd();
+
register_shutdown_function('bail');
-if (isset($_ENV['_'])) {
- $php = $_ENV['_'];
+if (my_env('_')) {
+ $php = my_env('_');
} else {
$php = which('php');
}
@@ -127,7 +141,7 @@
# User configurable options
####
-print "HTTP proxy (host:port), or Enter for none";
+print 'HTTP proxy (host:port), or Enter for none';
if (!empty($http_proxy)) {
print " [$http_proxy]";
}
@@ -210,7 +224,8 @@
}
print "
-Do you want to install the PEAR packages bundled with PHP? [Y/n] : ";
+Do you want to install the PEAR packages bundled with PHP?
+This packages are: " . implode(', ', $pfc_packages) . ". [Y/n] : ";
$install_pfc = !stristr(fgets($tty, 1024), "n");
print "\n";
@@ -218,17 +233,10 @@
# Temp stuff
####
-if (isset($_ENV['TMPDIR'])) {
- $tmp_dir = $_ENV['TMPDIR'];
-} else {
- $tmp_dir = '/tmp';
-}
-
-$ptmp = $tmp_dir . '/go-pear-' . $_ENV['USER'] . '-' . time();
+$ptmp = tempnam(tmp_dir(), 'gope');
rm_rf($ptmp);
mkdir_p($ptmp, 0700);
-$origpwd = getcwd();
chdir($ptmp);
####
@@ -274,17 +282,6 @@
$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 {
@@ -371,8 +368,7 @@
$fp = @fopen($pear_cmd, "r");
$wp = @fopen($tmpfile, "w");
if ($fp && $wp) {
- $hashbang = rtrim(fgets($fp, 1024)) .
- "d include_path=$php_dir\n";
+ $hashbang = rtrim(fgets($fp, 1024)) . "d include_path=$php_dir\n";
fwrite($wp, $hashbang);
while ($data = fread($fp, 2048)) {
fwrite($wp, $data);
@@ -390,6 +386,8 @@
}
}
+bail();
+
print "
The 'pear' command is now at your service. Try 'pear list' to see
what packages are installed, or 'pear help' for help.
@@ -471,7 +469,7 @@
function which($program)
{
$sep = WINDOWS ? ';' : ':';
- $dirs = explode($sep, $_ENV['PATH']);
+ $dirs = explode($sep, my_env('PATH'));
if (WINDOWS) {
foreach ($dirs as $dir) {
$tmp = "$dir/$program";
@@ -497,10 +495,10 @@
function bail($msg = '')
{
- global $ptmp;
+ global $ptmp, $origpwd;
if ($ptmp && is_dir($ptmp)) {
- chdir('/');
- system("rm -rf $ptmp");
+ chdir($origpwd);
+ rm_rf($ptmp);
}
if ($msg) {
die($msg);
@@ -556,3 +554,40 @@
}
// }}}
+// {{{ tmpdir()
+
+function tmp_dir()
+{
+ if (WINDOWS){
+ if (my_env('TEMP')) {
+ return my_env('TEMP');
+ }
+ if (my_env('TMP')) {
+ return my_env('TMP');
+ }
+ if (my_env('windir')) {
+ return my_env('windir') . '\temp';
+ }
+ return my_env('SystemRoot') . '\temp';
+ }
+ if (my_env('TMPDIR')) {
+ return my_env('TMPDIR');
+ }
+ return '/tmp';
+}
+
+// }}}
+// {{{ my_env()
+/*
+(cox) In my system PHP 4.2.1 (both cgi & cli) $_ENV is empty
+ but getenv() does work fine
+*/
+function my_env($var)
+{
+ if (is_array($_ENV) && isset($_ENV[$var])) {
+ return $_ENV[$var];
+ }
+ return getenv($var);
+}
+
+// }}}
\ No newline at end of file