diff --git a/app/Commands/MariadbInstallCommand.php b/app/Commands/MariadbInstallCommand.php index 9357eab..a0d44d8 100644 --- a/app/Commands/MariadbInstallCommand.php +++ b/app/Commands/MariadbInstallCommand.php @@ -32,7 +32,7 @@ class MariadbInstallCommand extends Command * * @var string */ - protected $signature = 'mariadb:install'; + protected $signature = 'mariadb:install {version=10.4}'; /** * The description of the command. @@ -49,8 +49,31 @@ class MariadbInstallCommand extends Command public function handle() { $this->info('Mariadb install...'); + $version = $this->argument('version'); exec('apt update 2>&1', $output); + + // @TODO apt add a Warning for no good, in a later version output will be scanned for helpfull infos + $this->line(implode("\n", Install::filterAptMessages($output))); + + if ($version === '10.4') { + + $this->info('Mariadb try install 10.04...'); + + // getting release + $release = Install::getDistributionRelease(); + + if (Install::getDistributionId() === 'Ubuntu' && ($release === '18.04' || $release === '20.04')) { + $this->info('Mariadb install for Ubuntu '.$release.'...'); + + $output = []; + exec('apt install -y software-properties-common 2>&1', $output); + exec('apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 2>&1', $output); + exec('add-apt-repository -y "deb [arch=amd64,arm64,ppc64el] http://mariadb.mirror.liquidtelecom.com/repo/10.4/ubuntu '.Install::getDistributionCodename().' main" 2>&1', $output); + exec('apt update 2>&1', $output); + } + } + exec('apt install -y mariadb-server mariadb-client 2>&1', $output); // @TODO apt add a Warning for no good, in a later version output will be scanned for helpfull infos @@ -73,11 +96,6 @@ class MariadbInstallCommand extends Command // getting password for root $password = $generator->generatePasswords()[0]; - // remove plugin for root and set password - $this->info('Mariadb add password for root...'); - exec('sudo mysql -u root -e "UPDATE mysql.user SET Password=PASSWORD(\''.$password.'\') WHERE User=\'root\';"'); - exec('sudo mysql -u root -e "UPDATE mysql.user SET plugin=\'\' where User=\'root\';"'); - // make sure root can only access from local $this->info('Mariadb make sure root can ony access from local...'); exec('sudo mysql -u root -e "DELETE FROM mysql.user WHERE User=\'root\' AND Host NOT IN (\'localhost\', \'127.0.0.1\', \'::1\');"'); @@ -91,8 +109,18 @@ class MariadbInstallCommand extends Command exec('sudo mysql -u root -e "DROP DATABASE IF EXISTS test;"'); exec('sudo mysql -u root -e "DELETE FROM mysql.db WHERE Db=\'test\' OR Db=\'test_%\';"'); + // remove plugin for root and set password + $this->info('Mariadb add password for root...'); + + if ($version === '10.4') { + exec('sudo mysql -u root -e "ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD(\''.$password.'\'); FLUSH PRIVILEGES;"'); + } else { + exec('sudo mysql -u root -e "UPDATE mysql.user SET Password=PASSWORD(\''.$password.'\') WHERE User=\'root\'; FLUSH PRIVILEGES;"'); + exec('sudo mysql -u root -e "UPDATE mysql.user SET plugin=\'\' where User=\'root\';"'); + } + // update privileges - exec('sudo mysql -u root -e "FLUSH PRIVILEGES;"'); + //exec('sudo mysql -u root --password='.$password.' -e "FLUSH PRIVILEGES;"'); file_put_contents(self::MCP_LOG_FILE, "Mariadb installed\nuser: root\npassword: $password\n--\n", FILE_APPEND); $this->info('Mariadb installing...Success! \o/ Check '.self::MCP_LOG_FILE); diff --git a/app/Helpers/InstallHelper.php b/app/Helpers/InstallHelper.php index 56309ef..af4fa27 100644 --- a/app/Helpers/InstallHelper.php +++ b/app/Helpers/InstallHelper.php @@ -3,7 +3,7 @@ namespace App\Helpers; /** - * Helper for install + * Helper for install * * @author Björn Hase, Tentakelfabrik * @license http://opensource.org/licenses/MIT The MIT License @@ -57,4 +57,58 @@ class InstallHelper return $results; } + + /** + * + * + * @return string + */ + public function getDistributionId() + { + return $this->getSystemInfo('DISTRIB_ID'); + } + + /** + * + * @return string + */ + public function getDistributionRelease() + { + return $this->getSystemInfo('DISTRIB_RELEASE'); + } + + /** + * + * + * @return string + */ + public function getDistributionCodename() + { + return $this->getSystemInfo('DISTRIB_CODENAME'); + } + + /** + * getting information about system version + * + * @param string $key + * @return string + * + */ + public function getSystemInfo($key) + { + exec('cat /etc/*release 2>&1', $output); + + $result = NULL; + + foreach($output as $row) { + $line = explode('=', $row); + + if (isset($line[0]) && $line[0] === $key) { + $result = $line[1]; + break; + } + } + + return $result; + } } \ No newline at end of file