Add librenms command (#9619)

* Add librenms command

Hook up to artisan.  Hide dev commands and most other commands if app environment is production.
Register all commands for php artisan or when not in production.

* remove dead end line

* Console application name and version.
Had to shift some stuff from legacy code, but deferred others as it was too extensive of a change.

* switch check order

* always get local version now

* update array format

* whitepace

* fix style
This commit is contained in:
Tony Murray
2019-01-08 21:42:56 -06:00
committed by GitHub
parent c6e5a3f283
commit def8b3e514
14 changed files with 244 additions and 150 deletions

43
LibreNMS/Util/Git.php Normal file
View File

@@ -0,0 +1,43 @@
<?php
/**
* Git.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\Util;
use LibreNMS\Config;
class Git
{
public static function repoPresent()
{
$install_dir = Config::get('install_dir', realpath(__DIR__ . '/../..'));
return file_exists("$install_dir/.git");
}
public static function binaryExists()
{
exec('git > /dev/null 2>&1', $response, $exit_code);
return $exit_code === 1;
}
}

53
LibreNMS/Util/Version.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
/**
* Version.php
*
* Get version info about LibreNMS and various components/dependencies
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\Util;
class Version
{
// Update this on release
const VERSION = '1.47';
protected $is_git_install = false;
public function __construct()
{
$this->is_git_install = Git::repoPresent() && Git::binaryExists();
}
public static function get()
{
return new static;
}
public function local()
{
if ($this->is_git_install) {
return rtrim(shell_exec('git describe --tags'));
}
return self::VERSION;
}
}