From: Sai Vishnu M <saivishnu725@xxxxxxxxx> Replace direct printf calls with run_if_interactive for installation commands across all distro-specific hint subroutines, enabling user prompts in interactive mode. Signed-off-by: Sai Vishnu M <saivishnu725@xxxxxxxxx> --- Patch series history: 1 -> implement the --interactive flag 2 -> add run_if_interactive subroutine 3 -> add fallback to unrecognized distributions Testing: ======== Tested: Debian, Ubuntu, Fedora, openSUSE Tumbleweed, Mageia. Skipped: Gentoo (setup complexity but similarity in modification to others) Steps taken: 1. Podman to download the containers: podman pull docker.io/debian:bookworm podman pull docker.io/ubuntu:24.04 podman pull docker.io/fedora:40 podman pull docker.io/opensuse/tumbleweed:latest podman pull docker.io/mageia:9 podman pull docker.io/gentoo/stage3:latest 2. Copy the script and related files to a temporary folder 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 3. Connect to the containers podman run -it --rm -v $(pwd):/work:z CONTAINER:VERSION bash Ex: podman run -it --rm -v $(pwd):/work:z debian:bookworm bash 4. Install perl and dependencies # Debian/Ubuntu apt-get update && apt-get install -y perl sudo # Fedora dnf install -y perl sudo # OpenSUSE zypper install -y perl sudo # Mageia dnf install -y perl sudo # Gentoo (requires more setup) emerge-webrsync && emerge dev-lang/perl 5. Run the script a. Interactive cd /work; perl sphinx-pre-install --interactive b. Non Interactive cd /work; perl sphinx-pre-install scripts/sphinx-pre-install | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/scripts/sphinx-pre-install b/scripts/sphinx-pre-install index 87eef15650f2..c2e10170e6c1 100755 --- a/scripts/sphinx-pre-install +++ b/scripts/sphinx-pre-install @@ -436,7 +436,8 @@ sub give_debian_hints() return if (!$need && !$optional); printf("You should run:\n") if ($verbose_warn_install); - printf("\n\tsudo apt-get install $install\n"); + my $command = "sudo apt-get install $install"; + run_if_interactive($command); } sub give_redhat_hints() @@ -514,11 +515,13 @@ sub give_redhat_hints() if (!$old) { # dnf, for Fedora 18+ printf("You should run:\n") if ($verbose_warn_install); - printf("\n\tsudo dnf install -y $install\n"); + my $command = "sudo dnf install -y $install"; + run_if_interactive($command); } else { # yum, for RHEL (and clones) or Fedora version < 18 printf("You should run:\n") if ($verbose_warn_install); - printf("\n\tsudo yum install -y $install\n"); + my $command = "sudo yum install -y $install"; + run_if_interactive($command); } } @@ -567,7 +570,8 @@ sub give_opensuse_hints() return if (!$need && !$optional); printf("You should run:\n") if ($verbose_warn_install); - printf("\n\tsudo zypper install --no-recommends $install\n"); + my $command = "sudo zypper install --no-recommends $install"; + run_if_interactive($command); } sub give_mageia_hints() @@ -612,7 +616,8 @@ sub give_mageia_hints() return if (!$need && !$optional); printf("You should run:\n") if ($verbose_warn_install); - printf("\n\tsudo $packager_cmd $install\n"); + my $command = "sudo $packager_cmd $install"; + run_if_interactive($command); } sub give_arch_linux_hints() @@ -643,7 +648,8 @@ sub give_arch_linux_hints() return if (!$need && !$optional); printf("You should run:\n") if ($verbose_warn_install); - printf("\n\tsudo pacman -S $install\n"); + my $command = "sudo pacman -S $install"; + run_if_interactive($command); } sub give_gentoo_hints() @@ -679,13 +685,16 @@ sub give_gentoo_hints() my $portage_cairo = "/etc/portage/package.use/graphviz"; if (qx(grep imagemagick $portage_imagemagick 2>/dev/null) eq "") { - printf("\tsudo su -c 'echo \"$imagemagick\" > $portage_imagemagick'\n") + my $imagemagick_command = "sudo su -c 'echo \"$imagemagick\" > $portage_imagemagick'"; + run_if_interactive($imagemagick_command); } if (qx(grep graphviz $portage_cairo 2>/dev/null) eq "") { - printf("\tsudo su -c 'echo \"$cairo\" > $portage_cairo'\n"); + my $portage_command = "sudo su -c 'echo \"$cairo\" > $portage_cairo'"; + run_if_interactive($portage_command); } - printf("\tsudo emerge --ask $install\n"); + my $command = "sudo emerge --ask $install"; + run_if_interactive($command); } -- 2.49.0