From 91bb473a1a2aed38000ca16063b32e9af7453906 Mon Sep 17 00:00:00 2001 From: Alessandro Cappellozza Date: Fri, 17 Sep 2021 12:44:17 +0000 Subject: [PATCH] Deprecated Ubuntu 18.04 --- app/Commands/CommonCommand.php | 13 ++++++++++++- app/Commands/ConfigCommand.php | 1 + app/Commands/RunCommand.php | 6 ++++++ app/Commands/StageCommand.php | 6 ++++++ installer.yml.old | 11 +++++++++++ src/Constants.php | 1 + src/Stages.php | 11 +++++++++++ src/Stages/V1804/Packages.php | 4 ++-- src/Stages/V1804/Sshd.php | 9 ++++----- 9 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 installer.yml.old diff --git a/app/Commands/CommonCommand.php b/app/Commands/CommonCommand.php index 9b944b2..8d8a839 100644 --- a/app/Commands/CommonCommand.php +++ b/app/Commands/CommonCommand.php @@ -2,7 +2,7 @@ use Illuminate\Support\Facades\File; use Sculptor\Services\Logs; -use Sculptor\Stages\Version; +use Illuminate\Support\Str; trait CommonCommand { @@ -35,4 +35,15 @@ private function dump(): void $this->info($logs); } } + + private function deprecated(bool $deprecated): bool + { + if ($deprecated) { + $continue = Str::lower($this->ask('This version is deprecated and untested with newer version, continue? (yes/no)')); + + return $continue == 'yes' || $continue == 'y'; + } + + return true; + } } diff --git a/app/Commands/ConfigCommand.php b/app/Commands/ConfigCommand.php index 943ed3e..8f4cc04 100644 --- a/app/Commands/ConfigCommand.php +++ b/app/Commands/ConfigCommand.php @@ -44,6 +44,7 @@ public function handle(Configuration $configuration, Templates $templates): int private function configuration(Configuration $configuration): void { $filename = getcwd() . '/' . APP_CONFIG_FILENAME; + if (File::exists($filename)) { $this->warn("Customized configuration already exists {$filename}"); diff --git a/app/Commands/RunCommand.php b/app/Commands/RunCommand.php index c1c6984..d21ad42 100644 --- a/app/Commands/RunCommand.php +++ b/app/Commands/RunCommand.php @@ -33,6 +33,12 @@ public function handle(Stages $stages): int { $this->preamble(); + if (!$this->deprecated($stages->deprecated())) { + $this->warn("Operation cancelled"); + + return 1; + } + if (!$stages->run($this)) { $this->error($stages->error()); diff --git a/app/Commands/StageCommand.php b/app/Commands/StageCommand.php index 932cd71..dfa2c1d 100644 --- a/app/Commands/StageCommand.php +++ b/app/Commands/StageCommand.php @@ -42,6 +42,12 @@ public function handle(Stages $stages): int $this->info("Run time taken {$this->elapsed()}"); + if (!$this->deprecated($stages->deprecated())) { + $this->warn("Operation cancelled"); + + return 1; + } + if (!$done) { $this->error("Error: {$stages->error()}"); diff --git a/installer.yml.old b/installer.yml.old new file mode 100644 index 0000000..9603be6 --- /dev/null +++ b/installer.yml.old @@ -0,0 +1,11 @@ +stages: + - Credentials # Mandatory do not remove + - Php + - NodeJs + - CheckServices + +php_versions: + - 7.3 + - 7.4 + +node_version: 14 diff --git a/src/Constants.php b/src/Constants.php index f2a201e..9ec5556 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -8,6 +8,7 @@ define('APP_PATH', '.installer'); define('APP_COMPATIBLE_VERSION', ['18.04' , '20.04']); +define('APP_DEPRECATED_VERSION', ['18.04']); define('APP_COMPATIBLE_ARCH', ['x86_64']); define('APP_PANEL_USER', 'sculptor'); define('APP_PANEL_DB', 'sculptor'); diff --git a/src/Stages.php b/src/Stages.php index 70facd7..7421472 100644 --- a/src/Stages.php +++ b/src/Stages.php @@ -62,6 +62,17 @@ private function compatible(): bool return true; } + public function deprecated(): bool + { + if (!$this->version->compatible(APP_DEPRECATED_VERSION, APP_COMPATIBLE_ARCH)) { + $this->error = 'This version of the operating system is deprecated'; + + return false; + } + + return true; + } + /** * @param Command|null $context * @return bool diff --git a/src/Stages/V1804/Packages.php b/src/Stages/V1804/Packages.php index 2660b07..06f8486 100644 --- a/src/Stages/V1804/Packages.php +++ b/src/Stages/V1804/Packages.php @@ -44,8 +44,8 @@ class Packages extends StageBase implements Stage 'sudo', 'ufw', 'git', - 'unattended-upgrades', - 'sysstat' + 'unattended-upgrades', + 'sysstat' ]; /** diff --git a/src/Stages/V1804/Sshd.php b/src/Stages/V1804/Sshd.php index 3562ad6..2c79c40 100644 --- a/src/Stages/V1804/Sshd.php +++ b/src/Stages/V1804/Sshd.php @@ -4,7 +4,6 @@ use Exception; use Illuminate\Support\Facades\Log; -use Illuminate\Support\Facades\File; use Sculptor\Contracts\Stage; use Sculptor\Stages\Environment; use Sculptor\Stages\StageBase; @@ -28,20 +27,20 @@ public function run(Environment $env): bool !$this->write( '/etc/ssh/sshd_config', $this->template('sshd.conf'), - 'Cannot read configuration' + 'Cannot read sshd configuration' ) ) { return false; } if (!$this->restart('sshd')) { - $this->internal = 'Cannot restart service'; - - return false; + throw new Exception('Cannot restart service'); } return true; } catch (Exception $e) { + $this->internal = $e->getMessage(); + Log::error($e->getMessage()); return false;