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