e8670761c918f8354ee8862ceebc77471f536b95
[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   return eval "use $module $version; 1";
55 }
56
57 sub check_kpsewhich {
58   my $exit = system("which kpsewhich > /dev/null");
59
60   return $exit > 0 ? 0 : 1;
61 }
62
63 sub template_dirs {
64   my ($path) = @_;
65   opendir my $dh, $path || die "can't open $path";
66   my @templates = sort grep { !/^\.\.?$/ } readdir $dh;
67   close $dh;
68
69   return @templates;
70 }
71
72 sub classes_from_latex {
73   my ($path, $class) = @_;
74   eval { use String::ShellQuote; 1 } or warn "can't load String::ShellQuote" && return;
75   $path  = shell_quote $path;
76   $class = shell_quote $class;
77
78   open my $pipe, q#egrep -rs '^[\ \t]*# . "$class' $path". q# | sed 's/ //g' | awk -F '{' '{print $2}' | awk -F '}' '{print $1}' |#;
79   my @cls = <$pipe>;
80   close $pipe;
81
82   # can't use uniq here
83   my %class_hash = map { $_ => 1 } map { s/\n//; $_ } split ',', join ',', @cls;
84   return sort keys %class_hash;
85 }
86
87 my %conditional_dependencies;
88
89 sub check_for_conditional_dependencies {
90   return if $conditional_dependencies{net_ldap}++;
91
92   push @required_modules, { 'name' => 'Net::LDAP', 'url' => 'http://search.cpan.org/~gbarr/' }
93     if $::lx_office_conf{authentication} && ($::lx_office_conf{authentication}->{module} eq 'LDAP');
94 }
95
96 sub test_all_modules {
97   return grep { !module_available($_->{name}) } @required_modules;
98 }
99
100 1;