-
Notifications
You must be signed in to change notification settings - Fork 63
/
makephar.php
40 lines (40 loc) · 1.54 KB
/
makephar.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
<?php
define('PHAR_NAME', 'TGUserbot.phar');
define('SRC_DIR', 'src');
if (trim(strtolower(readline('Run composer update? [y/n]: '))) === 'y') {
passthru('cd '.escapeshellarg(SRC_DIR).' && composer update');
}
$phar = new Phar(PHAR_NAME, 0, PHAR_NAME);
$phar->startBuffering();
$phar->buildFromDirectory(SRC_DIR);
echo "Changelog:\n";
touch(__DIR__.'/changelog');
passthru('nano '.escapeshellarg(__DIR__.'/changelog'));
$changelog = trim(file_get_contents(__DIR__.'/changelog'));
echo $changelog;
unlink(__DIR__.'/changelog');
echo "\n\nEval:\n";
touch(__DIR__.'/eval');
passthru('nano '.escapeshellarg(__DIR__.'/eval'));
$eval = trim(file_get_contents(__DIR__.'/eval'));
echo $eval;
unlink(__DIR__.'/eval');
echo "\n\nGit commit message:\n";
file_put_contents(__DIR__.'/commitMessage', $changelog);
passthru('nano '.escapeshellarg(__DIR__.'/commitMessage'));
$commitMessage = trim(file_get_contents(__DIR__.'/commitMessage'));
echo $commitMessage;
unlink(__DIR__.'/commitMessage');
$phar->addFromString('.changelog', gzdeflate(json_encode(['changelog' => $changelog, 'eval' => $eval]), 9));
//$stub = "#!/usr/bin/env php \n".$phar->createDefaultStub('index.php');
$stub = $phar->createDefaultStub('index.php');
$phar->setStub($stub);
$phar->stopBuffering();
file_put_contents('info.txt', json_encode(['md5' => md5_file(PHAR_NAME)]));
echo "\n\nDone!\n";
if (trim(strtolower(readline('publish? [y/n]: '))) === 'y') {
passthru('git add .');
if ($commitMessage == '') $commitMessage = '.';
passthru('git commit -m '.escapeshellarg($commitMessage));
passthru('git push');
}