Versionen im installcheck anzeigen.
[kivitendo-erp.git] / SL / InstallationCheck.pm
1 package SL::InstallationCheck;
2
3 use English '-no_match_vars';
4 use IO::File;
5
6 use vars qw(@required_modules @optional_modules @developer_modules);
7
8 use strict;
9
10 BEGIN {
11 @required_modules = (
12   { name => "parent",                              url => "http://search.cpan.org/~corion/",    debian => 'libparent-perl' },
13   { name => "Archive::Zip",    version => '1.16',  url => "http://search.cpan.org/~adamk/",     debian => 'libarchive-zip-perl' },
14   { name => "Config::Std",                         url => "http://search.cpan.org/~dconway/",   debian => 'libconfig-std-perl' },
15   { name => "DateTime",                            url => "http://search.cpan.org/~drolsky/",   debian => 'libdatetime-perl' },
16   { name => "DBI",             version => '1.50',  url => "http://search.cpan.org/~timb/",      debian => 'libdbi-perl' },
17   { name => "DBD::Pg",         version => '1.49',  url => "http://search.cpan.org/~dbdpg/",     debian => 'libdbd-pg' },
18   { name => "Email::Address",                      url => "http://search.cpan.org/~rjbs/",      debian => 'libemail-address-perl' },
19   { name => "FCGI",                                url => "http://search.cpan.org/~mstrout/",   debian => 'libfcgi-perl' },
20   { name => "JSON",                                url => "http://search.cpan.org/~makamaka",   debian => 'libjson-perl' },
21   { name => "List::MoreUtils", version => '0.21',  url => "http://search.cpan.org/~vparseval/", debian => 'liblist-moreutils-perl' },
22   { name => "Params::Validate",                    url => "http://search.cpan.org/~drolsky/",   debian => 'libparams-validate-perl' },
23   { name => "PDF::API2",       version => '2.000', url => "http://search.cpan.org/~areibens/",  debian => 'libpdf-api2-perl' },
24   { name => "Rose::Object",                        url => "http://search.cpan.org/~jsiracusa/", debian => 'librose-object-perl' },
25   { name => "Rose::DB",                            url => "http://search.cpan.org/~jsiracusa/", debian => 'librose-db-perl' },
26   { name => "Rose::DB::Object",                    url => "http://search.cpan.org/~jsiracusa/", debian => 'librose-db-object-perl' },
27   { name => "String::ShellQuote", version => 1.01, url => "http://search.cpan.org/~rosch/",     debian => 'libstring-shellquote-perl' },
28   { name => "Sort::Naturally",                     url => "http://search.cpan.org/~sburke/",    debian => 'libsort-naturally-perl' },
29   { name => "Template",        version => '2.18',  url => "http://search.cpan.org/~abw/",       debian => 'libtemplate-perl' },
30   { name => "Text::CSV_XS",    version => '0.23',  url => "http://search.cpan.org/~hmbrand/",   debian => 'libtext-csv-xs-perl' },
31   { name => "Text::Iconv",     version => '1.2',   url => "http://search.cpan.org/~mpiotr/",    debian => 'libtext-iconv-perl' },
32   { name => "URI",             version => '1.35',  url => "http://search.cpan.org/~gaas/",      debian => 'liburi-perl' },
33   { name => "XML::Writer",     version => '0.602', url => "http://search.cpan.org/~josephw/",   debian => 'libxml-writer-perl' },
34   { name => "YAML",            version => '0.62',  url => "http://search.cpan.org/~ingy/",      debian => 'libyaml-perl' },
35 );
36
37 @optional_modules = ();
38
39 @developer_modules = (
40   { name => "Devel::REPL",                         url => "http://search.cpan.org/~doy/",       debian => 'libdevel-repl-perl' },
41   { name => "Moose::Role",                         url => "http://search.cpan.org/~doy/",       debian => 'libmoose-role-perl' },
42   { name => "Perl::Tags",                          url => "http://search.cpan.org/~osfameron/", debian => 'libperl-tags-perl' },
43 );
44
45 $_->{fullname} = join ' ', grep $_, @$_{qw(name version)}
46   for @required_modules, @optional_modules, @developer_modules;
47
48 }
49
50 sub module_available {
51   my $module  = $_[0];
52   my $version = $_[1] || '' ;
53
54   my $got = eval "use $module $version; 1";
55
56   if ($got) {
57     return ($got, $module->VERSION);
58   } else {
59     return
60   }
61 }
62
63 sub check_kpsewhich {
64   my $exit = system("which kpsewhich > /dev/null");
65
66   return $exit > 0 ? 0 : 1;
67 }
68
69 sub template_dirs {
70   my ($path) = @_;
71   opendir my $dh, $path || die "can't open $path";
72   my @templates = sort grep { !/^\.\.?$/ } readdir $dh;
73   close $dh;
74
75   return @templates;
76 }
77
78 sub classes_from_latex {
79   my ($path, $class) = @_;
80   eval { use String::ShellQuote; 1 } or warn "can't load String::ShellQuote" && return;
81   $path  = shell_quote $path;
82   $class = shell_quote $class;
83
84   open my $pipe, q#egrep -rs '^[\ \t]*# . "$class' $path". q# | sed 's/ //g' | awk -F '{' '{print $2}' | awk -F '}' '{print $1}' |#;
85   my @cls = <$pipe>;
86   close $pipe;
87
88   # can't use uniq here
89   my %class_hash = map { $_ => 1 } map { s/\n//; $_ } split ',', join ',', @cls;
90   return sort keys %class_hash;
91 }
92
93 my %conditional_dependencies;
94
95 sub check_for_conditional_dependencies {
96   return if $conditional_dependencies{net_ldap}++;
97
98   push @required_modules, { 'name' => 'Net::LDAP', 'url' => 'http://search.cpan.org/~gbarr/' }
99     if $::lx_office_conf{authentication} && ($::lx_office_conf{authentication}->{module} eq 'LDAP');
100 }
101
102 sub test_all_modules {
103   return grep { !module_available($_->{name}) } @required_modules;
104 }
105
106 1;