From baf52da273848f7832bd9a7fa5f41ae608814233 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 16 Nov 2016 05:47:34 -0800 Subject: [PATCH 1/2] Don't require `--allow-root` with `cli update`; clarify docs --- README.md | 2 ++ php/WP_CLI/Runner.php | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6c2a98ec93..3d0dc8b557 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,8 @@ WP-CLI version: 0.25.0 You can update WP-CLI with `wp cli update` ([doc](https://wp-cli.org/commands/cli/update/)), or by repeating the installation steps. +If WP-CLI is owned by root or another system user, you'll need to run `sudo wp cli update`. + Want to live life on the edge? Run `wp cli update --nightly` to use the latest nightly build of WP-CLI. The nightly build is more or less stable enough for you to use in your development environment, and always includes the latest and greatest WP-CLI features. ### Tab completions diff --git a/php/WP_CLI/Runner.php b/php/WP_CLI/Runner.php index 34d60cdff1..98cf8325fe 100644 --- a/php/WP_CLI/Runner.php +++ b/php/WP_CLI/Runner.php @@ -661,12 +661,18 @@ private function init_config() { } private function check_root() { - if ( $this->config['allow-root'] ) + if ( $this->config['allow-root'] ) { return; # they're aware of the risks! - if ( !function_exists( 'posix_geteuid') ) + } + if ( 'cli' === $this->arguments[0] && 'update' === $this->arguments[1] ) { + return; # make it easier to update root-owned copies + } + if ( !function_exists( 'posix_geteuid') ) { return; # posix functions not available - if ( posix_geteuid() !== 0 ) + } + if ( posix_geteuid() !== 0 ) { return; # not root + } WP_CLI::error( "YIKES! It looks like you're running this as root. You probably meant to " . From 2d05e655a68ab3f2ae72544e262869dcd5df6756 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 16 Nov 2016 08:27:12 -0800 Subject: [PATCH 2/2] Prevent error notices when `arguments` doesn't contain two items --- php/WP_CLI/Runner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/WP_CLI/Runner.php b/php/WP_CLI/Runner.php index 98cf8325fe..0700d01ee7 100644 --- a/php/WP_CLI/Runner.php +++ b/php/WP_CLI/Runner.php @@ -664,7 +664,7 @@ private function check_root() { if ( $this->config['allow-root'] ) { return; # they're aware of the risks! } - if ( 'cli' === $this->arguments[0] && 'update' === $this->arguments[1] ) { + if ( count( $this->arguments ) >= 2 && 'cli' === $this->arguments[0] && 'update' === $this->arguments[1] ) { return; # make it easier to update root-owned copies } if ( !function_exists( 'posix_geteuid') ) {