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.

59 lines
1.3 KiB

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 nginx 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. }