diff --git a/docs/book/src/usage/start.rst b/docs/book/src/usage/start.rst index 943554a524a..294d0d36b46 100644 --- a/docs/book/src/usage/start.rst +++ b/docs/book/src/usage/start.rst @@ -48,9 +48,8 @@ If you used poetry to install dependencies, you should launch cape with the foll $ sudo -u cape poetry run python3 cuckoo.py -If you get any dependency-related error, make sure you execute the **extra/libvirt_installer.sh** script:: +If you get any dependency-related error, make sure the cape service is using the python environment configured by the installer. - $ sudo -u cape poetry run extra/libvirt_installer.sh Troubleshooting =============== diff --git a/installer/cape2.sh b/installer/cape2.sh index 7a9964b62ed..de1312ddc41 100755 --- a/installer/cape2.sh +++ b/installer/cape2.sh @@ -891,6 +891,7 @@ function install_libvirt() { cd "libvirt-python-${LIB_VERSION}" sudo chown -R ${USER}:${USER} "/tmp/libvirt-python-${LIB_VERSION}" ' + sudo apt-get install -y locate && sudo updatedb # used by install_libvirt temp_libvirt_so_path=$(locate libvirt-qemu.so | head -n1 | awk '{print $1;}') temp_export_path=$(locate libvirt.pc | head -n1 | awk '{print $1;}') libvirt_so_path="${temp_libvirt_so_path%/*}/" @@ -903,12 +904,14 @@ function install_libvirt() { export PKG_CONFIG_PATH=$export_path # Run build and install within the project environment - # We use sudo -u cape ... to install into the user's environment managed by poetry/uv + # We use sudo -u cape ... to install into the user's environment managed by poetry/uv/pip if [ "$USE_UV" = "true" ] || [ "$USE_UV" = "True" ]; then # sudo -u ${USER} bash -c "export PKG_CONFIG_PATH=$export_path; cd $CAPE_ROOT && $PYTHON_MGR pip install /tmp/libvirt-python-${LIB_VERSION}" sudo -u ${USER} bash -c "export PKG_CONFIG_PATH=$export_path; cd $CAPE_ROOT && $PYTHON_MGR pip install libvirt-python==${LIB_VERSION}" - else + elif [ "$PYTHON_MGR" = "/etc/poetry/bin/poetry" ]; then sudo -u ${USER} bash -c "export PKG_CONFIG_PATH=$export_path; $PYTHON_MGR --directory $CAPE_ROOT $PYTHON_MGR_CMD pip install libvirt-python==${LIB_VERSION}" + else + sudo -u ${USER} bash -c "export PKG_CONFIG_PATH=$export_path; pip3 install libvirt-python==${LIB_VERSION}" fi } @@ -1888,6 +1891,8 @@ case "$COMMAND" in install_IntroVirt;; 'passivedns') install_passivedns;; +'libvirt') + install_libvirt;; *) usage;; esac diff --git a/lib/cuckoo/common/abstracts.py b/lib/cuckoo/common/abstracts.py index 5cdb9d43646..7fbe0590474 100644 --- a/lib/cuckoo/common/abstracts.py +++ b/lib/cuckoo/common/abstracts.py @@ -435,7 +435,7 @@ class LibVirtMachinery(Machinery): def __init__(self): if not HAVE_LIBVIRT: raise CuckooDependencyError( - "Unable to import libvirt. Ensure that you properly installed it by running: cd /opt/CAPEv2/ ; sudo -u cape poetry run extra/libvirt_installer.sh" + "Unable to import libvirt. Ensure cape is being run from the same python environment configured by the installer script." ) super().__init__() diff --git a/lib/cuckoo/core/startup.py b/lib/cuckoo/core/startup.py index 8a7a7b26fbd..4c4342f2dbf 100644 --- a/lib/cuckoo/core/startup.py +++ b/lib/cuckoo/core/startup.py @@ -332,8 +332,8 @@ def check_snapshot_state(): from xml.etree import ElementTree except ImportError: raise CuckooStartupError( - "The 'libvirt-python' library is required for KVM/QEMU machinery but is not installed. " - "Please install it (e.g., 'cd /opt/CAPEv2/ ; sudo -u cape /etc/poetry/bin/poetry run extra/libvirt_installer.sh')." + "The 'libvirt-python' library is required for KVM/QEMU machinery but could not be imported. " + "Please ensure that CAPE is being launched by the same Python environment configured by the install script." ) machinery_config = Config(cuckoo.cuckoo.machinery) diff --git a/web/guac/views.py b/web/guac/views.py index d4dd3c00c0d..a33b2ea04a0 100644 --- a/web/guac/views.py +++ b/web/guac/views.py @@ -8,7 +8,7 @@ LIBVIRT_AVAILABLE = True except ImportError: - print("Missed python-libvirt. Use extra/libvirt_installer.sh") + print("Unable to import python-libvirt. Check that the CAPE python environment has it installed.") LIBVIRT_AVAILABLE = False machinery = Config().cuckoo.machinery