aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-10-03 21:59:40 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-10-03 21:59:40 +0200
commitd13e60f230ba540ee1df2e1495145307135006c6 (patch)
treef9712ddec957861888f4c6e81d0f65a2e1e09b52
parentedb591a23dd157471e29cee4e21cf61bc3152b1a (diff)
setup.pl: Make use of File::Slurp::write_file.
-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 "";