-
Notifications
You must be signed in to change notification settings - Fork 2
/
build
executable file
·679 lines (552 loc) · 21.4 KB
/
build
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
#!/usr/bin/env php
<?php
/*
* CardDAV Middleware UI
* Written by Massi-X <support@massi-x.dev> © 2024
* This file is protected under CC-BY-NC-ND-4.0, please see "LICENSE" file for more information
*/
/**
* This build script handles package creation, versioning, signing and everything.
*/
require 'build_config';
$rawname = 'temp'; //rawname is needed for create the tar archive (will change later to the chosen one)
//Thanks to https://stackoverflow.com/a/15322457 for the interactive shell hint
//Note that $allowed_answers is incompatible with $multiline
function interactive_shell($question, $type = null, $allowed_answers = null, $multiline = false)
{
$str = $question . ' ';
$res = '';
//print allowed answers
if (!empty($allowed_answers)) {
$str .= '(';
foreach ($allowed_answers as $answer)
$str .= $answer . '/';
$str = substr($str, 0, -1) . ') ';
}
//echo message
echo colorLog($str, $type);
//read input
if (!$multiline)
$res = readline();
else
while ($tmp = readline())
$res .= $tmp . "\n";
//keep looping till we get an allowed answer
if (!$multiline && !empty($allowed_answers)) {
foreach ($allowed_answers as $answer) {
if (strcasecmp($res, $answer) == 0)
return $res;
}
echo colorLog("I did not understand, please try again.\n", 'e');
return interactive_shell($question, $type, $allowed_answers);
}
return $res;
}
//Thanks to https://stackoverflow.com/a/66075475
function colorLog($str, $type)
{
switch ($type) {
case 'e': //error
echo "\033[31m$str\033[0m";
break;
case 's': //success
echo "\033[32m$str\033[0m";
break;
case 'w': //warning
echo "\033[33m$str\033[0m";
break;
case 'i': //info
echo "\033[36m$str\033[0m";
break;
case 'b': //boring
echo "\033[37m$str\033[0m";
break;
default:
echo $str;
break;
}
}
//redefined copy to recurse folders
function copy_i($from, $to, $exclude_list = [])
{
//don't copy hidden files
if (substr($from, 0, 1) == '.')
return true;
if (is_dir($from)) {
//don't need to array_diff with '.', '..' because hidden files will be removed anyway
$fileList = scandir($from);
if (!$fileList || !mkdir("$to"))
return false;
$fileList = array_diff($fileList, $exclude_list);
foreach ($fileList as $file) {
if (substr($file, 0, 1) == '.')
continue;
if (!copy_i("$from/$file", "$to/$file"))
return false;
}
return true;
} else
return copy($from, $to);
}
//die with error color
function die_i($msg)
{
global $tmpFolder;
@exec("rm -rf $tmpFolder"); //don't care about errors
die(colorLog($msg, 'e'));
}
/*****************************************************************/
/* ACTUAL SCRIPT */
/*****************************************************************/
echo colorLog("Welcome to the build script. A compress file will be created containing the module ready to be published.\n", 'i');
echo colorLog("REMEMBER THAT HIDDEN FILES WILL NOT BE INCLUDED IN THE OUTPUT!\n", 'i');
sleep(1);
//first change to the correct dir
if (!chdir(__DIR__))
die_i("Failed to change dir!\n");
if (!file_exists('core/core.php'))
die_i("Unable to find core class! ABORTING!\n");
if (file_exists('output.tar.gz')) {
$res = interactive_shell('output.tar.gz already exists, if you continue it will be overwritten! Are you sure?', 'w', ['Y', 'N']);
if ($res != 'Y' && $res != 'y')
die_i("ABORTING!\n");
echo "Deleting output.tar.gz...\n";
if (!unlink(__DIR__ . '/output.tar.gz'))
die_i("Cannot delete output.tar.gz!\n");
echo "Deleting output.tar...\n";
if (!unlink(__DIR__ . '/output.tar'))
die_i("Cannot delete output.tar!\n");
}
//create random folder
$tmpFolder = 'ph_' . uniqid();
while (true) {
if (file_exists($tmpFolder) || is_link($tmpFolder)) {
$tmpFolder = 'ph_' . uniqid();
continue;
}
$tmpFolder = sys_get_temp_dir() . '/' . $tmpFolder;
if (!@mkdir($tmpFolder . '/' . $rawname, 0777, true) || !@is_dir($tmpFolder . '/' . $rawname))
die_i("Cannot create tmp dir!\n");
break;
}
//list all the files in this dir
$fileList = scandir(__DIR__);
if (!$fileList)
die_i("Cannot scan dir!\n");
//remove excluded files from root (these are only mine, so $excludedLibraryFiles)
$fileList = array_diff($fileList, $excludedLibraryFiles);
//now copy everything
foreach ($fileList as $file)
copy_i($file, "$tmpFolder/$rawname/$file");
echo colorLog("Copied temporary files.\n", 's');
//ask some questions about the module details (that will be included in module.xml)
echo colorLog("It's now time to get some information about the module... If you want to skip any section press enter.\n", 'i');
echo colorLog("(PS. If you want to skip this for future releases, you can create a file called config (inside \"core\" directory) and it will be automatically loaded!)\n", 'i');
//if config exists, preload all the values
$config = false;
if (file_exists("$tmpFolder/$rawname/core/config")) {
$config = @include "$tmpFolder/$rawname/core/config";
if ($config === false)
die_i('Unable to include config file!');
if (!unlink("$tmpFolder/$rawname/core/config"))
die_i("Unable to delete config file!\n");
echo colorLog("Using the provided config file\n", 's');
}
//container for the xml below
$output_xml = new SimpleXMLElement('<?xml version="1.0"?><module></module>');
//add meta tag with UI version
$output_xml->addChild('meta-cmui-version', $UI_version);
//rawname
if (!$config)
$res = interactive_shell('What is the rawname of the module?');
else
$res = @$config['rawname'];
if (!empty($res)) {
echo colorLog("Set rawname to \"$res\"\n", 'b');
} else {
$res = (empty($modulexml['rawname']) ? 'none' : $modulexml['rawname']);
echo colorLog("Set rawname to default \"$res\"\n", 'b');
}
$output_xml->addChild('rawname', htmlspecialchars(trim($res)));
//now move the files to the new directory
if (!@rename("$tmpFolder/$rawname", $tmpFolder . '/' . trim($res)))
die_i("Unable to rename tmp folder!\n");
$rawname = trim($res);
//name
if (!$config)
$res = interactive_shell('What is the name (to display) of the module?');
else
$res = @$config['name'];
if (!empty($res)) {
echo colorLog("Set name to \"$res\"\n", 'b');
} else {
$res = (empty($modulexml['name']) ? 'none' : $modulexml['name']);
echo colorLog("Set name to default \"$res\"\n", 'b');
}
$output_xml->addChild('name', htmlspecialchars(trim($res)));
//version
if (!$config)
$res = interactive_shell('Which version is this? (use three digits, ex. 1.0.0):');
else
$res = @$config['version'];
if (!empty($res))
echo colorLog("Set version to \"$res\"\n", 'b');
else {
$res = (empty($modulexml['version']) ? 'none' : $modulexml['version']);
echo colorLog("Set version to default \"$res\"\n", 'b');
}
$output_xml->addChild('version', htmlspecialchars(trim($res)));
//category
$categories = [
0 => 'Uncategorized',
1 => 'Admin',
2 => 'Applications',
3 => 'Connectivity',
4 => 'Reports',
5 => 'Settings'
];
if (!$config) {
echo "Which category does your module belongs to?\n";
foreach ($categories as $index => $cat)
echo "[$index] $cat\n";
$res = interactive_shell('Input your choice:', null, array_keys($categories));
} else {
$res = @$config['category'];
if (!empty($res) && is_string($res)) {
$key = array_search($res, $categories);
if (is_int($key))
$res = $key;
else {
$res = null;
echo colorLog("Config file contains an invalid value for category, skipping.\n", 'e');
}
}
}
if (!empty($res) && strcasecmp('0', trim($res)) != 0) {
echo colorLog('Set category to "' . $categories[$res] . "\"\n", 'b');
$output_xml->addChild('category', htmlspecialchars($categories[$res]));
} else
echo colorLog("Skipped category\n", 'b');
//menu items
$menu_to_add = [];
if (isset($modulexml['menuitems']))
$menu_to_add = array_merge($modulexml['menuitems'], []); //add default values
if (!$config) {
//print info for user (adding default menu items)
if (!empty($menu_to_add)) {
echo "Adding default menu items...\n";
foreach ($menu_to_add as $key => $val)
echo colorLog("Add \"$key\" => \"$val\"\n", 'b');
}
$res = 'y';
while ($res != null) {
$res = interactive_shell('Does your module have any menu items? Then input here the (php) page name or skip with enter:');
if (!empty($res)) {
$key = $res;
$res = interactive_shell("OK, what is the name for the entry \"$res\"?");
if (!empty($res)) {
echo colorLog((isset($menu_to_add[$key]) ? 'Overwrite' : 'Add') . " menu item \"$key\" => \"$res\"\n", 'b');
$menu_to_add[$key] = $res;
} else
echo colorLog("Invalid value, please retry.\n", 'w');
} else
$res = null;
}
} else {
$arr = @$config['menuitems'];
if (!is_array($arr))
echo colorLog("Config file contains an invalid array for menuitems, skipping.\n", 'e');
else {
foreach ($arr as $key => $val)
$menu_to_add[$key] = $val;
}
}
//add all the values declared before (if any)
if (count($menu_to_add)) {
$menuitems_xml = $output_xml->addChild('menuitems'); //subnode for menu items
foreach ($menu_to_add as $key => $val) {
echo colorLog("Add menuitem \"$key\" => \"$val\"\n", 'b');
$menuitems_xml->addChild(trim($key), htmlspecialchars(trim($val)));
}
echo colorLog("Menu items set.\n", 'b');
} else
echo colorLog("Skipping menu items\n", 'b');
//publisher
if (!$config)
$res = interactive_shell('Do you want to be added as a publisher? Input your name then:');
else
$res = @$config['publisher'];
if (!empty($res)) {
$res = $res . ' w/ ' . $modulexml['publisher'];
echo colorLog("Set publisher to \"$res\"\n", 'b');
} else {
$res = (empty($modulexml['publisher']) ? 'none' : $modulexml['publisher']);
echo colorLog("Set publisher to default \"$res\"\n", 'b');
}
$output_xml->addChild('publisher', htmlspecialchars(trim($res)));
//description
if (!$config)
$res = interactive_shell('What is the short description of the module?');
else
$res = @$config['description'];
if (!empty($res))
echo colorLog("Set description to \"$res\"\n", 'b');
else {
$res = (empty($modulexml['description']) ? 'none' : $modulexml['description']);
echo colorLog("Set description to default \"$res\"\n", 'b');
}
$output_xml->addChild('description', htmlspecialchars(trim($res)));
//license
if (!$config)
$res = interactive_shell('What license are you using?');
else
$res = @$config['license'];
if (!empty($res)) {
echo colorLog("Set license to \"$res\"\n", 'b');
$output_xml->addChild('license', htmlspecialchars(trim($res)));
//license link is subject to license itself
if (!$config)
$res = interactive_shell("Please now input a link pointing to the license text of $res:");
else
$res = @$config['licenselink'];
if (!empty($res)) {
echo colorLog("Set license link to \"$res\"\n", 'b');
$output_xml->addChild('licenselink', htmlspecialchars(trim($res)));
} else
die_i("You MUST include a license link in case you choose a different license.\n");
} else {
$license = (empty($modulexml['license']) ? 'none' : $modulexml['license']);
echo colorLog("Set license to default \"$license\"\n", 'b');
$output_xml->addChild('license', htmlspecialchars(trim($license)));
$output_xml->addChild('licenselink', htmlspecialchars(trim($modulexml['licenselink'])));
}
//more-info
if (!$config)
$res = interactive_shell('Do you have a link with more info about the module? Please input it then:');
else
$res = @$config['more-info'];
if (!empty($res))
echo colorLog("Set more-info to \"$res\"\n", 'b');
else {
$res = (empty($modulexml['more-info']) ? 'none' : $modulexml['more-info']);
echo colorLog("Set more-info to default \"$res\"\n", 'b');
}
$output_xml->addChild('more-info', htmlspecialchars(trim($res)));
//updateurl
if (!$config)
$res = interactive_shell('Do you have an update json for automatic updates? Please input the link then:');
else
$res = @$config['updateurl'];
if (!empty($res))
echo colorLog("Set updateurl to \"$res\"\n", 'b');
else {
$res = (empty($modulexml['updateurl']) ? 'none' : $modulexml['updateurl']);
echo colorLog("Set updateurl to default \"$res\"\n", 'b');
}
$output_xml->addChild('updateurl', htmlspecialchars(trim($res)));
//changelog
if (!$config)
$res = interactive_shell('Do you want to insert any release notes? Please input them now (to finish hit enter twice):', null, null, true);
else
$res = @$config['changelog'];
if (!empty($res))
$modulexml['changelog'] .= $res;
echo colorLog("Set changelog to:\n" . trim(preg_replace('/\t+/', '', (empty($modulexml['changelog']) ? 'none' : $modulexml['changelog']))) . "\n", 'b');
$output_xml->addChild('changelog', htmlspecialchars(trim($modulexml['changelog'])));
//dependencies
function arrayLoopPrint($pattern, $arr, $header = null)
{
foreach ($arr as $key => $value) {
if (is_array($value)) {
arrayLoopPrint($pattern, $value, $key);
} else
echo colorLog(str_replace(['%key', '%value'], [(isset($header) ? $header : $key), $value], $pattern), 'b');
}
}
function arrayLoopAdd($arr, $header = null)
{
global $depends_xml;
foreach ($arr as $key => $value) {
if (is_array($value)) {
arrayLoopAdd($value, $key);
} else
$depends_xml->addChild(trim((isset($header) ? $header : $key)), htmlspecialchars(trim($value)));
}
}
const MODE_INTERACTIVE = 0;
const MODE_AUTO = 1;
function processValue($key, $val, $mode)
{
global $depends_to_add;
global $modulexml;
if (is_array($val)) {
foreach ($val as $value)
processValue($key, $value, $mode); //keep original key
return;
}
$val = trim($val);
if (strcasecmp($key, 'module') == 0) { //module is the only one that accepts multiple entries. Keep in mind that no check is done if the developer inputs a duplicated value
$add = true;
$overwriteWarn = false;
//prevent from overwriting default versions if lower than provided
if (isset($modulexml['depends']['module']) && is_array($modulexml['depends']['module'])) {
preg_match('/^(\S+)\s*([\d\.]*)/mi', $val, $matches); //matches the value provided splitting name and version (if present)
$module = $matches[1];
$version = isset($matches[2]) ? $matches[2] : null;
foreach ((array) $modulexml['depends']['module'] as $key => $value) {
preg_match('/^(' . $module . ')\s+([\d\.]*)/mi', $value, $matches); //check if the given value matches anything in the defaults
if (!isset($matches[1]))
continue;
$minimumVersion = isset($matches[2]) ? $matches[2] : null;
//compare versions, if the new version is higher then overwrite the defaults
if (
$minimumVersion != null && $version == null ||
$minimumVersion != null && version_compare($minimumVersion, $version) == 1
) {
echo colorLog(($mode == MODE_INTERACTIVE ? "Minimum version for \"$module\" is $minimumVersion, please retry" : "Unable to add dependency \"module\" => \"$module\" because minimum version is $minimumVersion") . ".\n", 'e');
$add = false;
break;
} else {
$overwriteWarn = true;
break; //the version is greater, let the code below handle this case (will overwrite)
}
}
}
//only if not already overwritten/rejected
if ($add) {
preg_match('/^(\S+)\s*.*/mi', $val, $matches); //matches the value provided extracting name only
$module = $matches[1];
for ($i = 0; $i < count($depends_to_add['module']); ++$i) {
preg_match('/^(' . $module . ')\s+.*/mi', $depends_to_add['module'][$i], $matches); //check if the given value matches another one the user input before
if (!isset($matches[1]))
continue;
echo colorLog('Overwrite ' . ($overwriteWarn ? 'default ' : '') . "dependecy \"module\" => \"$val\"\n", 'b');
$depends_to_add['module'][$i] = $val;
//if we go after the isset above it means we should continue and do not execute the add below
$add = false;
break;
}
if ($add) { //ok now this is REALLY a new value
echo colorLog("Add dependecy \"module\" => \"$val\"\n", 'b');
array_push($depends_to_add['module'], $val);
}
}
} else { //if not a module-type dependency
if (isset($depends_to_add[$key])) { //overwrite with check
if (version_compare($depends_to_add[$key], $val) == 1) {
echo colorLog(($mode == MODE_INTERACTIVE ? "Minimum version for \"$key\" is " . $depends_to_add[$key] . ", please retry" : "Unable to add dependency \"$key\" because minimum version is " . $depends_to_add[$key]) . ".\n", 'e');
} else {
echo colorLog("Overwrite default dependecy \"$key\" => \"$val\"\n", 'b');
$depends_to_add[$key] = $val;
}
} else { //add
echo colorLog("Add dependecy \"$key\" => \"$val\"\n", 'b');
$depends_to_add[$key] = $val;
}
}
}
$depends_xml = $output_xml->addChild('depends'); //subnode for depends
$depends_to_add = [];
if (isset($modulexml['depends']))
$depends_to_add = $modulexml['depends']; //store the used keys to print an info for the user (except 'module' that can have multiple ones) + set default keys
if (!is_array($depends_to_add['module'])) //initialize array
$depends_to_add['module'] = [$depends_to_add['module']];
//print info for user (adding default dependencies)
echo colorLog("Add default dependencies... (you can overwrite them later)\n", 'b');
arrayLoopPrint("Add \"%key\" => \"%value\"\n", $depends_to_add);
if (!$config) {
$res = 'y';
$first = true;
while ($res != null) {
$res = interactive_shell(($first ? 'Does your module have any dependencies? If yes input the first one here (version/module/phpversion...)' : 'Input another dependency') . ' or skip with enter:');
if (empty($res)) break; //user pressed enter
$key = trim($res);
$res = interactive_shell("OK, what is the description/version for dependecy \"$key\"?");
if (empty($res)) { //emtpy value
echo colorLog("Invalid value, please retry.\n", 'w');
$res = ' '; //set to something to avoid exiting the loop
continue;
}
processValue($key, $res, MODE_INTERACTIVE);
$first = false;
}
} else if (!is_array(@$config['depends'])) //fail if depends is not an array
echo colorLog("Config file contains an invalid array for depends, skipping.\n", 'e');
else { //add the config array
echo colorLog("Add core dependencies...\n", 'b');
foreach ($config['depends'] as $key => $value)
processValue($key, $value, MODE_AUTO);
}
arrayLoopAdd($depends_to_add); //add all the values declared before
echo colorLog("Dependencies set.\n", 'b'); //no need to skip this if no dependency is set (it will never happen because version is always there)
//icon
echo colorLog("Searching for core custom icon...\n", 'b');
//if icon exists, copy it into the assets folder
if (file_exists("$tmpFolder/$rawname/core/assets/images/icon.png")) {
if (!copy("$tmpFolder/$rawname/core/assets/images/icon.png", "$tmpFolder/$rawname/assets/images/icon_core.png"))
echo colorLog("Unable to copy core icon!\n", 'e');
else
echo colorLog("Using the provided core icon\n", 'b');
} else
echo colorLog("'core/assets/images/icon.png' not found\n", 'b');
//remove module.xml from output (if present)...
if (file_exists("$tmpFolder/$rawname/module.xml") && !unlink("$tmpFolder/$rawname/module.xml"))
die_i("Unable to delete module.xml!\n");
//...and replace it with our generated one
try {
$result = $output_xml->asXML("$tmpFolder/$rawname/module.xml");
file_put_contents("$tmpFolder/$rawname/module.xml", file_get_contents("$tmpFolder/$rawname/module.xml") . "<!-- AUTO GENERATED FILE. DO NOT TOUCH! -->"); //put comment at the end for xml parser
} catch (Throwable $t) {
die_i("Unable to write module.xml!\n");
}
if ($config)
echo colorLog("Finished loading values from config file. Please read above to assure everything is correct\n", 's');
echo colorLog("Checking for post_build_hook script...\n", 'i');
//call core post_build script if provided
if (file_exists("$tmpFolder/$rawname/core/post_build_hook")) {
try {
$output = array();
exec("php $tmpFolder/$rawname/core/post_build_hook 2> /dev/null", $output, $return);
if ($return != 0)
throw new Exception(implode("", $output));
else
echo colorLog("Executed post_build_hook script!\n", 's');
if (!unlink("$tmpFolder/$rawname/core/post_build_hook")) //delete after use
die_i("Unable to delete post_build_hook!\n");
} catch (Throwable $t) {
echo colorLog($t->getMessage() . "\n", 'e');
die_i("post_build_hook thrown an error, build canceled!\n");
}
} else
echo colorLog("No post_build_hook script found, proceeding.\n", 'i');
//signing is optional
$res = interactive_shell('Do you want to sign the module?', null, ['Y', 'N']);
if ($res == 'Y' || $res == 'y') {
//checks to be performed before everything else
if (!`which gpg`)
die_i('Please run `brew install gpg` to enable signing.');
if (!file_exists('devtools') || !is_dir('devtools'))
die_i("Unable to find devtools folder. Please download it from https://github.com/FreePBX/devtools and unzip it in the main directory (the same as this script) to continue. Make sure the name is \"devtools\".\n");
//a key ID is needed
$key = interactive_shell('Please provide now your GPG key ID to sign the module:');
if (empty($key))
die_i("GPG key cannot be empty! ABORTING!\n");
//exec the sign and echo every output
echo colorLog(exec("GPG_TTY=$(tty) && export GPG_TTY && php devtools/sign.php $tmpFolder/$rawname " . escapeshellarg($key)) . "\n", 'i');
}
//tar.gz the file (thanks to https://stackoverflow.com/a/20062628)
try {
$phar = new PharData(__DIR__ . "/output.tar");
$phar->buildFromDirectory("$tmpFolder");
//tar archive will be created only after closing object
$phar->compress(Phar::GZ);
// NOTE THAT BOTH FILES WILL EXISTS. SO IF YOU WANT YOU CAN UNLINK archive.tar
unlink(__DIR__ . "/output.tar");
} catch (Exception $e) {
die_i("Failed to create tar file!\n");
}
//delete tmp folder (don't care about exeptions)
@exec("rm -rf $tmpFolder");
//open output directory
@exec('open ' . escapeshellarg(__DIR__)); //don't care about exceptions
echo colorLog("Done, you can find the tar inside the source directory.\n", 's');