AppserverIo\Appserver\Meta\Composer\Script\Setup::getLinuxDistro PHP Method

getLinuxDistro() public static method

Returns the Linux distribution we're running on.
public static getLinuxDistro ( ) : string
return string The Linux distribution we're running on
    public static function getLinuxDistro()
    {
        // declare Linux distros (extensible list).
        $distros = array(SetupKeys::OS_ARCH => 'arch-release', SetupKeys::OS_DEBIAN => 'debian_version', SetupKeys::OS_FEDORA => 'fedora-release', SetupKeys::OS_UBUNTU => 'lsb-release', SetupKeys::OS_REDHAT => 'redhat-release', SetupKeys::OS_CENTOS => 'centos-release');
        // get everything from /etc directory.
        $etcList = scandir('/etc');
        // loop through /etc results...
        $distro = '';
        // iterate over all found files
        foreach ($etcList as $entry) {
            // loop through list of distros..
            foreach ($distros as $distroReleaseFile) {
                // match was found.
                if ($distroReleaseFile === $entry) {
                    // find distros array key (i.e. distro name) by value (i.e. distro release file)
                    $distro = array_search($distroReleaseFile, $distros);
                    break 2;
                    // break inner and outer loop.
                }
            }
        }
        // return the found distro string
        return $distro;
    }

Usage Example

Esempio n. 1
0
 /**
  * Prepares the context by given event or without event for other usage
  *
  * @param null|string $installDir The install dir to check for info files
  * @param null|Event  $event      The event instance or null
  *
  * @return void
  */
 public static function prepareContext($installDir = null, $event = null)
 {
     // initialize the installation directory
     if (is_null($installDir)) {
         $installDir = getcwd();
     }
     // check if we've a file with the actual version number
     $version = '';
     if (file_exists($filename = $installDir . '/etc/appserver/.release-version')) {
         $version = file_get_contents($filename);
     } else {
         // load the version (GIT) of this package as fallback if called with event instance
         if (!is_null($event)) {
             $version = $event->getComposer()->getPackage()->getPrettyVersion();
         }
     }
     // check if we've a file with the actual release name
     if (file_exists($filename = $installDir . '/etc/appserver/.release-name')) {
         $releaseName = file_get_contents($filename);
     } else {
         // set the release name to 'Unknown' if not
         $releaseName = 'Unknown';
     }
     // prepare the context properties
     $contextProperties = array(SetupKeys::VERSION => $version, SetupKeys::INSTALL_DIR => $installDir, SetupKeys::RELEASE_NAME => $releaseName);
     // load the OS signature => sscanf is necessary to detect Windows, e. g. Windows NT for Windows 7
     list($os, ) = sscanf(strtolower(php_uname('s')), '%s %s');
     // check what OS we are running on
     switch ($os) {
         // installation running on Linux
         case SetupKeys::OS_FAMILY_LINUX:
             // get the distribution
             $distribution = Setup::getLinuxDistro();
             // if we cant find one of the supported systems
             if ($distribution == null) {
                 // set debian as default
                 $distribution = SetupKeys::OS_DEBIAN;
                 // write a message to the console if called with event instance
                 if (!is_null($event)) {
                     $event->getIo()->write(sprintf('<warning>Unknown Linux distribution found, use Debian default values: ' . 'Please check user/group configuration in etc/appserver/appserver.xml</warning>'));
                 }
             }
             // merge the properties for the found Linux distribution
             Setup::prepareProperties($distribution, $contextProperties);
             break;
             // installation running on Mac OS X
         // installation running on Mac OS X
         case SetupKeys::OS_FAMILY_DARWIN:
             // merge the properties for Mac OS X
             Setup::prepareProperties($os, $contextProperties);
             break;
             // installation running on Windows
         // installation running on Windows
         case SetupKeys::OS_FAMILY_WINDOWS:
             // merge the properties for Windows
             Setup::prepareProperties($os, $contextProperties);
             break;
             // all other OS are NOT supported actually
         // all other OS are NOT supported actually
         default:
             break;
     }
 }