From 2dbec67088fa504cd080de46d29eac75173ef35e Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 1 Jul 2016 12:47:15 -0500 Subject: [PATCH 1/2] Run git as the configured user when ./validate.php is run as root Move the modified files check out of the get_version function --- includes/common.php | 4 ---- validate.php | 11 ++++++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/includes/common.php b/includes/common.php index 1a7c817b8f..a7a91999c1 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1039,10 +1039,6 @@ function version_info($remote=true) { $output['local_sha'] = rtrim(`git rev-parse HEAD`); $output['local_branch'] = rtrim(`git rev-parse --abbrev-ref HEAD`); - exec('git diff --name-only --exit-code', $cmdoutput, $code); - $output['git_modified'] = ($code !== 0); - $output['git_modified_files'] = $cmdoutput; - $output['db_schema'] = dbFetchCell('SELECT version FROM dbSchema'); $output['php_ver'] = phpversion(); $output['mysql_ver'] = dbFetchCell('SELECT version()'); diff --git a/validate.php b/validate.php index 9075a2ac7d..d39f9c4094 100755 --- a/validate.php +++ b/validate.php @@ -36,7 +36,7 @@ if (isset($options['h'])) { if (strstr(`php -ln config.php`, 'No syntax errors detected')) { $first_line = `head -n1 config.php`; $last_lines = explode(PHP_EOL, `tail -n2 config.php`); - if (strstr($first_line, '\<\?php')) { + if (substr($first_line, 0, 5) !== '' && $last_lines[1] == '') { @@ -84,9 +84,14 @@ else { if($versions['local_branch'] != 'master') { print_warn("Your local git branch is not master, this will prevent automatic updates."); } -if($versions['git_modified'] === true) { + +$modifiedcmd = 'git diff --name-only --exit-code'; +if($username === 'root') { + $modifiedcmd = 'su '.$config['user'].' -c "'.$modifiedcmd.'"'; +} +if(exec($modifiedcmd, $cmdoutput, $code) !== 0) { print_warn("Your local git contains modified files, this could prevent automatic updates.\nModified files:"); - echo(implode("\n", $versions['git_modified_files']) . "\n"); + echo(implode("\n", $cmdoutput) . "\n"); } echo "DB Schema: ".$versions['db_schema']."\n"; From 080c59c387cd277c784f621712a42ee5bd2f0161 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 1 Jul 2016 16:16:23 -0500 Subject: [PATCH 2/2] Correct check for command results. --- validate.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/validate.php b/validate.php index d39f9c4094..230ab0b393 100755 --- a/validate.php +++ b/validate.php @@ -85,11 +85,13 @@ if($versions['local_branch'] != 'master') { print_warn("Your local git branch is not master, this will prevent automatic updates."); } +// check for modified files $modifiedcmd = 'git diff --name-only --exit-code'; if($username === 'root') { $modifiedcmd = 'su '.$config['user'].' -c "'.$modifiedcmd.'"'; } -if(exec($modifiedcmd, $cmdoutput, $code) !== 0) { +exec($modifiedcmd, $cmdoutput, $code); +if($code !== 0) { print_warn("Your local git contains modified files, this could prevent automatic updates.\nModified files:"); echo(implode("\n", $cmdoutput) . "\n"); }