From 54c91f756ca084b873ed985a029eb301cea814db Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 22 Apr 2020 08:05:42 +0200 Subject: [PATCH] Adding function check_for_root() --- lib/functions.rc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/functions.rc b/lib/functions.rc index ae808a0..767201a 100644 --- a/lib/functions.rc +++ b/lib/functions.rc @@ -10,7 +10,7 @@ BLUE="" CYAN="" NORMAL="" -VERSION="0.2.0" +VERSION="0.3.0" STD_SHORT_OPTIONS="sdvhV" STD_LONG_OPTIONS="simulate,debug,verbose,nocolor,help,version" @@ -338,4 +338,14 @@ set_locale() { } +#------------------------------------------------------------------------------ +check_for_root() { + local my_id=$( id -u ) + if [[ "${my_id}" != "0" ]] ; then + error "You must be ${RED}root${NORMAL} to execute this script." + echo >&2 + exit 1 + fi +} + # vim: filetype=sh ts=4 et list -- 2.39.5