-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgo-pear.php
2721 lines (2409 loc) · 87 KB
/
go-pear.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php //; echo; echo "YOU NEED TO RUN THIS SCRIPT WITH PHP!"; echo; echo "Point your webbrowser to it or run: php -q go-pear.php"; echo; exit # -*- PHP -*-
#
# The PEAR installation wizard, both webbased or command line.
#
# Webbased installation:
# 1) Download this file and save it as go-pear.php
# 2) Put go-pear.php on your webserver, where you would put your website
# 3) Open http://yourdomain.example.org/go-pear.php in your browser
# 4) Follow the instructions, done!
#
# Command-line installation (for advanced users):
# 1) Download this file and save it as go-pear.php
# 2) Open a terminal/command prompt and type: php -q go-pear.php
# 3) Follow the instructions, done!
#
# Notes:
# * Get the latest go-pear version from http://pear.php.net/go-pear
# * This installer requires PHP 4.3.0 or newer.
# * On windows, the PHP CLI binary is php.exe, don't forget the -q option if using the CGI binary.
# * The default for the command-line installation is a system-wide configuration file, For a local install use: php -q go-pear.php local
/**
* go-pear is the online PEAR installer: just download it and run it
* (through a browser or command line), it will set up a minimal PEAR
* installation that will be ready for immediate use.
*
* @license http://www.php.net/license/2_02.txt PHP License 2.02
* @version CVS: $Id$
* @link http://pear.php.net/package/pearweb_gopear
* @author Tomas V.V.Cox <[email protected]>
* @author Stig Bakken <[email protected]>
* @author Christian Dickmann <[email protected]>
* @author Pierre-Alain Joye <[email protected]>
* @author Greg Beaver <[email protected]>
* @author Tias Guns <[email protected]>
*/
$sapi_name = php_sapi_name();
$safe_mode = (bool)ini_get('safe_mode');
if (!$safe_mode) {
set_time_limit(0);
}
@ob_end_clean();
ob_implicit_flush(true);
define('WEBINSTALLER', ($sapi_name != 'cli' && !(substr($sapi_name,0,3)=='cgi' && !isset($_SERVER['GATEWAY_INTERFACE']))));
ini_set('track_errors', true);
ini_set('html_errors', WEBINSTALLER);
ini_set('magic_quotes_runtime', false);
error_reporting( E_ALL & ~E_NOTICE);
define('WINDOWS', (substr(PHP_OS, 0, 3) == 'WIN'));
define('GO_PEAR_VER', '1.1.6');
define('WIN32GUI', !WEBINSTALLER && WINDOWS && $sapi_name=='cli' && which('cscript'));
/*
* See bug #23069
*/
if ( WEBINSTALLER && WINDOWS ) {
$php_sapi_name = win32DetectPHPSAPI();
if($php_sapi_name=='cgi'){
$msg = nl2br("
Sorry! The PEAR installer actually does not work on Windows platform
using CGI and Apache. Please install the module SAPI (see
http://www.php.net/manual/en/install.apache.php for the instructions) or
use the CLI (cli\php.exe) in the console.
");
displayHTML('error', $msg);
}
}
if (WEBINSTALLER && isset($_GET['action']) && $_GET['action'] == 'img' && isset($_GET['img'])) {
switch ($_GET['img'])
{
case 'note':
case 'pearlogo':
case 'smallpear':
showImage($_GET['img']);
exit;
default:
exit;
};
}
// Check if PHP version is sufficient
$phpVersion = phpversion();
if (function_exists("version_compare") && version_compare($phpVersion, "4.4",'<')) {
die("Sorry! Your PHP version is too old. PEAR and this script requires at
least PHP 4.4.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.4.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.
");
} elseif (!WEBINSTALLER && function_exists("version_compare") && version_compare($phpVersion, "5.1.6",'>=')) {
die("Sorry! Your PHP version is too new ($phpVersion) for this go-pear.
Instead use http://pear.php.net/go-pear.phar for a more stable and current
version of go-pear, more suited to your PHP version.
Thank you for your coopertion and sorry for the inconvenience!
");
}
$gopear_bundle_dir = dirname(__FILE__).'/go-pear-bundle';
$bootstrap_files = array(
'PEAR5.php' => 'https://raw.githubusercontent.com/pear/pear-core/master/PEAR5.php',
'PEAR.php' => 'https://raw.githubusercontent.com/pear/pear-core/master/PEAR.php',
'Archive/Tar.php' => 'https://raw.githubusercontent.com/pear/Archive_Tar/master/Archive/Tar.php',
'Console/Getopt.php' => 'https://raw.githubusercontent.com/pear/Console_Getopt/master/Console/Getopt.php'
);
$bootstrap_pkgs = array( // uses URL like http://pear.php.net/get/%s
'PEAR',
'Structures_Graph'
);
$installer_packages = array(
'PEAR',
'Structures_Graph-stable',
'Archive_Tar-stable',
'Console_Getopt-stable',
);
$pfc_packages = array(
'PEAR_Frontend_Web-beta' => 'Webbased PEAR Installer',
'PEAR_Frontend_Gtk2' => 'Graphical PEAR installer based on PHP-Gtk2',
'MDB2' => 'database abstraction layer.',
);
$config_desc = array(
'prefix' => 'Installation prefix ($prefix)',
'temp_dir' => 'Temporary files directory',
'bin_dir' => 'Binaries directory',
'php_dir' => 'PHP code directory ($php_dir)',
'doc_dir' => 'Documentation base directory',
'data_dir' => 'Data base directory',
'test_dir' => 'Tests base directory',
);
if(!WEBINSTALLER && WINDOWS){
$config_desc['php_bin'] = 'php.exe path';
}
if (WEBINSTALLER) {
$config_desc['cache_dir'] = 'PEAR Installer cache directory';
$config_desc['cache_ttl'] = 'Cache TimeToLive';
$config_desc['webfrontend_file'] = 'Filename of WebFrontend';
$config_desc['php_bin'] = "php.exe path, optional (CLI command tools)";
}
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 = '';
}
register_shutdown_function('bail');
detect_install_dirs();
if (WEBINSTALLER) {
@session_start();
// If welcome, just welcome
if (!isset($_GET['step'])) {
$_GET['step'] = 'Welcome';
/* clean up old sessions datas */
session_destroy();
}
if ($_GET['step'] == 'Welcome') {
displayHTML('Welcome');
exit();
}
if (!isset($_SESSION['go-pear']) || isset($_GET['restart'])) {
$_SESSION['go-pear'] = array(
'http_proxy' => $http_proxy,
'config' => array(
'prefix' => dirname(__FILE__),
'bin_dir' => $bin_dir,
'php_bin' => $php_bin,
'php_dir' => '$prefix/PEAR',
'doc_dir' => $doc_dir,
'data_dir' => $data_dir,
'test_dir' => $test_dir,
'temp_dir' => '$prefix/temp',
'cache_dir' => '$php_dir/cache',
'cache_ttl' => 300,
'webfrontend_file' => '$prefix/index.php',
),
'install_pfc' => true,
'install_optional_packages' => array(),
'DHTML' => true,
);
}
// save submited values
if ($_GET['step'] == 'install') {
$_SESSION['go-pear']['http_proxy'] = strip_magic_quotes($_POST['proxy']['host']).':'.strip_magic_quotes($_POST['proxy']['port']);
if ($_SESSION['go-pear']['http_proxy'] == ':') {
$_SESSION['go-pear']['http_proxy'] = '';
};
$config_errors = array();
foreach($_POST['config'] as $key => $value) {
$_POST['config'][$key] = strip_magic_quotes($value);
if ($key != 'cache_ttl' && $key != 'php_bin') {
if ( empty($_POST['config'][$key]) ) {
$config_errors[$key] = 'Please fill this path, you can use $prefix, $php_dir or a full path.';
}
}
}
if( sizeof($config_errors)>0){
$_GET['step'] = 'config';
}
$_SESSION['go-pear']['config'] = $_POST['config'];
$_SESSION['go-pear']['install_pfc'] = (isset($_POST['install_pfc']) && $_POST['install_pfc'] == 'on');
// webinstaller allows to choose pfc packages individually
foreach ($pfc_packages as $key => $value) {
$pos = array_search($key, $_SESSION['go-pear']['install_optional_packages']);
if (isset($_POST[$key]) && $_POST[$key] == 'on' && $pos === false) {
$_SESSION['go-pear']['install_optional_packages'][] = $key;
}
if (!isset($_POST[$key]) && $pos !== false) {
unset($_SESSION['go-pear']['install_optional_packages'][$pos]);
}
}
$_SESSION['go-pear']['DHTML'] = isset($_POST['BCmode']) ? false : true;
}
// export session values
$http_proxy = $_SESSION['go-pear']['http_proxy'];
$GLOBALS['config_vars'] = array_keys($config_desc);
array_unshift($GLOBALS['config_vars'], '');
unset($GLOBALS['config_vars'][0]); // make indices run from 1...
foreach($_SESSION['go-pear']['config'] as $var => $value) {
$$var = $value;
}
$install_pfc = $_SESSION['go-pear']['install_pfc'];
$install_optional_packages = $_SESSION['go-pear']['install_optional_packages'];
if ($_GET['step'] == 'config') {
displayHTML('config');
exit();
}
// Anything past this step has something to do with the installation
}
if (!WEBINSTALLER) {
$tty = WINDOWS ? @fopen('\con', 'r') : @fopen('/dev/tty', 'r');
if (!$tty) {
$tty = fopen('php://stdin', 'r');
}
$local = isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'local';
if ($local) {
$local = "
Running in local install mode
";
} elseif (WINDOWS) {
$local = "
Use 'php " . $_SERVER['argv'][0] . " local' to install a local copy of PEAR.
";
}
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.
$local
Go-pear also lets you download and install the following optional PEAR
packages: " . implode(', ', array_keys($pfc_packages)) . ".
If you wish to abort, press Control-C now, or press Enter to continue: ";
fgets($tty, 1024);
print "\n";
print "HTTP proxy (http://user:[email protected]:port), or Enter for none:";
if (!empty($http_proxy)) {
print " [$http_proxy]";
}
print ": ";
$tmp = trim(fgets($tty, 1024));
if (!empty($tmp)) {
$http_proxy = $tmp;
}
}
$origpwd = getcwd();
$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);
$progress = 0;
/*
* Checks PHP SAPI version under windows/CLI
*/
if( WINDOWS && !WEBINSTALLER && $php_bin=='') {
print "
We do not find any php.exe, please select the php.exe folder (CLI is
recommanded, usually in c:\php\cli\php.exe)
";
$php_bin_set = false;
} elseif ( WINDOWS && !WEBINSTALLER && strlen($php_bin) ) {
$php_bin_sapi = win32DetectPHPSAPI();
$php_bin_set = true;
switch($php_bin_sapi){
case 'cli':
break;
case 'cgi':
print "
*NOTICE*
We found php.exe under $php_bin, it uses a $php_bin_sapi SAPI. PEAR commandline
tool works well with it, if you have a CLI php.exe available, we
recommand to use it.
";
break;
default:
print "
*WARNING*
We found php.exe under $php_bin, it uses an unknown SAPI. PEAR commandline
tool has not been tested with it, if you have a CLI (or CGI) php.exe available,
we strongly recommand to use it.
";
break;
}
}
while (!WEBINSTALLER) {
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) ) {
if( WINDOWS && !$php_bin_set ){
echo "**ERROR**
Please, enter the php.exe path.
";
} else {
break;
}
}
if (isset($config_vars[(int)$tmp])) {
$var = $config_vars[(int)$tmp];
$desc = $config_desc[$var];
$current = $$var;
if(WIN32GUI){
$tmp = win32BrowseForFolder("$desc [$current] :");
} else {
print "$desc [$current] : ";
$tmp = trim(fgets($tty, 1024));
}
$old = $$var;
if(WINDOWS && $var=='php_bin' ){
if(file_exists($tmp.DIRECTORY_SEPARATOR.'php.exe')){
$tmp = $tmp.DIRECTORY_SEPARATOR.'php.exe';
$php_bin_sapi = win32DetectPHPSAPI();
if($php_bin_sapi=='cgi'){
print "
******************************************************************************
NOTICE! We found php.exe under $php_bin, it uses a $php_bin_sapi SAPI.
PEAR commandline tool works well with it.
If you have a CLI php.exe available, we recommand to use it.
";
} elseif ($php_bin_sapi=='unknown') {
print "
******************************************************************************
WARNING! We found php.exe under $php_bin, it uses an $php_bin_sapi SAPI.
PEAR commandline tool has not been tested with it.
If you have a CLI (or CGI) php.exe available, we strongly recommand to use it.
";
}
echo "php.exe (sapi: $php_bin_sapi) found.\n\n";
$php_bin_set = true;
} else {
echo "**ERROR**: no php.exe found in this folder.\n";
$tmp='';
}
}
if (!empty($tmp) ) {
$$var = parse_dirname($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;
}
}
}
}
####
# Installation stuff
####
// expand all subvars in the config vars
foreach ($config_vars as $n => $var) {
for ($m = 1; $m <= count($config_vars); $m++) {
$var2 = $config_vars[$m];
$$var = str_replace('$'.$var2, $$var2, $$var);
}
$$var = parse_dirname($$var);
}
// temp dir stuff (separate for windows bugs)
if (!empty($temp_dir)) {
$_found = temp_dir($temp_dir);
} else {
$_found = temp_dir();
}
if (!$_found) {
if (!WEBINSTALLER) {
print "
******************************************************************************
FATAL ERROR! We cannot initialize the temp directory. Please be sure to give
full write access to this directory and the install directory.
";
if (!empty($temp_dir)) {
print "'$temp_dir' was given.";
}
exit();
} else { // WEBINSTALLER
if (!is_dir($temp_dir)) {
$config_errors['temp_dir'] = 'FATAL ERROR! This directory does not exist and we can not create it. Create the directory manually or make sure we have full permission in its parent directory.';
if (!WINDOWS) {
$config_errors['temp_dir'] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
<tt>mkdir '.dirname($temp_dir).' && chmod 0777 '.dirname($temp_dir).'</tt></p>';
}
} else { // is_dir(temp_dir)
$config_errors['temp_dir'] = 'FATAL ERROR! This directory exists, but we have no write permission in it.';
if (!WINDOWS) {
$config_errors['temp_dir'] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
<tt>chmod 0777 '.$temp_dir.'</tt></p>';
}
}
}
}
if (@is_dir($ptmp)) {
chdir($ptmp);
}
// check every dir, existence and permissions
foreach ($config_vars as $var) {
if (!preg_match('/_dir$/', $var) || $var == 'temp_dir') {
continue;
}
$dir = $$var;
if (!@is_dir($dir)) {
if (!mkdir_p($dir)) {
if (!WEBINSTALLER) {
$root = WINDOWS ? 'administrator' : 'root';
bail("Unable to create {$config_desc[$var]} $dir.
Run this script as $root or pick another location.\n");
} else { // WEBINSTALLER
$config_errors[$var] = 'ERROR! This directory does not exist and we can not create it. Create the directory manually or make sure we have full permission in its parent directory.';
if (!WINDOWS) {
$config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
<tt>mkdir '.dirname($dir).' && chmod 0777 '.dirname($dir).'</tt></p>';
}
}
}
}
if (WEBINSTALLER && @is_dir($dir) && !is_writable($dir)) {
$config_errors[$var] = 'ERROR! This directory exists, but we have no write permission in it.';
if (!WINDOWS) {
$config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
<tt>chmod 0777 '.$dir.'</tt></p>';
}
}
}
// check every file, existence and permissions
foreach ($config_vars as $var) {
if (!preg_match('/_file$/', $var)) {
continue;
}
$file = $$var;
$dir = dirname($file);
if (!file_exists($file) && !is_writable($dir)) {
if (!WEBINSTALLER) {
$root = WINDOWS ? 'administrator' : 'root';
bail("Unable to create {$config_desc[$var]} $file.
Run this script as $root or pick another location.\n");
} else { // WEBINSTALLER
$config_errors[$var] = 'ERROR! This file does not exist and we can not create it. Make sure we have full permission in its parent directory.';
if (!WINDOWS) {
$config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
<tt>chmod 0777 '.$dir.'</tt></p>';
}
}
} elseif (WEBINSTALLER && file_exists($file) && !is_writable($file)) {
$config_errors[$var] = 'ERROR! This file exists, but we have no write permission on it.';
if (!WINDOWS) {
$config_errors[$var] .= '<p>You can grant this permission by logging on to the server and issuing the following command:<br />
<tt>chmod 0777 '.$file.'</tt></p>';
}
}
}
if (WEBINSTALLER) {
if ( isset($config_errors) && sizeof($config_errors) ) {
displayHTML('config');
exit();
} else {
if (isset($_SESSION['go-pear']['DHTML']) && $_SESSION['go-pear']['DHTML'] == true && $_GET['step'] == 'install') {
$_GET['step'] = 'preinstall';
}
if ($_GET['step'] != 'install' && $_GET['step'] != 'install-progress') {
displayHTML($_GET['step']);
exit;
}
if ($_GET['step'] == 'install-progress') {
displayHTMLHeader();
echo "Starting installation ...<br/>";
}
ob_start();
}
}
if (!WEBINSTALLER) {
$msg = "The following PEAR packages are bundled with PHP: " .
implode(', ', array_keys($pfc_packages));
print "\n" . wordwrap($msg, 75) . ".\n";
print "Would you like to install these as well? [Y/n] : ";
$install_pfc = !stristr(fgets($tty, 1024), "n");
$install_optional_packages = array();
print "\n";
}
####
# Download
####
if (function_exists('set_include_path')) {
set_include_path($ptmp);
} else {
ini_set('include_path', $ptmp);
}
if (!extension_loaded('zlib') && !WEBINSTALLER) { // In Web context we could be in multithread env which makes dl() end up with a fatal error.
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 = null;
} else {
$urltemplate = 'http://pear.php.net/get/%s';
$have_gzip = true;
}
print "Loading zlib: ".($have_gzip ? 'ok' : 'failed')."\n";
if (!$have_gzip) {
print "Downloading uncompressed packages\n";
};
if ($install_pfc) {
$to_install = array_merge($installer_packages, array_keys($pfc_packages));
} else {
$to_install = $installer_packages;
// webinstaller allows to choose pfc packages individually
foreach ($pfc_packages as $pkg => $desc) {
if (in_array($pkg, $install_optional_packages)) {
array_push($to_install, $pkg);
}
}
}
// gopear_bundle usage
$local_dir = array();
if (file_exists($gopear_bundle_dir) || is_dir($gopear_bundle_dir)) {
$dh = @opendir($gopear_bundle_dir);
while($file = @readdir($dh)) {
if ($file == '.' || $file == '..' || !is_file($gopear_bundle_dir.'/'.$file)) {
continue;
}
$_pos = strpos($file, '-');
if ($_pos === false) {
$local_dir[$file] = $file;
} else {
$local_dir[substr($file, 0, $_pos)] = $file;
}
}
closedir($dh);
unset($dh, $file, $_pos);
}
print "\n".'Bootstrapping Installer...................'."\n";
displayHTMLProgress($progress = 5);
// Bootstrap needed ?
$nobootstrap = false;
if (is_dir($php_dir)) {
$nobootstrap = true;
foreach ($bootstrap_files as $file => $url) {
$nobootstrap &= is_file($php_dir.'/'.$file);
}
}
if ($nobootstrap) {
print('Using previously install ... ');
if (function_exists('set_include_path')) {
set_include_path($php_dir);
} else {
ini_set('include_path', $php_dir);
}
include_once 'PEAR.php';
print "ok\n";
} else {
foreach($bootstrap_files as $name => $url) {
$file = basename($name);
$dir = dirname($name);
print 'Bootstrapping '.$name.'............';
displayHTMLProgress($progress += round(14 / count($bootstrap_files)));
if ($dir != '' && $dir != '.') {
mkdir($dir, 0700);
}
if (in_array($file, $local_dir)) {
copy($gopear_bundle_dir.'/'.$file, $name);
echo '(local) ';
} else {
download_url($url, $name, $http_proxy);
echo '(remote) ';
}
include_once $name;
print "ok\n";
}
}
unset($nobootstrap, $file, $url, $name, $dir);
PEAR::setErrorHandling(PEAR_ERROR_DIE, "\n%s\n");
print "\n".'Extracting installer..................'."\n";
displayHTMLProgress($progress = 20);
// Extract needed ?
$noextract = false;
if (is_dir($php_dir)) {
$noextract = @include_once 'PEAR/Registry.php';
if ($noextract) {
$registry = new PEAR_Registry($php_dir);
foreach ($bootstrap_pkgs as $pkg) {
$noextract &= $registry->packageExists($pkg);
}
}
}
if ($noextract) {
print('Using previously installed installer ... ');
print "ok\n";
} else {
$bootstrap_pkgs_tarballs = array();
foreach ($bootstrap_pkgs as $pkg) {
$tarball = null;
if (isset($local_dir[$pkg])) {
echo str_pad("Using local package: $pkg", max(38,21+strlen($pkg)+4), '.');
copy($gopear_bundle_dir.'/'.$local_dir[$pkg], $local_dir[$pkg]);
$tarball = $local_dir[$pkg];
} else {
print str_pad("Downloading package: $pkg", max(38,21+strlen($pkg)+4), '.');
$url = sprintf($urltemplate, $pkg);
$pkg = str_replace('-stable', '', $pkg);
$tarball = download_url($url, null, $http_proxy);
}
displayHTMLProgress($progress += round(19 / count($bootstrap_pkgs)));
$fullpkg = substr($tarball, 0, strrpos($tarball, '.'));
$tar = new Archive_Tar($tarball, $have_gzip);
if (!$tar->extractModify($ptmp, $fullpkg)) {
bail("Extraction for $fullpkg failed!\n");
}
$bootstrap_pkgs_tarballs[$pkg] = $tarball;
print "ok\n";
}
}
unset($noextract, $registry, $pkg, $tarball, $url, $fullpkg, $tar);
print "\n".'Preparing installer..................'."\n";
displayHTMLProgress($progress = 40);
// Default for sig_bin
putenv('PHP_PEAR_SIG_BIN=""');
// Default for sig_keydir
putenv('PHP_PEAR_SIG_KEYDIR=""');
putenv('PHP_PEAR_DOWNLOAD_DIR=' . $temp_dir . '/download');
putenv('PHP_PEAR_TEMP_DIR=' . $temp_dir);
include_once "PEAR/Config.php";
include_once "PEAR/Command.php";
include_once "PEAR/Registry.php";
if (WEBINSTALLER || isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'local') {
$config = &PEAR_Config::singleton($prefix."/pear.conf", '');
} else {
$config = &PEAR_Config::singleton();
}
$config->set('preferred_state', 'stable');
foreach ($config_vars as $var) {
if (isset($$var) && $$var != '') {
$config->set($var, $$var);
}
}
$config->set('download_dir', $temp_dir . '/download');
$config->set('temp_dir', $temp_dir);
$config->set('http_proxy', $http_proxy);
$config->store();
$registry = new PEAR_Registry($php_dir);
PEAR_Command::setFrontendType('CLI');
PEAR::staticPushErrorHandling(PEAR_ERROR_DIE); //fail silently
$ch_cmd = &PEAR_Command::factory('update-channels', $config);
$ch_cmd->run('update-channels', $options, array());
PEAR::staticPopErrorHandling(); // reset error handling
unset($ch_cmd);
print "\n".'Installing selected packages..................'."\n";
displayHTMLProgress($progress = 45);
$install = &PEAR_Command::factory('install', $config);
foreach ($to_install as $pkg) {
$pkg_basename = substr($pkg, 0, strpos($pkg, '-'));
if (in_array($pkg, $installer_packages)) {
$options = array('nodeps' => true);
} else {
$options = array('onlyreqdeps' => true);
}
if ($registry->packageExists($pkg) || $registry->packageExists($pkg_basename)) {
print(str_pad("Package: $pkg", max(50,9+strlen($pkg)+4), '.').' already installed ... ok'."\n");
displayHTMLProgress($progress += round(50 / count($to_install)));
continue;
}
$pkg_basename = substr($pkg, 0, strpos($pkg, '-'));
if (in_array($pkg_basename, $bootstrap_pkgs)) {
print(str_pad("Installing bootstrap package: $pkg_basename", max(50,30+strlen($pkg_basename)+4), '.')."...");
displayHTMLProgress($progress += round(25 / count($to_install)));
$install->run('install', $options, array($bootstrap_pkgs_tarballs[$pkg_basename]));
} elseif (isset($local_dir[$pkg_basename])) {
print(str_pad("Installing local package: $pkg", max(50,26+strlen($pkg)+4), '.')."...");
displayHTMLProgress($progress += round(25 / count($to_install)));
$install->run('install', $options, array($gopear_bundle_dir.'/'.$local_dir[$pkg_basename]));
} else { // no local copy
print(str_pad("Downloading and installing package: $pkg", max(50,36+strlen($pkg)+4), '.')."...");
displayHTMLProgress($progress += round(25 / count($to_install)));
$install->run('install', $options, array($pkg));
}
displayHTMLProgress($progress += round(25 / count($to_install)));
}
unset($pkg, $pkg_basename, $options, $bootstrap_pkgs_tarballs);
/* TODO: Memory exhaustion in webinstaller : / (8Mb)
print "\n".'Making sure every package is at the latest version........';
$install->run('upgrade-all', array('soft' => true), array());
print "ok\n";
*/
unset($config, $registry, $install);
displayHTMLProgress($progress = 99);
// Base installation finished
ini_restore("include_path");
if (!WEBINSTALLER) {
$sep = WINDOWS ? ';' : ':';
$include_path = explode($sep, ini_get('include_path'));
if (WINDOWS) {
$found = false;
$t = strtolower($php_dir);
foreach($include_path as $path) {
if ($t==strtolower($path)) {
$found = true;
break;
}
}
} else {
$found = in_array($php_dir, $include_path);
}
if (!$found) {
print "
******************************************************************************
WARNING! The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:
<$php_dir>
If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.
";
if ( $php_ini = getPhpiniPath() ) {
print "\n\nWould you like to alter php.ini <$php_ini>? [Y/n] : ";
$alter_phpini = !stristr(fgets($tty, 1024), "n");
if( $alter_phpini ) {
alterPhpIni($php_ini);
} else {
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 "
Current include path : ".ini_get('include_path')."
Configured directory : $php_dir
Currently used php.ini (guess) : $php_ini
";
print "Press Enter to continue: ";
fgets($tty, 1024);
}
$pear_cmd = $bin_dir . DIRECTORY_SEPARATOR . 'pear';
$pear_cmd = WINDOWS ? strtolower($pear_cmd).'.bat' : $pear_cmd;
// check that the installed pear and the one in tha path are the same (if any)
$pear_old = which(WINDOWS ? 'pear.bat' : 'pear', $bin_dir);
if ($pear_old && ($pear_old != $pear_cmd)) {
// check if it is a link or symlink
$islink = WINDOWS ? false : is_link($pear_old) ;
if ($islink && readlink($pear_old) != $pear_cmd) {
print "\n** WARNING! The link $pear_old does not point to the " .
"installed $pear_cmd\n";
} elseif (is_writable($pear_old) && !is_dir($pear_old)) {
rename($pear_old, "{$pear_old}_old");
print "\n** WARNING! Backed up old pear to {$pear_old}_old\n";
} else {
print "\n** WARNING! Old version found at $pear_old, please remove it or ".
"be sure to use the new $pear_cmd command\n";
}
}
print "\nThe 'pear' command is now at your service at $pear_cmd\n";
// Alert the user if the pear cmd is not in PATH
$old_dir = $pear_old ? dirname($pear_old) : false;
if (!which('pear', $old_dir)) {
print "
** The 'pear' command is not currently in your PATH, so you need to
** use '$pear_cmd' until you have added
** '$bin_dir' to your PATH environment variable.
";
print "Run it without parameters to see the available actions, try 'pear list'
to see what packages are installed, or 'pear help' for help.
For more information about PEAR, see:
http://pear.php.net/faq.php
http://pear.php.net/manual/
Thanks for using go-pear!
";
}
}
if (WEBINSTALLER) {
print "\n".'Writing WebFrontend file ... ';
@unlink($webfrontend_file); //Delete old one
copy ( $doc_dir.DIRECTORY_SEPARATOR.
'PEAR_Frontend_Web'.DIRECTORY_SEPARATOR.
'docs'.DIRECTORY_SEPARATOR.
'index.php.txt',
$webfrontend_file
);
print "ok\n";
if (!file_str_replace($webfrontend_file, '@pear_dir@', $GLOBALS['php_dir'])) {
print "You need to replace @pear_dir@ with the actual /path/to/PEAR/ in index.php\n";
}
if ($_GET['step'] == 'install-progress') {
displayHTMLProgress($progress = 100);
ob_end_clean();
displayHTMLInstallationSummary();
displayHTMLFooter();
} else {
$out = ob_get_contents();
$out = explode("\n", $out);
foreach($out as $line => $value) {
if (preg_match('/ok$/', $value)) {
$value = preg_replace('/(ok)$/', '<span class="green">\1</span>', $value);
};
if (preg_match('/^install ok:/', $value)) {
$value = preg_replace('/^(install ok:)/', '<span class="green">\1</span>', $value);
};
if (preg_match('/^Warning:/', $value)) {
$value = '<span style="color: #ff0000">'.$value.'</span>';
};
$out[$line] = $value;
};
$out = nl2br(implode("\n",$out));
ob_end_clean();
displayHTML('install', $out);
}
// Little hack, this will be fixed in PEAR later
if ( WINDOWS ) {
clearstatcache();
@unlink($bin_dir.DIRECTORY_SEPARATOR.'.tmppear');
}
exit;
}
// Little hack, this will be fixed in PEAR later
if ( WINDOWS ) {
clearstatcache();
@unlink($bin_dir.DIRECTORY_SEPARATOR.'.tmppear');
}
if (WINDOWS && !WEBINSTALLER) {
win32CreateRegEnv();
}
// Set of functions following
/**
* Parse the given dirname
* eg. expands '~' etc