diff options
Diffstat (limited to 'modulemanager')
-rwxr-xr-x | modulemanager | 90 |
1 files changed, 30 insertions, 60 deletions
diff --git a/modulemanager b/modulemanager index f00234994..50a86a7f7 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,29 +20,26 @@ # -use strict; -use warnings FATAL => qw(all); - -BEGIN { - require 5.8.0; - push @INC, '.'; -} - BEGIN { - # HACK: for some reason this needs to be in a second BEGIN block - # or it doesn't receive the updated @INC from above. - use make::configure; - 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 LWP::Simple; +use feature ':5.10'; +use strict; +use warnings FATAL => qw(all); + +use File::Basename qw(basename); +use FindBin qw($RealDir); -our @modlist; +use lib $RealDir; +use make::common; +use make::console; my %installed; # $installed{name} = $version @@ -108,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 { @@ -116,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>) { @@ -137,8 +122,6 @@ while (<SRC>) { } close SRC; -getmodules(1); - # determine core version `./src/version.sh` =~ /InspIRCd-([0-9.]+)/ or die "Cannot determine inspircd version"; $installed{core} = $1; @@ -162,9 +145,8 @@ $modules{core}{$1} = { }; # set up core module list -for my $modname (@modlist) { - my $mod = "m_$modname"; - my $modfile = "src/modules/$mod.cpp"; +for my $modname (<src/modules/m_*.cpp>) { + my $mod = basename($modname, '.cpp'); my $ver = getmodversion($mod) || '0.0'; $ver =~ s/\$Rev: (.*) \$/$1/; # for storing revision in SVN $installed{$mod} = $ver; @@ -271,10 +253,8 @@ sub resolve_deps { } } -my $action = $#ARGV >= 0 ? lc shift @ARGV : 'help'; - -if ($action eq 'install') { - for my $mod (@ARGV) { +command 'install', 'Install a third-party module', sub { + for my $mod (@_) { my $vers = $mod =~ s/=([-0-9.]+)// ? $1 : undef; $mod = lc $mod; unless ($modules{$mod}) { @@ -288,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_/; @@ -298,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}}; @@ -312,25 +296,16 @@ 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; -} + exit 0; +}; + +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"; @@ -368,11 +343,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"; |