forked from textpattern/textpattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtxp-checksums.php
More file actions
75 lines (61 loc) · 2.02 KB
/
Copy pathtxp-checksums.php
File metadata and controls
75 lines (61 loc) · 2.02 KB
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
<?php
/*
* Textpattern Content Management System
* https://textpattern.com/
*
* Copyright (C) 2020 The Textpattern Development Team
*
* This file is part of Textpattern.
*
* Textpattern is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2.
*
* Textpattern is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Textpattern. If not, see <https://www.gnu.org/licenses/>.
*/
if (php_sapi_name() !== 'cli') {
die('command line only');
}
define('txpath', 'textpattern');
define('n', "\n");
// Find `.php` and `.js` files in `textpattern` directory.
$files = glob_recursive('textpattern/*\.{php,js}', GLOB_BRACE);
$files = preg_replace('%^textpattern%', '', $files);
$files = array_flip($files);
$cs = @file_get_contents(txpath.'/checksums.txt');
if (preg_match_all('%^(\S+):\s+([\da-f]+)%im', $cs, $mm)) {
$out = '';
foreach ($mm[1] as $key => $file) {
$md5 = md5_file(txpath.$file);
$out .= "$file: $md5".n;
unset($files[$file]);
}
file_put_contents(txpath.'/checksums.txt', $out);
echo "Checksums updated.\n\n";
}
// New files.
$out = '';
foreach ($files as $file => $val) {
if (! preg_match('%^/(config-dist\.php|setup)%', $file)) {
$out .= "$file: ".md5_file(txpath.'/'.$file).n;
}
}
if ($out) {
echo "New files without checksums:".n.$out.n;
echo "Add new files to 'checksums.txt' before release.".n.n;
}
exit;
function glob_recursive($pattern, $flags = 0)
{
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
}
return $files;
}