pwndbg/setup.sh

230 lines
6.8 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2024-02-15 02:50:03 +08:00
set -e
# If we are a root in a container and `sudo` doesn't exist
# lets overwrite it with a function that just executes things passed to sudo
# (yeah it won't work for sudo executed with flags)
if ! hash sudo 2> /dev/null && whoami | grep -q root; then
sudo() {
Unit test fix (#868) * Fixed the failed unit testing; Improved the Dockerfile, again. * Fixed missing new line joiner in the Dockerfile. * Fixed the default Python version from 2 to 3. * Moved the installation of the nasm and golang packages to the setup script. * Fixed the extra quotes which fails the sudo check. * Added to the Git ignore file the output files assembled and linked in the test binaries. * Removed the output files from test binaries. * Added to the Git ignore file the virtual environment directory. * Added sudo to the remove and link the Python3 binary. * Added commands related to GO, to check why is failing. * Fixed the installation of GO, only install if not exists in Ubuntu. * Fixed the first test built in Assembler. Checks if it is working in GitHub. * Fixed the problem with all the assembler tests; Extracted the asserts into methods, avoiding duplicates. * Fixed some test, should be fail the Travis tests. * Fixed one test for Travis. * Fixed the asserts, now find all ecpected items into the output. * Fixed the split message, joined again. * Fixed the last error test for loads binary. * Fixed one missing number in the comparison. * Fixed the first Lint errors. * Added comment in the Dockerfile. The commented line about `git submodule`. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549075767 * Removed NASM and Go from the setup. Created a new bash script to install them and added to the Dockerfile. https://github.com/pwndbg/pwndbg/pull/868/files#r549075931 https://github.com/pwndbg/pwndbg/pull/868/files#r549076078 * Added the setup script in the GitHub test workflow. https://github.com/pwndbg/pwndbg/pull/868/files#r549075931 https://github.com/pwndbg/pwndbg/pull/868/files#r549076078 * Testing the emulate cases. It should be fail. I commented the emulation for the address 0x401000. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549111511 * Fixed the different start addresses in the assembler test. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549111511 https://github.com/pwndbg/pwndbg/pull/868#discussion_r549075485 * Experimenting with the python location. Commented the remove python binary and added some logs. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549076170 * Removed the commands about delete Python and link the Python3. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549076170
2020-12-31 11:35:52 +08:00
${*}
}
fi
# Helper functions
linux() {
uname | grep -iqs Linux
}
osx() {
uname | grep -iqs Darwin
}
install_apt() {
sudo apt-get update || true
sudo apt-get install -y git gdb gdbserver python3-dev python3-venv python3-setuptools libglib2.0-dev libc6-dbg curl
if uname -m | grep -q x86_64; then
sudo dpkg --add-architecture i386 || true
sudo apt-get update || true
sudo apt-get install -y libc6-dbg:i386 libgcc-s1:i386 || true
fi
}
install_dnf() {
sudo dnf update || true
sudo dnf -y install gdb gdb-gdbserver python-devel python3-devel glib2-devel make curl
sudo dnf -y debuginfo-install glibc
}
2020-05-11 03:23:59 +08:00
install_xbps() {
sudo xbps-install -Su
sudo xbps-install -Sy gdb gcc python-devel python3-devel glibc-devel make curl
2020-05-11 03:23:59 +08:00
sudo xbps-install -Sy glibc-dbg
}
2019-12-13 01:07:27 +08:00
install_swupd() {
sudo swupd update || true
sudo swupd bundle-add gdb python3-basic make c-basic curl
2019-12-13 01:07:27 +08:00
}
2020-03-28 23:16:24 +08:00
install_zypper() {
sudo zypper mr -e repo-oss-debug || sudo zypper mr -e repo-debug
2020-03-28 23:16:24 +08:00
sudo zypper refresh || true
sudo zypper install -y gdb gdbserver python-devel python3-devel glib2-devel make glibc-debuginfo curl
2024-06-07 23:37:27 +08:00
sudo zypper install -y python2-pip || true # skip py2 installation if it doesn't exist
2020-03-28 23:16:24 +08:00
if uname -m | grep -q x86_64; then
2020-03-28 23:16:24 +08:00
sudo zypper install -y glibc-32bit-debuginfo || true
fi
}
install_emerge() {
sudo emerge --oneshot --deep --newuse --changed-use --changed-deps dev-lang/python dev-debug/gdb
}
2024-08-26 20:28:21 +08:00
install_oma() {
sudo oma refresh || true
sudo oma install -y gdb gdbserver python-3 glib make glibc-dbg curl
if uname -m | grep -q x86_64; then
sudo oma install -y glibc+32-dbg || true
fi
}
install_pacman() {
2023-09-05 17:33:05 +08:00
read -p "Do you want to do a full system update? (y/n) [n] " answer
# user want to perform a full system upgrade
2023-09-05 17:33:05 +08:00
answer=${answer:-n} # n is default
if [[ "$answer" == "y" ]]; then
sudo pacman -Syu || true
fi
sudo pacman -S --noconfirm --needed git gdb python python-capstone python-unicorn python-pycparser python-psutil python-ptrace python-pyelftools python-six python-pygments which debuginfod curl
if ! grep -qs "^set debuginfod enabled on" ~/.gdbinit; then
echo "set debuginfod enabled on" >> ~/.gdbinit
fi
}
install_freebsd() {
sudo pkg install git gdb python py39-pip cmake gmake curl
which rustc || sudo pkg install rust
}
usage() {
Fix codecov (#1792) * Fix coverage combine toml issue This commit should fix this issue: ``` Run coverage combine coverage combine coverage xml shell: /usr/bin/bash -e {0} Can't read 'pyproject.toml' without TOML support. Install with [toml] extra Error: Process completed with exit code 1. ``` * setup.sh: cleanup the --user flag since we use venv now Cleans up the --user flag from setup.sh since it is unused after we changed setup.sh to install Python dependencies in a virtual environment * Remove --user flag from CI workflows * Fix codecov problem We need to run the python `coverage` library to collect coverage. However, gdb was failing to find it. Recently, pwndbg moved to using venvs. When pwndbg is initialized it setups the venv "manually", that is, no "source .venv/bin/activate" is needed. When we run gdb tests, we pass the `gdbinit.py` of pwndbg as a command to gdb to be executed like this: `gdb --silent --nx --nh -ex 'py import coverage;coverage.process_startup()' --command PATH_TO_gdbinit.py` The problem is that *order* matters. This means that *first* coverage is imported (by `-ex py ...`) and only *then* the init script is executed. When `coverage` is first imported, it's library search path only looks in system libraries of python, and not the venv that gdbinit.py would load. So we would try to import an old version of coverage and fail. One solution would be to move around the commands, but this would be an ugly hack IMHO. **Instead**, we should just tell gdb that this is an **init** command that has to be executed before other commands. Previously, the order did not matter. All of pwndbg's dependencies were installed directly as system libraries to python. So the library search path was the same before and after loading `gdbinit.py`. --------- Co-authored-by: disconnect3d <dominik.b.czarnota@gmail.com> Co-authored-by: intrigus <abc123zeus@live.de>
2023-07-12 02:27:25 +08:00
echo "Usage: $0 [--update]"
echo " --update: Install/update dependencies without checking ~/.gdbinit"
}
UPDATE_MODE=
for arg in "$@"; do
case $arg in
--update)
UPDATE_MODE=1
;;
-h | --help)
set +x
usage
exit 0
;;
*)
set +x
echo "Unknown argument: $arg"
usage
exit 1
;;
esac
done
PYTHON=''
# Check for the presence of the initializer line in the user's ~/.gdbinit file
if [ -z "$UPDATE_MODE" ] && grep -qs '^[^#]*source.*pwndbg/gdbinit.py' ~/.gdbinit; then
# Ask the user if they want to proceed and override the initializer line
2024-02-15 02:50:03 +08:00
read -p "A Pwndbg initializer line was found in your ~/.gdbinit file. Do you want to proceed and override it? (y/n) " answer
# If the user does not want to proceed, exit the script
if [[ "$answer" != "y" ]]; then
exit 0
fi
fi
if linux; then
2020-03-08 21:10:19 +08:00
distro=$(grep "^ID=" /etc/os-release | cut -d'=' -f2 | sed -e 's/"//g')
case $distro in
"ubuntu")
install_apt
;;
"fedora")
install_dnf
;;
2020-03-28 23:16:24 +08:00
"clear-linux-os")
install_swupd
;;
"opensuse-leap" | "opensuse-tumbleweed")
2020-03-28 23:16:24 +08:00
install_zypper
;;
"arch" | "archarm" | "endeavouros" | "manjaro" | "garuda" | "cachyos" | "archcraft" | "artix")
2022-10-31 04:51:00 +08:00
install_pacman
echo "Logging off and in or conducting a power cycle is required to get debuginfod to work."
echo "Alternatively you can manually set the environment variable: DEBUGINFOD_URLS=https://debuginfod.archlinux.org"
;;
2020-05-11 03:23:59 +08:00
"void")
install_xbps
;;
"gentoo")
install_emerge
if ! hash sudo 2> /dev/null && whoami | grep root; then
sudo() {
Unit test fix (#868) * Fixed the failed unit testing; Improved the Dockerfile, again. * Fixed missing new line joiner in the Dockerfile. * Fixed the default Python version from 2 to 3. * Moved the installation of the nasm and golang packages to the setup script. * Fixed the extra quotes which fails the sudo check. * Added to the Git ignore file the output files assembled and linked in the test binaries. * Removed the output files from test binaries. * Added to the Git ignore file the virtual environment directory. * Added sudo to the remove and link the Python3 binary. * Added commands related to GO, to check why is failing. * Fixed the installation of GO, only install if not exists in Ubuntu. * Fixed the first test built in Assembler. Checks if it is working in GitHub. * Fixed the problem with all the assembler tests; Extracted the asserts into methods, avoiding duplicates. * Fixed some test, should be fail the Travis tests. * Fixed one test for Travis. * Fixed the asserts, now find all ecpected items into the output. * Fixed the split message, joined again. * Fixed the last error test for loads binary. * Fixed one missing number in the comparison. * Fixed the first Lint errors. * Added comment in the Dockerfile. The commented line about `git submodule`. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549075767 * Removed NASM and Go from the setup. Created a new bash script to install them and added to the Dockerfile. https://github.com/pwndbg/pwndbg/pull/868/files#r549075931 https://github.com/pwndbg/pwndbg/pull/868/files#r549076078 * Added the setup script in the GitHub test workflow. https://github.com/pwndbg/pwndbg/pull/868/files#r549075931 https://github.com/pwndbg/pwndbg/pull/868/files#r549076078 * Testing the emulate cases. It should be fail. I commented the emulation for the address 0x401000. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549111511 * Fixed the different start addresses in the assembler test. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549111511 https://github.com/pwndbg/pwndbg/pull/868#discussion_r549075485 * Experimenting with the python location. Commented the remove python binary and added some logs. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549076170 * Removed the commands about delete Python and link the Python3. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549076170
2020-12-31 11:35:52 +08:00
${*}
}
fi
;;
"freebsd")
install_freebsd
;;
2024-08-26 20:28:21 +08:00
"aosc")
install_oma
;;
*) # we can add more install command for each distros.
echo "\"$distro\" is not supported distro. Will search for 'apt', 'dnf' or 'pacman' package managers."
if hash apt; then
install_apt
elif hash dnf; then
install_dnf
elif hash pacman; then
install_pacman
else
echo "\"$distro\" is not supported and your distro don't have a package manager that we support currently."
exit
fi
;;
esac
fi
2016-05-12 10:36:26 +08:00
if ! hash gdb; then
Unit test fix (#868) * Fixed the failed unit testing; Improved the Dockerfile, again. * Fixed missing new line joiner in the Dockerfile. * Fixed the default Python version from 2 to 3. * Moved the installation of the nasm and golang packages to the setup script. * Fixed the extra quotes which fails the sudo check. * Added to the Git ignore file the output files assembled and linked in the test binaries. * Removed the output files from test binaries. * Added to the Git ignore file the virtual environment directory. * Added sudo to the remove and link the Python3 binary. * Added commands related to GO, to check why is failing. * Fixed the installation of GO, only install if not exists in Ubuntu. * Fixed the first test built in Assembler. Checks if it is working in GitHub. * Fixed the problem with all the assembler tests; Extracted the asserts into methods, avoiding duplicates. * Fixed some test, should be fail the Travis tests. * Fixed one test for Travis. * Fixed the asserts, now find all ecpected items into the output. * Fixed the split message, joined again. * Fixed the last error test for loads binary. * Fixed one missing number in the comparison. * Fixed the first Lint errors. * Added comment in the Dockerfile. The commented line about `git submodule`. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549075767 * Removed NASM and Go from the setup. Created a new bash script to install them and added to the Dockerfile. https://github.com/pwndbg/pwndbg/pull/868/files#r549075931 https://github.com/pwndbg/pwndbg/pull/868/files#r549076078 * Added the setup script in the GitHub test workflow. https://github.com/pwndbg/pwndbg/pull/868/files#r549075931 https://github.com/pwndbg/pwndbg/pull/868/files#r549076078 * Testing the emulate cases. It should be fail. I commented the emulation for the address 0x401000. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549111511 * Fixed the different start addresses in the assembler test. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549111511 https://github.com/pwndbg/pwndbg/pull/868#discussion_r549075485 * Experimenting with the python location. Commented the remove python binary and added some logs. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549076170 * Removed the commands about delete Python and link the Python3. https://github.com/pwndbg/pwndbg/pull/868#discussion_r549076170
2020-12-31 11:35:52 +08:00
echo "Could not find gdb in $PATH"
exit
fi
# Find the Python version used by GDB.
PYVER=$(gdb -batch -q --nx -ex 'pi import platform; print(".".join(platform.python_version_tuple()[:2]))')
PYTHON+=$(gdb -batch -q --nx -ex 'pi import sys; print(sys.executable)')
2022-04-28 20:50:37 +08:00
if ! osx; then
PYTHON+="${PYVER}"
2022-04-28 20:50:37 +08:00
fi
# Install Poetry
if ! command -v poetry &> /dev/null; then
echo "Poetry not found. Installing Poetry..."
curl -sSL https://install.python-poetry.org | python3 -
export PATH="$HOME/.local/bin:$PATH"
else
echo "Poetry is already installed."
fi
# Create the Python virtual environment and install dependencies using poetry
if [[ -z "${PWNDBG_VENV_PATH}" ]]; then
PWNDBG_VENV_PATH="./.venv"
fi
echo "Creating virtualenv in path: ${PWNDBG_VENV_PATH}"
${PYTHON} -m venv -- ${PWNDBG_VENV_PATH}
source ${PWNDBG_VENV_PATH}/bin/activate
poetry install
2021-12-09 08:28:22 +08:00
if [ -z "$UPDATE_MODE" ]; then
# Comment old configs out
if grep -qs '^[^#]*source.*pwndbg/gdbinit.py' ~/.gdbinit; then
if ! osx; then
sed -i '/^[^#]*source.*pwndbg\/gdbinit.py/ s/^/# /' ~/.gdbinit
else
# In BSD sed we need to pass ' ' to indicate that no backup file should be created
sed -i ' ' '/^[^#]*source.*pwndbg\/gdbinit.py/ s/^/# /' ~/.gdbinit
fi
fi
# Load Pwndbg into GDB on every launch.
echo "source $PWD/gdbinit.py" >> ~/.gdbinit
2024-02-15 02:50:03 +08:00
echo "[*] Added 'source $PWD/gdbinit.py' to ~/.gdbinit so that Pwndbg will be loaded on every launch of GDB."
2021-12-09 08:28:22 +08:00
fi