|
|
- <?php
-
- namespace App\Helpers;
-
- /**
- * Helper for install
- *
- * @author Björn Hase, Tentakelfabrik
- * @license http://opensource.org/licenses/MIT The MIT License
- * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
- *
- */
- class InstallHelper
- {
- // message for status
- const PACKAGE_STATUS = 'Status: install ok installed';
-
- // not allowed message
- const NOT_ALLOWED = [
- 'WARNING: apt does not have a stable CLI interface. Use with caution in scripts.'
- ];
-
- /**
- * check if a packege is installed
- *
- * @param string $name
- * @return boolean
- */
- public function isReady($name)
- {
- $result = false;
-
- exec('echo $(dpkg -s nginx 2>&1 | grep "'.self::PACKAGE_STATUS.'")', $output);
-
- if (isset($output[0]) && $output[0] === self::PACKAGE_STATUS) {
- $result = true;
- }
-
- return $result;
- }
-
- /**
- * apt add a Warning for no good,
- *
- *
- * @return array
- */
- public function filterAptMessages($output)
- {
- $results = [];
-
- foreach($output as $message) {
- if (!in_array($message, self::NOT_ALLOWED) && !empty($message)) {
- $results[] = $message;
- }
- }
-
- return $results;
- }
-
- /**
- *
- *
- * @return string
- */
- public function getDistributionId()
- {
- return $this->getSystemInfo('DISTRIB_ID');
- }
-
- /**
- *
- * @return string
- */
- public function getDistributionRelease()
- {
- return $this->getSystemInfo('DISTRIB_RELEASE');
- }
-
- /**
- *
- *
- * @return string
- */
- public function getDistributionCodename()
- {
- return $this->getSystemInfo('DISTRIB_CODENAME');
- }
-
- /**
- * getting information about system version
- *
- * @param string $key
- * @return string
- *
- */
- public function getSystemInfo($key)
- {
- exec('cat /etc/*release 2>&1', $output);
-
- $result = NULL;
-
- foreach($output as $row) {
- $line = explode('=', $row);
-
- if (isset($line[0]) && $line[0] === $key) {
- $result = $line[1];
- break;
- }
- }
-
- return $result;
- }
- }
|