diff --git a/includes/common.php b/includes/common.php index a88d39e456..f18aa34a10 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1086,19 +1086,20 @@ function version_info($remote = true) { global $config; $output = array(); - if ($remote === true && $config['update_channel'] == 'master') { - $api = curl_init(); - set_curl_proxy($api); - curl_setopt($api, CURLOPT_USERAGENT, 'LibreNMS'); - curl_setopt($api, CURLOPT_URL, $config['github_api'].'commits/master'); - curl_setopt($api, CURLOPT_RETURNTRANSFER, 1); - $output['github'] = json_decode(curl_exec($api), true); + if (check_git_exists() === true) { + if ($remote === true && $config['update_channel'] == 'master') { + $api = curl_init(); + set_curl_proxy($api); + curl_setopt($api, CURLOPT_USERAGENT, 'LibreNMS'); + curl_setopt($api, CURLOPT_URL, $config['github_api'].'commits/master'); + curl_setopt($api, CURLOPT_RETURNTRANSFER, 1); + $output['github'] = json_decode(curl_exec($api), true); + } + list($local_sha, $local_date) = explode('|', rtrim(`git show --pretty='%H|%ct' -s HEAD`)); + $output['local_sha'] = $local_sha; + $output['local_date'] = $local_date; + $output['local_branch'] = rtrim(`git rev-parse --abbrev-ref HEAD`); } - list($local_sha, $local_date) = explode('|', rtrim(`git show --pretty='%H|%ct' -s HEAD`)); - $output['local_sha'] = $local_sha; - $output['local_date'] = $local_date; - $output['local_branch'] = rtrim(`git rev-parse --abbrev-ref HEAD`); - $output['db_schema'] = dbFetchCell('SELECT version FROM dbSchema'); $output['php_ver'] = phpversion(); $output['mysql_ver'] = dbFetchCell('SELECT version()'); @@ -1570,3 +1571,12 @@ function set_numeric($value, $default = 0) } return $value; } + +function check_git_exists() +{ + if (`which git`) { + return true; + } else { + return false; + } +} diff --git a/validate.php b/validate.php index 1bf8b5dccc..b2610f8014 100755 --- a/validate.php +++ b/validate.php @@ -75,6 +75,11 @@ if (!file_exists($config['install_dir'].'/config.php')) { exit; } +$git_found = check_git_exists(); +if ($git_found !== true) { + print_warn('Unable to locate git. This should probably be installed.'); +} + $versions = version_info(); $cur_sha = $versions['local_sha']; @@ -103,9 +108,11 @@ if (!($username === 'root' || (isset($config['user']) && $username === $config[' print_fail('You need to run this script as root' . (isset($config['user']) ? ' or '.$config['user'] : '')); } -if ($config['update_channel'] == 'master' && $cur_sha != $versions['github']['sha']) { - $commit_date = new DateTime('@'.$versions['local_date'], new DateTimeZone(date_default_timezone_get())); - print_warn("Your install is out of date, last update: " . $commit_date->format('r')); +if ($git_found === true) { + if ($config['update_channel'] == 'master' && $cur_sha != $versions['github']['sha']) { + $commit_date = new DateTime('@'.$versions['local_date'], new DateTimeZone(date_default_timezone_get())); + print_warn("Your install is out of date, last update: " . $commit_date->format('r')); + } } // Check php modules we use to make sure they are loaded @@ -252,21 +259,22 @@ if (count($devices = dbFetchColumn('SELECT `hostname` FROM `devices` WHERE last_ print_list($devices, "\t %s\n"); } -if ($versions['local_branch'] != 'master') { - print_warn("Your local git branch is not master, this will prevent automatic updates."); -} +if ($git_found === true) { + 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.'"'; + // check for modified files + $modifiedcmd = 'git diff --name-only --exit-code'; + if ($username === 'root') { + $modifiedcmd = 'su '.$config['user'].' -c "'.$modifiedcmd.'"'; + } + exec($modifiedcmd, $cmdoutput, $code); + if ($code !== 0 && !empty($cmdoutput)) { + print_warn("Your local git contains modified files, this could prevent automatic updates.\nModified files:"); + print_list($cmdoutput, "\t %s\n"); + } } -exec($modifiedcmd, $cmdoutput, $code); -if ($code !== 0 && !empty($cmdoutput)) { - print_warn("Your local git contains modified files, this could prevent automatic updates.\nModified files:"); - print_list($cmdoutput, "\t %s\n"); -} - // Modules test $modules = explode(',', $options['m']); foreach ($modules as $module) {