From 5328c51211515a61f1d7885984aa1ccdc8b6b41c Mon Sep 17 00:00:00 2001 From: stefan230 Date: Fri, 10 Jan 2020 18:53:17 +0100 Subject: [PATCH] Adds check if the script was run as root or with sudo adds a simple check at the beginning of the script to determine if the script was run with root priviliges or not. If the script was run as root (or using sudo) the script will continue as normal. If not run as root the script will abort with an error. --- linux_mint.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/linux_mint.sh b/linux_mint.sh index c5c92db..692bf6f 100644 --- a/linux_mint.sh +++ b/linux_mint.sh @@ -1,5 +1,11 @@ #!/usr/bin/env bash +# Check if ran with root permissions +if [ `id -u` -ne 0 ]; then + printf "Das Script muss als root ausgeführt werden! (Du kannst auch sudo verwenden)\n" + exit 1 +fi + ### # Set variables ###