diff --git a/.distignore b/.distignore new file mode 100644 index 0000000..acbaa32 --- /dev/null +++ b/.distignore @@ -0,0 +1,16 @@ +.DS_Store +.git +.gitignore +.gitlab-ci.yml +.editorconfig +.travis.yml +behat.yml +circle.yml +bin/ +features/ +utils/ +*.zip +*.tar.gz +*.swp +*.txt +*.log diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..fa483b1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,25 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +# WordPress Coding Standards +# https://make.wordpress.org/core/handbook/coding-standards/ + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = tab + +[{.jshintrc,*.json,*.yml,*.feature}] +indent_style = space +indent_size = 2 + +[{*.txt,wp-config-sample.php}] +end_of_line = crlf + +[composer.json] +indent_style = space +indent_size = 4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92b69bc --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +.DS_Store +wp-cli.local.yml +node_modules/ +vendor/ +*.zip +*.tar.gz +*.swp +*.txt +*.log +composer.lock +.idea +*.db diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..505b421 --- /dev/null +++ b/composer.json @@ -0,0 +1,25 @@ +{ + "name": "easyengine/shell-command", + "description": "Shell to run helpful commands inside containers.", + "type": "ee-cli-package", + "homepage": "https://github.com/easyengine/shell-command", + "license": "MIT", + "authors": [], + "minimum-stability": "dev", + "prefer-stable": true, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ "shell-command.php" ] + }, + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "bundled": true, + "commands": [ + "shell" + ] + } +} diff --git a/ee.yml b/ee.yml new file mode 100644 index 0000000..51a825a --- /dev/null +++ b/ee.yml @@ -0,0 +1,2 @@ +require: + - shell-command.php \ No newline at end of file diff --git a/shell-command.php b/shell-command.php new file mode 100644 index 0000000..f03a9b7 --- /dev/null +++ b/shell-command.php @@ -0,0 +1,12 @@ +] + * : Name of website to run shell on. + */ + public function __invoke( $args ) { + EE\Utils\delem_log( 'ee shell start' ); + $args = EE\Utils\set_site_arg( $args, 'shell' ); + $site_name = EE\Utils\remove_trailing_slash( $args[0] ); + if ( EE::db()::site_in_db( $site_name ) ) { + $db_select = EE::db()::select( ['site_path'], ['sitename' => $site_name]); + $site_root = $db_select[0]['site_path']; + } else { + EE::error( "Site $site_name does not exist." ); + } + chdir($site_root); + $this->run( "docker-compose exec --user='www-data' php bash" ); + EE\Utils\delem_log( 'ee shell end' ); + } + + private function run( $cmd, $descriptors = null ) { + EE\Utils\check_proc_available( 'ee_shell' ); + if ( ! $descriptors ) { + $descriptors = array( STDIN, STDOUT, STDERR ); + } + + $final_cmd = EE\Utils\force_env_on_nix_systems( $cmd ); + $proc = EE\Utils\proc_open_compat( $final_cmd, $descriptors, $pipes ); + if ( ! $proc ) { + exit( 1 ); + } + $r = proc_close( $proc ); + if ( $r ) { + exit( $r ); + } + } + +}