hotfix: Updated facts, added facts subcommand
This commit is contained in:
		
							
								
								
									
										33
									
								
								src/Command/FactsCommand.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/Command/FactsCommand.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace NoccyLabs\Hotfix\Command;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Symfony\Component\Console\Command\Command;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Symfony\Component\Console\Input\InputInterface;
 | 
				
			||||||
 | 
					use Symfony\Component\Console\Input\InputArgument;
 | 
				
			||||||
 | 
					use Symfony\Component\Console\Input\InputOption;
 | 
				
			||||||
 | 
					use Symfony\Component\Console\Output\OutputInterface;
 | 
				
			||||||
 | 
					use Symfony\Component\Console\Question\ConfirmationQuestion;
 | 
				
			||||||
 | 
					use Symfony\Component\Console\Question\ChoiceQuestion;
 | 
				
			||||||
 | 
					use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
 | 
				
			||||||
 | 
					use NoccyLabs\Hotfix\Hotfix\Loader;
 | 
				
			||||||
 | 
					use NoccyLabs\Hotfix\System\Facts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class FactsCommand extends Command
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected function configure()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -11,6 +11,7 @@ class HotfixApplication extends Application
 | 
				
			|||||||
        parent::__construct("Hotfix", APP_VERSION.(defined('PHAR_BUILD_DATE')?" (".PHAR_BUILD_DATE.")":""));
 | 
					        parent::__construct("Hotfix", APP_VERSION.(defined('PHAR_BUILD_DATE')?" (".PHAR_BUILD_DATE.")":""));
 | 
				
			||||||
        $this->add(new Command\ApplyCommand());
 | 
					        $this->add(new Command\ApplyCommand());
 | 
				
			||||||
        $this->add(new Command\SignCommand());
 | 
					        $this->add(new Command\SignCommand());
 | 
				
			||||||
 | 
					        $this->add(new Command\FactsCommand());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,10 +21,19 @@ class Facts
 | 
				
			|||||||
    public function read()
 | 
					    public function read()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $facts = [];
 | 
					        $facts = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $facts['lsb'] = $this->readLsbInfo();
 | 
				
			||||||
 | 
					        $facts['system'] = $this->readSystemInfo();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        $this->facts = $facts;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private function readLsbInfo()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        $has_lsb_release = exec("which lsb_release");
 | 
					        $has_lsb_release = exec("which lsb_release");
 | 
				
			||||||
        if ($has_lsb_release) {
 | 
					        if ($has_lsb_release) {
 | 
				
			||||||
            exec("lsb_release -idrcs", $output);
 | 
					            exec("lsb_release -idrcs", $output);
 | 
				
			||||||
            $facts['lsb'] = (object)[
 | 
					            $facts = (object)[
 | 
				
			||||||
                'id' => strtolower($output[0]),
 | 
					                'id' => strtolower($output[0]),
 | 
				
			||||||
                'description' => $output[1],
 | 
					                'description' => $output[1],
 | 
				
			||||||
                'release' => $output[2],
 | 
					                'release' => $output[2],
 | 
				
			||||||
@@ -32,15 +41,26 @@ class Facts
 | 
				
			|||||||
            ];
 | 
					            ];
 | 
				
			||||||
        } elseif (file_exists("/etc/os-release")) {
 | 
					        } elseif (file_exists("/etc/os-release")) {
 | 
				
			||||||
            $ini = parse_ini_file("/etc/os-release");
 | 
					            $ini = parse_ini_file("/etc/os-release");
 | 
				
			||||||
            $facts['lsb'] = (object)[
 | 
					            $facts = (object)[
 | 
				
			||||||
                'id' => strtolower(@$ini['ID']),
 | 
					                'id' => strtolower(@$ini['ID']),
 | 
				
			||||||
                'description' => @$ini['PRETTY_NAME'],
 | 
					                'description' => @$ini['PRETTY_NAME'],
 | 
				
			||||||
                'release' => @$ini['VERSION_ID'],
 | 
					                'release' => @$ini['VERSION_ID'],
 | 
				
			||||||
                'codename' => @$ini['VERSION_CODENAME']
 | 
					                'codename' => @$ini['VERSION_CODENAME']
 | 
				
			||||||
            ];
 | 
					            ];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        return $facts;
 | 
				
			||||||
        $this->facts = $facts;
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private function readSystemInfo()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $facts = (object)[
 | 
				
			||||||
 | 
					            'bits' => trim(exec('getconf LONG_BIT')),
 | 
				
			||||||
 | 
					            'arch' => trim(exec('uname -m')),  
 | 
				
			||||||
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $facts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getFacts()
 | 
					    public function getFacts()
 | 
				
			||||||
@@ -48,4 +68,23 @@ class Facts
 | 
				
			|||||||
        return $this->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;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user