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

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

if ($file !== false) {
    while(!feof($file)) {
        $line = fgets($file);
        $serialized = @unserialize($line);
        if (is_array($serialized)) {
            $serialized['temp_dir'] = "{$varPath}/temp";
            $serialized['cache_dir'] = "{$varPath}/cache";
            $serialized['download_dir'] = "{$varPath}/download";
            $serialized['metadata_dir'] = "{$varPath}/metadata";
            $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);