From baee503407fc6dbc25f0868e365f3129eff866e6 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 24 Mar 2017 21:48:17 +0000 Subject: Amend modulemanager to use {read,write}_config_file. --- modulemanager | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) (limited to 'modulemanager') diff --git a/modulemanager b/modulemanager index e859f683b..2681e8326 100755 --- a/modulemanager +++ b/modulemanager @@ -3,6 +3,7 @@ # # InspIRCd -- Internet Relay Chat Daemon # +# Copyright (C) 2012-2017 Peter Powell # Copyright (C) 2008-2009 Robin Burchell # # This file is part of InspIRCd. InspIRCd is free software: you can @@ -102,7 +103,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 +111,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 () - { - 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 () { @@ -359,11 +347,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"; -- cgit v1.2.3 From 5c88e3df25dde6aa6ff849263a79ffda6144cf4d Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 24 Mar 2017 21:55:29 +0000 Subject: Replace module_installed with eval. --- make/common.pm | 9 +-------- modulemanager | 4 ++-- 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'modulemanager') diff --git a/make/common.pm b/make/common.pm index f0174e0b3..6ca280bec 100644 --- a/make/common.pm +++ b/make/common.pm @@ -37,8 +37,7 @@ our @EXPORT = qw(create_directory get_cpu_count get_version read_config_file - write_config_file - module_installed); + write_config_file); sub create_directory($$) { my ($location, $permissions) = @_; @@ -90,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/) { diff --git a/modulemanager b/modulemanager index 2681e8326..9f9c03344 100755 --- a/modulemanager +++ b/modulemanager @@ -26,10 +26,10 @@ use warnings FATAL => qw(all); use make::common; BEGIN { - unless (module_installed("LWP::Simple")) { + 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!"; } -- cgit v1.2.3 From d43056bf6abc2e63ecf798085bf78b2aabd61618 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 24 Mar 2017 22:00:00 +0000 Subject: Use the standard Perl prelude in ModuleManager. --- modulemanager | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'modulemanager') diff --git a/modulemanager b/modulemanager index 9f9c03344..1ac0c936a 100755 --- a/modulemanager +++ b/modulemanager @@ -20,23 +20,25 @@ # -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; my %installed; # $installed{name} = $version -- cgit v1.2.3 From 5ac5440a44595a7d7073a311bc280274aaed449e Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 24 Mar 2017 23:20:28 +0000 Subject: Adapt modulemanager for the API added in the previous commit. --- modulemanager | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'modulemanager') diff --git a/modulemanager b/modulemanager index 1ac0c936a..d44ccbeb9 100755 --- a/modulemanager +++ b/modulemanager @@ -39,6 +39,7 @@ use FindBin qw($RealDir); use lib $RealDir; use make::common; +use make::console; my %installed; # $installed{name} = $version @@ -252,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; @@ -269,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_/; @@ -279,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}}; @@ -293,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 < -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"; -- cgit v1.2.3