1c25ce589SFinn Behrens#!/usr/bin/env perl 2c942fddfSThomas Gleixner# SPDX-License-Identifier: GPL-2.0-or-later 324071ac1SMauro Carvalho Chehabuse strict; 424071ac1SMauro Carvalho Chehab 52f9c5025SMauro Carvalho Chehab# Copyright (c) 2017-2020 Mauro Carvalho Chehab <mchehab@kernel.org> 624071ac1SMauro Carvalho Chehab# 724071ac1SMauro Carvalho Chehab 88c69b77aSMike Rapoportmy $prefix = "./"; 98c69b77aSMike Rapoport$prefix = "$ENV{'srctree'}/" if ($ENV{'srctree'}); 108c69b77aSMike Rapoport 118c69b77aSMike Rapoportmy $conf = $prefix . "Documentation/conf.py"; 128c69b77aSMike Rapoportmy $requirement_file = $prefix . "Documentation/sphinx/requirements.txt"; 1344f42165SMauro Carvalho Chehabmy $virtenv_prefix = "sphinx_"; 145be33182SMauro Carvalho Chehab 1524071ac1SMauro Carvalho Chehab# 1624071ac1SMauro Carvalho Chehab# Static vars 1724071ac1SMauro Carvalho Chehab# 1824071ac1SMauro Carvalho Chehab 1924071ac1SMauro Carvalho Chehabmy %missing; 2024071ac1SMauro Carvalho Chehabmy $system_release; 2124071ac1SMauro Carvalho Chehabmy $need = 0; 2224071ac1SMauro Carvalho Chehabmy $optional = 0; 2324071ac1SMauro Carvalho Chehabmy $need_symlink = 0; 2424071ac1SMauro Carvalho Chehabmy $need_sphinx = 0; 25a5f785f1SMauro Carvalho Chehabmy $need_pip = 0; 262f9c5025SMauro Carvalho Chehabmy $need_virtualenv = 0; 27a5f785f1SMauro Carvalho Chehabmy $rec_sphinx_upgrade = 0; 2824071ac1SMauro Carvalho Chehabmy $install = ""; 2944f42165SMauro Carvalho Chehabmy $virtenv_dir = ""; 302f9c5025SMauro Carvalho Chehabmy $python_cmd = ""; 31a5f785f1SMauro Carvalho Chehabmy $activate_cmd; 3244f42165SMauro Carvalho Chehabmy $min_version; 332834a741SMauro Carvalho Chehabmy $cur_version; 341ef70cedSMauro Carvalho Chehabmy $rec_version = "1.7.9"; # PDF won't build here 351ef70cedSMauro Carvalho Chehabmy $min_pdf_version = "2.4.4"; # Min version where pdf builds 36a5f785f1SMauro Carvalho Chehabmy $latest_avail_ver; 37e5089912SMauro Carvalho Chehab 3824071ac1SMauro Carvalho Chehab# 3924071ac1SMauro Carvalho Chehab# Command line arguments 4024071ac1SMauro Carvalho Chehab# 4124071ac1SMauro Carvalho Chehab 4224071ac1SMauro Carvalho Chehabmy $pdf = 1; 4324071ac1SMauro Carvalho Chehabmy $virtualenv = 1; 449b88ad54SMauro Carvalho Chehabmy $version_check = 0; 4524071ac1SMauro Carvalho Chehab 4624071ac1SMauro Carvalho Chehab# 4724071ac1SMauro Carvalho Chehab# List of required texlive packages on Fedora and OpenSuse 4824071ac1SMauro Carvalho Chehab# 4924071ac1SMauro Carvalho Chehab 5024071ac1SMauro Carvalho Chehabmy %texlive = ( 5124071ac1SMauro Carvalho Chehab 'amsfonts.sty' => 'texlive-amsfonts', 5224071ac1SMauro Carvalho Chehab 'amsmath.sty' => 'texlive-amsmath', 5324071ac1SMauro Carvalho Chehab 'amssymb.sty' => 'texlive-amsfonts', 5424071ac1SMauro Carvalho Chehab 'amsthm.sty' => 'texlive-amscls', 5524071ac1SMauro Carvalho Chehab 'anyfontsize.sty' => 'texlive-anyfontsize', 5624071ac1SMauro Carvalho Chehab 'atbegshi.sty' => 'texlive-oberdiek', 5724071ac1SMauro Carvalho Chehab 'bm.sty' => 'texlive-tools', 5824071ac1SMauro Carvalho Chehab 'capt-of.sty' => 'texlive-capt-of', 5924071ac1SMauro Carvalho Chehab 'cmap.sty' => 'texlive-cmap', 6024071ac1SMauro Carvalho Chehab 'ecrm1000.tfm' => 'texlive-ec', 6124071ac1SMauro Carvalho Chehab 'eqparbox.sty' => 'texlive-eqparbox', 6224071ac1SMauro Carvalho Chehab 'eu1enc.def' => 'texlive-euenc', 6324071ac1SMauro Carvalho Chehab 'fancybox.sty' => 'texlive-fancybox', 6424071ac1SMauro Carvalho Chehab 'fancyvrb.sty' => 'texlive-fancyvrb', 6524071ac1SMauro Carvalho Chehab 'float.sty' => 'texlive-float', 6624071ac1SMauro Carvalho Chehab 'fncychap.sty' => 'texlive-fncychap', 6724071ac1SMauro Carvalho Chehab 'footnote.sty' => 'texlive-mdwtools', 6824071ac1SMauro Carvalho Chehab 'framed.sty' => 'texlive-framed', 6924071ac1SMauro Carvalho Chehab 'luatex85.sty' => 'texlive-luatex85', 7024071ac1SMauro Carvalho Chehab 'multirow.sty' => 'texlive-multirow', 7124071ac1SMauro Carvalho Chehab 'needspace.sty' => 'texlive-needspace', 7224071ac1SMauro Carvalho Chehab 'palatino.sty' => 'texlive-psnfss', 7324071ac1SMauro Carvalho Chehab 'parskip.sty' => 'texlive-parskip', 7424071ac1SMauro Carvalho Chehab 'polyglossia.sty' => 'texlive-polyglossia', 7524071ac1SMauro Carvalho Chehab 'tabulary.sty' => 'texlive-tabulary', 7624071ac1SMauro Carvalho Chehab 'threeparttable.sty' => 'texlive-threeparttable', 7724071ac1SMauro Carvalho Chehab 'titlesec.sty' => 'texlive-titlesec', 7824071ac1SMauro Carvalho Chehab 'ucs.sty' => 'texlive-ucs', 7924071ac1SMauro Carvalho Chehab 'upquote.sty' => 'texlive-upquote', 8024071ac1SMauro Carvalho Chehab 'wrapfig.sty' => 'texlive-wrapfig', 817baab965SMauro Carvalho Chehab 'ctexhook.sty' => 'texlive-ctex', 8224071ac1SMauro Carvalho Chehab); 8324071ac1SMauro Carvalho Chehab 8424071ac1SMauro Carvalho Chehab# 8524071ac1SMauro Carvalho Chehab# Subroutines that checks if a feature exists 8624071ac1SMauro Carvalho Chehab# 8724071ac1SMauro Carvalho Chehab 8824071ac1SMauro Carvalho Chehabsub check_missing(%) 8924071ac1SMauro Carvalho Chehab{ 9024071ac1SMauro Carvalho Chehab my %map = %{$_[0]}; 9124071ac1SMauro Carvalho Chehab 9224071ac1SMauro Carvalho Chehab foreach my $prog (sort keys %missing) { 9324071ac1SMauro Carvalho Chehab my $is_optional = $missing{$prog}; 9424071ac1SMauro Carvalho Chehab 9556e5a633SMauro Carvalho Chehab # At least on some LTS distros like CentOS 7, texlive doesn't 9656e5a633SMauro Carvalho Chehab # provide all packages we need. When such distros are 9756e5a633SMauro Carvalho Chehab # detected, we have to disable PDF output. 9856e5a633SMauro Carvalho Chehab # 9956e5a633SMauro Carvalho Chehab # So, we need to ignore the packages that distros would 10056e5a633SMauro Carvalho Chehab # need for LaTeX to work 10156e5a633SMauro Carvalho Chehab if ($is_optional == 2 && !$pdf) { 10256e5a633SMauro Carvalho Chehab $optional--; 10356e5a633SMauro Carvalho Chehab next; 10456e5a633SMauro Carvalho Chehab } 10556e5a633SMauro Carvalho Chehab 10624071ac1SMauro Carvalho Chehab if ($is_optional) { 10724071ac1SMauro Carvalho Chehab print "Warning: better to also install \"$prog\".\n"; 10824071ac1SMauro Carvalho Chehab } else { 10924071ac1SMauro Carvalho Chehab print "ERROR: please install \"$prog\", otherwise, build won't work.\n"; 11024071ac1SMauro Carvalho Chehab } 11124071ac1SMauro Carvalho Chehab if (defined($map{$prog})) { 11224071ac1SMauro Carvalho Chehab $install .= " " . $map{$prog}; 11324071ac1SMauro Carvalho Chehab } else { 11424071ac1SMauro Carvalho Chehab $install .= " " . $prog; 11524071ac1SMauro Carvalho Chehab } 11624071ac1SMauro Carvalho Chehab } 11724071ac1SMauro Carvalho Chehab 11824071ac1SMauro Carvalho Chehab $install =~ s/^\s//; 11924071ac1SMauro Carvalho Chehab} 12024071ac1SMauro Carvalho Chehab 12124071ac1SMauro Carvalho Chehabsub add_package($$) 12224071ac1SMauro Carvalho Chehab{ 12324071ac1SMauro Carvalho Chehab my $package = shift; 12424071ac1SMauro Carvalho Chehab my $is_optional = shift; 12524071ac1SMauro Carvalho Chehab 12624071ac1SMauro Carvalho Chehab $missing{$package} = $is_optional; 12724071ac1SMauro Carvalho Chehab if ($is_optional) { 12824071ac1SMauro Carvalho Chehab $optional++; 12924071ac1SMauro Carvalho Chehab } else { 13024071ac1SMauro Carvalho Chehab $need++; 13124071ac1SMauro Carvalho Chehab } 13224071ac1SMauro Carvalho Chehab} 13324071ac1SMauro Carvalho Chehab 13424071ac1SMauro Carvalho Chehabsub check_missing_file($$$) 13524071ac1SMauro Carvalho Chehab{ 136ff8fdb36SJeremy MAURO my $files = shift; 13724071ac1SMauro Carvalho Chehab my $package = shift; 13824071ac1SMauro Carvalho Chehab my $is_optional = shift; 13924071ac1SMauro Carvalho Chehab 140ff8fdb36SJeremy MAURO for (@$files) { 141ff8fdb36SJeremy MAURO return if(-e $_); 142ff8fdb36SJeremy MAURO } 14324071ac1SMauro Carvalho Chehab 14424071ac1SMauro Carvalho Chehab add_package($package, $is_optional); 14524071ac1SMauro Carvalho Chehab} 14624071ac1SMauro Carvalho Chehab 14724071ac1SMauro Carvalho Chehabsub findprog($) 14824071ac1SMauro Carvalho Chehab{ 14924071ac1SMauro Carvalho Chehab foreach(split(/:/, $ENV{PATH})) { 15024071ac1SMauro Carvalho Chehab return "$_/$_[0]" if(-x "$_/$_[0]"); 15124071ac1SMauro Carvalho Chehab } 15224071ac1SMauro Carvalho Chehab} 15324071ac1SMauro Carvalho Chehab 154412b09ddSMauro Carvalho Chehabsub find_python_no_venv() 155412b09ddSMauro Carvalho Chehab{ 156412b09ddSMauro Carvalho Chehab my $prog = shift; 157412b09ddSMauro Carvalho Chehab 158412b09ddSMauro Carvalho Chehab my $cur_dir = qx(pwd); 159412b09ddSMauro Carvalho Chehab $cur_dir =~ s/\s+$//; 160412b09ddSMauro Carvalho Chehab 161412b09ddSMauro Carvalho Chehab foreach my $dir (split(/:/, $ENV{PATH})) { 162412b09ddSMauro Carvalho Chehab next if ($dir =~ m,($cur_dir)/sphinx,); 163412b09ddSMauro Carvalho Chehab return "$dir/python3" if(-x "$dir/python3"); 164412b09ddSMauro Carvalho Chehab } 165412b09ddSMauro Carvalho Chehab foreach my $dir (split(/:/, $ENV{PATH})) { 166412b09ddSMauro Carvalho Chehab next if ($dir =~ m,($cur_dir)/sphinx,); 167412b09ddSMauro Carvalho Chehab return "$dir/python" if(-x "$dir/python"); 168412b09ddSMauro Carvalho Chehab } 169412b09ddSMauro Carvalho Chehab return "python"; 170412b09ddSMauro Carvalho Chehab} 171412b09ddSMauro Carvalho Chehab 17224071ac1SMauro Carvalho Chehabsub check_program($$) 17324071ac1SMauro Carvalho Chehab{ 17424071ac1SMauro Carvalho Chehab my $prog = shift; 17524071ac1SMauro Carvalho Chehab my $is_optional = shift; 17624071ac1SMauro Carvalho Chehab 1772f9c5025SMauro Carvalho Chehab return $prog if findprog($prog); 17824071ac1SMauro Carvalho Chehab 17924071ac1SMauro Carvalho Chehab add_package($prog, $is_optional); 18024071ac1SMauro Carvalho Chehab} 18124071ac1SMauro Carvalho Chehab 18224071ac1SMauro Carvalho Chehabsub check_perl_module($$) 18324071ac1SMauro Carvalho Chehab{ 18424071ac1SMauro Carvalho Chehab my $prog = shift; 18524071ac1SMauro Carvalho Chehab my $is_optional = shift; 18624071ac1SMauro Carvalho Chehab 18724071ac1SMauro Carvalho Chehab my $err = system("perl -M$prog -e 1 2>/dev/null /dev/null"); 18824071ac1SMauro Carvalho Chehab return if ($err == 0); 18924071ac1SMauro Carvalho Chehab 19024071ac1SMauro Carvalho Chehab add_package($prog, $is_optional); 19124071ac1SMauro Carvalho Chehab} 19224071ac1SMauro Carvalho Chehab 19324071ac1SMauro Carvalho Chehabsub check_python_module($$) 19424071ac1SMauro Carvalho Chehab{ 19524071ac1SMauro Carvalho Chehab my $prog = shift; 19624071ac1SMauro Carvalho Chehab my $is_optional = shift; 19724071ac1SMauro Carvalho Chehab 1982f9c5025SMauro Carvalho Chehab return if (!$python_cmd); 1992f9c5025SMauro Carvalho Chehab 2002f9c5025SMauro Carvalho Chehab my $err = system("$python_cmd -c 'import $prog' 2>/dev/null /dev/null"); 20124071ac1SMauro Carvalho Chehab return if ($err == 0); 20224071ac1SMauro Carvalho Chehab 20324071ac1SMauro Carvalho Chehab add_package($prog, $is_optional); 20424071ac1SMauro Carvalho Chehab} 20524071ac1SMauro Carvalho Chehab 20624071ac1SMauro Carvalho Chehabsub check_rpm_missing($$) 20724071ac1SMauro Carvalho Chehab{ 20824071ac1SMauro Carvalho Chehab my @pkgs = @{$_[0]}; 20924071ac1SMauro Carvalho Chehab my $is_optional = $_[1]; 21024071ac1SMauro Carvalho Chehab 21124071ac1SMauro Carvalho Chehab foreach my $prog(@pkgs) { 21224071ac1SMauro Carvalho Chehab my $err = system("rpm -q '$prog' 2>/dev/null >/dev/null"); 21324071ac1SMauro Carvalho Chehab add_package($prog, $is_optional) if ($err); 21424071ac1SMauro Carvalho Chehab } 21524071ac1SMauro Carvalho Chehab} 21624071ac1SMauro Carvalho Chehab 21724071ac1SMauro Carvalho Chehabsub check_pacman_missing($$) 21824071ac1SMauro Carvalho Chehab{ 21924071ac1SMauro Carvalho Chehab my @pkgs = @{$_[0]}; 22024071ac1SMauro Carvalho Chehab my $is_optional = $_[1]; 22124071ac1SMauro Carvalho Chehab 22224071ac1SMauro Carvalho Chehab foreach my $prog(@pkgs) { 22324071ac1SMauro Carvalho Chehab my $err = system("pacman -Q '$prog' 2>/dev/null >/dev/null"); 22424071ac1SMauro Carvalho Chehab add_package($prog, $is_optional) if ($err); 22524071ac1SMauro Carvalho Chehab } 22624071ac1SMauro Carvalho Chehab} 22724071ac1SMauro Carvalho Chehab 22824071ac1SMauro Carvalho Chehabsub check_missing_tex($) 22924071ac1SMauro Carvalho Chehab{ 23024071ac1SMauro Carvalho Chehab my $is_optional = shift; 23124071ac1SMauro Carvalho Chehab my $kpsewhich = findprog("kpsewhich"); 23224071ac1SMauro Carvalho Chehab 23324071ac1SMauro Carvalho Chehab foreach my $prog(keys %texlive) { 23424071ac1SMauro Carvalho Chehab my $package = $texlive{$prog}; 23524071ac1SMauro Carvalho Chehab if (!$kpsewhich) { 23624071ac1SMauro Carvalho Chehab add_package($package, $is_optional); 23724071ac1SMauro Carvalho Chehab next; 23824071ac1SMauro Carvalho Chehab } 23924071ac1SMauro Carvalho Chehab my $file = qx($kpsewhich $prog); 24024071ac1SMauro Carvalho Chehab add_package($package, $is_optional) if ($file =~ /^\s*$/); 24124071ac1SMauro Carvalho Chehab } 24224071ac1SMauro Carvalho Chehab} 24324071ac1SMauro Carvalho Chehab 24477d09ad9SMauro Carvalho Chehabsub get_sphinx_fname() 24524071ac1SMauro Carvalho Chehab{ 24677d09ad9SMauro Carvalho Chehab my $fname = "sphinx-build"; 24777d09ad9SMauro Carvalho Chehab return $fname if findprog($fname); 24824071ac1SMauro Carvalho Chehab 24977d09ad9SMauro Carvalho Chehab $fname = "sphinx-build-3"; 25077d09ad9SMauro Carvalho Chehab if (findprog($fname)) { 25124071ac1SMauro Carvalho Chehab $need_symlink = 1; 25277d09ad9SMauro Carvalho Chehab return $fname; 25324071ac1SMauro Carvalho Chehab } 25424071ac1SMauro Carvalho Chehab 25577d09ad9SMauro Carvalho Chehab return ""; 25677d09ad9SMauro Carvalho Chehab} 25777d09ad9SMauro Carvalho Chehab 258a8b380c3SMauro Carvalho Chehabsub get_sphinx_version($) 259a8b380c3SMauro Carvalho Chehab{ 260a8b380c3SMauro Carvalho Chehab my $cmd = shift; 261a8b380c3SMauro Carvalho Chehab my $ver; 262a8b380c3SMauro Carvalho Chehab 263a8b380c3SMauro Carvalho Chehab open IN, "$cmd --version 2>&1 |"; 264a8b380c3SMauro Carvalho Chehab while (<IN>) { 265e9dfeed2SJonathan Corbet if (m/^\s*sphinx-build\s+([\d\.]+)((\+\/[\da-f]+)|(b\d+))?$/) { 266a8b380c3SMauro Carvalho Chehab $ver=$1; 267a8b380c3SMauro Carvalho Chehab last; 268a8b380c3SMauro Carvalho Chehab } 269a8b380c3SMauro Carvalho Chehab # Sphinx 1.2.x uses a different format 270a8b380c3SMauro Carvalho Chehab if (m/^\s*Sphinx.*\s+([\d\.]+)$/) { 271a8b380c3SMauro Carvalho Chehab $ver=$1; 272a8b380c3SMauro Carvalho Chehab last; 273a8b380c3SMauro Carvalho Chehab } 274a8b380c3SMauro Carvalho Chehab } 275a8b380c3SMauro Carvalho Chehab close IN; 276a8b380c3SMauro Carvalho Chehab return $ver; 277a8b380c3SMauro Carvalho Chehab} 278a8b380c3SMauro Carvalho Chehab 27977d09ad9SMauro Carvalho Chehabsub check_sphinx() 28077d09ad9SMauro Carvalho Chehab{ 2811ef70cedSMauro Carvalho Chehab my $default_version; 28277d09ad9SMauro Carvalho Chehab 28377d09ad9SMauro Carvalho Chehab open IN, $conf or die "Can't open $conf"; 28477d09ad9SMauro Carvalho Chehab while (<IN>) { 28577d09ad9SMauro Carvalho Chehab if (m/^\s*needs_sphinx\s*=\s*[\'\"]([\d\.]+)[\'\"]/) { 28677d09ad9SMauro Carvalho Chehab $min_version=$1; 28777d09ad9SMauro Carvalho Chehab last; 28877d09ad9SMauro Carvalho Chehab } 28977d09ad9SMauro Carvalho Chehab } 29077d09ad9SMauro Carvalho Chehab close IN; 29177d09ad9SMauro Carvalho Chehab 29277d09ad9SMauro Carvalho Chehab die "Can't get needs_sphinx version from $conf" if (!$min_version); 29377d09ad9SMauro Carvalho Chehab 29477d09ad9SMauro Carvalho Chehab open IN, $requirement_file or die "Can't open $requirement_file"; 29577d09ad9SMauro Carvalho Chehab while (<IN>) { 29677d09ad9SMauro Carvalho Chehab if (m/^\s*Sphinx\s*==\s*([\d\.]+)$/) { 2971ef70cedSMauro Carvalho Chehab $default_version=$1; 29877d09ad9SMauro Carvalho Chehab last; 29977d09ad9SMauro Carvalho Chehab } 30077d09ad9SMauro Carvalho Chehab } 30177d09ad9SMauro Carvalho Chehab close IN; 30277d09ad9SMauro Carvalho Chehab 3031ef70cedSMauro Carvalho Chehab die "Can't get default sphinx version from $requirement_file" if (!$default_version); 30477d09ad9SMauro Carvalho Chehab 3051ef70cedSMauro Carvalho Chehab $virtenv_dir = $virtenv_prefix . $default_version; 30677d09ad9SMauro Carvalho Chehab 30777d09ad9SMauro Carvalho Chehab my $sphinx = get_sphinx_fname(); 3082f9c5025SMauro Carvalho Chehab if ($sphinx eq "") { 3092f9c5025SMauro Carvalho Chehab $need_sphinx = 1; 3102f9c5025SMauro Carvalho Chehab return; 3112f9c5025SMauro Carvalho Chehab } 31277d09ad9SMauro Carvalho Chehab 313a8b380c3SMauro Carvalho Chehab $cur_version = get_sphinx_version($sphinx); 314a8b380c3SMauro Carvalho Chehab die ("$sphinx returned an error") if (!$cur_version); 31577d09ad9SMauro Carvalho Chehab 31677d09ad9SMauro Carvalho Chehab die "$sphinx didn't return its version" if (!$cur_version); 31777d09ad9SMauro Carvalho Chehab 31877d09ad9SMauro Carvalho Chehab if ($cur_version lt $min_version) { 3199b88ad54SMauro Carvalho Chehab printf "ERROR: Sphinx version is %s. It should be >= %s (recommended >= %s)\n", 3201ef70cedSMauro Carvalho Chehab $cur_version, $min_version, $default_version; 32177d09ad9SMauro Carvalho Chehab $need_sphinx = 1; 32277d09ad9SMauro Carvalho Chehab return; 32377d09ad9SMauro Carvalho Chehab } 32477d09ad9SMauro Carvalho Chehab 325e5089912SMauro Carvalho Chehab return if ($cur_version lt $rec_version); 3269b88ad54SMauro Carvalho Chehab 3279b88ad54SMauro Carvalho Chehab # On version check mode, just assume Sphinx has all mandatory deps 3289b88ad54SMauro Carvalho Chehab exit (0) if ($version_check); 32924071ac1SMauro Carvalho Chehab} 33024071ac1SMauro Carvalho Chehab 33124071ac1SMauro Carvalho Chehab# 33224071ac1SMauro Carvalho Chehab# Ancillary subroutines 33324071ac1SMauro Carvalho Chehab# 33424071ac1SMauro Carvalho Chehab 33524071ac1SMauro Carvalho Chehabsub catcheck($) 33624071ac1SMauro Carvalho Chehab{ 33724071ac1SMauro Carvalho Chehab my $res = ""; 33824071ac1SMauro Carvalho Chehab $res = qx(cat $_[0]) if (-r $_[0]); 33924071ac1SMauro Carvalho Chehab return $res; 34024071ac1SMauro Carvalho Chehab} 34124071ac1SMauro Carvalho Chehab 34224071ac1SMauro Carvalho Chehabsub which($) 34324071ac1SMauro Carvalho Chehab{ 34424071ac1SMauro Carvalho Chehab my $file = shift; 34524071ac1SMauro Carvalho Chehab my @path = split ":", $ENV{PATH}; 34624071ac1SMauro Carvalho Chehab 34724071ac1SMauro Carvalho Chehab foreach my $dir(@path) { 34824071ac1SMauro Carvalho Chehab my $name = $dir.'/'.$file; 34924071ac1SMauro Carvalho Chehab return $name if (-x $name ); 35024071ac1SMauro Carvalho Chehab } 35124071ac1SMauro Carvalho Chehab return undef; 35224071ac1SMauro Carvalho Chehab} 35324071ac1SMauro Carvalho Chehab 35424071ac1SMauro Carvalho Chehab# 35524071ac1SMauro Carvalho Chehab# Subroutines that check distro-specific hints 35624071ac1SMauro Carvalho Chehab# 35724071ac1SMauro Carvalho Chehab 35824071ac1SMauro Carvalho Chehabsub give_debian_hints() 35924071ac1SMauro Carvalho Chehab{ 36024071ac1SMauro Carvalho Chehab my %map = ( 36124071ac1SMauro Carvalho Chehab "python-sphinx" => "python3-sphinx", 36224071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "python3-sphinx-rtd-theme", 3632f9c5025SMauro Carvalho Chehab "ensurepip" => "python3-venv", 36424071ac1SMauro Carvalho Chehab "virtualenv" => "virtualenv", 36524071ac1SMauro Carvalho Chehab "dot" => "graphviz", 36624071ac1SMauro Carvalho Chehab "convert" => "imagemagick", 36724071ac1SMauro Carvalho Chehab "Pod::Usage" => "perl-modules", 36824071ac1SMauro Carvalho Chehab "xelatex" => "texlive-xetex", 3698e7d5d15SMauro Carvalho Chehab "rsvg-convert" => "librsvg2-bin", 37024071ac1SMauro Carvalho Chehab ); 37124071ac1SMauro Carvalho Chehab 37224071ac1SMauro Carvalho Chehab if ($pdf) { 37387d6576dSMauro Carvalho Chehab check_missing_file(["/usr/share/texlive/texmf-dist/tex/latex/ctex/ctexhook.sty"], 37487d6576dSMauro Carvalho Chehab "texlive-lang-chinese", 2); 37587d6576dSMauro Carvalho Chehab 376ff8fdb36SJeremy MAURO check_missing_file(["/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"], 37756e5a633SMauro Carvalho Chehab "fonts-dejavu", 2); 37827eed923SMauro Carvalho Chehab 3799692f2fdSJeremy MAURO check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc", 380bfc7f428SMauro Carvalho Chehab "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", 3819692f2fdSJeremy MAURO "/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc"], 38227eed923SMauro Carvalho Chehab "fonts-noto-cjk", 2); 38324071ac1SMauro Carvalho Chehab } 38424071ac1SMauro Carvalho Chehab 38556e5a633SMauro Carvalho Chehab check_program("dvipng", 2) if ($pdf); 38624071ac1SMauro Carvalho Chehab check_missing(\%map); 38724071ac1SMauro Carvalho Chehab 38824071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 38924071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo apt-get install $install\n"); 39024071ac1SMauro Carvalho Chehab} 39124071ac1SMauro Carvalho Chehab 39224071ac1SMauro Carvalho Chehabsub give_redhat_hints() 39324071ac1SMauro Carvalho Chehab{ 39424071ac1SMauro Carvalho Chehab my %map = ( 39524071ac1SMauro Carvalho Chehab "python-sphinx" => "python3-sphinx", 39624071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "python3-sphinx_rtd_theme", 39724071ac1SMauro Carvalho Chehab "virtualenv" => "python3-virtualenv", 39824071ac1SMauro Carvalho Chehab "dot" => "graphviz", 39924071ac1SMauro Carvalho Chehab "convert" => "ImageMagick", 40024071ac1SMauro Carvalho Chehab "Pod::Usage" => "perl-Pod-Usage", 40124071ac1SMauro Carvalho Chehab "xelatex" => "texlive-xetex-bin", 4028e7d5d15SMauro Carvalho Chehab "rsvg-convert" => "librsvg2-tools", 40324071ac1SMauro Carvalho Chehab ); 40424071ac1SMauro Carvalho Chehab 4055d88953cSMauro Carvalho Chehab my @fedora26_opt_pkgs = ( 4065d88953cSMauro Carvalho Chehab "graphviz-gd", # Fedora 26: needed for PDF support 4075d88953cSMauro Carvalho Chehab ); 4085d88953cSMauro Carvalho Chehab 40924071ac1SMauro Carvalho Chehab my @fedora_tex_pkgs = ( 41024071ac1SMauro Carvalho Chehab "texlive-collection-fontsrecommended", 41124071ac1SMauro Carvalho Chehab "texlive-collection-latex", 41227eed923SMauro Carvalho Chehab "texlive-xecjk", 41324071ac1SMauro Carvalho Chehab "dejavu-sans-fonts", 41424071ac1SMauro Carvalho Chehab "dejavu-serif-fonts", 41524071ac1SMauro Carvalho Chehab "dejavu-sans-mono-fonts", 41624071ac1SMauro Carvalho Chehab ); 41724071ac1SMauro Carvalho Chehab 4189b756a9dSMauro Carvalho Chehab # 4199b756a9dSMauro Carvalho Chehab # Checks valid for RHEL/CentOS version 7.x. 4209b756a9dSMauro Carvalho Chehab # 42156e5a633SMauro Carvalho Chehab my $old = 0; 42256e5a633SMauro Carvalho Chehab my $rel; 42356e5a633SMauro Carvalho Chehab $rel = $1 if ($system_release =~ /release\s+(\d+)/); 42456e5a633SMauro Carvalho Chehab 425b308467cSMauro Carvalho Chehab if (!($system_release =~ /Fedora/)) { 4269b756a9dSMauro Carvalho Chehab $map{"virtualenv"} = "python-virtualenv"; 42756e5a633SMauro Carvalho Chehab 42856e5a633SMauro Carvalho Chehab if ($rel && $rel < 8) { 42956e5a633SMauro Carvalho Chehab $old = 1; 43056e5a633SMauro Carvalho Chehab $pdf = 0; 43156e5a633SMauro Carvalho Chehab 43256e5a633SMauro Carvalho Chehab printf("Note: texlive packages on RHEL/CENTOS <= 7 are incomplete. Can't support PDF output\n"); 43356e5a633SMauro Carvalho Chehab printf("If you want to build PDF, please read:\n"); 43456e5a633SMauro Carvalho Chehab printf("\thttps://www.systutorials.com/241660/how-to-install-tex-live-on-centos-7-linux/\n"); 43556e5a633SMauro Carvalho Chehab } 43656e5a633SMauro Carvalho Chehab } else { 43756e5a633SMauro Carvalho Chehab if ($rel && $rel < 26) { 43856e5a633SMauro Carvalho Chehab $old = 1; 43956e5a633SMauro Carvalho Chehab } 44056e5a633SMauro Carvalho Chehab } 44156e5a633SMauro Carvalho Chehab if (!$rel) { 44256e5a633SMauro Carvalho Chehab printf("Couldn't identify release number\n"); 44356e5a633SMauro Carvalho Chehab $old = 1; 44456e5a633SMauro Carvalho Chehab $pdf = 0; 4459b756a9dSMauro Carvalho Chehab } 4469b756a9dSMauro Carvalho Chehab 44727eed923SMauro Carvalho Chehab if ($pdf) { 448ff8fdb36SJeremy MAURO check_missing_file(["/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc"], 44927eed923SMauro Carvalho Chehab "google-noto-sans-cjk-ttc-fonts", 2); 45027eed923SMauro Carvalho Chehab } 45127eed923SMauro Carvalho Chehab 45256e5a633SMauro Carvalho Chehab check_rpm_missing(\@fedora26_opt_pkgs, 2) if ($pdf && !$old); 45356e5a633SMauro Carvalho Chehab check_rpm_missing(\@fedora_tex_pkgs, 2) if ($pdf); 45456e5a633SMauro Carvalho Chehab check_missing_tex(2) if ($pdf); 45524071ac1SMauro Carvalho Chehab check_missing(\%map); 45624071ac1SMauro Carvalho Chehab 45724071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 4589b756a9dSMauro Carvalho Chehab 45956e5a633SMauro Carvalho Chehab if (!$old) { 4609b756a9dSMauro Carvalho Chehab # dnf, for Fedora 18+ 46124071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo dnf install -y $install\n"); 4629b756a9dSMauro Carvalho Chehab } else { 4639b756a9dSMauro Carvalho Chehab # yum, for RHEL (and clones) or Fedora version < 18 4649b756a9dSMauro Carvalho Chehab printf("You should run:\n\n\tsudo yum install -y $install\n"); 4659b756a9dSMauro Carvalho Chehab } 46624071ac1SMauro Carvalho Chehab} 46724071ac1SMauro Carvalho Chehab 46824071ac1SMauro Carvalho Chehabsub give_opensuse_hints() 46924071ac1SMauro Carvalho Chehab{ 47024071ac1SMauro Carvalho Chehab my %map = ( 47124071ac1SMauro Carvalho Chehab "python-sphinx" => "python3-sphinx", 47224071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "python3-sphinx_rtd_theme", 47324071ac1SMauro Carvalho Chehab "virtualenv" => "python3-virtualenv", 47424071ac1SMauro Carvalho Chehab "dot" => "graphviz", 47524071ac1SMauro Carvalho Chehab "convert" => "ImageMagick", 47624071ac1SMauro Carvalho Chehab "Pod::Usage" => "perl-Pod-Usage", 47724071ac1SMauro Carvalho Chehab "xelatex" => "texlive-xetex-bin", 47824071ac1SMauro Carvalho Chehab ); 47924071ac1SMauro Carvalho Chehab 480b3df6223SMauro Carvalho Chehab # On Tumbleweed, this package is also named rsvg-convert 481b3df6223SMauro Carvalho Chehab $map{"rsvg-convert"} = "rsvg-view" if (!($system_release =~ /Tumbleweed/)); 482b3df6223SMauro Carvalho Chehab 48324071ac1SMauro Carvalho Chehab my @suse_tex_pkgs = ( 48424071ac1SMauro Carvalho Chehab "texlive-babel-english", 48524071ac1SMauro Carvalho Chehab "texlive-caption", 48624071ac1SMauro Carvalho Chehab "texlive-colortbl", 48724071ac1SMauro Carvalho Chehab "texlive-courier", 48824071ac1SMauro Carvalho Chehab "texlive-dvips", 48924071ac1SMauro Carvalho Chehab "texlive-helvetic", 49024071ac1SMauro Carvalho Chehab "texlive-makeindex", 49124071ac1SMauro Carvalho Chehab "texlive-metafont", 49224071ac1SMauro Carvalho Chehab "texlive-metapost", 49324071ac1SMauro Carvalho Chehab "texlive-palatino", 49424071ac1SMauro Carvalho Chehab "texlive-preview", 49524071ac1SMauro Carvalho Chehab "texlive-times", 49624071ac1SMauro Carvalho Chehab "texlive-zapfchan", 49724071ac1SMauro Carvalho Chehab "texlive-zapfding", 49824071ac1SMauro Carvalho Chehab ); 49924071ac1SMauro Carvalho Chehab 500353290a9SMauro Carvalho Chehab $map{"latexmk"} = "texlive-latexmk-bin"; 501353290a9SMauro Carvalho Chehab 50227eed923SMauro Carvalho Chehab # FIXME: add support for installing CJK fonts 50327eed923SMauro Carvalho Chehab # 50427eed923SMauro Carvalho Chehab # I tried hard, but was unable to find a way to install 50527eed923SMauro Carvalho Chehab # "Noto Sans CJK SC" on openSUSE 50627eed923SMauro Carvalho Chehab 50756e5a633SMauro Carvalho Chehab check_rpm_missing(\@suse_tex_pkgs, 2) if ($pdf); 50856e5a633SMauro Carvalho Chehab check_missing_tex(2) if ($pdf); 50924071ac1SMauro Carvalho Chehab check_missing(\%map); 51024071ac1SMauro Carvalho Chehab 51124071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 51224071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo zypper install --no-recommends $install\n"); 51324071ac1SMauro Carvalho Chehab} 51424071ac1SMauro Carvalho Chehab 515800d408aSMauro Carvalho Chehabsub give_mageia_hints() 516800d408aSMauro Carvalho Chehab{ 517800d408aSMauro Carvalho Chehab my %map = ( 518800d408aSMauro Carvalho Chehab "python-sphinx" => "python3-sphinx", 519800d408aSMauro Carvalho Chehab "sphinx_rtd_theme" => "python3-sphinx_rtd_theme", 520800d408aSMauro Carvalho Chehab "virtualenv" => "python3-virtualenv", 521800d408aSMauro Carvalho Chehab "dot" => "graphviz", 522800d408aSMauro Carvalho Chehab "convert" => "ImageMagick", 523800d408aSMauro Carvalho Chehab "Pod::Usage" => "perl-Pod-Usage", 524800d408aSMauro Carvalho Chehab "xelatex" => "texlive", 525d6ebf189SMauro Carvalho Chehab "rsvg-convert" => "librsvg2", 526800d408aSMauro Carvalho Chehab ); 527800d408aSMauro Carvalho Chehab 528800d408aSMauro Carvalho Chehab my @tex_pkgs = ( 529800d408aSMauro Carvalho Chehab "texlive-fontsextra", 530800d408aSMauro Carvalho Chehab ); 531800d408aSMauro Carvalho Chehab 532353290a9SMauro Carvalho Chehab $map{"latexmk"} = "texlive-collection-basic"; 533353290a9SMauro Carvalho Chehab 534d6ebf189SMauro Carvalho Chehab my $packager_cmd; 535d6ebf189SMauro Carvalho Chehab my $noto_sans; 536d6ebf189SMauro Carvalho Chehab if ($system_release =~ /OpenMandriva/) { 537d6ebf189SMauro Carvalho Chehab $packager_cmd = "dnf install"; 538d6ebf189SMauro Carvalho Chehab $noto_sans = "noto-sans-cjk-fonts"; 539d6ebf189SMauro Carvalho Chehab @tex_pkgs = ( "texlive-collection-fontsextra" ); 540d6ebf189SMauro Carvalho Chehab } else { 541d6ebf189SMauro Carvalho Chehab $packager_cmd = "urpmi"; 542d6ebf189SMauro Carvalho Chehab $noto_sans = "google-noto-sans-cjk-ttc-fonts"; 543d6ebf189SMauro Carvalho Chehab } 544d6ebf189SMauro Carvalho Chehab 545d6ebf189SMauro Carvalho Chehab 54627eed923SMauro Carvalho Chehab if ($pdf) { 547d6ebf189SMauro Carvalho Chehab check_missing_file(["/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc", 548d6ebf189SMauro Carvalho Chehab "/usr/share/fonts/TTF/NotoSans-Regular.ttf"], 549d6ebf189SMauro Carvalho Chehab $noto_sans, 2); 55027eed923SMauro Carvalho Chehab } 55127eed923SMauro Carvalho Chehab 55256e5a633SMauro Carvalho Chehab check_rpm_missing(\@tex_pkgs, 2) if ($pdf); 553800d408aSMauro Carvalho Chehab check_missing(\%map); 554800d408aSMauro Carvalho Chehab 555800d408aSMauro Carvalho Chehab return if (!$need && !$optional); 556d6ebf189SMauro Carvalho Chehab printf("You should run:\n\n\tsudo $packager_cmd $install\n"); 557800d408aSMauro Carvalho Chehab} 558800d408aSMauro Carvalho Chehab 55924071ac1SMauro Carvalho Chehabsub give_arch_linux_hints() 56024071ac1SMauro Carvalho Chehab{ 56124071ac1SMauro Carvalho Chehab my %map = ( 56224071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "python-sphinx_rtd_theme", 56324071ac1SMauro Carvalho Chehab "virtualenv" => "python-virtualenv", 56424071ac1SMauro Carvalho Chehab "dot" => "graphviz", 56524071ac1SMauro Carvalho Chehab "convert" => "imagemagick", 56624071ac1SMauro Carvalho Chehab "xelatex" => "texlive-bin", 5670d0da9aaSLouis Taylor "latexmk" => "texlive-core", 5688e7d5d15SMauro Carvalho Chehab "rsvg-convert" => "extra/librsvg", 56924071ac1SMauro Carvalho Chehab ); 57024071ac1SMauro Carvalho Chehab 57124071ac1SMauro Carvalho Chehab my @archlinux_tex_pkgs = ( 57224071ac1SMauro Carvalho Chehab "texlive-core", 57324071ac1SMauro Carvalho Chehab "texlive-latexextra", 57424071ac1SMauro Carvalho Chehab "ttf-dejavu", 57524071ac1SMauro Carvalho Chehab ); 57656e5a633SMauro Carvalho Chehab check_pacman_missing(\@archlinux_tex_pkgs, 2) if ($pdf); 57756e5a633SMauro Carvalho Chehab 57827eed923SMauro Carvalho Chehab if ($pdf) { 579ff8fdb36SJeremy MAURO check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc"], 58027eed923SMauro Carvalho Chehab "noto-fonts-cjk", 2); 58127eed923SMauro Carvalho Chehab } 58227eed923SMauro Carvalho Chehab 58324071ac1SMauro Carvalho Chehab check_missing(\%map); 58424071ac1SMauro Carvalho Chehab 58524071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 58624071ac1SMauro Carvalho Chehab printf("You should run:\n\n\tsudo pacman -S $install\n"); 58724071ac1SMauro Carvalho Chehab} 58824071ac1SMauro Carvalho Chehab 58924071ac1SMauro Carvalho Chehabsub give_gentoo_hints() 59024071ac1SMauro Carvalho Chehab{ 59124071ac1SMauro Carvalho Chehab my %map = ( 59224071ac1SMauro Carvalho Chehab "sphinx_rtd_theme" => "dev-python/sphinx_rtd_theme", 59324071ac1SMauro Carvalho Chehab "virtualenv" => "dev-python/virtualenv", 59424071ac1SMauro Carvalho Chehab "dot" => "media-gfx/graphviz", 59524071ac1SMauro Carvalho Chehab "convert" => "media-gfx/imagemagick", 59624071ac1SMauro Carvalho Chehab "xelatex" => "dev-texlive/texlive-xetex media-fonts/dejavu", 5978e7d5d15SMauro Carvalho Chehab "rsvg-convert" => "gnome-base/librsvg", 59824071ac1SMauro Carvalho Chehab ); 59924071ac1SMauro Carvalho Chehab 600ff8fdb36SJeremy MAURO check_missing_file(["/usr/share/fonts/dejavu/DejaVuSans.ttf"], 60156e5a633SMauro Carvalho Chehab "media-fonts/dejavu", 2) if ($pdf); 60224071ac1SMauro Carvalho Chehab 60327eed923SMauro Carvalho Chehab if ($pdf) { 604e45a6317SMauro Carvalho Chehab check_missing_file(["/usr/share/fonts/noto-cjk/NotoSansCJKsc-Regular.otf", 605e45a6317SMauro Carvalho Chehab "/usr/share/fonts/noto-cjk/NotoSerifCJK-Regular.ttc"], 60627eed923SMauro Carvalho Chehab "media-fonts/noto-cjk", 2); 60727eed923SMauro Carvalho Chehab } 60827eed923SMauro Carvalho Chehab 60924071ac1SMauro Carvalho Chehab check_missing(\%map); 61024071ac1SMauro Carvalho Chehab 61124071ac1SMauro Carvalho Chehab return if (!$need && !$optional); 612bba1e4cbSMauro Carvalho Chehab 613bba1e4cbSMauro Carvalho Chehab printf("You should run:\n\n"); 6144ea96d57SMauro Carvalho Chehab 6154ea96d57SMauro Carvalho Chehab my $imagemagick = "media-gfx/imagemagick svg png"; 6164ea96d57SMauro Carvalho Chehab my $cairo = "media-gfx/graphviz cairo pdf"; 6174ea96d57SMauro Carvalho Chehab my $portage_imagemagick = "/etc/portage/package.use/imagemagick"; 6184ea96d57SMauro Carvalho Chehab my $portage_cairo = "/etc/portage/package.use/graphviz"; 6194ea96d57SMauro Carvalho Chehab 620e45a6317SMauro Carvalho Chehab if (qx(grep imagemagick $portage_imagemagick 2>/dev/null) eq "") { 6214ea96d57SMauro Carvalho Chehab printf("\tsudo su -c 'echo \"$imagemagick\" > $portage_imagemagick'\n") 6224ea96d57SMauro Carvalho Chehab } 623e45a6317SMauro Carvalho Chehab if (qx(grep graphviz $portage_cairo 2>/dev/null) eq "") { 6244ea96d57SMauro Carvalho Chehab printf("\tsudo su -c 'echo \"$cairo\" > $portage_cairo'\n"); 6254ea96d57SMauro Carvalho Chehab } 6264ea96d57SMauro Carvalho Chehab 627bba1e4cbSMauro Carvalho Chehab printf("\tsudo emerge --ask $install\n"); 628bba1e4cbSMauro Carvalho Chehab 62924071ac1SMauro Carvalho Chehab} 63024071ac1SMauro Carvalho Chehab 63124071ac1SMauro Carvalho Chehabsub check_distros() 63224071ac1SMauro Carvalho Chehab{ 63324071ac1SMauro Carvalho Chehab # Distro-specific hints 63424071ac1SMauro Carvalho Chehab if ($system_release =~ /Red Hat Enterprise Linux/) { 63524071ac1SMauro Carvalho Chehab give_redhat_hints; 63624071ac1SMauro Carvalho Chehab return; 63724071ac1SMauro Carvalho Chehab } 6389b756a9dSMauro Carvalho Chehab if ($system_release =~ /CentOS/) { 6399b756a9dSMauro Carvalho Chehab give_redhat_hints; 6409b756a9dSMauro Carvalho Chehab return; 6419b756a9dSMauro Carvalho Chehab } 6429b756a9dSMauro Carvalho Chehab if ($system_release =~ /Scientific Linux/) { 6439b756a9dSMauro Carvalho Chehab give_redhat_hints; 6449b756a9dSMauro Carvalho Chehab return; 6459b756a9dSMauro Carvalho Chehab } 6469b756a9dSMauro Carvalho Chehab if ($system_release =~ /Oracle Linux Server/) { 6479b756a9dSMauro Carvalho Chehab give_redhat_hints; 6489b756a9dSMauro Carvalho Chehab return; 6499b756a9dSMauro Carvalho Chehab } 65024071ac1SMauro Carvalho Chehab if ($system_release =~ /Fedora/) { 65124071ac1SMauro Carvalho Chehab give_redhat_hints; 65224071ac1SMauro Carvalho Chehab return; 65324071ac1SMauro Carvalho Chehab } 65424071ac1SMauro Carvalho Chehab if ($system_release =~ /Ubuntu/) { 65524071ac1SMauro Carvalho Chehab give_debian_hints; 65624071ac1SMauro Carvalho Chehab return; 65724071ac1SMauro Carvalho Chehab } 65824071ac1SMauro Carvalho Chehab if ($system_release =~ /Debian/) { 65924071ac1SMauro Carvalho Chehab give_debian_hints; 66024071ac1SMauro Carvalho Chehab return; 66124071ac1SMauro Carvalho Chehab } 66224071ac1SMauro Carvalho Chehab if ($system_release =~ /openSUSE/) { 66324071ac1SMauro Carvalho Chehab give_opensuse_hints; 66424071ac1SMauro Carvalho Chehab return; 66524071ac1SMauro Carvalho Chehab } 666800d408aSMauro Carvalho Chehab if ($system_release =~ /Mageia/) { 667800d408aSMauro Carvalho Chehab give_mageia_hints; 668800d408aSMauro Carvalho Chehab return; 669800d408aSMauro Carvalho Chehab } 670d6ebf189SMauro Carvalho Chehab if ($system_release =~ /OpenMandriva/) { 671d6ebf189SMauro Carvalho Chehab give_mageia_hints; 672d6ebf189SMauro Carvalho Chehab return; 673d6ebf189SMauro Carvalho Chehab } 67424071ac1SMauro Carvalho Chehab if ($system_release =~ /Arch Linux/) { 67524071ac1SMauro Carvalho Chehab give_arch_linux_hints; 67624071ac1SMauro Carvalho Chehab return; 67724071ac1SMauro Carvalho Chehab } 67824071ac1SMauro Carvalho Chehab if ($system_release =~ /Gentoo/) { 67924071ac1SMauro Carvalho Chehab give_gentoo_hints; 68024071ac1SMauro Carvalho Chehab return; 68124071ac1SMauro Carvalho Chehab } 68224071ac1SMauro Carvalho Chehab 68324071ac1SMauro Carvalho Chehab # 68424071ac1SMauro Carvalho Chehab # Fall-back to generic hint code for other distros 68524071ac1SMauro Carvalho Chehab # That's far from ideal, specially for LaTeX dependencies. 68624071ac1SMauro Carvalho Chehab # 68724071ac1SMauro Carvalho Chehab my %map = ( 68824071ac1SMauro Carvalho Chehab "sphinx-build" => "sphinx" 68924071ac1SMauro Carvalho Chehab ); 69056e5a633SMauro Carvalho Chehab check_missing_tex(2) if ($pdf); 69124071ac1SMauro Carvalho Chehab check_missing(\%map); 69224071ac1SMauro Carvalho Chehab print "I don't know distro $system_release.\n"; 69324071ac1SMauro Carvalho Chehab print "So, I can't provide you a hint with the install procedure.\n"; 69424071ac1SMauro Carvalho Chehab print "There are likely missing dependencies.\n"; 69524071ac1SMauro Carvalho Chehab} 69624071ac1SMauro Carvalho Chehab 69724071ac1SMauro Carvalho Chehab# 69824071ac1SMauro Carvalho Chehab# Common dependencies 69924071ac1SMauro Carvalho Chehab# 70024071ac1SMauro Carvalho Chehab 7012730ce01SShuah Khansub deactivate_help() 7022730ce01SShuah Khan{ 7032f9c5025SMauro Carvalho Chehab printf "\nIf you want to exit the virtualenv, you can use:\n"; 7042730ce01SShuah Khan printf "\tdeactivate\n"; 7052730ce01SShuah Khan} 7062730ce01SShuah Khan 707e5089912SMauro Carvalho Chehabsub get_virtenv() 708e5089912SMauro Carvalho Chehab{ 709a5f785f1SMauro Carvalho Chehab my $ver; 710e5089912SMauro Carvalho Chehab my $min_activate = "$ENV{'PWD'}/${virtenv_prefix}${min_version}/bin/activate"; 711e5089912SMauro Carvalho Chehab my @activates = glob "$ENV{'PWD'}/${virtenv_prefix}*/bin/activate"; 712e5089912SMauro Carvalho Chehab 713e5089912SMauro Carvalho Chehab @activates = sort {$b cmp $a} @activates; 714a5f785f1SMauro Carvalho Chehab 715e5089912SMauro Carvalho Chehab foreach my $f (@activates) { 716e5089912SMauro Carvalho Chehab next if ($f lt $min_activate); 717e5089912SMauro Carvalho Chehab 718e5089912SMauro Carvalho Chehab my $sphinx_cmd = $f; 719e5089912SMauro Carvalho Chehab $sphinx_cmd =~ s/activate/sphinx-build/; 720e5089912SMauro Carvalho Chehab next if (! -f $sphinx_cmd); 721e5089912SMauro Carvalho Chehab 722e5089912SMauro Carvalho Chehab my $ver = get_sphinx_version($sphinx_cmd); 723e5089912SMauro Carvalho Chehab if ($need_sphinx && ($ver ge $min_version)) { 724e5089912SMauro Carvalho Chehab return ($f, $ver); 725e5089912SMauro Carvalho Chehab } elsif ($ver gt $cur_version) { 726e5089912SMauro Carvalho Chehab return ($f, $ver); 727e5089912SMauro Carvalho Chehab } 728e5089912SMauro Carvalho Chehab } 729e5089912SMauro Carvalho Chehab return ("", ""); 730e5089912SMauro Carvalho Chehab} 731e5089912SMauro Carvalho Chehab 732a5f785f1SMauro Carvalho Chehabsub recommend_sphinx_upgrade() 733a5f785f1SMauro Carvalho Chehab{ 734a5f785f1SMauro Carvalho Chehab my $venv_ver; 735a5f785f1SMauro Carvalho Chehab 736a5f785f1SMauro Carvalho Chehab # Avoid running sphinx-builds from venv if $cur_version is good 737a5f785f1SMauro Carvalho Chehab if ($cur_version && ($cur_version ge $rec_version)) { 738a5f785f1SMauro Carvalho Chehab $latest_avail_ver = $cur_version; 739a5f785f1SMauro Carvalho Chehab return; 740a5f785f1SMauro Carvalho Chehab } 741a5f785f1SMauro Carvalho Chehab 742a5f785f1SMauro Carvalho Chehab # Get the highest version from sphinx_*/bin/sphinx-build and the 743a5f785f1SMauro Carvalho Chehab # corresponding command to activate the venv/virtenv 744*7c2d45a3SMauro Carvalho Chehab ($activate_cmd, $venv_ver) = get_virtenv(); 745a5f785f1SMauro Carvalho Chehab 746a5f785f1SMauro Carvalho Chehab # Store the highest version from Sphinx existing virtualenvs 747a5f785f1SMauro Carvalho Chehab if (($activate_cmd ne "") && ($venv_ver gt $cur_version)) { 748a5f785f1SMauro Carvalho Chehab $latest_avail_ver = $venv_ver; 749a5f785f1SMauro Carvalho Chehab } else { 750a5f785f1SMauro Carvalho Chehab $latest_avail_ver = $cur_version if ($cur_version); 751a5f785f1SMauro Carvalho Chehab } 752a5f785f1SMauro Carvalho Chehab 753a5f785f1SMauro Carvalho Chehab # As we don't know package version of Sphinx, and there's no 754a5f785f1SMauro Carvalho Chehab # virtual environments, don't check if upgrades are needed 755a5f785f1SMauro Carvalho Chehab if (!$virtualenv) { 756a5f785f1SMauro Carvalho Chehab return if (!$latest_avail_ver); 757a5f785f1SMauro Carvalho Chehab } 758a5f785f1SMauro Carvalho Chehab 759a5f785f1SMauro Carvalho Chehab # Either there are already a virtual env or a new one should be created 760a5f785f1SMauro Carvalho Chehab $need_pip = 1; 761a5f785f1SMauro Carvalho Chehab 762*7c2d45a3SMauro Carvalho Chehab return if (!$latest_avail_ver); 763*7c2d45a3SMauro Carvalho Chehab 764a5f785f1SMauro Carvalho Chehab # Return if the reason is due to an upgrade or not 765a5f785f1SMauro Carvalho Chehab if ($latest_avail_ver lt $rec_version) { 766a5f785f1SMauro Carvalho Chehab $rec_sphinx_upgrade = 1; 767a5f785f1SMauro Carvalho Chehab } 768*7c2d45a3SMauro Carvalho Chehab 769*7c2d45a3SMauro Carvalho Chehab return $latest_avail_ver; 770a5f785f1SMauro Carvalho Chehab} 771a5f785f1SMauro Carvalho Chehab 772e5089912SMauro Carvalho Chehab# 773e5089912SMauro Carvalho Chehab# The logic here is complex, as it have to deal with different versions: 774e5089912SMauro Carvalho Chehab# - minimal supported version; 775e5089912SMauro Carvalho Chehab# - minimal PDF version; 776e5089912SMauro Carvalho Chehab# - recommended version. 777e5089912SMauro Carvalho Chehab# It also needs to work fine with both distro's package and venv/virtualenv 778e5089912SMauro Carvalho Chehabsub recommend_sphinx_version($) 779e5089912SMauro Carvalho Chehab{ 780e5089912SMauro Carvalho Chehab my $virtualenv_cmd = shift; 781e5089912SMauro Carvalho Chehab 782a5f785f1SMauro Carvalho Chehab if ($latest_avail_ver lt $min_pdf_version) { 783a5f785f1SMauro Carvalho Chehab print "note: If you want pdf, you need at least Sphinx $min_pdf_version.\n"; 784e5089912SMauro Carvalho Chehab } 785e5089912SMauro Carvalho Chehab 786a5f785f1SMauro Carvalho Chehab # Version is OK. Nothing to do. 787a5f785f1SMauro Carvalho Chehab return if ($cur_version && ($cur_version ge $rec_version)); 788a5f785f1SMauro Carvalho Chehab 789e5089912SMauro Carvalho Chehab if (!$need_sphinx) { 790e5089912SMauro Carvalho Chehab # sphinx-build is present and its version is >= $min_version 791e5089912SMauro Carvalho Chehab 792e5089912SMauro Carvalho Chehab #only recommend enabling a newer virtenv version if makes sense. 793e5089912SMauro Carvalho Chehab if ($latest_avail_ver gt $cur_version) { 794a5f785f1SMauro Carvalho Chehab printf "\nYou may also use the newer Sphinx version $latest_avail_ver with:\n"; 795e5089912SMauro Carvalho Chehab printf "\tdeactivate\n" if ($ENV{'PWD'} =~ /${virtenv_prefix}/); 796a5f785f1SMauro Carvalho Chehab printf "\t. $activate_cmd\n"; 797e5089912SMauro Carvalho Chehab deactivate_help(); 798e5089912SMauro Carvalho Chehab 799e5089912SMauro Carvalho Chehab return; 800e5089912SMauro Carvalho Chehab } 801e5089912SMauro Carvalho Chehab return if ($latest_avail_ver ge $rec_version); 802e5089912SMauro Carvalho Chehab } 803e5089912SMauro Carvalho Chehab 804e5089912SMauro Carvalho Chehab if (!$virtualenv) { 805e5089912SMauro Carvalho Chehab # No sphinx either via package or via virtenv. As we can't 806e5089912SMauro Carvalho Chehab # Compare the versions here, just return, recommending the 807e5089912SMauro Carvalho Chehab # user to install it from the package distro. 808e5089912SMauro Carvalho Chehab return if (!$latest_avail_ver); 809e5089912SMauro Carvalho Chehab 810e5089912SMauro Carvalho Chehab # User doesn't want a virtenv recommendation, but he already 811e5089912SMauro Carvalho Chehab # installed one via virtenv with a newer version. 812e5089912SMauro Carvalho Chehab # So, print commands to enable it 813e5089912SMauro Carvalho Chehab if ($latest_avail_ver gt $cur_version) { 814a5f785f1SMauro Carvalho Chehab printf "\nYou may also use the Sphinx virtualenv version $latest_avail_ver with:\n"; 815e5089912SMauro Carvalho Chehab printf "\tdeactivate\n" if ($ENV{'PWD'} =~ /${virtenv_prefix}/); 816a5f785f1SMauro Carvalho Chehab printf "\t. $activate_cmd\n"; 817e5089912SMauro Carvalho Chehab deactivate_help(); 818e5089912SMauro Carvalho Chehab 819e5089912SMauro Carvalho Chehab return; 820e5089912SMauro Carvalho Chehab } 821e5089912SMauro Carvalho Chehab print "\n"; 822e5089912SMauro Carvalho Chehab } else { 823e5089912SMauro Carvalho Chehab $need++ if ($need_sphinx); 824e5089912SMauro Carvalho Chehab } 825e5089912SMauro Carvalho Chehab 826e5089912SMauro Carvalho Chehab # Suggest newer versions if current ones are too old 827*7c2d45a3SMauro Carvalho Chehab if ($latest_avail_ver && $latest_avail_ver ge $min_version) { 828e5089912SMauro Carvalho Chehab # If there's a good enough version, ask the user to enable it 829e5089912SMauro Carvalho Chehab if ($latest_avail_ver ge $rec_version) { 830a5f785f1SMauro Carvalho Chehab printf "\nNeed to activate Sphinx (version $latest_avail_ver) on virtualenv with:\n"; 831a5f785f1SMauro Carvalho Chehab printf "\t. $activate_cmd\n"; 832e5089912SMauro Carvalho Chehab deactivate_help(); 833e5089912SMauro Carvalho Chehab 834e5089912SMauro Carvalho Chehab return; 835e5089912SMauro Carvalho Chehab } 836e5089912SMauro Carvalho Chehab 837e5089912SMauro Carvalho Chehab # Version is above the minimal required one, but may be 838e5089912SMauro Carvalho Chehab # below the recommended one. So, print warnings/notes 839e5089912SMauro Carvalho Chehab 840e5089912SMauro Carvalho Chehab if ($latest_avail_ver lt $rec_version) { 841e5089912SMauro Carvalho Chehab print "Warning: It is recommended at least Sphinx version $rec_version.\n"; 842e5089912SMauro Carvalho Chehab } 843e5089912SMauro Carvalho Chehab } 844e5089912SMauro Carvalho Chehab 845e5089912SMauro Carvalho Chehab # At this point, either it needs Sphinx or upgrade is recommended, 846e5089912SMauro Carvalho Chehab # both via pip 847e5089912SMauro Carvalho Chehab 848e5089912SMauro Carvalho Chehab if ($rec_sphinx_upgrade) { 849e5089912SMauro Carvalho Chehab if (!$virtualenv) { 850e5089912SMauro Carvalho Chehab print "Instead of install/upgrade Python Sphinx pkg, you could use pip/pypi with:\n\n"; 851e5089912SMauro Carvalho Chehab } else { 852e5089912SMauro Carvalho Chehab print "To upgrade Sphinx, use:\n\n"; 853e5089912SMauro Carvalho Chehab } 854e5089912SMauro Carvalho Chehab } else { 855e5089912SMauro Carvalho Chehab print "Sphinx needs to be installed either as a package or via pip/pypi with:\n"; 856e5089912SMauro Carvalho Chehab } 857e5089912SMauro Carvalho Chehab 858e5089912SMauro Carvalho Chehab $python_cmd = find_python_no_venv(); 859e5089912SMauro Carvalho Chehab 860e5089912SMauro Carvalho Chehab printf "\t$virtualenv_cmd $virtenv_dir\n"; 861a5f785f1SMauro Carvalho Chehab 862e5089912SMauro Carvalho Chehab printf "\t. $virtenv_dir/bin/activate\n"; 863e5089912SMauro Carvalho Chehab printf "\tpip install -r $requirement_file\n"; 864e5089912SMauro Carvalho Chehab deactivate_help(); 865e5089912SMauro Carvalho Chehab} 866e5089912SMauro Carvalho Chehab 86724071ac1SMauro Carvalho Chehabsub check_needs() 86824071ac1SMauro Carvalho Chehab{ 8692f9c5025SMauro Carvalho Chehab # Check if Sphinx is already accessible from current environment 87024071ac1SMauro Carvalho Chehab check_sphinx(); 8719b88ad54SMauro Carvalho Chehab 8729b88ad54SMauro Carvalho Chehab if ($system_release) { 873ec43a27fSMauro Carvalho Chehab print "Detected OS: $system_release.\n"; 8749b88ad54SMauro Carvalho Chehab } else { 875ec43a27fSMauro Carvalho Chehab print "Unknown OS\n"; 8769b88ad54SMauro Carvalho Chehab } 877ec43a27fSMauro Carvalho Chehab printf "Sphinx version: %s\n\n", $cur_version if ($cur_version); 8789b88ad54SMauro Carvalho Chehab 8792f9c5025SMauro Carvalho Chehab # Check python command line, trying first python3 8802f9c5025SMauro Carvalho Chehab $python_cmd = findprog("python3"); 8812f9c5025SMauro Carvalho Chehab $python_cmd = check_program("python", 0) if (!$python_cmd); 8822f9c5025SMauro Carvalho Chehab 8832f9c5025SMauro Carvalho Chehab # Check the type of virtual env, depending on Python version 8842f9c5025SMauro Carvalho Chehab if ($python_cmd) { 8852f9c5025SMauro Carvalho Chehab if ($virtualenv) { 8862f9c5025SMauro Carvalho Chehab my $tmp = qx($python_cmd --version 2>&1); 8872f9c5025SMauro Carvalho Chehab if ($tmp =~ m/(\d+\.)(\d+\.)/) { 8882f9c5025SMauro Carvalho Chehab if ($1 < 3) { 8894217e507SJonathan Corbet # Fail if it finds python2 (or worse) 8904217e507SJonathan Corbet die "Python 3 is required to build the kernel docs\n"; 8912f9c5025SMauro Carvalho Chehab } 892a5f785f1SMauro Carvalho Chehab if ($1 == 3 && $2 < 3) { 893a5f785f1SMauro Carvalho Chehab # Need Python 3.3 or upper for venv 894a5f785f1SMauro Carvalho Chehab $need_virtualenv = 1; 895a5f785f1SMauro Carvalho Chehab } 8962f9c5025SMauro Carvalho Chehab } else { 8972f9c5025SMauro Carvalho Chehab die "Warning: couldn't identify $python_cmd version!"; 8982f9c5025SMauro Carvalho Chehab } 8992f9c5025SMauro Carvalho Chehab } else { 9002f9c5025SMauro Carvalho Chehab add_package("python-sphinx", 0); 9012f9c5025SMauro Carvalho Chehab } 9022f9c5025SMauro Carvalho Chehab } 9032f9c5025SMauro Carvalho Chehab 904*7c2d45a3SMauro Carvalho Chehab my $venv_ver = recommend_sphinx_upgrade(); 905a5f785f1SMauro Carvalho Chehab 9062f9c5025SMauro Carvalho Chehab my $virtualenv_cmd; 907a5f785f1SMauro Carvalho Chehab 908a5f785f1SMauro Carvalho Chehab if ($need_pip) { 909a5f785f1SMauro Carvalho Chehab # Set virtualenv command line, if python < 3.3 9102f9c5025SMauro Carvalho Chehab if ($need_virtualenv) { 9112f9c5025SMauro Carvalho Chehab $virtualenv_cmd = findprog("virtualenv-3"); 9122f9c5025SMauro Carvalho Chehab $virtualenv_cmd = findprog("virtualenv-3.5") if (!$virtualenv_cmd); 9132f9c5025SMauro Carvalho Chehab if (!$virtualenv_cmd) { 9142f9c5025SMauro Carvalho Chehab check_program("virtualenv", 0); 9152f9c5025SMauro Carvalho Chehab $virtualenv_cmd = "virtualenv"; 9162f9c5025SMauro Carvalho Chehab } 917a5f785f1SMauro Carvalho Chehab } else { 918a5f785f1SMauro Carvalho Chehab $virtualenv_cmd = "$python_cmd -m venv"; 919a5f785f1SMauro Carvalho Chehab check_python_module("ensurepip", 0); 920a5f785f1SMauro Carvalho Chehab } 9212f9c5025SMauro Carvalho Chehab } 9222f9c5025SMauro Carvalho Chehab 9239b88ad54SMauro Carvalho Chehab # Check for needed programs/tools 92424071ac1SMauro Carvalho Chehab check_perl_module("Pod::Usage", 0); 92524071ac1SMauro Carvalho Chehab check_program("make", 0); 92624071ac1SMauro Carvalho Chehab check_program("gcc", 0); 92724071ac1SMauro Carvalho Chehab check_python_module("sphinx_rtd_theme", 1) if (!$virtualenv); 92824071ac1SMauro Carvalho Chehab check_program("dot", 1); 92924071ac1SMauro Carvalho Chehab check_program("convert", 1); 93056e5a633SMauro Carvalho Chehab 93156e5a633SMauro Carvalho Chehab # Extra PDF files - should use 2 for is_optional 93256e5a633SMauro Carvalho Chehab check_program("xelatex", 2) if ($pdf); 93356e5a633SMauro Carvalho Chehab check_program("rsvg-convert", 2) if ($pdf); 93456e5a633SMauro Carvalho Chehab check_program("latexmk", 2) if ($pdf); 93524071ac1SMauro Carvalho Chehab 9362f9c5025SMauro Carvalho Chehab # Do distro-specific checks and output distro-install commands 93724071ac1SMauro Carvalho Chehab check_distros(); 93824071ac1SMauro Carvalho Chehab 9392f9c5025SMauro Carvalho Chehab if (!$python_cmd) { 9402f9c5025SMauro Carvalho Chehab if ($need == 1) { 9412f9c5025SMauro Carvalho Chehab die "Can't build as $need mandatory dependency is missing"; 9422f9c5025SMauro Carvalho Chehab } elsif ($need) { 9432f9c5025SMauro Carvalho Chehab die "Can't build as $need mandatory dependencies are missing"; 9442f9c5025SMauro Carvalho Chehab } 9452f9c5025SMauro Carvalho Chehab } 9462f9c5025SMauro Carvalho Chehab 9472f9c5025SMauro Carvalho Chehab # Check if sphinx-build is called sphinx-build-3 94824071ac1SMauro Carvalho Chehab if ($need_symlink) { 94924071ac1SMauro Carvalho Chehab printf "\tsudo ln -sf %s /usr/bin/sphinx-build\n\n", 95024071ac1SMauro Carvalho Chehab which("sphinx-build-3"); 95124071ac1SMauro Carvalho Chehab } 9522f9c5025SMauro Carvalho Chehab 953e5089912SMauro Carvalho Chehab recommend_sphinx_version($virtualenv_cmd); 95424071ac1SMauro Carvalho Chehab printf "\n"; 95524071ac1SMauro Carvalho Chehab 95654002b56SBjorn Helgaas print "All optional dependencies are met.\n" if (!$optional); 95724071ac1SMauro Carvalho Chehab 95824071ac1SMauro Carvalho Chehab if ($need == 1) { 95924071ac1SMauro Carvalho Chehab die "Can't build as $need mandatory dependency is missing"; 96024071ac1SMauro Carvalho Chehab } elsif ($need) { 96124071ac1SMauro Carvalho Chehab die "Can't build as $need mandatory dependencies are missing"; 96224071ac1SMauro Carvalho Chehab } 96324071ac1SMauro Carvalho Chehab 96424071ac1SMauro Carvalho Chehab print "Needed package dependencies are met.\n"; 96524071ac1SMauro Carvalho Chehab} 96624071ac1SMauro Carvalho Chehab 96724071ac1SMauro Carvalho Chehab# 96824071ac1SMauro Carvalho Chehab# Main 96924071ac1SMauro Carvalho Chehab# 97024071ac1SMauro Carvalho Chehab 97124071ac1SMauro Carvalho Chehabwhile (@ARGV) { 97224071ac1SMauro Carvalho Chehab my $arg = shift(@ARGV); 97324071ac1SMauro Carvalho Chehab 97424071ac1SMauro Carvalho Chehab if ($arg eq "--no-virtualenv") { 97524071ac1SMauro Carvalho Chehab $virtualenv = 0; 97624071ac1SMauro Carvalho Chehab } elsif ($arg eq "--no-pdf"){ 97724071ac1SMauro Carvalho Chehab $pdf = 0; 9789b88ad54SMauro Carvalho Chehab } elsif ($arg eq "--version-check"){ 9799b88ad54SMauro Carvalho Chehab $version_check = 1; 98024071ac1SMauro Carvalho Chehab } else { 9819b88ad54SMauro Carvalho Chehab print "Usage:\n\t$0 <--no-virtualenv> <--no-pdf> <--version-check>\n\n"; 9829b88ad54SMauro Carvalho Chehab print "Where:\n"; 9839b88ad54SMauro Carvalho Chehab print "\t--no-virtualenv\t- Recommend installing Sphinx instead of using a virtualenv\n"; 9849b88ad54SMauro Carvalho Chehab print "\t--version-check\t- if version is compatible, don't check for missing dependencies\n"; 9859b88ad54SMauro Carvalho Chehab print "\t--no-pdf\t- don't check for dependencies required to build PDF docs\n\n"; 98624071ac1SMauro Carvalho Chehab exit -1; 98724071ac1SMauro Carvalho Chehab } 98824071ac1SMauro Carvalho Chehab} 98924071ac1SMauro Carvalho Chehab 99024071ac1SMauro Carvalho Chehab# 99124071ac1SMauro Carvalho Chehab# Determine the system type. There's no standard unique way that would 99224071ac1SMauro Carvalho Chehab# work with all distros with a minimal package install. So, several 99324071ac1SMauro Carvalho Chehab# methods are used here. 99424071ac1SMauro Carvalho Chehab# 99524071ac1SMauro Carvalho Chehab# By default, it will use lsb_release function. If not available, it will 99624071ac1SMauro Carvalho Chehab# fail back to reading the known different places where the distro name 99724071ac1SMauro Carvalho Chehab# is stored 99824071ac1SMauro Carvalho Chehab# 99924071ac1SMauro Carvalho Chehab 100024071ac1SMauro Carvalho Chehab$system_release = qx(lsb_release -d) if which("lsb_release"); 100124071ac1SMauro Carvalho Chehab$system_release =~ s/Description:\s*// if ($system_release); 100224071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/system-release") if !$system_release; 100324071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/redhat-release") if !$system_release; 100424071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/lsb-release") if !$system_release; 100524071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/gentoo-release") if !$system_release; 1006d14d0c1aSMauro Carvalho Chehab 1007d14d0c1aSMauro Carvalho Chehab# This seems more common than LSB these days 1008d14d0c1aSMauro Carvalho Chehabif (!$system_release) { 1009d14d0c1aSMauro Carvalho Chehab my %os_var; 1010d14d0c1aSMauro Carvalho Chehab if (open IN, "cat /etc/os-release|") { 1011d14d0c1aSMauro Carvalho Chehab while (<IN>) { 1012d14d0c1aSMauro Carvalho Chehab if (m/^([\w\d\_]+)=\"?([^\"]*)\"?\n/) { 1013d14d0c1aSMauro Carvalho Chehab $os_var{$1}=$2; 1014d14d0c1aSMauro Carvalho Chehab } 1015d14d0c1aSMauro Carvalho Chehab } 1016d14d0c1aSMauro Carvalho Chehab $system_release = $os_var{"NAME"}; 1017d14d0c1aSMauro Carvalho Chehab if (defined($os_var{"VERSION_ID"})) { 1018d14d0c1aSMauro Carvalho Chehab $system_release .= " " . $os_var{"VERSION_ID"} if (defined($os_var{"VERSION_ID"})); 1019d14d0c1aSMauro Carvalho Chehab } else { 1020d14d0c1aSMauro Carvalho Chehab $system_release .= " " . $os_var{"VERSION"}; 1021d14d0c1aSMauro Carvalho Chehab } 1022d14d0c1aSMauro Carvalho Chehab } 1023d14d0c1aSMauro Carvalho Chehab} 102424071ac1SMauro Carvalho Chehab$system_release = catcheck("/etc/issue") if !$system_release; 102524071ac1SMauro Carvalho Chehab$system_release =~ s/\s+$//; 102624071ac1SMauro Carvalho Chehab 102724071ac1SMauro Carvalho Chehabcheck_needs; 1028