diff --git a/app/modules/cli/Commands/CommandBase.php b/app/modules/cli/Commands/CommandBase.php index c5b852b4..15cfed0a 100644 --- a/app/modules/cli/Commands/CommandBase.php +++ b/app/modules/cli/Commands/CommandBase.php @@ -3,6 +3,8 @@ namespace SP\Modules\Cli\Commands; use Psr\Log\LoggerInterface; +use SP\Config\Config; +use SP\Config\ConfigData; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Style\SymfonyStyle; @@ -21,18 +23,32 @@ abstract class CommandBase extends Command * @var SymfonyStyle */ protected $io; + /** + * @var Config + */ + protected $config; + /** + * @var ConfigData + */ + protected $configData; /** * CommandBase constructor. * * @param LoggerInterface $logger * @param SymfonyStyle $io + * @param Config $config */ - public function __construct(LoggerInterface $logger, SymfonyStyle $io) + public function __construct( + LoggerInterface $logger, + SymfonyStyle $io, + Config $config) { parent::__construct(); $this->logger = $logger; $this->io = $io; + $this->config = $config; + $this->configData = $this->config->getConfigData(); } } \ No newline at end of file diff --git a/app/modules/cli/Commands/InstallCommand.php b/app/modules/cli/Commands/InstallCommand.php index af79f7bb..b7179ea9 100644 --- a/app/modules/cli/Commands/InstallCommand.php +++ b/app/modules/cli/Commands/InstallCommand.php @@ -27,6 +27,7 @@ namespace SP\Modules\Cli\Commands; use Exception; use Psr\Log\LoggerInterface; use RuntimeException; +use SP\Config\Config; use SP\Core\Exceptions\InvalidArgumentException; use SP\Core\Language; use SP\Services\Install\InstallData; @@ -52,9 +53,10 @@ final class InstallCommand extends CommandBase public function __construct(LoggerInterface $logger, SymfonyStyle $io, + Config $config, Installer $installer) { - parent::__construct($logger, $io); + parent::__construct($logger, $io, $config); $this->installer = $installer; } @@ -95,7 +97,12 @@ final class InstallCommand extends CommandBase ->addOption('language', null, InputOption::VALUE_OPTIONAL, - __('Sets the global app language. You can set a per user language on preferences.')); + __('Sets the global app language. You can set a per user language on preferences.')) + ->addOption('force', + null, + InputOption::VALUE_OPTIONAL, + __('Force sysPass installation.'), + false); } /** @@ -106,6 +113,14 @@ final class InstallCommand extends CommandBase */ protected function execute(InputInterface $input, OutputInterface $output) { + $force = (bool)$input->getOption('force'); + + if ($this->configData->isInstalled() && $force === false) { + $this->io->warning(__('sysPass is already installed. Use \'--force\' to install it again.')); + + return self::FAILURE; + } + $adminPassword = $input->getOption('adminPassword'); $passNonEmptyValidator = function ($value) { diff --git a/lib/SP/Bootstrap.php b/lib/SP/Bootstrap.php index 57479b09..620c579e 100644 --- a/lib/SP/Bootstrap.php +++ b/lib/SP/Bootstrap.php @@ -113,6 +113,7 @@ final class Bootstrap * Bootstrap constructor. * * @param Container $container + * @param bool $useRouter * * @throws DependencyException * @throws NotFoundException