aboutsummaryrefslogtreecommitdiff
path: root/lib/Net/MulkyID/Setup.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Net/MulkyID/Setup.pm')
-rwxr-xr-xlib/Net/MulkyID/Setup.pm140
1 files changed, 81 insertions, 59 deletions
diff --git a/lib/Net/MulkyID/Setup.pm b/lib/Net/MulkyID/Setup.pm
index 59ad0d6..2709c87 100755
--- a/lib/Net/MulkyID/Setup.pm
+++ b/lib/Net/MulkyID/Setup.pm
@@ -15,13 +15,15 @@ use Data::Dumper;
#use autodie;
use base 'Exporter';
-our @EXPORT = qw(setup);
+our @EXPORT = qw(configure build);
+
+our $conffile = "www/config.pl";
sub prompt($$) {
my ($question, $default) = @_;
$|++;
print "${question} \[${default}\] ";
- $_ = <>;
+ $_ = <STDIN>;
chomp;
if ($_) {
return $_;
@@ -39,15 +41,85 @@ sub makespec($$) {
"provisioning" => "$basepath/provision.html"});
};
-sub setup() {
- my $conffile = "www/config.pl";
-
- # Generate configuration file.
+sub load_configuration() {
$::MULKONF = { };
if (stat($conffile)) {
say "Found existing configuration ($conffile).";
do $conffile;
}
+}
+
+sub write_configuration() {
+ 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
+ ) or die "Could not write configuration to $conffile: $!";
+ say "Configuration saved to: $conffile";
+
+ say "";
+ say "******************************************************************";
+ say "* FINISHED. *";
+ say "* *";
+ say "* Please put browserid.json where it will be served as *";
+ say "* https://<whatever>/.well-known/browserid *";
+ say "* with a content type of: *";
+ say "* application/json *";
+ say "* *";
+ say "* In addition, please ensure that the private key file can be *";
+ say "* read by the web server by assigning the file to the *";
+ say "* appropriate owner. *";
+ say "******************************************************************";
+}
+
+sub build_deps() {
+ # Download jQuery.
+ make_path("www/jquery");
+ if (stat("www/jquery/jquery.js")) {
+ say "Using existing copy of jQuery (www/jquery/jquery.js).";
+ } else {
+ say "Fetching jQuery...";
+ getstore("http://code.jquery.com/jquery-1.7.2.min.js", "www/jquery/jquery.js")
+ or die "Could not fetch jQuery";
+ say "jQuery saved to: www/jquery/jquery.js";
+ }
+}
+
+sub build_spec() {
+ # Generate the private key and generate the BrowserID spec file.
+ my $pemfile = $::MULKONF->{pemfile} // die "pemfile not defined";
+ my $basepath = $::MULKONF->{basepath} // die "basepath not defined";
+ my $configpath = $::MULKONF->{configpath} // die "configpath not defined";
+
+ my $key;
+ if (stat($pemfile)) {
+ say "Using existing private key ($pemfile).";
+ $key = Crypt::OpenSSL::RSA->new_private_key(scalar read_file($pemfile));
+ } else {
+ say "Generating private key...";
+ $key = Crypt::OpenSSL::RSA->generate_key(2048);
+ make_path($configpath);
+ 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;
+ }
+
+ write_file("browserid.json", makespec($key, $basepath))
+ or die "Could not write spec to browserid.json: $!";
+ say "Persona spec file saved to: browserid.json";
+}
+
+sub build() {
+ load_configuration;
+ build_deps;
+ build_spec;
+}
+
+sub configure() {
+ load_configuration;
my $configpath = $::MULKONF->{configpath} // "/etc/mulkyid";
my $pemfile = $::MULKONF->{pemfile} // "$configpath/rsa2048.pem";
@@ -88,38 +160,6 @@ sub setup() {
say "OK.";
- # Download jQuery.
- make_path("www/jquery");
- if (stat("www/jquery/jquery.js")) {
- say "Using existing copy of jQuery (www/jquery/jquery.js).";
- } else {
- say "Fetching jQuery...";
- getstore("http://code.jquery.com/jquery-1.7.2.min.js", "www/jquery/jquery.js")
- or die "Could not fetch jQuery";
- say "jQuery saved to: www/jquery/jquery.js";
- }
-
- # Generate the private key.
- my $key;
- if (stat($pemfile)) {
- say "Using existing private key ($pemfile).";
- $key = Crypt::OpenSSL::RSA->new_private_key(scalar read_file($pemfile));
- } else {
- say "Generating private key...";
- $key = Crypt::OpenSSL::RSA->generate_key(2048);
- make_path($configpath);
- 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.
- write_file("browserid.json", makespec($key, $basepath))
- or die "Could not write spec to browserid.json: $!";
- say "Persona spec file saved to: browserid.json";
-
- # Generate configuration file.
$::MULKONF = {
configpath => $configpath,
pemfile => $pemfile,
@@ -133,28 +173,10 @@ sub setup() {
google_oauth2_client_secret => $google_oauth2_client_secret,
google_oauth2_client_id => $google_oauth2_client_id
};
- 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
- ) or die "Could not write configuration to $conffile: $!";
- say "Configuration saved to: $conffile";
- say "";
- say "******************************************************************";
- say "* FINISHED. *";
- say "* *";
- say "* Please put browserid.json where it will be served as *";
- say "* https://<whatever>/.well-known/browserid *";
- say "* with a content type of: *";
- say "* application/json *";
- say "* *";
- say "* In addition, please ensure that the private key file can be *";
- say "* read by the web server by assigning the file to the *";
- say "* appropriate owner. *";
- say "******************************************************************";
+ build_deps;
+ build_spec;
+ write_configuration;
}
1;