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
|
#!/usr/bin/php
<?php
require_once 'Cache/Lite.php';
class PkgClient {
const URL = 'https://packagist.org/';
protected $cache;
function __construct () {
$dir = "/tmp/pkgist-".posix_getlogin()."/";
@mkdir($dir);
$this->cache = new Cache_Lite(
array(
'memoryCaching' => true,
'cacheDir' => $dir,
'automaticSerialization' => true
)
);
}
function getPackage($name) {
$url = self::URL.'packages/'.$name.'.json';
$rep = $this->cache->get(__METHOD__, $url);
if (!$rep) {
$rep = @file_get_contents($url);
$this->cache->save($rep, __METHOD__, $url);
}
return ($rep ? json_decode($rep, true) : false);
}
}
if (in_array('-h', $_SERVER['argv']) || in_array('--help', $_SERVER['argv'])) {
echo <<<END
usage checkpkg [ options ]
-h
--help Display help (this page)
-v
--verbose Display all packages, with upsteam information
-q
--quiet Don't display not installed packages
or packages with latest version installed
END;
die("\n\n");
}
$verb = (in_array('-v', $_SERVER['argv']) || in_array('--verbose', $_SERVER['argv']));
$quiet = (in_array('-q', $_SERVER['argv']) || in_array('--quiet', $_SERVER['argv']));
$client = new PkgClient();
$pkgs = file_get_contents(__DIR__."/checkpkgist.json");
if (!$pkgs) {
die("Missing configuration file\n");
}
$pkgs = json_decode($pkgs, true, 5, JSON_PARSER_NOTSTRICT);
if (!$pkgs) {
die("Bad configuration file\n");
}
printf(" %-40s %15s %15s %15s\n", "Name", "Version", "Upstream", "Date");
foreach ($pkgs as $name => $rpm) {
$rpmver = exec("rpm -q --qf '%{VERSION}' $rpm", $out, $ret);
if ($ret) {
if ($quiet) {
continue;
}
$rpmver = "n/a";
}
$pkgs = $client->getPackage($name);
if ($pkgs) {
foreach ($pkgs['package']['versions'] as $pkver => $pkg) {
if (strpos($pkver, 'dev') !== false) {
continue;
}
if (version_compare($pkver, $rpmver, 'gt')) {
$date = new DateTime($pkg['time']);
$diff = $date->diff(new DateTime("now"));
if ($diff->days <2) {
$note = "(Just released)";
} else if ($diff->days <20) {
$note = $diff->format("(%a days)");
} else {
$note = "";
}
//print_r($pkg);
printf(" %-40s %15s %15s %15s %s\n", $rpm, $rpmver, $pkver, $date->format("Y-m-d"), $note);
if ($pkg['source']['type']=='git' && $verb) {
printf("\tURL: %s\n\tHash: %s\n",
($pkg['source']['url']?:'unkown'),
($pkg['source']['reference']?:'unkown'));
}
break;
}
else if (version_compare($pkver, $rpmver, 'eq') && $verb) {
printf(" %-40s %15s %15s\n", $rpm, $rpmver, $pkver);
break;
}
}
} else {
printf(" %-40s %15s %15s\n", $rpm, $rpmver, 'Not found !');
}
}
|