From f5cb46e316cb2bfddd3bdd6d44536830286c9858 Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Mon, 24 Apr 2023 20:24:22 +0200 Subject: [PATCH] Toolchain: Exit Build*.sh scripts if executed as root --- Toolchain/BuildCMake.sh | 5 +++++ Toolchain/BuildClang.sh | 5 +++++ Toolchain/BuildFuseExt2.sh | 6 ++++++ Toolchain/BuildGDB.sh | 9 +++++++-- Toolchain/BuildIt.sh | 6 +++++- Toolchain/BuildMold.sh | 5 +++++ Toolchain/BuildPython.sh | 5 +++++ Toolchain/BuildQemu.sh | 5 +++++ Toolchain/BuildRuby.sh | 5 +++++ 9 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Toolchain/BuildCMake.sh b/Toolchain/BuildCMake.sh index 2242d3a7385..ba832b05a2f 100755 --- a/Toolchain/BuildCMake.sh +++ b/Toolchain/BuildCMake.sh @@ -5,6 +5,11 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# shellcheck source=/dev/null +. "${DIR}/../Meta/shell_include.sh" + +exit_if_running_as_root "Do not run BuildCMake.sh as root, parts of your Toolchain directory will become root-owned" + PREFIX_DIR="$DIR/Local/cmake" BUILD_DIR="$DIR/Build/cmake" TARBALLS_DIR="$DIR/Tarballs" diff --git a/Toolchain/BuildClang.sh b/Toolchain/BuildClang.sh index 985278f9bfe..ce0c247e9af 100755 --- a/Toolchain/BuildClang.sh +++ b/Toolchain/BuildClang.sh @@ -5,6 +5,11 @@ set -eo pipefail DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# shellcheck source=/dev/null +. "${DIR}/../Meta/shell_include.sh" + +exit_if_running_as_root "Do not run BuildClang.sh as root, parts of your Toolchain directory will become root-owned" + echo "$DIR" PREFIX="$DIR/Local/clang/" diff --git a/Toolchain/BuildFuseExt2.sh b/Toolchain/BuildFuseExt2.sh index 0247f68f7fd..3af66ae4358 100755 --- a/Toolchain/BuildFuseExt2.sh +++ b/Toolchain/BuildFuseExt2.sh @@ -3,6 +3,12 @@ set -e # This file will need to be run in bash. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# shellcheck source=/dev/null +. "${DIR}/../Meta/shell_include.sh" + +exit_if_running_as_root "Do not run BuildFuseExt2.sh as root, parts of your Toolchain directory will become root-owned" + export PATH="/usr/local/opt/m4/bin:$PATH" die() { diff --git a/Toolchain/BuildGDB.sh b/Toolchain/BuildGDB.sh index 75d16d9fd26..fba89b0aa71 100755 --- a/Toolchain/BuildGDB.sh +++ b/Toolchain/BuildGDB.sh @@ -1,14 +1,19 @@ #!/usr/bin/env bash set -e +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# shellcheck source=/dev/null +. "${DIR}/../Meta/shell_include.sh" + +exit_if_running_as_root "Do not run BuildGDB.sh as root, parts of your Toolchain directory will become root-owned" + GDB_VERSION="13.1" GDB_MD5SUM="4aaad768ff2585464173c091947287ec" GDB_NAME="gdb-$GDB_VERSION" GDB_PKG="${GDB_NAME}.tar.xz" GDB_BASE_URL="https://ftp.gnu.org/gnu/gdb" -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - ARCH=${1:-"x86_64"} TARGET="$ARCH-pc-serenity" PREFIX="$DIR/Local/$ARCH-gdb" diff --git a/Toolchain/BuildIt.sh b/Toolchain/BuildIt.sh index 69c2c5af2d6..8147127714b 100755 --- a/Toolchain/BuildIt.sh +++ b/Toolchain/BuildIt.sh @@ -2,11 +2,15 @@ set -eo pipefail # This file will need to be run in bash, for now. - # === CONFIGURATION AND SETUP === DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# shellcheck source=/dev/null +. "${DIR}/../Meta/shell_include.sh" + +exit_if_running_as_root "Do not run BuildIt.sh as root, your Build directory will become root-owned" + echo "$DIR" ARCH=${ARCH:-"x86_64"} diff --git a/Toolchain/BuildMold.sh b/Toolchain/BuildMold.sh index 1b1bb51fac5..2ca4a144cc1 100755 --- a/Toolchain/BuildMold.sh +++ b/Toolchain/BuildMold.sh @@ -6,6 +6,11 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# shellcheck source=/dev/null +. "${DIR}/../Meta/shell_include.sh" + +exit_if_running_as_root "Do not run BuildMold.sh as root, parts of your Toolchain directory will become root-owned" + NPROC="nproc" SYSTEM_NAME="$(uname -s)" diff --git a/Toolchain/BuildPython.sh b/Toolchain/BuildPython.sh index a988d5ecda5..8166a32835e 100755 --- a/Toolchain/BuildPython.sh +++ b/Toolchain/BuildPython.sh @@ -5,6 +5,11 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# shellcheck source=/dev/null +. "${DIR}/../Meta/shell_include.sh" + +exit_if_running_as_root "Do not run BuildPython.sh as root, parts of your Toolchain directory will become root-owned" + PREFIX_DIR="$DIR/Local/python" BUILD_DIR="$DIR/Build/python" TARBALLS_DIR="$DIR/Tarballs" diff --git a/Toolchain/BuildQemu.sh b/Toolchain/BuildQemu.sh index 03ff3733ffd..f7a87de1abc 100755 --- a/Toolchain/BuildQemu.sh +++ b/Toolchain/BuildQemu.sh @@ -5,6 +5,11 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# shellcheck source=/dev/null +. "${DIR}/../Meta/shell_include.sh" + +exit_if_running_as_root "Do not run BuildQemu.sh as root, parts of your Toolchain directory will become root-owned" + echo "$DIR" PREFIX="$DIR/Local/qemu" diff --git a/Toolchain/BuildRuby.sh b/Toolchain/BuildRuby.sh index ec970227e26..2d2b94765fc 100755 --- a/Toolchain/BuildRuby.sh +++ b/Toolchain/BuildRuby.sh @@ -5,6 +5,11 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# shellcheck source=/dev/null +. "${DIR}/../Meta/shell_include.sh" + +exit_if_running_as_root "Do not run BuildRuby.sh as root, parts of your Toolchain directory will become root-owned" + PREFIX_DIR="$DIR/Local/ruby" BUILD_DIR="$DIR/Build/ruby" TARBALLS_DIR="$DIR/Tarballs"