From ab46a7943fd1362c66bff4d085cdd0f5ee42e5ea Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Wed, 17 Oct 2018 18:33:15 +0200 Subject: [PATCH] Improve setup.sh distro and docker handling (#549) * Make setup.sh work with Docker on root w/o sudo * setup.sh: fallback to apt/dnf If the OS is not detected/supported, try checking for apt/dnf. * setup.sh: inform about arch's AUR package --- setup.sh | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/setup.sh b/setup.sh index 77aa3932b..5bd8dfe5e 100755 --- a/setup.sh +++ b/setup.sh @@ -1,6 +1,14 @@ #!/bin/bash set -ex +# If we are a root in a Docker 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 [ -f /.dockerenv ] && ! hash sudo 2>/dev/null && whoami | grep root; then + sudo() { + $* + } +fi # Helper functions linux() { @@ -10,6 +18,20 @@ osx() { uname | grep -i Darwin &>/dev/null } +install_apt() { + sudo apt-get update || true + sudo apt-get -y install gdb python-dev python3-dev python-pip python3-pip libglib2.0-dev libc6-dbg + + if uname -m | grep x86_64 > /dev/null; then + sudo apt-get install libc6-dbg:i386 || true + fi +} + +install_dnf() { + sudo dnf update || true + sudo dnf -y install gdb python-devel python3-devel python-pip python3-pip glib2-devel make + sudo dnf -y debuginfo-install glibc +} PYTHON='' INSTALLFLAGS='' @@ -25,20 +47,26 @@ if linux; then case $distro in "ubuntu") - sudo apt-get update || true - sudo apt-get -y install gdb python-dev python3-dev python-pip python3-pip libglib2.0-dev libc6-dbg - - if uname -m | grep x86_64 > /dev/null; then - sudo apt-get install libc6-dbg:i386 || true - fi + install_apt ;; "fedora") - sudo dnf update || true - sudo dnf -y install gdb python-devel python3-devel python-pip python3-pip glib2-devel make - sudo dnf -y debuginfo-install glibc + install_dnf + ;; + "arch") + echo "Install Arch linux using a community package. See:" + echo " - https://www.archlinux.org/packages/community/any/pwndbg/" + echo " - https://aur.archlinux.org/packages/pwndbg-git/" + exit 1 ;; *) # we can add more install command for each distros. - echo "\"$distro\" is not supported distro." + echo "\"$distro\" is not supported distro. Will search for 'apt' or 'dnf' package managers." + if hash apt; then + install_apt + elif hash dnf; then + install_dnf + else + echo "\"$distro\" is not supported and your distro don't have apt or dnf that we support currently." + fi exit ;; esac