1
1
# !/usr/bin/env perl
2
- #
3
2
4
3
=head1 NAME
5
4
6
- check_modules.pl - check to ensure that all applications and perl modules are installed.
5
+ check_modules.pl - Check to ensure that applications and perl modules needed by
6
+ webwork2 are installed.
7
7
8
8
=head1 SYNOPSIS
9
9
10
10
check_modules.pl [options]
11
11
12
12
Options:
13
- -m|--modules Lists the perl modules needed to be installed.
14
- -p|--programs Lists the programs/applications that are needed.
15
- -A|--all checks both programs and modules (Default if -m or -p is not selected)
13
+ -m|--modules Check that the perl modules needed by webwork2 can be loaded.
14
+ -p|--programs Check that the programs needed by webwork2 exist.
15
+
16
+ Both programs and modules are checked if no options are given.
16
17
17
18
=head1 DESCRIPTION
18
19
19
- Lists all needed applications for webwork as well as a perl modules.
20
+ Checks that modules needed by webwork2 can be loaded and are at the sufficient
21
+ version, and that applications needed by webwork2 exist.
20
22
21
23
=cut
22
24
23
25
use strict;
24
26
use warnings;
25
27
use version;
28
+ use feature ' say' ;
29
+
26
30
use Getopt::Long qw( :config bundling) ;
27
31
use Pod::Usage;
28
32
29
- my @applicationsList = qw(
30
- convert
31
- curl
32
- dvisvgm
33
- mkdir
34
- mv
35
- mysql
36
- node
37
- tar
38
- git
39
- gzip
40
- latex
41
- pandoc
42
- xelatex
43
- dvipng
44
- ) ;
45
-
46
33
my @modulesList = qw(
47
34
Archive::Tar
48
35
Archive::Zip
49
36
Archive::Zip::SimpleZip
50
- Array::Utils
51
37
Benchmark
52
38
Carp
53
39
Class::Accessor
@@ -60,12 +46,10 @@ =head1 DESCRIPTION
60
46
Date::Format
61
47
Date::Parse
62
48
DateTime
63
- DBD::mysql
64
49
DBI
65
50
Digest::MD5
66
51
Digest::SHA
67
52
Email::Address::XS
68
- Email::Sender::Simple
69
53
Email::Sender::Transport::SMTP
70
54
Email::Stuffer
71
55
Errno
@@ -85,11 +69,8 @@ =head1 DESCRIPTION
85
69
Getopt::Long
86
70
Getopt::Std
87
71
HTML::Entities
88
- HTML::Tagset
89
- HTML::Template
90
72
HTTP::Async
91
73
IO::File
92
- IO::Socket::SSL
93
74
Iterator
94
75
Iterator::Util
95
76
Locale::Maketext::Lexicon
@@ -104,29 +85,22 @@ =head1 DESCRIPTION
104
85
Mojolicious::Plugin::NotYAMLConfig
105
86
Mojolicious::Plugin::RenderFile
106
87
Net::IP
107
- Net::LDAPS
108
88
Net::OAuth
109
- Net::SMTP
110
- Net::SSLeay
111
89
Opcode
112
- PadWalker
113
90
Pandoc
114
- Path::Class
115
91
Perl::Tidy
116
92
PHP::Serialization
117
93
Pod::Simple::Search
118
94
Pod::Simple::XHTML
119
95
Pod::Usage
120
96
Pod::WSDL
121
- Safe
122
97
Scalar::Util
123
98
SOAP::Lite
124
99
Socket
125
100
SQL::Abstract
126
101
Statistics::R::IO
127
102
String::ShellQuote
128
103
SVG
129
- Template
130
104
Text::CSV
131
105
Text::Wrap
132
106
Tie::IxHash
@@ -147,90 +121,146 @@ =head1 DESCRIPTION
147
121
' IO::Socket::SSL' => 2.007,
148
122
' LWP::Protocol::https' => 6.06,
149
123
' Mojolicious' => 9.34,
150
- ' Net::SSLeay' => 1.46,
151
124
' SQL::Abstract' => 2.000000
152
125
);
153
126
154
- my ($test_programs , $test_modules , $show_help );
155
- my $test_all = 1;
127
+ my @programList = qw(
128
+ convert
129
+ curl
130
+ mkdir
131
+ mv
132
+ mysql
133
+ mysqldump
134
+ node
135
+ npm
136
+ tar
137
+ git
138
+ gzip
139
+ latex
140
+ latex2pdf
141
+ pandoc
142
+ dvipng
143
+ ) ;
144
+
145
+ my ($test_modules , $test_programs , $show_help );
156
146
157
147
GetOptions(
158
148
' m|modules' => \$test_modules ,
159
149
' p|programs' => \$test_programs ,
160
- ' A|all' => \$test_all ,
161
150
' h|help' => \$show_help ,
162
151
);
163
152
pod2usage(2) if $show_help ;
164
153
165
- my @PATH = split (/ :/ , $ENV {PATH });
166
-
167
- if ($test_all or $test_programs ) {
168
- check_apps(@applicationsList );
169
- }
170
-
171
- if ($test_all or $test_modules ) {
172
- check_modules(@modulesList );
173
- }
154
+ $test_modules = $test_programs = 1 unless $test_programs || $test_modules ;
174
155
175
- sub check_apps {
176
- my @applicationsList = @_ ;
177
- print " \n Checking your \$ PATH for executables required by WeBWorK...\n " ;
178
- print " \$ PATH=" ;
179
- print join (" \n " , map (" $_ " , @PATH )), " \n\n " ;
180
-
181
- foreach my $app (@applicationsList ) {
182
- my $found = which($app );
183
- if ($found ) {
184
- print " $app found at $found \n " ;
185
- } else {
186
- print " ** $app not found in \$ PATH\n " ;
187
- }
188
- }
189
-
190
- # # Check that the node version is sufficient.
191
- my $node_version_str = qx/ node -v/ ;
192
- my ($node_version ) = $node_version_str =~ m / v(\d +)\. / ;
156
+ my @PATH = split (/ :/ , $ENV {PATH });
193
157
194
- print " \n\n **The version of node should be at least 16. You have version $node_version "
195
- if ( $node_version < 16) ;
196
- }
158
+ check_modules() if $test_modules ;
159
+ say ' ' if $test_modules && $test_programs ;
160
+ check_apps() if $test_programs ;
197
161
198
162
sub which {
199
- my $app = shift ;
200
- foreach my $path (@PATH ) {
201
- return " $path /$app " if -e " $path /$app " ;
163
+ my $program = shift ;
164
+ for my $path (@PATH ) {
165
+ return " $path /$program " if -e " $path /$program " ;
202
166
}
167
+ return ;
203
168
}
204
169
205
170
sub check_modules {
206
- my @modulesList = @_ ;
171
+ say " Checking for modules required by WeBWorK... " ;
207
172
208
- print " \n Checking your \@ INC for modules required by WeBWorK...\n " ;
209
- my @inc = @INC ;
210
- print " \@ INC=" ;
211
- print join (" \n " , map (" $_ " , @inc )), " \n\n " ;
173
+ my $moduleNotFound = 0;
212
174
213
- no strict ' refs' ;
175
+ my $checkModule = sub {
176
+ my $module = shift ;
214
177
215
- foreach my $module ( @modulesList ) {
178
+ no strict ' refs ' ;
216
179
eval " use $module " ;
217
180
if ($@ ) {
218
- my $file = $module ;
219
- $file =~ s | ::| /| g ;
220
- $file .= " .pm" ;
181
+ $moduleNotFound = 1;
182
+ my $file = ($module =~ s | ::| /| gr ) . ' .pm' ;
221
183
if ($@ =~ / Can't locate $file in \@ INC/ ) {
222
- print " ** $module not found in \@ INC\n " ;
184
+ say " ** $module not found in \@ INC" ;
223
185
} else {
224
- print " ** $module found, but failed to load: $@ " ;
186
+ say " ** $module found, but failed to load: $@ " ;
225
187
}
226
188
} elsif (defined ($moduleVersion {$module })
227
189
&& version-> parse(${ $module . ' ::VERSION' }) < version-> parse($moduleVersion {$module }))
228
190
{
229
- print " ** $module found, but not version $moduleVersion {$module } or better\n " ;
191
+ $moduleNotFound = 1;
192
+ say " ** $module found, but not version $moduleVersion {$module } or better" ;
193
+ } else {
194
+ say " $module found and loaded" ;
195
+ }
196
+ use strict ' refs' ;
197
+ };
198
+
199
+ for my $module (@modulesList ) {
200
+ $checkModule -> ($module );
201
+ }
202
+
203
+ if ($moduleNotFound ) {
204
+ say ' ' ;
205
+ say ' Some requred modules were not found, could not be loaded, or were not at the sufficient version.' ;
206
+ say ' Exiting as this is required to check the database driver and programs.' ;
207
+ exit 0;
208
+ }
209
+
210
+ say ' ' ;
211
+ say ' Checking for the database driver required by WeBWorK...' ;
212
+ my $ce = loadCourseEnvironment();
213
+ my $driver = $ce -> {database_driver } =~ / ^mysql$ /i ? ' DBD::mysql' : ' DBD::MariaDB' ;
214
+ say " Configured to use $driver in site.conf" ;
215
+ $checkModule -> ($driver );
216
+
217
+ return ;
218
+ }
219
+
220
+ sub check_apps {
221
+ my $ce = loadCourseEnvironment();
222
+
223
+ say ' Checking external programs required by WeBWorK...' ;
224
+
225
+ push (@programList , $ce -> {pg }{specialPGEnvironmentVars }{latexImageSVGMethod });
226
+
227
+ for my $program (@programList ) {
228
+ if ($ce -> {externalPrograms }{$program }) {
229
+ # Remove command line arguments (for latex and latex2pdf).
230
+ my $executable = $ce -> {externalPrograms }{$program } =~ s / .*$// gr ;
231
+ if (-e $executable ) {
232
+ say " $executable found for $program " ;
233
+ } else {
234
+ say " ** $executable not found for $program " ;
235
+ }
230
236
} else {
231
- print " $module found and loaded\n " ;
237
+ my $found = which($program );
238
+ if ($found ) {
239
+ say " $found found for $program " ;
240
+ } else {
241
+ say " ** $program not found in \$ PATH" ;
242
+ }
232
243
}
233
244
}
245
+
246
+ # Check that the node version is sufficient.
247
+ my $node_version_str = qx/ node -v/ ;
248
+ my ($node_version ) = $node_version_str =~ m / v(\d +)\. / ;
249
+
250
+ say " \n **The version of node should be at least 18. You have version $node_version ."
251
+ if $node_version < 18;
252
+
253
+ return ;
254
+ }
255
+
256
+ sub loadCourseEnvironment {
257
+ eval ' require Mojo::File' ;
258
+ die " Unable to load Mojo::File: $@ " if $@ ;
259
+ my $webworkRoot = Mojo::File-> curfile-> dirname-> dirname;
260
+ push @INC , " $webworkRoot /lib" ;
261
+ eval ' require WeBWorK::CourseEnvironment' ;
262
+ die " Unable to load WeBWorK::CourseEnvironment: $@ " if $@ ;
263
+ return WeBWorK::CourseEnvironment-> new({ webwork_dir => $webworkRoot });
234
264
}
235
265
236
266
1;
0 commit comments