installationcheck.pl: In Vorbereitung auf LaTeX die Funktionen auf perl/module umbenannt.
[kivitendo-erp.git] / scripts / installation_check.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Getopt::Long;
5 use Pod::Usage;
6 use Term::ANSIColor;
7
8 BEGIN {
9   unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
10   push    @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
11 }
12
13 use SL::InstallationCheck;
14
15 my %check;
16 Getopt::Long::Configure ("bundling");
17 GetOptions(
18   "v|verbose"   => \ my $v,
19   "a|all"       => \ $check{a},
20   "o|optional!" => \ $check{o},
21   "d|devel!"    => \ $check{d},
22   "r|required!" => \ $check{r},
23   "h|help"      => sub { pod2usage(-verbose => 2) },
24   "c|color!"    => \ ( my $c = 1 ),
25 );
26
27 # if notihing is requested check "required"
28 $check{r} = 1 unless defined $check{a} ||
29                      defined $check{o} ||
30                      defined $check{d};
31
32 if ($check{a}) {
33   foreach my $check (keys %check) {
34     $check{$check} = 1 unless defined $check{$check};
35   }
36 }
37
38
39 $| = 1;
40
41 if ($check{r}) {
42   check_module($_, required => 1) for @SL::InstallationCheck::required_modules;
43 }
44 if ($check{o}) {
45   check_module($_, optional => 1) for @SL::InstallationCheck::optional_modules;
46 }
47 if ($check{d}) {
48   check_module($_, devel => 1) for @SL::InstallationCheck::developer_modules;
49 }
50
51 sub check_module {
52   my ($module, %role) = @_;
53
54   my $line = "Looking for $module->{fullname}";
55   my $res = SL::InstallationCheck::module_available($module->{"name"}, $module->{version});
56   print_result($line, $res);
57
58   return if $res;
59
60   my $needed_text =
61       $role{optional} ? 'It is OPTIONAL for Lx-Office but RECOMMENDED for improved functionality.'
62     : $role{required} ? 'It is NEEDED by Lx-Office and must be installed.'
63     : $role{devel}    ? 'It is OPTIONAL for Lx-Office and only useful for developers.'
64     :                   'It is not listed as a dependancy yet. Please tell this the developers.';
65
66   my @source_texts = module_source_texts($module);
67   local $" = $/;
68   print STDERR <<EOL if $v;
69 +------------------------------------------------------------------------------+
70   $module->{fullname} could not be loaded.
71
72   This module is either too old or not available on your system.
73   $needed_text
74
75   Here are some ideas how to get it:
76
77 @source_texts
78 +------------------------------------------------------------------------------+
79 EOL
80 }
81
82 sub module_source_texts {
83   my ($module) = @_;
84   my @texts;
85   push @texts, <<EOL;
86   - You can get it from CPAN:
87       perl -MCPAN -e "install $module->{name}"
88 EOL
89   push @texts, <<EOL if $module->{url};
90   - You can download it from this URL and install it manually:
91       $module->{url}
92 EOL
93   push @texts, <<EOL if $module->{debian};
94   - On Debian, Ubuntu and other distros you can install it with apt-get:
95       sudo apt-get install $module->{debian}
96     Note: These may be out of date as well if your system is old.
97 EOL
98  # TODO: SuSE and Fedora packaging. Windows packaging.
99
100   return @texts;
101 }
102
103 sub mycolor {
104   return $_[0] unless $c;
105   return colored(@_);
106 }
107
108 sub print_result {
109   my ($test, $exit) = @_;
110   print $test, " ", ('.' x (72 - length $test));
111   print $exit ? '.... '. mycolor('ok', 'green') : ' '. mycolor('NOT ok', 'red');
112   print "\n";
113   return;
114 }
115
116 1;
117
118 __END__
119
120 =encoding UTF-8
121
122 =head1 NAME
123
124 scripts/installation_check.pl - check Lx-Office dependancies
125
126 =head1 SYNOPSIS
127
128   scripts/installation_check.pl [OPTION]
129
130 =head1 DESCRIPTION
131
132 Check dependencys. List all perl modules needed by Lx-Office, probes for them,
133 and warns if one is not available.
134
135 =head1 OPTIONS
136
137 =over 4
138
139 =item C<-a, --all>
140
141 Probe for all perl modules and all LaTeX master templates.
142
143 =item C<-c, --color>
144
145 Color output. Default on.
146
147 =item C<--no-color>
148
149 No color output. Helpful to avoid terminal escape problems.
150
151 =item C<-d, --devel>
152
153 Probe for perl developer dependancies. (Used for console  and tags file)
154
155 =item C<--no-devel>
156
157 Dont't probe for perl developer dependancies. (Usefull in combination with --all)
158
159 =item C<-h, --help>
160
161 Display this help.
162
163 =item C<-o, --optional>
164
165 Probe for optional modules.
166
167 =item C<--no-optional>
168
169 Dont't probe for optional perl modules. (Usefull in combination with --all)
170
171 =item C<-r, --required>
172
173 Probe for required perl modules (default).
174
175 =item C<--no-required>
176
177 Dont't probe for required perl modules. (Usefull in combination with --all)
178
179 =item C<-v. --verbose>
180
181 Print additional info for missing dependancies
182
183 =back
184
185 =head1 BUGS, CAVEATS and TODO
186
187 =over 4
188
189 =item *
190
191 Fedora packages not listed yet.
192
193 =item *
194
195 Not possible yet to generate a combined cpan/apt-get string to install all needed.
196
197 =item *
198
199 Not able to handle devel cpan modules yet.
200
201 =item *
202
203 Version requirements not fully tested yet.
204
205 =back
206
207 =head1 AUTHOR
208
209   Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
210   Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>
211   Wulf Coulmann E<lt>wulf@coulmann.deE<gt>
212
213 =cut