diff options
author | Matthias Benkard <matthias.benkard@egym.de> | 2015-04-22 11:56:27 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2015-04-23 21:55:52 +0200 |
commit | ccb82fe054a73a6e662b1998aaee5609c62a3b32 (patch) | |
tree | dc2a50247496a53819b397f7e358097137c00694 | |
parent | 057a1869cace85f8ea2931a92329988e509225d8 (diff) |
-rw-r--r-- | Build.PL (renamed from build.PL) | 0 | ||||
-rw-r--r-- | MANIFEST | 2 | ||||
-rw-r--r-- | lib/Net/MulkyID/Builder.pm | 13 | ||||
-rwxr-xr-x | lib/Net/MulkyID/Setup.pm | 140 | ||||
-rwxr-xr-x | setup.pl | 3 |
5 files changed, 93 insertions, 65 deletions
@@ -11,4 +11,4 @@ www/logged_in_p.pl www/sign.pl COPYING.AGPL README.md -build.PL +Build.PL diff --git a/lib/Net/MulkyID/Builder.pm b/lib/Net/MulkyID/Builder.pm index bd5058f..2100cf3 100644 --- a/lib/Net/MulkyID/Builder.pm +++ b/lib/Net/MulkyID/Builder.pm @@ -10,14 +10,19 @@ sub new { my ($class, @args) = @_; my $self = $class->SUPER::new(@args); return bless $self, $class; - #my $self = $self->SUPER::new(); - #return $self; - #return bless {}, shift; +} + +sub ACTION_configure { + my ($self, @args) = @_; + eval "use Net::MulkyID::Setup; configure();"; + if ($@) { + die $@; + } } sub ACTION_build { my ($self, @args) = @_; - eval "use Net::MulkyID::Setup; setup();"; + eval "use Net::MulkyID::Setup; build();"; if ($@) { die $@; } 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; @@ -1,5 +1,6 @@ #! /usr/bin/env perl -system "perl build.PL"; +system "perl Build.PL"; system "perl Build installdeps"; +system "perl Build configure"; system "perl Build"; |