forked from auraphp/system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.php
77 lines (63 loc) · 1.66 KB
/
update.php
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
<?php
/**
*
* This file is part of the Aura project for PHP.
*
* @license http://opensource.org/licenses/bsd-license.php BSD
*
*/
/**
* Need 'allow_url_fopen' to be on.
*/
if (! ini_get('allow_url_fopen')) {
echo "Cannot update when 'allow_url_fopen' is turned off." . PHP_EOL;
exit(1);
}
/**
* Pull changes the system as a whole.
*/
passthru('git pull');
/**
* Update the library packages.
*/
// the package directory
$dir = __DIR__ . DIRECTORY_SEPARATOR . 'package';
if (! is_dir($dir)) {
mkdir($dir, 0777);
}
// get the list of available repositories
$url = 'https://api.github.com/orgs/auraphp/repos';
$context = stream_context_create([
'http' => [
'method' => "GET",
'header' => "Accept: application/json"
],
]);
$json = file_get_contents($url, FALSE, $context);
$data = json_decode($json);
// sort the repos
$repos = [];
foreach ($data as $repo) {
$repos[$repo->name] = $repo;
}
ksort($repos);
// for each of the repositories ...
foreach ($repos as $repo) {
// only use 'Aura.Package' repositories as packages
if (! preg_match('/Aura\.[A-Z0-9_]+/', $repo->name)) {
continue;
}
// does the package exist locally ?
$sub = $dir . DIRECTORY_SEPARATOR . $repo->name;
if (is_dir($sub)) {
// pull changes to existing package
echo "Pulling package '{$repo->name}'." . PHP_EOL;
passthru("cd $sub; git pull --all");
} else {
// clone new package for installation
echo "Cloning package '{$repo->name}'." . PHP_EOL;
passthru("cd $dir; git clone {$repo->clone_url}");
}
}
// done!
echo 'Done!' . PHP_EOL;