diff mbox series

[3/7] scripts: ignore unavailable interpreters

Message ID 20231109135148.42688-3-cgzones@googlemail.com (mailing list archive)
State Accepted
Commit 2d2e872886e9
Delegated to: Petr Lautrbach
Headers show
Series [1/7] Drop LGTM.com configuration | expand

Commit Message

Christian Göttsche Nov. 9, 2023, 1:51 p.m. UTC
Skip running and setting environment variables for unavailable
interpreters in the env_use_destdir wrapper script to avoid output
like:

    $ ./scripts/env_use_destdir $DESTDIR/usr/sbin/getenforce
    ./scripts/env_use_destdir: 59: ruby: not found
    ./scripts/env_use_destdir: 59: ruby: not found
    Enforcing

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 scripts/env_use_destdir | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/scripts/env_use_destdir b/scripts/env_use_destdir
index 89d989a2..e8069be8 100755
--- a/scripts/env_use_destdir
+++ b/scripts/env_use_destdir
@@ -43,17 +43,21 @@  if [ -n "${SBINDIR:-}" ] ; then
     PATH="$DESTDIR$SBINDIR:$PATH"
 fi
 
-NEW_PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "import sysconfig; print(sysconfig.get_path('platlib', vars={'platbase': '/usr', 'base': '/usr'}))"):$DESTDIR$(${PYTHON:-python3} -c "import sysconfig; print(sysconfig.get_path('purelib', vars={'platbase': '/usr', 'base': '/usr'}))")"
-if [ -n "${PYTHONPATH:-}" ] ; then
-    # Prefix the PYTHONPATH with the new directories
-    export PYTHONPATH="$NEW_PYTHONPATH:$PYTHONPATH"
-else
-    # Define PYTHONPATH
-    export PYTHONPATH="$NEW_PYTHONPATH"
+if command -v "${PYTHON:-python3}" > /dev/null ; then
+    NEW_PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "import sysconfig; print(sysconfig.get_path('platlib', vars={'platbase': '/usr', 'base': '/usr'}))"):$DESTDIR$(${PYTHON:-python3} -c "import sysconfig; print(sysconfig.get_path('purelib', vars={'platbase': '/usr', 'base': '/usr'}))")"
+    if [ -n "${PYTHONPATH:-}" ] ; then
+        # Prefix the PYTHONPATH with the new directories
+        export PYTHONPATH="$NEW_PYTHONPATH:$PYTHONPATH"
+    else
+        # Define PYTHONPATH
+        export PYTHONPATH="$NEW_PYTHONPATH"
+    fi
 fi
 
 # shellcheck disable=SC2155
-export RUBYLIB="$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorarchdir"]')"
+if command -v "${RUBY:-ruby}" > /dev/null ; then
+    export RUBYLIB="$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorarchdir"]')"
+fi
 
 # Run the command given on the command line
 if [ $# -gt 0 ] ; then