-
Notifications
You must be signed in to change notification settings - Fork 16
/
check-version.php
executable file
·67 lines (57 loc) · 2.05 KB
/
check-version.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
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2024 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0 Alpha 1
*/
try {
$smf_version = '';
$versions = [];
$years = [];
foreach (['./index.php', './SSI.php', './cron.php', './proxy.php'] as $path)
{
if (in_array($path, ['./SSI.php', './cron.php', './proxy.php']) && version_compare($smf_version, '3.0 Alpha 1', '>='))
continue;
$contents = file_get_contents($path, false, null, 0, 1500);
if (!preg_match('/define\(\'SMF_VERSION\', \'([^\']+)\'\);/i', $contents, $versionResults)) {
throw new Exception('Error: Could not locate SMF_VERSION in ' . $path);
}
$versions[$versionResults[1]][] = $path;
if (empty($smf_version)) {
$smf_version = $versionResults[1];
}
if (!preg_match('/define\(\'SMF_SOFTWARE_YEAR\', \'(\d{4})\'\);/i', $contents, $yearResults)) {
throw new Exception('Error: Could not locate SMF_SOFTWARE_YEAR in ' . $path);
}
$years[$yearResults[1]][] = $path;
}
if (count($versions) != 1) {
$errmsg = 'Error: SMF_VERSION differs between files.';
foreach ($versions as $version => $paths) {
$errmsg .= ' "' . $version . '" in ' . implode(', ', $paths) . '.';
}
throw new Exception($errmsg);
}
if (count($years) != 1) {
$errmsg = 'Error: SMF_SOFTWARE_YEAR differs between files.';
foreach ($years as $year => $paths) {
$errmsg .= ' "' . $year . '" in ' . implode(', ', $paths) . '.';
}
throw new Exception($errmsg);
}
if (!preg_match('~^((\d+)\.(\d+)[. ]?((?:(?<= )(?>RC|Beta |Alpha ))?\d+)?)$~', key($versions))) {
throw new Exception('Error: SMF_VERSION string is invalid: "' . key($versions) . '"');
}
if (($headyear = (int) substr(shell_exec('git show -s --format=%ci HEAD'), 0, 4)) > (int) key($years)) {
throw new Exception('Error: SMF_SOFTWARE_YEAR is ' . (int) key($years) . ', should be ' . $headyear . '.');
}
}
catch (Exception $e) {
fwrite(STDERR, $e->getMessage());
exit(1);
}