1
0
angie-conv-image/image-entry.d/12-core-user.envsh
2024-09-17 14:11:00 +03:00

71 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
if [ "${IEP_ROOT}" = 0 ] ; then
log "Running as non-root: user/group configuration may be excessive"
fi
unset _NGX_USER _NGX_GROUP
## here should be SANE defaults (!)
_NGX_USER=angie
_NGX_GROUP=angie
[ -n "${NGX_USER:-}" ] || NGX_USER=${_NGX_USER}
case "${NGX_USER}" in
"${_NGX_USER}" ) ;;
## numeric id - remap to name
[1-9]* )
_user_name=$(getent passwd "${NGX_USER}" | cut -d: -f1)
if [ -n "${_user_name}" ] ; then
NGX_USER=${_user_name}
else
log_always "NGX_USER: ID is not known in /etc/passwd: ${NGX_USER}"
log_always "setting NGX_USER=${_NGX_USER}"
NGX_USER=${_NGX_USER}
fi
unset _user_name
;;
* )
_user_name=$(getent passwd "${NGX_USER}" | cut -d: -f1)
if [ -n "${_user_name}" ] ; then
NGX_USER=${_user_name}
else
log_always "NGX_USER: name is not known in /etc/passwd: ${NGX_USER}"
log_always "setting NGX_USER=${_NGX_USER}"
NGX_USER=${_NGX_USER}
fi
unset _user_name
;;
esac
[ -n "${NGX_GROUP:-}" ] || NGX_GROUP=${_NGX_GROUP}
case "${NGX_GROUP}" in
"${_NGX_GROUP}" ) ;;
## numeric id - remap to name
[1-9]* )
_group_name=$(getent group "${NGX_GROUP}" | cut -d: -f1)
if [ -n "${_group_name}" ] ; then
NGX_GROUP=${_group_name}
else
log_always "NGX_GROUP: ID is not known in /etc/group: ${NGX_GROUP}"
log_always "setting NGX_GROUP=${_NGX_GROUP}"
NGX_GROUP=${_NGX_GROUP}
fi
unset _group_name
;;
* )
_group_name=$(getent group "${NGX_GROUP}" | cut -d: -f1)
if [ -n "${_group_name}" ] ; then
NGX_GROUP=${_group_name}
else
log_always "NGX_GROUP: name is not known in /etc/group: ${NGX_GROUP}"
log_always "setting NGX_GROUP=${_NGX_GROUP}"
NGX_GROUP=${_NGX_GROUP}
fi
unset _group_name
;;
esac
export NGX_USER NGX_GROUP
unset _NGX_USER _NGX_GROUP