From 4920cf317c75160a62b6ce667da8132bf2a3db76 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Tue, 3 May 2022 13:11:03 -0600 Subject: [PATCH] entry point: update sys.path for non-distutils install When bundled with Suricata, Suricata-Update will not be installed with distutils/setuptools and will be installed in a custom location. Update the search path for these changes. This will still work correctly if installed from pip, or running from a custom directory not bundled with Suricata. Issue: #5313 --- bin/suricata-update | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bin/suricata-update b/bin/suricata-update index f2e8557..94ea2ba 100755 --- a/bin/suricata-update +++ b/bin/suricata-update @@ -20,12 +20,15 @@ import sys import os exec_dir = os.path.dirname(__file__) -version_info = sys.version_info -pyver = "%d.%d" % (version_info.major, version_info.minor) -site_path = "%s/../lib/python%s/site-packages" % (exec_dir, pyver) -if os.path.exists("%s/suricata/update" % (site_path)): - sys.path.insert(0, site_path) +# Check if we were installed along with Suricata, and setup the path if so. +libpath = os.path.realpath( + os.path.join(exec_dir, os.pardir, "lib/suricata/python")) +if os.path.exists(os.path.join(libpath, "suricata", "update")): + sys.path.insert(0, libpath) + +# If running out of the source directory, make sure we pick up the +# library from the current directory. sys.path.insert( 0, os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))) -- 2.47.3