summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-08-11 17:15:13 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2018-08-11 17:15:13 -0400
commit33038503143e7f5e3e3b48c0aa4dadd142c229e6 (patch)
tree3416e2dd11c20de782ddb0c6a1fe329392b4bf15 /lib
parentae58deb68af6c7f147b7e96b27444599e0f364bc (diff)
more
Diffstat (limited to 'lib')
-rw-r--r--lib/osi.sh22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/osi.sh b/lib/osi.sh
index f32e49d..4ee758b 100644
--- a/lib/osi.sh
+++ b/lib/osi.sh
@@ -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