diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2018-08-11 17:15:13 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2018-08-11 17:15:13 -0400 |
commit | 33038503143e7f5e3e3b48c0aa4dadd142c229e6 (patch) | |
tree | 3416e2dd11c20de782ddb0c6a1fe329392b4bf15 /lib | |
parent | ae58deb68af6c7f147b7e96b27444599e0f364bc (diff) |
more
Diffstat (limited to 'lib')
-rw-r--r-- | lib/osi.sh | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -26,18 +26,36 @@ in_array() { return 1 } +is_sudo() { + (( UID == 0 && ${SUDO_UID:-0} != 0 )) +} + +is_root() { + (( UID = 0 )) +} + needs_sudo() { - if (( UID != 0 || ${SUDO_UID:-0} == 0 )); then + if ! is_sudo; then error 4 "Must be invoked through sudo." fi } needs_root() { - if (( UID != 0 )); then + if ! is_root; then error 4 "Must be invoked as root." fi } +become_sudo() { + if is_sudo; then + return 0 + fi + if is_root; then + needs_sudo + fi + sudo "${BASH_SOURCE[0]}" "$@" +} + with_mount() { arg_device=$1 arg_mountpoint=$2 |