forked from maxpozdeev/mytinytodo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildtar.php
executable file
·122 lines (99 loc) · 2.99 KB
/
buildtar.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
#!/usr/bin/env php
<?php
// PHP 5.4 is required
if ( !isset($argv) || !isset($argv[1]) ) {
die("Usage: buildtar.php <path_to_repo> [-o source.tar.gz] [-v VERSION]\n");
}
$repo = $argv[1];
$dir = sys_get_temp_dir(). DIRECTORY_SEPARATOR. "mytinytodo.build";
$curdir = getcwd();
$archive = $curdir. DIRECTORY_SEPARATOR. 'mytinytodo-v@[email protected]';
$ver = 0;
while ($arg = next($argv))
{
if ($arg == '-o') {
$archive = next($argv);
}
elseif ($arg == '-v') {
$ver = next($argv);
}
}
deleteTreeIfDir($dir);
$out = `git clone $repo $dir 2>&1`;
if (!is_dir($dir)) {
die("Error while clone: $out\n");
}
print "> Repository was cloned to temp dir: $dir\n";
#get current version number if not specified
if (!$ver) {
require_once(__DIR__ . '/src/includes/version.php');
$ver = mytinytodo\Version::VERSION;
}
chdir($dir. DIRECTORY_SEPARATOR. 'src');
$rev = trim(`git show --format=format:%H --summary`);
$rev = substr($rev, 0, 8);
##$ver = str_replace('@REV', $rev, $ver);
print "> Version is $ver\n";
unlink('./docker-config.php');
unlink('./includes/lang/en-rtl.json');
unlink('./mtt-edit-settings.php');
unlink('./content/theme/images/svg2base64.php');
chdir('..'); # to the root of repo
assert( strpos(getcwd(), ':') === false ); # FIXME: if path contains a colon ':'
echo("> Run Composer\n");
$retval = 0;
if (false === system( "./composer.sh install --no-dev --no-interaction --optimize-autoloader", $retval) || $retval != 0) {
die("Failed to install composer libs via docker\n");
}
# ext
if (is_dir('src/ext')) {
mkdir('src/ext2');
chdir('src/ext');
deleteTreeIfDir('_examples');
$extCount = 0;
$exts = array_diff(scandir('.') ?? [], ['.', '..']);
foreach ($exts as $ext) {
if (is_dir($ext)) {
rename($ext, "../ext2/$ext");
$extCount++;
}
}
chdir('../ext2');
if ($extCount > 0) {
`tar --no-xattrs -czf ../ext/extensions.tar.gz *`; #OS dep.!!!
}
chdir('../..');
deleteTreeIfDir('src/ext2');
echo("> Extensions were packed\n");
}
rename('src', 'mytinytodo') or die("Cant rename 'src'\n");
`tar --no-xattrs -czf mytinytodo.tar.gz mytinytodo`; #OS dep.!!!
if (!file_exists('mytinytodo.tar.gz')) {
die("Failed to pack files (no output tar.gz file)\n");
}
$archive = str_replace('@VERSION', $ver, $archive);
$archive = str_replace('@REV', $rev, $archive);
chdir($curdir);
if ( ! rename("$dir/mytinytodo.tar.gz", $archive) ) {
die("Failed to move mytinytodo.tar.gz to $archive");
}
deleteTreeIfDir($dir);
echo("> Temp dir was cleaned\n");
echo("> Build is stored in $archive\n");
function deleteTreeIfDir($dir)
{
if ( !is_dir($dir) ) {
return;
}
switch (PHP_OS) {
case 'Darwin':
case 'Linux':
system("rm -rf ". escapeshellarg($dir));
break;
case 'Windows':
system("rmdir /s /q ". escapeshellarg($dir));
break;
default:
die("Unknown system ". PHP_OS. "\n");
}
}