+if (!SL::LxOfficeConf->read(undef, 'may fail')) {
+ print_header('Could not load the config file. If you have dependencies from any features enabled in the configuration these will still show up as optional because of this. Please rerun this script after installing the dependencies needed to load the configuration.')
+} else {
+ SL::InstallationCheck::check_for_conditional_dependencies();
+}
+
+if ($check{r}) {
+ print_header('Checking Required Modules');
+ check_module($_, required => 1) for @SL::InstallationCheck::required_modules;
+ check_pdfinfo();
+}
+if ($check{o}) {
+ print_header('Checking Optional Modules');
+ check_module($_, optional => 1) for @SL::InstallationCheck::optional_modules;
+}
+if ($check{d}) {
+ print_header('Checking Developer Modules');
+ check_module($_, devel => 1) for @SL::InstallationCheck::developer_modules;
+}
+if ($check{l}) {
+ check_latex();
+}
+
+my $fail = @missing_modules;
+print_header('Result');
+print_line('All', $fail ? 'NOT ok' : 'OK', $fail ? 'red' : 'green');
+
+if ($default_run && !$check{s}) {
+ if (@missing_modules) {
+ $apt = 1;
+ print <<"EOL";
+
+HEY! It seems there are modules MISSING! Look for the red lines with "NOT ok"
+above. You'll want to fix those, I've enabled --install-command for you...
+EOL
+ } else {
+ print <<"EOL";
+
+Standard check done, everything is OK and up to date. Have a look at the --help
+section of this script to see some more advanced checks for developer and
+optional dependencies, as well as LaTeX packages you might need.
+EOL
+ }
+}
+
+if (@missing_modules && $apt && !$check{s}) {
+ print "\nHere are some sample installation lines, choose one appropriate for your system:\n\n";
+ local $Text::Wrap::separator = " \\\n";
+
+ for (keys %install_methods) {
+ my $method = $install_methods{$_};
+ if (my @install_candidates = grep $_, map { $_->{$method->{key}} } @missing_modules) {
+ print "$method->{system}:\n";
+ print wrap(" ", " ", $method->{install}, @install_candidates);
+ print $/;
+ }
+ }
+}
+
+exit !!@missing_modules;
+
+sub check_latex {
+ my ($res) = check_kpsewhich();
+ print_result("Looking for LaTeX kpsewhich", $res);
+
+ # no pdfx -> no zugferd possible
+ my $ret = kpsewhich('template/print/', 'sty', 'pdfx');
+ die "Cannot use pdfx. Please install this package first (debian: apt install texlive-latex-extra)" if $ret;
+ # check version 2018
+ my $latex = $::lx_office_conf{applications}->{latex} || 'pdflatex';
+ my $pdfx = (system ${latex} . ' --interaction=batchmode "\documentclass{minimal} \RequirePackage{pdfx} \csname @ifpackagelater\endcsname{pdfx}{2018/12/22}{}{\show\relax} \begin{document} \end{document}"');
+
+ print_result ("Looking for pdfx version 2018 or higher", !$pdfx);
+ push @missing_modules, \(name => 'pdfx') if $pdfx;
+
+ if ($res) {
+ check_template_dir($_) for SL::InstallationCheck::template_dirs($master_templates);
+ }
+ print STDERR <<EOL if $pdfx;
++------------------------------------------------------------------------------+
+ Your pdfx version is too old. You cannot use ZuGFeRD or modern (2018+)
+ templates. Please consider using a more recent LaTeX environment.
+ Verify with:
+ pdflatex --interaction=batchmode "\RequirePackage{pdfx}[2018/12/22]"
++------------------------------------------------------------------------------+
+EOL
+}
+
+sub check_template_dir {
+ my ($dir) = @_;
+ my $path = $master_templates . $dir;
+
+ print_header("Checking LaTeX Dependencies for Master Templates '$dir'");
+ kpsewhich($path, 'cls', $_) for SL::InstallationCheck::classes_from_latex($path, '\documentclass');
+
+ my @sty = sort { $a cmp $b } uniq (
+ SL::InstallationCheck::classes_from_latex($path, '\usepackage'),
+ qw(textcomp ulem embedfile)
+ );
+ kpsewhich($path, 'sty', $_) for @sty;
+}
+
+our $mastertemplate_path = './templates/print/';
+
+sub check_kpsewhich {
+ return 1 if SL::InstallationCheck::check_kpsewhich();