linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sai Vishnu M <saivishnu725@gmail.com>
To: corbet@lwn.net, mchehab@kernel.org
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	shuah@kernel.org, Sai Vishnu M <saivishnu725@gmail.com>
Subject: [PATCH 3/4] scripts: sphinx-pre-install: add fallback to distro detection
Date: Wed, 25 Jun 2025 21:52:36 +0530	[thread overview]
Message-ID: <20250625162237.3996-3-saivishnu725@gmail.com> (raw)
In-Reply-To: <20250625162237.3996-1-saivishnu725@gmail.com>

From: Sai Vishnu M <saivishnu725@gmail.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@gmail.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


  parent reply	other threads:[~2025-06-25 16:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-25 16:22 [PATCH 1/4] scripts: sphinx-pre-install: Add --interactive flag Sai Vishnu M
2025-06-25 16:22 ` [PATCH 2/4] scripts: sphinx-pre-install: add a helper subroutine Sai Vishnu M
2025-06-25 16:22 ` Sai Vishnu M [this message]
2025-06-25 16:22 ` [PATCH 4/4] scripts: sphinx-pre-install: Integrate interactive mode Sai Vishnu M
2025-06-25 20:32 ` [PATCH 1/4] scripts: sphinx-pre-install: Add --interactive flag Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250625162237.3996-3-saivishnu725@gmail.com \
    --to=saivishnu725@gmail.com \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).