From 7366541dce1a5d08a67dc4b40bed3e873e9f95be Mon Sep 17 00:00:00 2001 From: Daniel Hansson Date: Wed, 4 Oct 2023 16:41:28 +0200 Subject: [PATCH] add root function to lib --- lib.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib.sh b/lib.sh index 6b6e75f..8eececf 100644 --- a/lib.sh +++ b/lib.sh @@ -14,6 +14,35 @@ WANIP4=$(curl -s -k -m 5 -4 https://api64.ipify.org) ############ Functions +is_root() { + if [[ "$EUID" -ne 0 ]] + then + return 1 + else + return 0 + fi +} + +root_check() { +if ! is_root +then + msg_box "Sorry, you are not root. You now have two options: + +1. Use SUDO directly: + a) :~$ sudo bash name-of-script.sh + +2. Become ROOT and then type your command: + a) :~$ sudo -i + b) :~# bash name-of-script.sh + +In both cases above you can leave out $SCRIPTS/ if the script +is directly in your PATH. + +More information can be found here: https://unix.stackexchange.com/a/3064" + exit 1 +fi +} + print_text_in_color() { printf "%b%s%b\n" "$1" "$2" "$Color_Off" }