2018-05-05 17:03:04 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-03-04 23:53:39 +01:00
|
|
|
#=================================================
|
|
|
|
# PERSONAL HELPERS
|
|
|
|
#=================================================
|
2018-08-02 09:54:43 +02:00
|
|
|
|
2019-03-04 23:53:39 +01:00
|
|
|
#=================================================
|
|
|
|
# EXPERIMENTAL HELPERS
|
|
|
|
#=================================================
|
2018-08-02 09:54:43 +02:00
|
|
|
|
2019-05-08 14:40:34 +02:00
|
|
|
# Execute a command as another user
|
|
|
|
# usage: exec_as USER COMMAND [ARG ...]
|
|
|
|
# Source : https://github.com/YunoHost-Apps/Experimental_helpers/tree/master/ynh_exec_as
|
|
|
|
exec_as() {
|
|
|
|
local USER=$1
|
|
|
|
shift 1
|
2018-08-02 09:54:43 +02:00
|
|
|
|
2019-05-08 14:40:34 +02:00
|
|
|
if [[ $USER = $(whoami) ]]; then
|
|
|
|
eval "$@"
|
|
|
|
else
|
|
|
|
sudo -u "$USER" "$@"
|
|
|
|
fi
|
2018-08-02 09:54:43 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 23:53:39 +01:00
|
|
|
#=================================================
|
|
|
|
# FUTURE OFFICIAL HELPERS
|
|
|
|
#=================================================
|