add os distribution detection

This commit is contained in:
Ante de Baas
2020-05-29 13:36:31 +02:00
parent d4c0acb353
commit 67d74406bd
5 changed files with 93 additions and 8 deletions

View File

@@ -159,6 +159,7 @@ class FroxlorInstall
$this->_guessServerName();
$this->_guessServerIP();
$this->_guessWebserver();
$this->_guessDistribution();
$this->_getPostField('mysql_host', '127.0.0.1');
$this->_getPostField('mysql_database', 'froxlor');
@@ -840,6 +841,20 @@ class FroxlorInstall
*/
$section = $this->_lng['install']['serversettings'];
eval("\$formdata .= \"" . $this->_getTemplate("datasection") . "\";");
// distribution
if (! empty($_POST['installstep']) && $this->_data['distribution'] == '') {
$diststyle = 'color:red;';
} else {
$diststyle = '';
}
$formdata .= $this->_GETsectionItemCheckbox('distribution', 'jessie', ($this->_data['distribution'] == 'jessie'), $diststyle);
$formdata .= $this->_getSectionItemCheckbox('distribution', 'stretch', ($this->_data['distribution'] == 'stretch'), $diststyle);
$formdata .= $this->_getSectionItemCheckbox('distribution', 'buster', ($this->_data['distribution'] == 'buster'), $diststyle);
$formdata .= $this->_getSectionItemCheckbox('distribution', 'xenial', ($this->_data['distribution'] == 'xenial'), $diststyle);
$formdata .= $this->_getSectionItemCheckbox('distribution', 'bionic', ($this->_data['distribution'] == 'bionic'), $diststyle);
$formdata .= $this->_getSectionItemCheckbox('distribution', 'focal', ($this->_data['distribution'] == 'focal'), $diststyle);
$formdata .= $this->_getSectionItemCheckbox('distribution', 'rhel7', ($this->_data['distribution'] == 'rhel7'), $diststyle);
$formdata .= $this->_getSectionItemCheckbox('distribution', 'rhel8', ($this->_data['distribution'] == 'rhel8'), $diststyle);
// servername
if (! empty($_POST['installstep']) && $this->_data['servername'] == '') {
$style = 'color:red;';
@@ -861,12 +876,12 @@ class FroxlorInstall
$websrvstyle = '';
}
// apache
$formdata .= $this->_getSectionItemCheckbox('apache2', ($this->_data['webserver'] == 'apache2'), $websrvstyle);
$formdata .= $this->_getSectionItemCheckbox('apache24', ($this->_data['webserver'] == 'apache24'), $websrvstyle);
$formdata .= $this->_getSectionItemCheckbox('webserver', 'apache2', ($this->_data['webserver'] == 'apache2'), $websrvstyle);
$formdata .= $this->_getSectionItemCheckbox('webserver', 'apache24', ($this->_data['webserver'] == 'apache24'), $websrvstyle);
// lighttpd
$formdata .= $this->_getSectionItemCheckbox('lighttpd', ($this->_data['webserver'] == 'lighttpd'), $websrvstyle);
$formdata .= $this->_getSectionItemCheckbox('webserver', 'lighttpd', ($this->_data['webserver'] == 'lighttpd'), $websrvstyle);
// nginx
$formdata .= $this->_getSectionItemCheckbox('nginx', ($this->_data['webserver'] == 'nginx'), $websrvstyle);
$formdata .= $this->_getSectionItemCheckbox('webserver', 'NGINx', ($this->_data['webserver'] == 'nginx'), $websrvstyle);
// webserver-user
if (! empty($_POST['installstep']) && $this->_data['httpuser'] == '') {
$style = 'color:red;';
@@ -918,7 +933,7 @@ class FroxlorInstall
}
/**
* generate form radio field for webserver-selection
* generate form radio field
*
* @param string $fieldname
* @param boolean $checked
@@ -926,8 +941,9 @@ class FroxlorInstall
*
* @return string
*/
private function _getSectionItemCheckbox($fieldname = null, $checked = false, $style = "")
private function _getSectionItemCheckbox($groupname = null, $fieldname = null, $checked = false, $style = "")
{
$groupname = $this->_lng['install'][$groupname];
$fieldlabel = $this->_lng['install'][$fieldname];
if ($checked) {
$checked = 'checked="checked"';
@@ -1273,6 +1289,48 @@ class FroxlorInstall
}
}
/**
* get/guess linux distribution
*/
private function _guessDistribution()
{
// post
if (! empty($_POST['distribution'])) {
$this->_data['distribution'] = $_POST['distribution'];
} else {
$os_version = parse_ini_file('/etc/os-release', false);
if ($os_version['ID'] == 'debian') {
} elseif ($os_version['ID'] == 'debian') {
if(explode('.',$os_version['VERSION_ID'])[0] == '8') {
$this->_data['distribution'] = 'jessie';
} elseif(explode('.',$os_version['VERSION_ID'])[0] == '9') {
$this->_data['distribution'] = 'stretch';
} elseif(explode('.',$os_version['VERSION_ID'])[0] == '10') {
$this->_data['distribution'] = 'buster';
}
} elseif ($os_version['ID'] == 'ubuntu') {
if(explode('.',$os_version['VERSION_ID'])[0] == '16') {
$this->_data['distribution'] = 'xenial';
} elseif(explode('.',$os_version['VERSION_ID'])[0] == '18') {
$this->_data['distribution'] = 'bionic';
} elseif(explode('.',$os_version['VERSION_ID'])[0] == '20') {
$this->_data['distribution'] = 'focal';
}
} elseif($os_version['ID'] == 'rhel' || $os_version['ID'] == 'centos' || $os_version['ID'] == 'fedora') {
if(explode('.',$os_version['VERSION_ID'])[0] == '7') {
$this->_data['distribution'] = 'rhel7';
} elseif(explode('.',$os_version['VERSION_ID'])[0] == '8') {
$this->_data['distribution'] = 'rhel8';
}
} else {
// we don't need to bail out, since unknown does not affect any critical installation routines
$this->_data['distribution'] = 'unknown';
}
}
}
/**
* check if POST field is set and get value for the
* internal data array, if not set use either '' or $default if != null

View File

@@ -63,6 +63,15 @@ $lng['install']['admin_pass1'] = 'Administrator Password';
$lng['install']['admin_pass2'] = 'Administrator-Password (confirm)';
$lng['install']['activate_newsfeed'] = 'Enable the official newsfeed<br><small>(https://inside.froxlor.org/news/)</small>';
$lng['install']['serversettings'] = 'Server settings';
$lng['install']['distribution'] = 'Distribution';
$lng['install']['jessie'] = 'Debian Jessie';
$lng['install']['stretch'] = 'Debian Stretch';
$lng['install']['buster'] = 'Debian Buster';
$lng['install']['xenial'] = 'Ubuntu Xenial';
$lng['install']['bionic'] = 'Ubuntu Bionic';
$lng['install']['focal'] = 'Ubuntu Focal';
$lng['install']['rhel7'] = 'RHEL 7';
$lng['install']['rhel8'] = 'RHEL 8';
$lng['install']['servername'] = 'Server name (FQDN, no ip-address)';
$lng['install']['serverip'] = 'Server IP';
$lng['install']['webserver'] = 'Webserver';

View File

@@ -53,6 +53,15 @@ $lng['install']['admin_user'] = 'Nom d\'utilisateur administrateur';
$lng['install']['admin_pass1'] = 'Mot de passe administrateur';
$lng['install']['admin_pass2'] = 'Mot de passe administrateur (confirmez)';
$lng['install']['serversettings'] = 'Réglages serveur';
$lng['install']['distribution'] = 'Distribution';
$lng['install']['jessie'] = 'Debian Jessie';
$lng['install']['stretch'] = 'Debian Stretch';
$lng['install']['buster'] = 'Debian Buster';
$lng['install']['xenial'] = 'Ubuntu Xenial';
$lng['install']['bionic'] = 'Ubuntu Bionic';
$lng['install']['focal'] = 'Ubuntu Focal';
$lng['install']['rhel7'] = 'RHEL 7';
$lng['install']['rhel8'] = 'RHEL 8';
$lng['install']['servername'] = 'Nom du serveur (FQDN, pas d\'adresse IP)';
$lng['install']['serverip'] = 'Adresse IP du serveur';
$lng['install']['webserver'] = 'Serveur Web';

View File

@@ -63,6 +63,15 @@ $lng['install']['admin_pass1'] = 'Administrator-Passwort';
$lng['install']['admin_pass2'] = 'Administrator-Passwort (Bestätigung)';
$lng['install']['activate_newsfeed'] = 'Aktiviere das offizielle Newsfeed<br><small>(https://inside.froxlor.org/news/)</small>';
$lng['install']['serversettings'] = 'Servereinstellungen';
$lng['install']['distribution'] = 'Verteilung';
$lng['install']['jessie'] = 'Debian Jessie';
$lng['install']['stretch'] = 'Debian Stretch';
$lng['install']['buster'] = 'Debian Buster';
$lng['install']['xenial'] = 'Ubuntu Xenial';
$lng['install']['bionic'] = 'Ubuntu Bionic';
$lng['install']['focal'] = 'Ubuntu Focal';
$lng['install']['rhel7'] = 'RHEL 7';
$lng['install']['rhel8'] = 'RHEL 8';
$lng['install']['servername'] = 'Servername (FQDN, keine IP-Adresse)';
$lng['install']['serverip'] = 'Server-IP';
$lng['install']['webserver'] = 'Webserver';

View File

@@ -1,4 +1,4 @@
<p>
<label for="{$fieldname}" class="install-block {$style}">{$this->_lng['install']['webserver']} {$fieldlabel}:</label>
<input type="radio" name="webserver" id="{$fieldname}" value="{$fieldname}" {$checked} /><span>{$fieldlabel}</span>
<label for="{$fieldname}" class="install-block {$style}">{$groupname} {$fieldlabel}:</label>
<input type="radio" name="{$groupname}" id="{$fieldname}" value="{$fieldname}" {$checked} /><span>{$fieldlabel}</span>
</p>