-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathenvcheck.php
64 lines (56 loc) · 1.74 KB
/
envcheck.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
<?php
$path = isset($argv[1]) ? $argv[1] : '';
if (!$path) die('can not found phpmyadmin path');
array_shift($argv);
array_shift($argv);
$config = [];
foreach ($argv as $val) {
if (preg_match('/^--(.+?)=(.+?)$/', $val, $m)) {
$config[$m[1]] = $m[2];
}
}
if (!isset($config['version'])) die('can not found phpmyadmin version');
$verArr = explode('.', $config['version']);
$verDir = implode('.', [$verArr[0], $verArr[1], 'x']);
$curVer = $verArr[0] * 100 + $verArr[1];
if (!file_exists($path . '/' . 'config.inc.php') && !file_exists($path . '/' . 'config.sample.inc.php'))
die('invalid phpmyadmin path');
if (!file_exists(__DIR__ . '/phpmyadmin/' . $verDir)) {
die('invalid phpmyadmin version, allow version:' . PHP_EOL . implode(PHP_EOL, array_filter(scandir(__DIR__ . '/phpmyadmin'), function($item) {
return !preg_match('/^\./', $item);
})));
}
function copyFile($from, $to) {
if (is_dir($from)) {
if (!file_exists($to)) mkdir($to, '0777', true);
$arr = array_filter(scandir($from), function ($item){
return !preg_match('/^\./', $item);
});
$res = true;
foreach ($arr as $item) {
$absolute = $from . '/' . $item;
$toAbsolute = $to . '/' . $item;
$res = $res && copyFile($absolute, $toAbsolute);
}
return $res;
} else {
$dir = dirname($to);
if (!file_exists($dir)) mkdir ($dir, '0777', true);
return copy($from, $to);
}
}
function rmFile($from) {
if (is_dir($from)) {
$arr = array_filter(scandir($from), function ($item){
return !preg_match('/^\./', $item);
});
$res = true;
foreach ($arr as $item) {
$absolute = $from . '/' . $item;
$res = $res && rmFile($absolute);
}
return rmdir($from);
} else {
return unlink($from);
}
}