From afd5f537d833f377e864306a7a72ceef34bb9c1b Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Thu, 8 Jul 2021 17:13:54 +0200
Subject: [PATCH] added function runas

---
 deploy_app.sh | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/deploy_app.sh b/deploy_app.sh
index 1823657..8fe2f66 100755
--- a/deploy_app.sh
+++ b/deploy_app.sh
@@ -8,6 +8,7 @@
 # 2021-05-09  v0.2  <axel.hahn@iml.unibe.ch>  chown includes dot files
 # 2021-05-14  v0.3  <axel.hahn@iml.unibe.ch>  add params (list, force, help)
 # 2021-05-27  v0.4  <axel.hahn@iml.unibe.ch>  FIX first install
+# 2021-07-08  v0.5  <axel.hahn@iml.unibe.ch>  added function "runas"
 # ======================================================================
 
 
@@ -88,6 +89,24 @@ function header(){
     echo
 }
 
+# run a command as another posix user (even if it does not have a shell)
+# to be used in taskas_*install.sh
+#
+# example:
+# runas www-data "./hooks/ondeploy"
+#
+# param  string  username
+# param  string  command to execute. Needs to be quoted.
+# param  string  optional: shell (default: /bin/sh)
+function runas(){
+    local _user=$1
+    local _cmd=$2
+    local _shell=$3
+    test -z "$_shell" && _shell=/bin/sh
+
+    su $_user -s $_shell -c "$_cmd"
+}
+
 # execute a task/ hook - if the given task script exists and has executable
 # persmissions; if not it is not an error
 # param  string  filename
-- 
GitLab