Installationcheck: Mehr Optionen
[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 GetOptions(
16   "verbose"   => \ my $v,
17   "all"       => \ my $a,
18   "optional!" => \ my $o,
19   "devel!"    => \ my $d,
20   "required!" => \ ( my $r = 1 ),
21   "help"      => sub { pod2usage(-verbose => 2) },
22   "color"     => \ ( my $c = 1 ),
23 );
24
25 $d = $r = $o = 1 if $a;
26
27 $| = 1;
28
29 if ($r) {
30   check($_, required => 1) for @SL::InstallationCheck::required_modules;
31 }
32 if ($o) {
33   check($_, optional => 1) for @SL::InstallationCheck::optional_modules;
34 }
35 if ($d) {
36   check($_, devel => 1) for @SL::InstallationCheck::developer_modules;
37 }
38
39 sub check {
40   my ($module, %role) = @_;
41
42   my $line = "Looking for $module->{fullname}";
43   print $line;
44   my $res = SL::InstallationCheck::module_available($module->{"name"}, $module->{version});
45   print dot_pad(length $line, $res ? 2 : 6, $res ? mycolor("ok", 'green') : mycolor("NOT ok", 'red')), $/;
46
47   return if $res;
48
49   my $needed_text =
50       $role{optional} ? 'It is OPTIONAL for Lx-Office but RECOMMENDED for improved functionality.'
51     : $role{required} ? 'It is NEEDED by Lx-Office and must be installed.'
52     : $role{devel}    ? 'It is OPTIONAL for Lx-Office and only useful for developers.'
53     :                   'It is not listed as a dependancy yet. Please tell this the developers.';
54
55   my @source_texts = source_texts($module);
56   local $" = $/;
57   print STDERR <<EOL if $v;
58 +------------------------------------------------------------------------------+
59   $module->{fullname} could not be loaded.
60
61   This module is either too old or not available on your system.
62   $needed_text
63
64   Here are some ideas how to get it:
65
66 @source_texts
67 +------------------------------------------------------------------------------+
68 EOL
69 }
70
71 sub source_texts {
72   my ($module) = @_;
73   my @texts;
74   push @texts, <<EOL;
75   - You can get it from CPAN:
76       perl -MCPAN -e "install $module->{name}"
77 EOL
78   push @texts, <<EOL if $module->{url};
79   - You can download it from this URL and install it manually:
80       $module->{url}
81 EOL
82   push @texts, <<EOL if $module->{debian};
83   - On Debian, Ubuntu and other distros you can install it with apt-get:
84       sudo apt-get install $module->{debian}
85     Note: These may be out of date as well if your system is old.
86 EOL
87  # TODO: SuSE and Fedora packaging. Windows packaging.
88
89   return @texts;
90 }
91
92 sub mycolor {
93   return $_[0] unless $c;
94   return colored(@_);
95 }
96
97 sub dot_pad {
98   my ($s, $l, $text) = @_;
99   print " ";
100   print '.' x (80 - $s - 2 - $l);
101   print " ";
102   return $text;
103 }
104
105 1;
106
107 __END__
108
109 =encoding UTF-8
110
111 =head1 NAME
112
113 scripts/installation_check.pl - check Lx-Office dependancies
114
115 =head1 SYNOPSIS
116
117   scripts/installation_check.pl [OPTION]
118
119 =head1 DESCRIPTION
120
121 List all modules needed by Lx-Office, probes for them, and warns if one is not available.
122
123 =over 4
124
125 =item C<-a, --all>
126
127 Probe for all modules.
128
129 =item C<-c, --color>
130
131 Color output. Default on.
132
133 =item C<-d, --devel>
134
135 Probe for developer dependancies. (Used for console  and tags file)
136
137 =item C<-h, --help>
138
139 Display this help.
140
141 =item C<-o, --optional>
142
143 Probe for optional modules.
144
145 =item C<-r, --required>
146
147 Probe for required modules (default).
148
149 =item C<-v. --verbose>
150
151 Print additional info for modules that are missing
152
153 =back
154
155 =head1 BUGS, CAVEATS and TODO
156
157 =over 4
158
159 =item *
160
161 Fedora packages not listed yet.
162
163 =item *
164
165 Not possible yet to generate a combined cpan/apt-get string to install all needed.
166
167 =item *
168
169 Not able to handle devel cpan modules yet.
170
171 =item *
172
173 Version requirements not fully tested yet.
174
175 =back
176
177 =head1 AUTHOR
178
179   Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
180   Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>
181
182 =cut