From f640512319570ba3727e81b0d97d07de9a079e67 Mon Sep 17 00:00:00 2001 From: snare Date: Sun, 9 Apr 2017 18:12:18 -0700 Subject: [PATCH] Default to user site-packages, install updated six, add virtualenv option --- install.sh | 72 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/install.sh b/install.sh index 62e99f2..46fd9c0 100755 --- a/install.sh +++ b/install.sh @@ -3,26 +3,42 @@ # Install Voltron for whichever debuggers are detected (only GDB and LLDB so # far). # -# Adapted from pwndbg's install script. -# -# Usage: ./install.sh [ -u -d ] [ -b BACKEND ] -# -u Install to user's site-packages directory -# -d Install in developer mode (-e flag passed to pip) -# -b Select backend ("", "gdb", "lldb", or "gdb,lldb") to install for -SUDO='sudo' + +function usage { + cat <&2 - exit 1 + usage ;; esac done @@ -67,8 +86,7 @@ if [ "${BACKEND_LLDB}" -eq 1 ] && [ -z "${LLDB}" ]; then exit 1 fi - -set -e +set -ex function install_apt { if [ -n "${APT_GET}" ]; then @@ -112,7 +130,6 @@ function install_packages { install_yum } - if [ "${BACKEND_GDB}" -eq 1 ]; then # Find the Python version used by GDB GDB_PYVER=$(${GDB} -batch -q --nx -ex 'pi import platform; print(".".join(platform.python_version_tuple()[:2]))') @@ -149,7 +166,16 @@ if [ "${BACKEND_LLDB}" -eq 1 ]; then LLDB_PYVER=$(${LLDB} -Qxb --one-line 'script import platform; print(".".join(platform.python_version_tuple()[:2]))'|tail -1) LLDB_PYTHON=$(${LLDB} -Qxb --one-line 'script import sys; print(sys.executable)'|tail -1) LLDB_PYTHON="${LLDB_PYTHON/%$LLDB_PYVER/}${LLDB_PYVER}" - if [ -z $USER_MODE ]; then + + ${LLDB_PYTHON} -m pip install --user --upgrade six + + if [ -n "${VENV}" ]; then + echo "Creating virtualenv..." + ${LLDB_PYTHON} -m pip install --user virtualenv + ${LLDB_PYTHON} -m virtualenv "${VENV}" + LLDB_PYTHON="${VENV}/bin/python" + LLDB_SITE_PACKAGES=$(find "${VENV}" -name site-packages) + elif [ -z "${USER_MODE}" ]; then LLDB_SITE_PACKAGES=$(${LLDB} -Qxb --one-line 'script import site; print(site.getsitepackages()[0])'|tail -1) else LLDB_SITE_PACKAGES=$(${LLDB} -Qxb --one-line 'script import site; print(site.getusersitepackages())'|tail -1) @@ -170,11 +196,15 @@ if [ "${BACKEND_LLDB}" -eq 1 ]; then sed -i.bak '/voltron/d' ${LLDB_INIT_FILE} fi - if [ -z $DEV_MODE ]; then + if [ -z "${DEV_MODE}" ]; then LLDB_ENTRY_FILE="$LLDB_SITE_PACKAGES/voltron/entry.py" else LLDB_ENTRY_FILE="$(pwd)/voltron/entry.py" fi + + if [ -n "${VENV}" ]; then + echo "script import sys;sys.path.append('${LLDB_SITE_PACKAGES}')" >> ${LLDB_INIT_FILE} + fi echo "command script import $LLDB_ENTRY_FILE" >> ${LLDB_INIT_FILE} fi