diff --git a/bin/terminus b/bin/terminus index 1b5a18740..dd402b7a4 100755 --- a/bin/terminus +++ b/bin/terminus @@ -1,81 +1,50 @@ -#!/usr/bin/env php -=') === true) { - fwrite(STDERR, "\n"); - fwrite(STDERR, 'PHP 8.5+ is not supported by this version of Terminus.' . "\n"); - fwrite(STDERR, 'Check for new versions at https://github.com/pantheon-systems/terminus/releases' . "\n"); - fwrite(STDERR, "\n"); - fwrite(STDERR, 'Set environment variable TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP to try continuing anyway.' . "\n"); - fwrite(STDERR, "Stopping.\n\n"); - exit(1); -} - -// This variable is automatically managed via updateDependenciesversion() in /RoboFile.php, -// which is run after every call to composer update. -$terminusPluginsDependenciesVersion = '51e2c517dd'; - -// Cannot use $_SERVER superglobal since that's empty during phpunit testing -// getenv('HOME') isn't set on Windows and generates a Notice. -$home = @getenv('HOME'); -if (!empty($home)) { - // home should never end with a trailing slash. - $home = rtrim($home, '/'); -} - -if (empty($home) && !empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH'])) { - // home on windows - $home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH']; - // If HOMEPATH is a root directory the path can end with a slash. Make sure - // that doesn't happen. - $home = rtrim($home, '\\/'); - @putenv("HOME={$home}"); -} - -$pharPath = \Phar::running(true); -if ($pharPath) { - include_once("$pharPath/vendor/autoload.php"); -} elseif (file_exists($path = __DIR__ . '/../vendor/autoload.php') - || file_exists($path = __DIR__ . '/../../autoload.php') - || file_exists($path = __DIR__ . '/../../../autoload.php') -) { - include_once($path); -} else { - throw new \Exception('Could not locate autoload.php'); -} - -use Pantheon\Terminus\Terminus; - -$home_tokens_folder = '.terminus' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'tokens'; - -$tokens_dir = $home . DIRECTORY_SEPARATOR . $home_tokens_folder; -if (!is_dir($tokens_dir)) { - mkdir( - $tokens_dir, - 0700, - true - ); -} - -$terminus = Terminus::factory($terminusPluginsDependenciesVersion); -$status_code = $terminus->run(); -exit($status_code); +#!/usr/bin/env sh + +SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" + +# If we can find a .env file next to the `terminus` binary, source it. +# TODO: Is this a reasonable location? Where else should we look? +# Should we make the filename more specific, e.g. `.terminus-env`? +if [ -f "$SCRIPTPATH/.env" ]; then + source "$SCRIPTPATH/.env" +fi + +# One good fallback location is in the Terminus config directory. +# Note that we already have $HOME/.terminus/config.yml, but I +# don't think we should parse that here. +if [ -f "$HOME/.terminus/.env" ]; then + source "$HOME/.terminus/.env" +fi + +# The logic below is ideal for scripts that are distributed +# in `vendor/bin`. We might benefit if we decide to support +# `terminus create-project pantheon-systems/terminus` as an +# installation method. If we decide aginst this, we could +# remove "$COMPOSER_RUNTIME_BIN_DIR" checks. +if [ -z "$COMPOSER_RUNTIME_BIN_DIR" ]; then + # This branch is for the development of Drush itself. + # @see https://stackoverflow.com/questions/4774054 + TERMINUS_EXECUTABLE="$SCRIPTPATH/terminus.php" +else + TERMINUS_EXECUTABLE="$COMPOSER_RUNTIME_BIN_DIR/terminus.php" +fi + +# If we can't find `terminus.php` next to `terminus`, +# look for `terminus.php` in the same directory. +if [ ! -f "$TERMINUS_EXECUTABLE" ]; then + TERMINUS_EXECUTABLE="$SCRIPTPATH/terminus.phar" +fi + +# If there is no `terminus.phar` nearby, check for one +# in the $PATH. +if [ ! -f "$TERMINUS_EXECUTABLE" ]; then + TERMINUS_EXECUTABLE="terminus.phar" +fi + +# Use the PHP binary indicated by $TERMINUS_PHP, or use +# the one in the $PATH if $TERMINUS_PHP is not set. +PHP="${TERMINUS_PHP=php}" + +# Run Terminus with the selected version of PHP, passing +# through all parameters. +exec "$TERMINUS_PHP" "$TERMINUS_EXECUTABLE" "$@" diff --git a/bin/terminus.php b/bin/terminus.php new file mode 100755 index 000000000..1b5a18740 --- /dev/null +++ b/bin/terminus.php @@ -0,0 +1,81 @@ +#!/usr/bin/env php +=') === true) { + fwrite(STDERR, "\n"); + fwrite(STDERR, 'PHP 8.5+ is not supported by this version of Terminus.' . "\n"); + fwrite(STDERR, 'Check for new versions at https://github.com/pantheon-systems/terminus/releases' . "\n"); + fwrite(STDERR, "\n"); + fwrite(STDERR, 'Set environment variable TERMINUS_ALLOW_UNSUPPORTED_NEWER_PHP to try continuing anyway.' . "\n"); + fwrite(STDERR, "Stopping.\n\n"); + exit(1); +} + +// This variable is automatically managed via updateDependenciesversion() in /RoboFile.php, +// which is run after every call to composer update. +$terminusPluginsDependenciesVersion = '51e2c517dd'; + +// Cannot use $_SERVER superglobal since that's empty during phpunit testing +// getenv('HOME') isn't set on Windows and generates a Notice. +$home = @getenv('HOME'); +if (!empty($home)) { + // home should never end with a trailing slash. + $home = rtrim($home, '/'); +} + +if (empty($home) && !empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH'])) { + // home on windows + $home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH']; + // If HOMEPATH is a root directory the path can end with a slash. Make sure + // that doesn't happen. + $home = rtrim($home, '\\/'); + @putenv("HOME={$home}"); +} + +$pharPath = \Phar::running(true); +if ($pharPath) { + include_once("$pharPath/vendor/autoload.php"); +} elseif (file_exists($path = __DIR__ . '/../vendor/autoload.php') + || file_exists($path = __DIR__ . '/../../autoload.php') + || file_exists($path = __DIR__ . '/../../../autoload.php') +) { + include_once($path); +} else { + throw new \Exception('Could not locate autoload.php'); +} + +use Pantheon\Terminus\Terminus; + +$home_tokens_folder = '.terminus' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'tokens'; + +$tokens_dir = $home . DIRECTORY_SEPARATOR . $home_tokens_folder; +if (!is_dir($tokens_dir)) { + mkdir( + $tokens_dir, + 0700, + true + ); +} + +$terminus = Terminus::factory($terminusPluginsDependenciesVersion); +$status_code = $terminus->run(); +exit($status_code); diff --git a/composer.json b/composer.json index 83ddfc823..5cc2f1170 100644 --- a/composer.json +++ b/composer.json @@ -64,6 +64,7 @@ ] }, "bin": [ + "bin/terminus.php", "bin/terminus" ], "scripts": {