add root function to lib

This commit is contained in:
Daniel Hansson 2023-10-04 16:41:28 +02:00 committed by GitHub
parent 077e892e6d
commit 7366541dce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

29
lib.sh
View File

@ -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"
}