postgresql-citus-patroni-image/scripts/dumb-run-as.sh
2024-06-23 11:54:59 +03:00

18 lines
567 B
Bash
Executable File

#!/bin/sh
set -ef
_user="${1%%:*}" ; _group="${1#*:}" ; shift
getent passwd "${_user}" >/dev/null
_home=$(getent passwd "${_user}" | cut -d: -f6)
_test_dir() { setpriv --reuid="$1" --regid="$2" --init-groups test -d "$3" ; }
unset _cwd
if ! _test_dir "${_user}" "${_group}" . ; then
_cwd=${_home}
if ! _test_dir "${_user}" "${_group}" "${_cwd}" ; then
_cwd=/
fi
fi
exec \
setpriv --reuid="${_user}" --regid="${_group}" --init-groups \
env ${_cwd:+ -C "${_cwd}" } USER="${_user}" LOGNAME="${_user}" "HOME=${_home}" SHELL=/bin/sh \
"$@"