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.

105 lines
3.6 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\Commands;
  3. use Illuminate\Console\Scheduling\Schedule;
  4. use LaravelZero\Framework\Commands\Command;
  5. use Illuminate\Support\Facades\File;
  6. use App\Facades\Install;
  7. use Hackzilla\PasswordGenerator\Generator\ComputerPasswordGenerator;
  8. use Hackzilla\PasswordGenerator\RandomGenerator\Php7RandomGenerator;
  9. /**
  10. * Install Mariadb Client for Remote Access
  11. *
  12. * @author Björn Hase, Tentakelfabrik
  13. * @license http://opensource.org/licenses/MIT The MIT License
  14. * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
  15. *
  16. */
  17. class MariadbClientInstallCommand extends Command
  18. {
  19. /**
  20. * The signature of the command.
  21. *
  22. * @var string
  23. */
  24. protected $signature = 'mariadb-client:install {remote_user} {remote_host} {version=10.4}';
  25. /**
  26. * The description of the command.
  27. *
  28. * @var string
  29. */
  30. protected $description = 'Install Mariadb Client and set configuration';
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. $this->info('Mariadb Client install...');
  39. $version = $this->argument('version');
  40. exec('apt update 2>&1', $output);
  41. // @TODO apt add a Warning for no good, in a later version output will be scanned for helpfull infos
  42. $this->line(implode("\n", Install::filterAptMessages($output)));
  43. if ($version === '10.4') {
  44. $this->info('Mariadb try install 10.04...');
  45. // getting release
  46. $release = Install::getDistributionRelease();
  47. if (Install::getDistributionId() === 'Ubuntu' && ($release === '18.04' || $release === '20.04')) {
  48. $this->info('Mariadb install for Ubuntu '.$release.'...');
  49. $output = [];
  50. exec('apt install -y software-properties-common 2>&1', $output);
  51. exec('apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 2>&1', $output);
  52. 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);
  53. exec('apt update 2>&1', $output);
  54. }
  55. }
  56. exec('apt install -y mariadb-client 2>&1', $output);
  57. // @TODO apt add a Warning for no good, in a later version output will be scanned for helpfull infos
  58. $this->line(implode("\n", Install::filterAptMessages($output)));
  59. if (Install::isReady('mariadb-client')) {
  60. if (!is_dir('/etc/mysql/ssl')) {
  61. system('mkdir /etc/mysql/ssl');
  62. }
  63. // getting
  64. system('rsync -rv --include="ca-cert.pem" --include="client-cert.pem" --include="client-key.pem" --exclude="*" '.$this->argument('remote_user').'@'.$this->argument('remote_host').':/etc/mysql/ssl/ /etc/mysql/ssl/');
  65. // checking if certificates are exists from remote server
  66. if (!file_exists('/etc/mysql/ssl/ca-cert.pem') || !file_exists('/etc/mysql/ssl/client-cert.pem') || !file_exists('/etc/mysql/ssl/client-key.pem')) {
  67. $this->error('Failed! Certificates not found!');
  68. exit();
  69. }
  70. system('cat >> /etc/mysql/my.cnf << EOF
  71. [client]
  72. ssl-ca=/etc/mysql/ssl/ca-cert.pem
  73. ssl-cert=/etc/mysql/ssl/client-cert.pem
  74. ssl-key=/etc/mysql/ssl/client-key.pem
  75. ssl');
  76. system('chown -R mysql:mysql /etc/mysql/ssl');
  77. system('chmod 644 /etc/mysql/ssl/*cert*');
  78. system('chmod 644 /etc/mysql/ssl/*key*');
  79. } else {
  80. $this->error('Failed! Please check log-file!');
  81. }
  82. }
  83. }