]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
suricatasc: allow to run from non-standard python locations
authorJason Ish <ish@unx.ca>
Mon, 26 Mar 2018 13:49:17 +0000 (07:49 -0600)
committerVictor Julien <victor@inliniac.net>
Wed, 28 Mar 2018 06:49:41 +0000 (08:49 +0200)
When we install to a non-standard prefix, the Python modules
are not in the standard location requiring the PYTHONPATH
to be fixed up.

This wa a pre-existing issue with suricatasc, and not due to
the move into the python directory.

python/bin/suricatasc.in

index 63b4ebfaf5ab67f48713f5c8cdd0e54d893f7055..00b39d4d3d0fbdd2d3c0938e06ce3930de81f4ed 100755 (executable)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-
 from __future__ import print_function
+
 import sys
+import os
 import argparse
+
+# Find the Python libdir.
+exec_dir = os.path.dirname(__file__)
+if os.path.exists(os.path.join(exec_dir, "..", "suricata", "ctl", "main.py")):
+    # Looks like we're running from the development directory.
+    sys.path.insert(0, ".")
+else:
+    # This is to find the suricata module in the case of being installed
+    # to a non-standard prefix.
+    version_info = sys.version_info
+    pyver = "%d.%d" % (version_info.major, version_info.minor)
+    path = os.path.join(
+        exec_dir, "..", "lib", "python%s" % (pyver), "site-packages",
+        "suricata")
+    if os.path.exists(path):
+        sys.path.insert(0, os.path.dirname(path))
+
 from suricatasc import *
 
 parser = argparse.ArgumentParser(prog='suricatasc', description='Client for Suricata unix socket')