diff --git a/src/Command/FactsCommand.php b/src/Command/FactsCommand.php new file mode 100644 index 0000000..e5047c7 --- /dev/null +++ b/src/Command/FactsCommand.php @@ -0,0 +1,33 @@ +setName("facts"); + $this->setDescription("List the facts as collected on this system"); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $facts = Facts::getSystemFacts()->getFlat(); + + print_r($facts); + + } +} diff --git a/src/HotfixApplication.php b/src/HotfixApplication.php index 42e59a4..21598c3 100644 --- a/src/HotfixApplication.php +++ b/src/HotfixApplication.php @@ -11,6 +11,7 @@ class HotfixApplication extends Application parent::__construct("Hotfix", APP_VERSION.(defined('PHAR_BUILD_DATE')?" (".PHAR_BUILD_DATE.")":"")); $this->add(new Command\ApplyCommand()); $this->add(new Command\SignCommand()); + $this->add(new Command\FactsCommand()); } diff --git a/src/System/Facts.php b/src/System/Facts.php index 061d62a..78dc968 100644 --- a/src/System/Facts.php +++ b/src/System/Facts.php @@ -21,10 +21,19 @@ class Facts public function read() { $facts = []; + + $facts['lsb'] = $this->readLsbInfo(); + $facts['system'] = $this->readSystemInfo(); + + $this->facts = $facts; + } + + private function readLsbInfo() + { $has_lsb_release = exec("which lsb_release"); if ($has_lsb_release) { exec("lsb_release -idrcs", $output); - $facts['lsb'] = (object)[ + $facts = (object)[ 'id' => strtolower($output[0]), 'description' => $output[1], 'release' => $output[2], @@ -32,15 +41,26 @@ class Facts ]; } elseif (file_exists("/etc/os-release")) { $ini = parse_ini_file("/etc/os-release"); - $facts['lsb'] = (object)[ + $facts = (object)[ 'id' => strtolower(@$ini['ID']), 'description' => @$ini['PRETTY_NAME'], 'release' => @$ini['VERSION_ID'], 'codename' => @$ini['VERSION_CODENAME'] ]; } - - $this->facts = $facts; + return $facts; + } + + private function readSystemInfo() + { + + $facts = (object)[ + 'bits' => trim(exec('getconf LONG_BIT')), + 'arch' => trim(exec('uname -m')), + ]; + + return $facts; + } public function getFacts() @@ -48,4 +68,23 @@ class Facts return $this->facts; } + public function getFlat() + { + return $this->flatten($this->facts, []); + } + + private function flatten($facts, array $path) + { + $ret = []; + foreach ((array)$facts as $fact=>$value) { + $sub = array_merge($path, [ $fact ]); + if (is_object($value)) { + $ret = array_merge($ret, $this->flatten($value, $sub)); + } else { + $ret[join(".",$sub)] = $value; + } + } + return $ret; + } + }