diff --git a/ci/prepare.sh b/ci/prepare.sh index 7ae98d55f..5f2a38056 100755 --- a/ci/prepare.sh +++ b/ci/prepare.sh @@ -10,4 +10,7 @@ if [[ "$TRAVIS_BRANCH" != $DEPLOY_BRANCH ]]; then sed -i 's/\:\ \"\(.*\)\"/\:\ \"\1-nightly\"/g' img-versions.json fi -php -dphar.readonly=0 ./utils/make-phar.php easyengine.phar --quiet \ No newline at end of file +php -dphar.readonly=0 ./utils/make-phar.php easyengine.phar --quiet + +# Checking the phar is working. +./easyengine.phar cli info \ No newline at end of file diff --git a/php/EE/Runner.php b/php/EE/Runner.php index c7227ae16..99a2549b8 100644 --- a/php/EE/Runner.php +++ b/php/EE/Runner.php @@ -64,28 +64,48 @@ private function init_ee() { if ( ! empty( $this->arguments ) && - ( 'help' !== $this->arguments[0] ) - && $this->arguments !== [ 'cli', 'version' ] - ) - { + ( ! in_array( $this->arguments[0], [ 'cli', 'config', 'help' ], true ) ) + ) { + $this->check_requirements(); + $this->maybe_trigger_migration(); + } + if ( [ 'cli', 'info' ] === $this->arguments && $this->check_requirements( false ) ) { + $this->maybe_trigger_migration(); + } + } - // Minimum requirement checks. - $docker_running = 'docker ps > /dev/null'; - if ( ! EE::exec( $docker_running ) ) { - EE::error( 'docker not installed or not running.' ); - } + /** + * Check EE requirements for required commands. + * + * @param bool $show_error To display error or to retutn status. + */ + public function check_requirements( $show_error = true ) { - $docker_compose_installed = 'command -v docker-compose > /dev/null'; - if ( ! EE::exec( $docker_compose_installed ) ) { - EE::error( 'EasyEngine requires docker-compose.' ); - } + $status = true; + $error = []; - if ( version_compare( PHP_VERSION, '7.2.0' ) < 0 ) { - EE::error( 'EasyEngine requires minimum PHP 7.2.0 to run.' ); - } + $docker_running = 'docker ps > /dev/null'; + if ( ! EE::exec( $docker_running ) ) { + $status = false; + $error[] = 'Docker not installed or not running.'; + } - $this->maybe_trigger_migration(); + $docker_compose_installed = 'command -v docker-compose > /dev/null'; + if ( ! EE::exec( $docker_compose_installed ) ) { + $status = false; + $error[] = 'EasyEngine requires docker-compose.'; } + + if ( version_compare( PHP_VERSION, '7.2.0' ) < 0 ) { + $status = false; + $error[] = 'EasyEngine requires minimum PHP 7.2.0 to run.'; + } + + if ( $show_error && ! $status ) { + EE::error( reset( $error ) ); + } + + return $status; } /** diff --git a/php/commands/src/CLI_Command.php b/php/commands/src/CLI_Command.php index c1bafea71..a80198165 100644 --- a/php/commands/src/CLI_Command.php +++ b/php/commands/src/CLI_Command.php @@ -286,6 +286,7 @@ public function update( $_, $assoc_args ) { $download_url = $newest['package_url']; $md5_url = str_replace( '.phar', '.phar.md5', $download_url ); } + EE::get_runner()->check_requirements(); EE::log( sprintf( 'Downloading from %s...', $download_url ) ); $temp = \EE\Utils\get_temp_dir() . uniqid( 'ee_', true ) . '.phar'; $headers = array(); @@ -493,6 +494,11 @@ public function cmd_dump() { */ public function self_uninstall( $args, $assoc_args ) { + if ( ! EE::get_runner()->check_requirements( false ) ) { + EE::error( 'Unable to proceed with uninstallation. Seems there is a dependency down.', false ); + die; + } + EE::confirm( "Are you sure you want to remove EasyEngine and all its sites(along with their data)?\nThis is an irreversible action. No backup will be kept.", $assoc_args ); EE::exec( 'docker rm -f $(docker ps -aqf label=org.label-schema.vendor="EasyEngine")' );