From d13e60f230ba540ee1df2e1495145307135006c6 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Wed, 3 Oct 2012 21:59:40 +0200 Subject: setup.pl: Make use of File::Slurp::write_file. --- setup.pl | 32 +++++++++++++------------------- 1 file 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 <Dump([$::MULKONF], ["::MULKONF"])]} 1; EOF -close $conffd; +) or die "Could not write configuration to $conffile: $!"; say "Configuration saved to: $conffile"; say ""; -- cgit v1.2.3