summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
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