diff options
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 |