From b4a0fee03d00a4cbe5e2a6dfcd2937f51562f55a Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Mon, 24 Apr 2023 21:09:23 +0200 Subject: [PATCH] Meta: Add exit_if_running_as_root() to shell_include.sh This adds the method exit_if_running_as_root() which checks if the script is executed under root, and if that's the case exits the script. --- Meta/shell_include.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Meta/shell_include.sh b/Meta/shell_include.sh index 0d95a6b880e..78aa59e9e59 100644 --- a/Meta/shell_include.sh +++ b/Meta/shell_include.sh @@ -17,6 +17,12 @@ die() { exit 1 } +exit_if_running_as_root() { + if [ "$(id -u)" -eq 0 ]; then + die "$*" + fi +} + find_executable() { paths=("/usr/sbin" "/sbin")