Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colorize terminals even when home is overridden #575

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions base-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ RUN echo "Installing Miniforge..." \
# quite a bit unfortunately - see https://github.com/2i2c-org/infrastructure/issues/2047
&& find ${CONDA_DIR} -follow -type f -name '*.a' -delete

# Default to using /etc/skel/.profile and /etc/skel/.bashrc if not in the user's
# home directory.
USER root
RUN echo ". /etc/bash.bashrc-skel-appendix" >> /etc/bash.bashrc
COPY bash.bashrc-skel-appendix /etc/bash.bashrc-skel-appendix
USER ${NB_USER}

EXPOSE 8888
ENTRYPOINT ["/srv/start"]
#CMD ["jupyter", "notebook", "--ip", "0.0.0.0"]
Expand Down
70 changes: 70 additions & 0 deletions base-image/bash.bashrc-skel-appendix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# /etc/skel files should have been copied to a user's home directory, but if the
# user's home directory is mounted for example it may not contain files initially
# copied from /etc/skel. This can lead to terminals without colors etc.
#
# This script is made to be sourced from the end of /etc/bash.bashrc in order to
# default to source files from /etc/skel as a fallback to missing files in the
# home directory.
#
# ref: https://github.com/pangeo-data/pangeo-docker-images/issues/574.
#

# ~/.bash_profile, ~/.bash_login, or ~/.profile are defined, it doesn't make
# sense to fallback to /etc/skel/.profile, so then return.
[ -f "$HOME/.bash_profile" ] && return
[ -f "$HOME/.bash_login" ] && return
[ -f "$HOME/.profile" ] && return

# /etc/skel/.profile directly sources ~/.bashrc if defined, so we first check if
# it isn't, and then sources /etc/skel/.bashrc instead.
#
if [ ! -f "$HOME/.bashrc" ]; then
. /etc/skel/.bashrc

# --------------------------------------------------------------------------
# The section below is adjusted from an Ubuntu 22.04 /etc/skel/.bashrc file
# in order to tweak how PS1 was set, influencing the terminal color, prompt
# and title.
#
# CHANGES:
# - removed "#" from the line with force_color_prompt=yes
# - removed "@\h" from PS1's prompt section
# - removed "\u@\h: " from the PS1's xterm title section
# --------------------------------------------------------------------------

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\w\a\]$PS1"
;;
*)
;;
esac
fi


# Now run /etc/skel/.profile as it wasn't in the user's home directory.
. /etc/skel/.profile