-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgitp.php
150 lines (123 loc) · 4.07 KB
/
gitp.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env php
<?php
/**
* gitp.phar - A cli administration tool to help deploying Moodle plugins via Git
*
* @copyright 2017-2024 Silecs {@link http://www.silecs.info/societe}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @link https://github.com/silecs/moodle-gitplugins
* download from https://github.com/silecs/moodle-gitplugins/releases
*/
const GITPLUGINS_VERSION = '2.3.0 2024-12-17';
if (php_sapi_name() !== 'cli') {
die ('CLI mode only');
}
require_once __DIR__ . '/gitpPlugin.php';
require_once __DIR__ . '/gitpCollection.php';
define('RETURN_OK', 0);
define('RETURN_ERROR', 1);
$longopts = [
'help',
'version',
'verbose::',
'gen-exclude',
'gen-config',
'diag',
'list',
'detail::',
'status-all',
'check-config',
'install-all',
'install::',
'upgrade-all',
'upgrade::',
'cleanup',
];
$help = "Plugin installation or upgrade via Git, as declared in gitplugins.conf
Options:
--help Print out this help
--version Print version revision and build datetime
--verbose=N Verbosity = 0-2, default=1
(non-git commands)
--gen-config Generate a sample gitplugins.conf file
--gen-exclude Generate a chunk of lines to insert in your .git/info/exclude file
--list List all declared plugins (without diagnostic)
--diag Diagnostic of all declared plugins
(local-git commands)
--detail=<name> Display details about one plugin
--status-all Git status on each declared plugin
--cleanup Remove all plugins in an inconsistent state (by RENAMING them so restoration is possible)
(remote-git commands)
--check-config Check the consistency of the configuration file
--install-all Install all plugins that are not already present
--install=<name> Install this plugin according to gitplugins.conf
--upgrade-all Upgrade all plugins already installed
--upgrade=<name> Upgrade this plugin according to gitplugins.conf
";
$options = getopt('', $longopts);
if (empty($options) || isset($options['help'])) {
echo $help;
return RETURN_OK;
}
if (isset($options['version'])) {
printf("Gitplugins Version %s, Phar built @horodatage@ @git_commit_short@\n@copyright@\n\n", GITPLUGINS_VERSION);
return RETURN_OK;
}
if (isset($options['gen-config'])) {
printf("Config sample ; to be completed and redirected to %s.\n\n", gitpCollection::CONFIG_FILE);
return gitpCollection::generateConfig();
}
if (isset($options['verbose'])) {
$verbosity = (int)$options['verbose'];
} else {
$verbosity = 1;
}
$pCollection = new gitpCollection($verbosity);
$pCollection->setDiagnostic();
if (isset($options['diag'])) {
echo $pCollection->displayDiagnostic();
return RETURN_OK;
}
if (isset($options['list'])) {
echo $pCollection->list();
return RETURN_OK;
}
if (isset($options['detail'])) {
if (empty($options['detail'])) {
die ('--detail=<plugin_name>');
}
return $pCollection->detail($options['detail']);
}
if (isset($options['check-config'])) {
return $pCollection->check_config();
}
if (isset($options['status-all'])) {
return $pCollection->status_all();
}
if (isset($options['install-all'])) {
return $pCollection->install_all();
}
if (isset($options['install'])) {
if (empty($options['install'])) {
die ('--install=<plugin_name>. You can use --list to list the plugins ; otherwise try --install-all');
}
return $pCollection->install($options['install']);
}
if (isset($options['upgrade-all'])) {
return $pCollection->upgrade_all();
}
if (isset($options['upgrade'])) {
if (! isset($options['upgrade'])) {
die ('--upgrade=<plugin_name> ; you can use --diag to list the plugins, otherwise try --upgrade-all');
}
return $pCollection->upgrade($options['upgrade']);
}
if (isset($options['cleanup'])) {
return $pCollection->cleanup();
}
if (isset($options['gen-exclude'])) {
echo "You can insert the following lines in the file `.git/info/exclude`\n";
echo "\n" . $pCollection->generateExclude() . "\n";
return RETURN_OK;
}
exit;