From ccb82fe054a73a6e662b1998aaee5609c62a3b32 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Wed, 22 Apr 2015 11:56:27 +0200 Subject: Separate configure and build steps. --- Build.PL | 46 +++++++++++++++ MANIFEST | 2 +- build.PL | 46 --------------- lib/Net/MulkyID/Builder.pm | 13 +++-- lib/Net/MulkyID/Setup.pm | 140 ++++++++++++++++++++++++++------------------- setup.pl | 3 +- 6 files changed, 139 insertions(+), 111 deletions(-) create mode 100644 Build.PL delete mode 100644 build.PL diff --git a/Build.PL b/Build.PL new file mode 100644 index 0000000..7c320e2 --- /dev/null +++ b/Build.PL @@ -0,0 +1,46 @@ +#! /usr/bin/env perl + +use lib q(./lib); +use Net::MulkyID::Builder; # Or whatever you want to call it + +my $build = Net::MulkyID::Builder->new + ( + module_name => 'Net::MulkyID', + #license => 'agpl_3', + dist_author => 'Matthias Andreas Benkard ', + dist_abstract => 'A simple Persona IdP.', + requires => { + "Carp" => 0, + "CGI" => 0, + "CGI::Fast" => 0, + "CGI::Session" => 0, + "common::sense" => 0, + "Crypt::OpenSSL::RSA" => 0, + "Crypt::OpenSSL::Bignum" => 0, + "File::Slurp" => 0, + "JSON" => 0, + "MIME::Base64" => 0, + "Mail::ExpandAliases" => 0, + "Mail::IMAPTalk" => 0, + "Modern::Perl" => 0, + "Time::HiRes" => 0, + "Syntax::Keyword::Junction" => 0, + "OIDC::Lite" => 0, + "OIDC::Lite::Client::WebServer" => 0, + "OIDC::Lite::Model::IDToken" => 0, + "LWP::UserAgent" => 0, + "HTTP::Request" => 0, + "Math::Random::ISAAC::XS" => 0, + "Bytes::Random::Secure" => 0 + }, + build_requires => { + "LWP::Simple" => 0, + "Modern::Perl" => 0, + "Crypt::OpenSSL::RSA" => 0, + "Crypt::OpenSSL::Bignum" => 0, + "File::Slurp" => 0, + "JSON" => 0, + "common::sense" => 0 + }, + ); +$build->create_build_script; diff --git a/MANIFEST b/MANIFEST index 0c359d8..30f3b86 100644 --- a/MANIFEST +++ b/MANIFEST @@ -11,4 +11,4 @@ www/logged_in_p.pl www/sign.pl COPYING.AGPL README.md -build.PL +Build.PL diff --git a/build.PL b/build.PL deleted file mode 100644 index 7c320e2..0000000 --- a/build.PL +++ /dev/null @@ -1,46 +0,0 @@ -#! /usr/bin/env perl - -use lib q(./lib); -use Net::MulkyID::Builder; # Or whatever you want to call it - -my $build = Net::MulkyID::Builder->new - ( - module_name => 'Net::MulkyID', - #license => 'agpl_3', - dist_author => 'Matthias Andreas Benkard ', - dist_abstract => 'A simple Persona IdP.', - requires => { - "Carp" => 0, - "CGI" => 0, - "CGI::Fast" => 0, - "CGI::Session" => 0, - "common::sense" => 0, - "Crypt::OpenSSL::RSA" => 0, - "Crypt::OpenSSL::Bignum" => 0, - "File::Slurp" => 0, - "JSON" => 0, - "MIME::Base64" => 0, - "Mail::ExpandAliases" => 0, - "Mail::IMAPTalk" => 0, - "Modern::Perl" => 0, - "Time::HiRes" => 0, - "Syntax::Keyword::Junction" => 0, - "OIDC::Lite" => 0, - "OIDC::Lite::Client::WebServer" => 0, - "OIDC::Lite::Model::IDToken" => 0, - "LWP::UserAgent" => 0, - "HTTP::Request" => 0, - "Math::Random::ISAAC::XS" => 0, - "Bytes::Random::Secure" => 0 - }, - build_requires => { - "LWP::Simple" => 0, - "Modern::Perl" => 0, - "Crypt::OpenSSL::RSA" => 0, - "Crypt::OpenSSL::Bignum" => 0, - "File::Slurp" => 0, - "JSON" => 0, - "common::sense" => 0 - }, - ); -$build->create_build_script; 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}\] "; - $_ = <>; + $_ = ; 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, <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:///.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, <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:///.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; diff --git a/setup.pl b/setup.pl index 7ec038b..4a6337c 100755 --- a/setup.pl +++ b/setup.pl @@ -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"; -- cgit v1.2.3