script to copy pear package dependencies
[bdrem.git] / bin / fetch-deps.php
1 #!/usr/bin/env php
2 <?php
3 /**
4  * reads pear package dependencies from deps.txt and copies them into lib/
5  */
6 $deps = file(__DIR__ . '/../deps.txt');
7 $libdir = __DIR__ . '/../lib/';
8
9 error_reporting(error_reporting() & ~E_STRICT & ~E_DEPRECATED);
10 require_once 'PEAR/Registry.php';
11 $reg = new PEAR_Registry();
12
13 foreach ($deps as $dep) {
14     $dep = trim($dep);
15     list($channel, $pkgname) = explode('/', $dep);
16     $pkginfo = $reg->packageInfo($pkgname, null, $channel);
17     if ($pkginfo === null) {
18         echo 'Package not found: ' . $dep . "\n";
19         exit(1);
20     }
21
22     echo "Copying " . $channel . '/' . $pkgname . "\n";
23     $files = 0;
24     foreach ($pkginfo['filelist'] as $fileinfo) {
25         if ($fileinfo['role'] != 'php') {
26             continue;
27         }
28
29         $orig = $fileinfo['installed_as'];
30         $path = $libdir . ltrim(
31             $fileinfo['baseinstalldir'] . '/' . $fileinfo['name'], '/'
32         );
33         $dir = dirname($path);
34         if (!is_dir($dir)) {
35             mkdir($dir, 0777, true);
36         }
37         if (!copy($orig, $path)) {
38             echo " Error copying $orig to $path\n";
39             exit(2);
40         }
41         ++$files;
42     }
43     echo " copied $files files\n";
44 }
45 ?>