diff options
author | Tom Gundersen <teg@jklm.no> | 2011-06-18 22:30:22 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2011-06-18 22:30:22 +0200 |
commit | f5d571110b9cfe45ecb32602510c924409e52d63 (patch) | |
tree | f7738f1b652c909eb6b27103b6b9393e5af563a6 /functions | |
parent | 4cad51425325abf13b7a8772ff09f852238423c2 (diff) | |
parent | 042d197b4d989ec6461204b9d897054e5f5dd492 (diff) | |
download | initscripts-f5d571110b9cfe45ecb32602510c924409e52d63.tar.xz |
Merge remote-tracking branch 'seblu/master'
Diffstat (limited to 'functions')
-rw-r--r-- | functions | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -394,5 +394,15 @@ for f in /etc/rc.d/functions.d/*; do [[ -e $f ]] && . "$f" done +# Exit current shell if user is not root +need_root() { + (( $EUID != 0 )) && printf 'You need to be root.\n' && exit 1 +} + +# Quit script if it's not running by root +# This can be disabled in scripts sourcing functions by setting NEED_ROOT=0 +# A local call to need_root can be done to ensure part of script need root privilege +(( ${NEED_ROOT:-1} == 1 )) && need_root + # End of file # vim: set ts=2 sw=2 noet: |