summaryrefslogtreecommitdiffstats
path: root/roundcubemail-bundled.php
blob: c963e9e731e469f8b3a51d8383effd11bc23c47e (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
44
45
46
47
48
<?php

if (!isset($_SERVER['argv'][1])) {
	echo "Missing arg\n";
	exit(1);
}
$pkgs = file_get_contents($_SERVER['argv'][1]);
if (!$pkgs) {
	echo "can't read json file\n";
	exit(2);
}

$pkgs = json_decode($pkgs, true);
if (!is_array($pkgs)) {
	echo "can't decode json file\n";
	exit(3);
}

if (isset($pkgs['packages'])) {
	$res = [];
    foreach($pkgs["packages"] as $pkg) {
		$lic = implode(" and ", $pkg["license"]);
		if (!isset($res[$lic])) $res[$lic] = [];
		$res[$lic][] = sprintf("Provides: bundled(php-%s) = %s", str_replace(["/", "_"], ["-", "-"], $pkg["name"]), $pkg["version"]);
	}
	ksort($res);
	foreach($res as $lic => $lib) {
		sort($lib);
		printf("# License %s\n%s\n", $lic, implode("\n", $lib));
	}
} else if (isset($pkgs['dependencies'])) {
	$res = [];
	foreach($pkgs['dependencies'] as $pkg) {
		$n = strtolower($pkg['name'] ?? $pkg['lib']);
		$n = str_replace('.js', '', $n);
		$lic = ($pkg['license'] ?? "Unkown");
		if (!isset($res[$lic])) $res[$lic] = [];
		$res[$lic][] = sprintf("Provides: bundled(js-%s) = %s", $n, $pkg['version']);
	}
	ksort($res);
	foreach($res as $lic => $lib) {
		sort($lib);
		printf("# License %s\n%s\n", $lic, implode("\n", $lib));
	}
} else {
	echo "unkown content\n";
	exit(4);
}