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.

56 lines
1.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Helpers;
  3. /**
  4. *
  5. *
  6. *
  7. */
  8. class InstallHelper
  9. {
  10. // message for status
  11. const PACKAGE_STATUS = 'Status: install ok installed';
  12. // not allowed message
  13. const NOT_ALLOWED = [
  14. 'WARNING: apt does not have a stable CLI interface. Use with caution in scripts.'
  15. ];
  16. /**
  17. * check if a packege is installed
  18. *
  19. * @param string $name
  20. * @return boolean
  21. */
  22. public function isReady($name)
  23. {
  24. $result = false;
  25. exec('echo $(dpkg -s nginx 2>&1 | grep "'.self::PACKAGE_STATUS.'")', $output);
  26. if (isset($output[0]) && $output[0] === self::PACKAGE_STATUS) {
  27. $result = true;
  28. }
  29. return $result;
  30. }
  31. /**
  32. * apt add a Warning for no good,
  33. *
  34. *
  35. * @return array
  36. */
  37. public function filterAptMessages($output)
  38. {
  39. $results = [];
  40. foreach($output as $message) {
  41. if (!in_array($message, self::NOT_ALLOWED) && !empty($message)) {
  42. $results[] = $message;
  43. }
  44. }
  45. return $results;
  46. }
  47. }