| 1 |
<?php |
| 2 |
|
| 3 |
namespace WindPressPackages; |
| 4 |
|
| 5 |
$dist = \dirname(__DIR__) . '/dist'; |
| 6 |
if (!\is_dir($dist)) { |
| 7 |
\mkdir($dist, 0755); |
| 8 |
} |
| 9 |
if (\file_exists($dist . '/random_compat.phar')) { |
| 10 |
\unlink($dist . '/random_compat.phar'); |
| 11 |
} |
| 12 |
$phar = new \Phar($dist . '/random_compat.phar', \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME, 'random_compat.phar'); |
| 13 |
\rename(\dirname(__DIR__) . '/lib/random.php', \dirname(__DIR__) . '/lib/index.php'); |
| 14 |
$phar->buildFromDirectory(\dirname(__DIR__) . '/lib'); |
| 15 |
\rename(\dirname(__DIR__) . '/lib/index.php', \dirname(__DIR__) . '/lib/random.php'); |
| 16 |
/** |
| 17 |
* If we pass an (optional) path to a private key as a second argument, we will |
| 18 |
* sign the Phar with OpenSSL. |
| 19 |
* |
| 20 |
* If you leave this out, it will produce an unsigned .phar! |
| 21 |
*/ |
| 22 |
if ($argc > 1) { |
| 23 |
if (!@\is_readable($argv[1])) { |
| 24 |
echo 'Could not read the private key file:', $argv[1], "\n"; |
| 25 |
exit(255); |
| 26 |
} |
| 27 |
$pkeyFile = \file_get_contents($argv[1]); |
| 28 |
$private = \openssl_get_privatekey($pkeyFile); |
| 29 |
if ($private !== \false) { |
| 30 |
$pkey = ''; |
| 31 |
\openssl_pkey_export($private, $pkey); |
| 32 |
$phar->setSignatureAlgorithm(\Phar::OPENSSL, $pkey); |
| 33 |
/** |
| 34 |
* Save the corresponding public key to the file |
| 35 |
*/ |
| 36 |
if (!@\is_readable($dist . '/random_compat.phar.pubkey')) { |
| 37 |
$details = \openssl_pkey_get_details($private); |
| 38 |
\file_put_contents($dist . '/random_compat.phar.pubkey', $details['key']); |
| 39 |
} |
| 40 |
} else { |
| 41 |
echo 'An error occurred reading the private key from OpenSSL.', "\n"; |
| 42 |
exit(255); |
| 43 |
} |
| 44 |
} |
| 45 |
|