-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate-phar.php
More file actions
executable file
·35 lines (32 loc) · 874 Bytes
/
Copy pathcreate-phar.php
File metadata and controls
executable file
·35 lines (32 loc) · 874 Bytes
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
#!/usr/bin/php
<?php
$pharFile = '/tmp/ovh-cli.phar';
if (0 == posix_getuid()) {
$finalDir = '/usr/local/bin';
} else {
$finalDir = getenv('HOME').'/bin';
if (!file_exists($finalDir)) {
@mkdir($finalDir);
}
if (!is_dir($finalDir)) {
exit("Unable to create directory {$finalDir}!\n");
}
$finalFile = $finalDir;
}
$finalFile = $finalDir.'/ovh-cli';
foreach ([$pharFile, $pharFile.'.gz'] as $file) {
if (file_exists($file)) {
unlink($file);
}
}
$phar = new Phar($pharFile);
$phar->startBuffering();
$defaultStub = $phar->createDefaultStub('cli.php');
$phar->buildFromDirectory(__DIR__, '/^((?!\.git).)*$/');
$stub = "#!/usr/bin/php \n".$defaultStub;
$phar->setStub($stub);
$phar->stopBuffering();
$phar->compressFiles(Phar::GZ);
chmod($pharFile, 0755);
rename($pharFile, $finalFile);
echo "{$finalFile} has been successfully created!".PHP_EOL;