about summary refs log tree commit diff
path: root/tools/test-sudo-wrapper.sh
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2015-01-22 00:29:53 +0100
committerMichael Biebl <biebl@debian.org>2015-01-22 00:29:53 +0100
commit4d939c60d4ac257a2977871baf3b8b3671b5a4f7 (patch)
tree318c08dea542d7865422af76e2d36a9559340cd3 /tools/test-sudo-wrapper.sh
parentbb9eef75b2aaaab741e2b99911c8be3db6d1bc0b (diff)
parent2c032d8f1c6292c1338a615e6ec40252889ba85c (diff)
Merge tag 'upstream/1.0.0' into experimental
Upstream version 1.0.0
Diffstat (limited to 'tools/test-sudo-wrapper.sh')
-rwxr-xr-xtools/test-sudo-wrapper.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/test-sudo-wrapper.sh b/tools/test-sudo-wrapper.sh
new file mode 100755
index 00000000..b375368e
--- /dev/null
+++ b/tools/test-sudo-wrapper.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+CMD="$1"
+shift;
+
+# convert the libtool internal path
+resolve_cmd() {
+    local C="$1"
+
+    local C2="$(echo "$C" | sed 's#^\(.*/\)\.libs/lt-\([^/]\+\)$#\1\2#')"
+    if [[ "$C2" != "$C" && ! -x "$C2" ]]; then
+        # such a file does not exist... back to $C
+        C2="$C"
+    fi
+    echo "$C2"
+}
+
+if [[ $UID == 0 ]]; then
+    # we are already root. Execute directly.
+    exec "$(resolve_cmd "$CMD")" "$@"
+elif [[ "$NMTST_SUDO_NO_CALL_SELF" != "" ]]; then
+    # when setting $NMTST_SUDO_NO_CALL_SELF, pass the (resolved) command
+    # directly to sudo.
+    exec sudo "$(resolve_cmd "$CMD")" "$@"
+else
+    # by default, call self again with sudo.
+    exec sudo -E "$0" "$CMD" "$@"
+fi
+