[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250625162237.3996-3-saivishnu725@gmail.com>
Date: Wed, 25 Jun 2025 21:52:36 +0530
From: Sai Vishnu M <saivishnu725@...il.com>
To: corbet@....net,
mchehab@...nel.org
Cc: linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org,
shuah@...nel.org,
Sai Vishnu M <saivishnu725@...il.com>
Subject: [PATCH 3/4] scripts: sphinx-pre-install: add fallback to distro detection
From: Sai Vishnu M <saivishnu725@...il.com>
Implement derived_distro_detection to prompt users to select a base
distro in interactive mode for unrecognized distributions. Move the
fallback code for unknown distributions to fallback_unknown_distro.
Update check_distros to use these functions.
Signed-off-by: Sai Vishnu M <saivishnu725@...il.com>
---
Patch series history:
1 -> implement the --interactive flag
2 -> add run_if_interactive subroutine
Testing:
=========
Tested on a Debian container
Steps taken:
1. Start a container with all files
podman pull docker.io/debian:bookworm
mkdir -p /tmp/sphinx-test/Documentation
cp ./scripts/sphinx-pre-install /tmp/sphinx-test
cp ./Documentation/conf.py /tmp/sphinx-test/Documentation
cd /tmp/sphinx-test
podman run -it --rm -v $(pwd):/work:z debian:bookworm bash
2. Modify /etc/os-release to simulate an unknown distro:
echo -e 'NAME="UnknownDistro"\nID=unknowndistro' > /etc/os-release
rm /etc/lsb-release 2>/dev/null
3. Install perl and dependencies
apt-get update && apt-get install -y perl sudo
4. Run the script in interactive mode
cd /work; perl sphinx-pre-install --interactive
scripts/sphinx-pre-install | 63 ++++++++++++++++++++++++++++++--------
1 file changed, 50 insertions(+), 13 deletions(-)
diff --git a/scripts/sphinx-pre-install b/scripts/sphinx-pre-install
index 16eb739fd633..e4f8a658857a 100755
--- a/scripts/sphinx-pre-install
+++ b/scripts/sphinx-pre-install
@@ -355,6 +355,51 @@ sub run_if_interactive($)
}
}
+sub fallback_unknown_distro()
+{
+ # Fall-back to generic hint code for other distros
+ # That's far from ideal, especially for LaTeX dependencies.
+ my %map = (
+ "sphinx-build" => "sphinx"
+ );
+ check_missing_tex(2) if ($pdf);
+ check_missing(\%map);
+ print "I don't know distro $system_release.\n";
+ print "So, I can't provide you a hint with the install procedure.\n";
+ print "There are likely missing dependencies.\n";
+}
+
+#
+# if the distribution is not recognised
+# but it is derived from the available options
+#
+sub derived_distro_detection()
+{
+ my @distros = (
+ { name => "Debian/Ubuntu", func => \&give_debian_hints },
+ { name => "RedHat/CentOS/Fedora", func => \&give_redhat_hints },
+ { name => "OpenSUSE", func => \&give_opensuse_hints },
+ { name => "Mageia", func => \&give_mageia_hints },
+ { name => "Arch Linux", func => \&give_arch_linux_hints },
+ { name => "Gentoo", func => \&give_gentoo_hints },
+ );
+ print "Which distro is your OS based on?\n";
+ for my $i (0 .. $#distros) {
+ printf("[%d] %s\n", $i + 1, $distros[$i]->{name});
+ }
+ print "[99] Others\n";
+
+ print "Select a number: ";
+ my $choice = <STDIN>;
+ chomp $choice;
+
+ if ($choice =~ /^\d+$/ && $choice >= 1 && $choice <= scalar(@distros)) {
+ $distros[$choice - 1]->{func}->();
+ } else {
+ fallback_unknown_distro();
+ }
+}
+
#
# Subroutines that check distro-specific hints
#
@@ -695,19 +740,11 @@ sub check_distros()
give_gentoo_hints;
return;
}
-
- #
- # Fall-back to generic hint code for other distros
- # That's far from ideal, specially for LaTeX dependencies.
- #
- my %map = (
- "sphinx-build" => "sphinx"
- );
- check_missing_tex(2) if ($pdf);
- check_missing(\%map);
- print "I don't know distro $system_release.\n";
- print "So, I can't provide you a hint with the install procedure.\n";
- print "There are likely missing dependencies.\n";
+ if ( $interactive ) {
+ derived_distro_detection();
+ return;
+ }
+ fallback_unknown_distro();
}
#
--
2.49.0
Powered by blists - more mailing lists