aboutsummaryrefslogtreecommitdiff
path: root/scripts/_common.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/_common.sh')
-rw-r--r--scripts/_common.sh14
1 files changed, 14 insertions, 0 deletions
diff --git a/scripts/_common.sh b/scripts/_common.sh
index dce035f..7d4f823 100644
--- a/scripts/_common.sh
+++ b/scripts/_common.sh
@@ -1,5 +1,19 @@
#!/bin/bash
+
+# Execute a command as another user
+# usage: exec_as USER COMMAND [ARG ...]
+exec_as() {
+ local user=$1
+ shift 1
+
+ if [[ $user = $(whoami) ]]; then
+ eval "$@"
+ else
+ sudo --login --user="$user" "$@"
+ fi
+}
+
#=================================================
#
# POSTGRES HELPERS