36 lines
1.6 KiB
Bash
Executable File
36 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Shim to emit warning and call start-notebook.py
|
|
echo "WARNING: Use start-notebook.py instead"
|
|
|
|
if id jovyan &> /dev/null; then
|
|
if ! usermod --home "/home/${NB_USER}" --login "${NB_USER}" jovyan 2>&1 | grep "no changes" > /dev/null; then
|
|
echo "Updated the jovyan user:"
|
|
echo "- username: jovyan -> ${NB_USER}"
|
|
echo "- home dir: /home/jovyan -> /home/${NB_USER}"
|
|
fi
|
|
elif ! id -u "${NB_USER}" &> /dev/null; then
|
|
echo "ERROR: Neither the jovyan user nor '${NB_USER}' exists. This could be the result of stopping and starting, the container with a different NB_USER environment variable."
|
|
exit 1
|
|
fi
|
|
# Ensure the desired user (NB_USER) gets its desired user id (NB_UID) and is
|
|
# a member of the desired group (NB_GROUP, NB_GID)
|
|
if [ "${NB_UID}" != "$(id -u "${NB_USER}")" ] || [ "${NB_GID}" != "$(id -g "${NB_USER}")" ]; then
|
|
echo "Update ${NB_USER}'s UID:GID to ${NB_UID}:${NB_GID}"
|
|
# Ensure the desired group's existence
|
|
if [ "${NB_GID}" != "$(id -g "${NB_USER}")" ]; then
|
|
groupadd --force --gid "${NB_GID}" --non-unique "${NB_GROUP:-${NB_USER}}"
|
|
fi
|
|
# Recreate the desired user as we want it
|
|
userdel "${NB_USER}"
|
|
useradd --no-log-init --home "/home/${NB_USER}" --shell /bin/bash --uid "${NB_UID}" --gid "${NB_GID}" --groups 100 "${NB_USER}"
|
|
fi
|
|
|
|
|
|
# if root change user to jovyan
|
|
if [ "$EUID" -eq 0 ]; then
|
|
echo "WARNING: Running as root. Use start-notebook.py to run as ${NB_USER} user"
|
|
exec su ${NB_USER} -c "exec /usr/local/bin/start-notebook.py $@"
|
|
else
|
|
exec /usr/local/bin/start-notebook.py "$@"
|
|
fi
|