aboutsummaryrefslogtreecommitdiff
path: root/scripts/_common.sh
diff options
context:
space:
mode:
authorJean-Baptiste Holcroft <jean-baptiste@holcroft.fr>2018-05-01 18:48:06 +0200
committerJean-Baptiste Holcroft <jean-baptiste@holcroft.fr>2018-05-01 18:48:06 +0200
commit69ddc4592be8122630130eda748ccaf85f4355a4 (patch)
tree0a5b9ee7f6182ea9fca59c82a554cc7828f19e89 /scripts/_common.sh
parentf0b132281241bcfdc38be62dd79324b78a4972f2 (diff)
downloadmastodon_ynh-69ddc4592be8122630130eda748ccaf85f4355a4.tar.gz
mastodon_ynh-69ddc4592be8122630130eda748ccaf85f4355a4.tar.bz2
mastodon_ynh-69ddc4592be8122630130eda748ccaf85f4355a4.zip
Add helpers (multi-file systemd and exec_as)
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