summarylogtreecommitdiffstats
path: root/pear-config-patcher.php
blob: 3c724c2e196e420cd5f7b2d4741bef0048dff1d3 (plain)
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
<?php
if (!isset($argv, $argc)) {
    echo "No command line args provided\n";
    exit(1);
}
if ($argc < 4) {
    echo "Not all command line args provided\n";
    exit(2);
}
$targetFile = $confFile = $argv[1];
$phpBin = $argv[2];
$pearSuffix = $argv[3];

$data = '';
$file = fopen($confFile, "r");

if ($file !== false) {
    while(!feof($file)) {
        $line = fgets($file);
        $serialized = @unserialize($line);
        if (is_array($serialized)) {
            $serialized['cache_dir'] = "/tmp/pear{$pearSuffix}/cache";
            $serialized['temp_dir'] = "/tmp/pear{$pearSuffix}";
            $serialized['download_dir'] = "/tmp/pear{$pearSuffix}/download";
            $serialized['php_bin'] = $phpBin;
            $data .= @serialize($serialized);
            $data .= "\n";
        } else {
            $data .= $line;
        }
    }
    fclose($file);
    if (false !== file_put_contents($targetFile, $data)) {
        echo "Written to $targetFile\n";
    } else {
        echo "Failed to write to $targetFile\n";
        exit(3);
    }
} else {
    echo "File was not found {$confFile}\n";
    exit(4);
}
exit(0);