aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsetup.pl32
1 files changed, 13 insertions, 19 deletions
diff --git a/setup.pl b/setup.pl
index b4fb9e4..44c2241 100755
--- a/setup.pl
+++ b/setup.pl
@@ -5,7 +5,7 @@ use common::sense;
use Modern::Perl;
use JSON;
use Crypt::OpenSSL::RSA;
-use File::Slurp;
+use File::Slurp qw(write_file read_file);
use File::Path qw(make_path);
use File::Copy;
use LWP::Simple qw(getstore);
@@ -24,13 +24,13 @@ sub prompt($$) {
}
}
-sub printspec($$) {
- my ($outfile, $key) = @_;
+sub makespec($) {
+ my ($key) = @_;
my ($n, $e, @stuff) = $key->get_key_parameters;
- say $outfile
- encode_json({"public-key" => {e => $e->to_decimal, n => $n->to_decimal, algorithm => "RS"},
- "authentication" => "/browserid/authenticate.html",
- "provisioning" => "/browserid/provision.html"});
+ return
+ encode_json({"public-key" => {e => $e->to_decimal, n => $n->to_decimal, algorithm => "RS"},
+ "authentication" => "/browserid/authenticate.html",
+ "provisioning" => "/browserid/provision.html"});
};
my $conffile = "www/config.pl";
@@ -75,19 +75,15 @@ if (stat($pemfile)) {
say "Generating private key...";
$key = Crypt::OpenSSL::RSA->generate_key(2048);
make_path($configpath);
- open(my $keyfile, ">", $pemfile)
- or die "Cannot open $pemfile for writing: $!";
- print $keyfile $key->get_private_key_string();
- close $keyfile;
+ write_file($pemfile, $key->get_private_key_string())
+ or die "Could not write private key to $pemfile: $!";
say "Private key saved to: $pemfile".
chmod 0440, $pemfile;
}
# Generate spec file.
-open(my $specfile, ">", "browserid.json")
- or die "Cannot open browserid.json for writing: $!";
-printspec $specfile, $key;
-close($specfile);
+write_file("browserid.json", makespec $key)
+ or die "Could not write spec to browserid.json: $!";
say "Persona spec file saved to: browserid.json";
# Generate configuration file.
@@ -98,15 +94,13 @@ $::MULKONF = {
imap_server => $imap_server,
imap_port => $imap_port
};
-open(my $conffd, ">", $conffile)
- or die "Cannot open $conffile for writing: $!";
-print $conffd <<EOF;
+write_file($conffile, <<EOF
#! /usr/bin/env perl
# NB. Do not edit this file directly. It is overwritten with each run of setup.pl.
@{[Data::Dumper->Dump([$::MULKONF], ["::MULKONF"])]}
1;
EOF
-close $conffd;
+) or die "Could not write configuration to $conffile: $!";
say "Configuration saved to: $conffile";
say "";