setName('backup:key:confirm') ->setDescription('Confirm that the recovery kit is stored safely (required before the first backup)') ->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'Admin user id recorded with the confirmation', 'occ') ->addOption('code', null, InputOption::VALUE_REQUIRED, 'Confirmation code from the kit file (for scripts; asked otherwise)') ->addOption('confirm', null, InputOption::VALUE_REQUIRED, 'The confirmation phrase "' . self::CONFIRMATION . '" (for scripts; asked otherwise)'); } protected function execute(InputInterface $input, OutputInterface $output): int { if (!$this->keys->isInitialized()) { $output->writeln('No backup key yet: run occ backup:key:init first.'); return 1; } $output->writeln('Key fingerprint: ' . $this->keys->fingerprint() . ''); $output->writeln(''); $output->writeln(wordwrap(self::STATEMENT, 78)); $output->writeln(''); $code = $input->getOption('code') ?? (string)$this->getHelper('question')->ask($input, $output, new Question('Confirmation code from the recovery kit file ("confirmation_code"): ')); if (!$this->keys->checkKitCode($code)) { $output->writeln('That code does not match the current recovery kit (download it with occ backup:key:kit first).'); return 1; } $answer = $input->getOption('confirm') ?? (string)$this->getHelper('question')->ask($input, $output, new Question('Type "' . self::CONFIRMATION . '" to proceed: ')); if (trim($answer) !== self::CONFIRMATION) { $output->writeln('Not confirmed.'); return 1; } $this->keys->confirmRecoveryKit((string)$input->getOption('user')); $output->writeln('Confirmed. Backups can now run.'); return 0; } }