125 lines
3.1 KiB
Plaintext
Raw Normal View History

2014-07-04 12:15:38 +04:00
#!/usr/bin/env php
2013-07-11 15:47:09 +04:00
<?php
2016-01-11 12:51:59 +07:00
/* (c) Anton Medvedev <anton@medv.io>
2013-07-11 15:47:09 +04:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// Deployer constants
2016-03-11 14:59:34 +01:00
define('DEPLOYER', true);
define('DEPLOYER_BIN', __FILE__);
2017-05-16 17:26:00 +07:00
// Check for php7
if (!defined('PHP_MAJOR_VERSION') || PHP_MAJOR_VERSION < 7) {
fwrite(
STDERR,
2017-05-16 17:26:00 +07:00
'Upgrade to php7' . PHP_EOL .
'Deployer 5.x supports only php7 and above.' . PHP_EOL .
'If you want to use older php version use Deployer 4.x' . PHP_EOL
);
exit(1);
2017-05-16 17:26:00 +07:00
}
2016-11-12 17:02:13 +07:00
// Detect deploy.php script
$options = getopt('f::', ['file::']);
$userSpecifiedFile = null;
if (isset($options['f'])) {
$userSpecifiedFile = $options['f'];
2015-06-18 12:41:40 +02:00
} elseif (isset($options['file'])) {
$userSpecifiedFile = $options['file'];
}
if (empty($userSpecifiedFile)) {
$deployFile = getcwd() . '/deploy.php';
2016-11-07 20:43:31 +07:00
2017-01-27 20:06:31 +07:00
if (!is_readable($deployFile)) {
2016-11-07 20:43:31 +07:00
$currentDir = getcwd();
$count = 0;
do {
$currentDir = dirname($currentDir);
$deployFile = $currentDir . '/deploy.php';
$count++;
} while (!is_readable($deployFile) && $count < 100);
}
} else {
$deployFile = ($userSpecifiedFile[0] === '/' ? '' : getcwd() . '/') . $userSpecifiedFile;
}
2014-07-04 13:39:57 +04:00
2016-11-12 17:02:13 +07:00
$deployFilePath = dirname($deployFile);
// Detect source location
$autoload = [
$deployFilePath . '/vendor/autoload.php',
__DIR__ . '/../../../autoload.php',
__DIR__ . '/../vendor/autoload.php'
];
$includes = [
$deployFilePath . '/vendor/deployer/deployer',
__DIR__ . '/../../../deployer/deployer',
__DIR__ . '/../'
];
$loaded = false;
$includePath = false;
$vendorDir = false;
2016-11-12 17:02:13 +07:00
for ($i = 0; $i < count($autoload); $i++) {
if (file_exists($autoload[$i]) && file_exists($includes[$i])) {
2016-11-12 17:02:13 +07:00
require $autoload[$i];
$vendorDir = dirname($autoload[$i]);
2016-11-12 17:02:13 +07:00
$includePath = $includes[$i];
$loaded = true;
break;
}
}
if (!$loaded) {
fwrite(
STDERR,
2016-11-12 17:02:13 +07:00
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'wget http://getcomposer.org/composer.phar' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
exit(1);
2016-11-12 17:02:13 +07:00
}
// Setup include path
set_include_path($includePath . PATH_SEPARATOR . get_include_path());
// Detect version
$version = 'master';
$installedFile = $vendorDir . '/composer/installed.json';
if (is_readable($installedFile)) {
$packages = json_decode(file_get_contents($installedFile), true);
foreach ($packages as $package) {
2016-11-12 17:02:13 +07:00
if ($package['name'] === 'deployer/deployer') {
$version = $package['version'];
break;
2016-11-12 17:02:13 +07:00
}
}
}
2017-03-25 16:08:21 +07:00
$method = new ReflectionMethod('Deployer\Deployer', 'run');
if (!$method->isStatic()) {
fwrite(
STDERR,
2017-03-25 16:09:18 +07:00
'You need to update Deployer to the latest version:' . PHP_EOL .
2017-03-25 16:08:21 +07:00
PHP_EOL .
2017-03-25 16:10:31 +07:00
' dep self-update' . PHP_EOL .
2017-03-25 16:08:21 +07:00
PHP_EOL .
'Or use composer installed version:' . PHP_EOL .
PHP_EOL .
' php vendor/bin/dep' . PHP_EOL .
PHP_EOL
);
exit(1);
}
2017-03-25 16:08:21 +07:00
\Deployer\Deployer::run($version, $deployFile);