Skip to content

Commit

Permalink
cleanup and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mwr committed Nov 4, 2023
1 parent 6e02edb commit 6d04fdf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
7 changes: 3 additions & 4 deletions src/Cli/Command/Dnsmasq/InitDnsmasqConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,16 @@ private function initialiseResolverConf(OutputInterface $output, bool $force = f
/** @throws \RuntimeException */
private function execOrFail(string $command): void
{
$output = $resultCode = null;
exec($command, $output, $resultCode);
$resultCode = null;
exec(command: $command, result_code: $resultCode);
if ($resultCode !== 0) {
throw new \RuntimeException("Failed to execute: '$command'");
}
}

private function ensureDir(string $dirname): void
{
if (!is_dir($dirname)
&& !mkdir($dirname, 0755, true) && !is_dir($dirname)) {
if (!is_dir($dirname) && !mkdir($dirname, 0755, true) && !is_dir($dirname)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dirname));
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/Cli/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->initTraefik->run(new ArrayInput([]), $output);

// Generate ROOT CA and trust ROOT CA
$output->writeln('==> Initialising Certificates');
$this->generateCertificates($output, $force);

return 0;
Expand All @@ -77,11 +78,13 @@ private function generateCertificates(OutputInterface $output, bool $force = fal
file_put_contents("$rootCaDir/serial", '1000');
}

// Generate ROOT CA
if ($force === true || !file_exists($caKeyPemFile)) {
$output->writeln('==> Generating private key for local root certificate');
$this->execOrFail("openssl genrsa -out $caKeyPemFile 2048");
}

// Sign ROOT CA
if ($force === true || !file_exists($caCertPemFile)) {
$hostname = gethostname();
$output->writeln("==> Signing root certificate 'ROOTER Proxy Local CA ('$hostname')'");
Expand All @@ -97,6 +100,7 @@ private function generateCertificates(OutputInterface $output, bool $force = fal
unlink($tmpRootCaConf);
}

// Trust ROOT CA
if (str_starts_with($osType, 'Linux')) {
if (is_dir('/etc/pki/ca-trust/source/anchors')
&& ($force === true || !file_exists('/etc/pki/ca-trust/source/anchors/rooter-proxy-local-ca.cert.pem'))
Expand Down Expand Up @@ -125,18 +129,16 @@ private function generateCertificates(OutputInterface $output, bool $force = fal
/** @throws RuntimeException */
private function execOrFail(string $command): void
{
$output = $resultCode = null;
exec($command, $output, $resultCode);
$resultCode = null;
exec(command: $command, result_code: $resultCode);
if ($resultCode !== 0) {
throw new \RuntimeException("Failed to execute: '$command'");
}
}

private function ensureDir(string $dirname, int $permissions = 0755): void
{
if (!is_dir($dirname)
&& !mkdir($dirname, $permissions, true)
&& !is_dir($dirname)
if (!is_dir($dirname) && !mkdir($dirname, $permissions, true) && !is_dir($dirname)
) {
throw new RuntimeException(sprintf('Directory "%s" was not created', $dirname));
}
Expand Down
1 change: 1 addition & 0 deletions src/Cli/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::FAILURE;
}

// forces a re-download of the phar by setting ttl to 0
shell_exec('nix profile upgrade ".*.rooter" --tarball-ttl 0');

return Command::SUCCESS;
Expand Down
3 changes: 1 addition & 2 deletions src/Cli/Command/Traefik/InitTraefikConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ static function ($matches) use ($tmplVars) {

private function ensureDir(string $dirname): void
{
if (!is_dir($dirname)
&& !mkdir($dirname, 0755, true) && !is_dir($dirname)) {
if (!is_dir($dirname) && !mkdir($dirname, 0755, true) && !is_dir($dirname)) {
throw new RuntimeException(sprintf('Directory "%s" was not created', $dirname));
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/Service/GenerateCertificateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class GenerateCertificateService
{

public function __construct(private readonly RooterConfig $rooterConfig)
{
}
Expand Down Expand Up @@ -59,18 +58,16 @@ public function generate(string $certificateName, CertConfig $certConfig, Output
/** @throws RuntimeException */
private function execOrFail(string $command): void
{
$output = $resultCode = null;
exec($command, $output, $resultCode);
$resultCode = null;
exec(command: $command, result_code: $resultCode);
if ($resultCode !== 0) {
throw new \RuntimeException("Failed to execute: '$command'");
}
}

private function ensureDir(string $dirname, int $permissions = 0755): void
{
if (!is_dir($dirname)
&& !mkdir($dirname, $permissions, true)
&& !is_dir($dirname)
if (!is_dir($dirname) && !mkdir($dirname, $permissions, true) && !is_dir($dirname)
) {
throw new RuntimeException(sprintf('Directory "%s" was not created', $dirname));
}
Expand Down

0 comments on commit 6d04fdf

Please sign in to comment.