OpenSource CLI-App to install and handle stuff related to Web-Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Helpers;
  3. /**
  4. * Helper for install
  5. *
  6. * @author Björn Hase, Tentakelfabrik
  7. * @license http://opensource.org/licenses/MIT The MIT License
  8. * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
  9. *
  10. */
  11. class InstallHelper
  12. {
  13. // message for status
  14. const PACKAGE_STATUS = 'Status: install ok installed';
  15. // not allowed message
  16. const NOT_ALLOWED = [
  17. 'WARNING: apt does not have a stable CLI interface. Use with caution in scripts.'
  18. ];
  19. /**
  20. * check if a packege is installed
  21. *
  22. * @param string $name
  23. * @return boolean
  24. */
  25. public function isReady($name)
  26. {
  27. $result = false;
  28. exec('echo $(dpkg -s '.$name.' 2>&1 | grep "'.self::PACKAGE_STATUS.'")', $output);
  29. if (isset($output[0]) && $output[0] === self::PACKAGE_STATUS) {
  30. $result = true;
  31. }
  32. return $result;
  33. }
  34. /**
  35. * apt add a Warning for no good,
  36. *
  37. *
  38. * @return array
  39. */
  40. public function filterAptMessages($output)
  41. {
  42. $results = [];
  43. foreach($output as $message) {
  44. if (!in_array($message, self::NOT_ALLOWED) && !empty($message)) {
  45. $results[] = $message;
  46. }
  47. }
  48. return $results;
  49. }
  50. /**
  51. *
  52. *
  53. * @return string
  54. */
  55. public function getDistributionId()
  56. {
  57. return $this->getSystemInfo('DISTRIB_ID');
  58. }
  59. /**
  60. *
  61. * @return string
  62. */
  63. public function getDistributionRelease()
  64. {
  65. return $this->getSystemInfo('DISTRIB_RELEASE');
  66. }
  67. /**
  68. *
  69. *
  70. * @return string
  71. */
  72. public function getDistributionCodename()
  73. {
  74. return $this->getSystemInfo('DISTRIB_CODENAME');
  75. }
  76. /**
  77. * getting information about system version
  78. *
  79. * @param string $key
  80. * @return string
  81. *
  82. */
  83. public function getSystemInfo($key)
  84. {
  85. exec('cat /etc/*release 2>&1', $output);
  86. $result = NULL;
  87. foreach($output as $row) {
  88. $line = explode('=', $row);
  89. if (isset($line[0]) && $line[0] === $key) {
  90. $result = $line[1];
  91. break;
  92. }
  93. }
  94. return $result;
  95. }
  96. }