X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=modulemanager;h=50a86a7f7cac40b993396f4e77a5dccd63160962;hb=94eb36566e0de00c158bcbdd57a5d372bb76b264;hp=9f9c0334415c59e9fbaf68bd85611ff5cae55b83;hpb=5c88e3df25dde6aa6ff849263a79ffda6144cf4d;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/modulemanager b/modulemanager index 9f9c03344..50a86a7f7 100755 --- a/modulemanager +++ b/modulemanager @@ -20,23 +20,26 @@ # -use strict; -use warnings FATAL => qw(all); - -use make::common; - BEGIN { + require 5.10.0; unless (eval "use LWP::Simple; 1") { die "Your system is missing the LWP::Simple Perl module!"; } 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 @@ -70,7 +73,7 @@ sub parse_url { } my $mod; - for (split /\n+/, $response->decoded_content) { + for (split /\n+/, $response->content) { s/^\s+//; # ignore whitespace at start next if /^#/; if (/^module (\S+) (\S+) (\S+)/) { @@ -94,7 +97,7 @@ sub parse_url { $mod->{description} = $1; } elsif (/^mask (.*)/) { $mod->{mask} = $1; - } elsif (m#^source (http://\S+)#) { + } elsif (/^source (\S+)/) { parse_url $1; } else { print "Unknown line in $src: $_\n"; @@ -250,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}) { @@ -267,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_/; @@ -277,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}}; @@ -291,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 < -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"; @@ -338,7 +334,7 @@ for my $mod (sort keys %todo) { if ($response->is_success) { open(MF, ">src/modules/$mod.cpp") or die "\nFilesystem not writable: $!"; - print MF $response->decoded_content; + print MF $response->content; close(MF); print " - done\n"; } else {