summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <adam@sigterm.info>2017-04-04 18:26:03 -0400
committerGitHub <noreply@github.com>2017-04-04 18:26:03 -0400
commit127683c29e6eb33c21f85cf1ccba6fb85fc0cdec (patch)
treeea5d76da7bc0573b8fe8b2200ed5890fb9ae055c
parent1442616f09681e6d0b68544a2df771eaeb02b7aa (diff)
parent5ac5440a44595a7d7073a311bc280274aaed449e (diff)
Merge pull request #1311 from SaberUK/master+mm-cleanup
Initial ModuleManager cleanup.
-rwxr-xr-xconfigure3
-rw-r--r--make/common.pm37
-rw-r--r--make/configure.pm24
-rw-r--r--make/console.pm55
-rwxr-xr-xmodulemanager76
5 files changed, 111 insertions, 84 deletions
diff --git a/configure b/configure
index 62f7b341b..d2da2a9ef 100755
--- a/configure
+++ b/configure
@@ -3,6 +3,7 @@
#
# InspIRCd -- Internet Relay Chat Daemon
#
+# Copyright (C) 2012-2017 Peter Powell <petpow@saberuk.com>
# Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
# Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
# Copyright (C) 2003, 2006-2008 Craig Edwards <craigedwards@brainbox.cc>
@@ -131,7 +132,7 @@ print_format "<|BOLD Configuring InspIRCd $version{FULL} on $^O.|>\n";
our %config;
if ($interactive) {
- %config = read_configure_cache();
+ %config = read_config_file(CONFIGURE_CACHE_FILE);
run_test CONFIGURE_CACHE_FILE, %config;
if (!defined $config{VERSION}) {
$config{VERSION} = CONFIGURE_CACHE_VERSION;
diff --git a/make/common.pm b/make/common.pm
index b1608db56..6ca280bec 100644
--- a/make/common.pm
+++ b/make/common.pm
@@ -1,7 +1,7 @@
#
# InspIRCd -- Internet Relay Chat Daemon
#
-# Copyright (C) 2013-2014 Peter Powell <petpow@saberuk.com>
+# Copyright (C) 2013-2017 Peter Powell <petpow@saberuk.com>
#
# This file is part of InspIRCd. InspIRCd is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
@@ -31,10 +31,13 @@ use Exporter qw(import);
use File::Path qw(mkpath);
use File::Spec::Functions qw(rel2abs);
+use make::console;
+
our @EXPORT = qw(create_directory
get_cpu_count
get_version
- module_installed);
+ read_config_file
+ write_config_file);
sub create_directory($$) {
my ($location, $permissions) = @_;
@@ -86,12 +89,6 @@ sub get_version {
return %version;
}
-sub module_installed($) {
- my $module = shift;
- eval("use $module;");
- return !$@;
-}
-
sub get_cpu_count {
my $count = 1;
if ($^O =~ /bsd/) {
@@ -107,4 +104,28 @@ sub get_cpu_count {
return $count;
}
+sub read_config_file($) {
+ my $path = shift;
+ my %config;
+ open(my $fh, $path) or return %config;
+ while (my $line = <$fh>) {
+ next if $line =~ /^\s*($|\#)/;
+ my ($key, $value) = ($line =~ /^(\S+)(?:\s(.*))?$/);
+ $config{$key} = $value;
+ }
+ close $fh;
+ return %config;
+}
+
+sub write_config_file($%) {
+ my $path = shift;
+ my %config = @_;
+ open(my $fh, '>', $path) or print_error "unable to write to $path: $!";
+ while (my ($key, $value) = each %config) {
+ $value //= '';
+ say $fh "$key $value";
+ }
+ close $fh;
+}
+
1;
diff --git a/make/configure.pm b/make/configure.pm
index 59657bfc4..a10493318 100644
--- a/make/configure.pm
+++ b/make/configure.pm
@@ -1,7 +1,7 @@
#
# InspIRCd -- Internet Relay Chat Daemon
#
-# Copyright (C) 2012-2014 Peter Powell <petpow@saberuk.com>
+# Copyright (C) 2012-2017 Peter Powell <petpow@saberuk.com>
# Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
# Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
# Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
@@ -52,7 +52,6 @@ our @EXPORT = qw(CONFIGURE_CACHE_FILE
run_test
test_file
test_header
- read_configure_cache
write_configure_cache
get_compiler_info
find_compiler
@@ -180,7 +179,7 @@ EOH
sub cmd_update {
print_error "You have not run $0 before. Please do this before trying to update the generated files." unless -f CONFIGURE_CACHE_FILE;
say 'Updating...';
- my %config = read_configure_cache();
+ my %config = read_config_file(CONFIGURE_CACHE_FILE);
my %compiler = get_compiler_info($config{CXX});
my %version = get_version $config{DISTRIBUTION};
parse_templates(\%config, \%compiler, \%version);
@@ -215,18 +214,6 @@ sub test_header($$;$) {
return !$?;
}
-sub read_configure_cache {
- my %config;
- open(CACHE, CONFIGURE_CACHE_FILE) or return %config;
- while (my $line = <CACHE>) {
- next if $line =~ /^\s*($|\#)/;
- my ($key, $value) = ($line =~ /^(\S+)(?:\s(.*))?$/);
- $config{$key} = $value;
- }
- close(CACHE);
- return %config;
-}
-
sub write_configure_cache(%) {
unless (-e CONFIGURE_DIRECTORY) {
print_format "Creating <|GREEN ${\CONFIGURE_DIRECTORY}|> ...\n";
@@ -235,12 +222,7 @@ sub write_configure_cache(%) {
print_format "Writing <|GREEN ${\CONFIGURE_CACHE_FILE}|> ...\n";
my %config = @_;
- open(CACHE, '>', CONFIGURE_CACHE_FILE) or print_error "unable to write ${\CONFIGURE_CACHE_FILE}: $!";
- while (my ($key, $value) = each %config) {
- $value //= '';
- say CACHE "$key $value";
- }
- close(CACHE);
+ write_config_file CONFIGURE_CACHE_FILE, %config;
}
sub get_compiler_info($) {
diff --git a/make/console.pm b/make/console.pm
index 84fbaae4a..0d3c1b38d 100644
--- a/make/console.pm
+++ b/make/console.pm
@@ -1,7 +1,7 @@
#
# InspIRCd -- Internet Relay Chat Daemon
#
-# Copyright (C) 2014 Peter Powell <petpow@saberuk.com>
+# Copyright (C) 2014-2017 Peter Powell <petpow@saberuk.com>
#
# This file is part of InspIRCd. InspIRCd is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
@@ -27,11 +27,14 @@ use feature ':5.10';
use strict;
use warnings FATAL => qw(all);
+use Class::Struct qw(struct);
+use Exporter qw(import);
use File::Path qw(mkpath);
use File::Spec::Functions qw(rel2abs);
-use Exporter qw(import);
-our @EXPORT = qw(print_format
+our @EXPORT = qw(command
+ execute_command
+ print_format
print_error
print_warning
prompt_bool
@@ -39,8 +42,9 @@ our @EXPORT = qw(print_format
prompt_string);
my %FORMAT_CODES = (
- DEFAULT => "\e[0m",
- BOLD => "\e[1m",
+ DEFAULT => "\e[0m",
+ BOLD => "\e[1m",
+ UNDERLINE => "\e[4m",
RED => "\e[1;31m",
GREEN => "\e[1;32m",
@@ -48,6 +52,13 @@ my %FORMAT_CODES = (
BLUE => "\e[1;34m"
);
+my %commands;
+
+struct 'command' => {
+ 'callback' => '$',
+ 'description' => '$',
+};
+
sub __console_format($$) {
my ($name, $data) = @_;
return $data unless -t STDOUT;
@@ -111,4 +122,38 @@ sub prompt_string($$$) {
return $answer ? $answer : $default;
}
+sub command($$$) {
+ my ($name, $description, $callback) = @_;
+ $commands{$name} = command->new;
+ $commands{$name}->callback($callback);
+ $commands{$name}->description($description);
+}
+
+sub command_alias($$) {
+ my ($source, $target) = @_;
+ command $source, undef, sub(@) {
+ execute_command $target, @_;
+ };
+}
+
+sub execute_command(@) {
+ my $command = defined $_[0] ? lc shift : 'help';
+ if ($command eq 'help') {
+ print_format "<|GREEN Usage:|> $0 <<|UNDERLINE COMMAND|>> [<|UNDERLINE OPTIONS...|>]\n\n";
+ print_format "<|GREEN Commands:|>\n";
+ for my $key (sort keys %commands) {
+ next unless defined $commands{$key}->description;
+ my $name = sprintf "%-15s", $key;
+ my $description = $commands{$key}->description;
+ print_format " <|BOLD $name|> # $description\n";
+ }
+ exit 0;
+ } elsif (!$commands{$command}) {
+ print_error "no command called <|BOLD $command|> exists!",
+ "See <|BOLD $0 help|> for a list of commands.";
+ } else {
+ return $commands{$command}->callback->(@_);
+ }
+}
+
1;
diff --git a/modulemanager b/modulemanager
index e859f683b..d44ccbeb9 100755
--- a/modulemanager
+++ b/modulemanager
@@ -3,6 +3,7 @@
#
# InspIRCd -- Internet Relay Chat Daemon
#
+# Copyright (C) 2012-2017 Peter Powell <petpow@saberuk.com>
# Copyright (C) 2008-2009 Robin Burchell <robin+git@viroteck.net>
#
# This file is part of InspIRCd. InspIRCd is free software: you can
@@ -19,23 +20,26 @@
#
-use strict;
-use warnings FATAL => qw(all);
-
-use make::common;
-
BEGIN {
- unless (module_installed("LWP::Simple")) {
+ require 5.10.0;
+ unless (eval "use LWP::Simple; 1") {
die "Your system is missing the LWP::Simple Perl module!";
}
- unless (module_installed("Crypt::SSLeay") || module_installed("IO::Socket::SSL")) {
+ unless (eval "use Crypt::SSLeay; 1" || eval "use IO::Socket::SSL; 1") {
die "Your system is missing the Crypt::SSLeay or IO::Socket::SSL Perl modules!";
}
-
}
-use File::Basename;
-use LWP::Simple;
+use feature ':5.10';
+use strict;
+use warnings FATAL => qw(all);
+
+use File::Basename qw(basename);
+use FindBin qw($RealDir);
+
+use lib $RealDir;
+use make::common;
+use make::console;
my %installed;
# $installed{name} = $version
@@ -102,7 +106,7 @@ sub parse_url {
}
# hash of installed module versions from our mini-database, key (m_foobar) to version (00abacca..).
-my %mod_versions;
+my %mod_versions = read_config_file '.modulemanager';
# useless helper stub
sub getmodversion {
@@ -110,19 +114,6 @@ sub getmodversion {
return $mod_versions{$file};
}
-# read in installed versions
-if (-e '.modulemanager')
-{
- open SRC, '.modulemanager' or die ".modulemanager exists but i can't read it: $!";
- while (<SRC>)
- {
- s/\n//;
- (my $mod, my $ver) = split(/ /, $_);
- $mod_versions{$mod} = $ver;
- }
- close SRC;
-}
-
# read in external URL sources
open SRC, 'sources.list' or die "Could not open sources.list: $!";
while (<SRC>) {
@@ -262,9 +253,7 @@ sub resolve_deps {
}
}
-my $action = $#ARGV >= 0 ? lc shift @ARGV : 'help';
-
-if ($action eq 'install') {
+command 'install', 'Install a third-party module', sub {
for my $mod (@ARGV) {
my $vers = $mod =~ s/=([-0-9.]+)// ? $1 : undef;
$mod = lc $mod;
@@ -279,7 +268,9 @@ if ($action eq 'install') {
}
$todo{$mod} = $ver;
}
-} elsif ($action eq 'upgrade') {
+};
+
+command 'upgrade', 'Upgrade a third-party module', sub {
my @installed = sort keys %installed;
for my $mod (@installed) {
next unless $mod =~ /^m_/;
@@ -289,7 +280,9 @@ if ($action eq 'install') {
%todo = %saved;
}
}
-} elsif ($action eq 'list') {
+};
+
+command 'list', 'List available third-party modules', sub {
my @all = sort keys %modules;
for my $mod (@all) {
my @vers = sort { ver_cmp() } keys %{$modules{$mod}};
@@ -303,25 +296,15 @@ if ($action eq 'install') {
my $vers = join ' ', map { $_ eq $instver ? "\e[1m$_\e[m" : $_ } @vers;
print "$mod ($vers) - $desc\n";
}
-} else {
- print <<ENDUSAGE
-Use: $0 <action> <args>
-Action is one of the following
- install install new modules
- upgrade upgrade installed modules
- list lists available modules
-
-For installing a package, specify its name or name=version to force the
-installation of a specific version.
-ENDUSAGE
-;exit 1;
-}
+};
+
+execute_command @ARGV;
resolve_deps(0);
$| = 1; # immediate print of lines without \n
-print "Processing changes for $action...\n";
+print "Processing changes...\n";
for my $mod (keys %installed) {
next if $todo{$mod};
print "Uninstalling $mod $installed{$mod}\n";
@@ -359,11 +342,6 @@ for my $mod (sort keys %todo) {
}
# write database of installed versions
-open SRC, '>.modulemanager' or die "can't write installed versions to .modulemanager, won't be able to track upgrades properly: $!";
-foreach my $key (keys %mod_versions)
-{
- print SRC "$key $mod_versions{$key}\n";
-}
-close SRC;
+write_config_file '.modulemanager', %mod_versions;
print "Finished!\n";