Neubauer-Group / dgx-setup

New user setup for DGX
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Restoring shell defaults and development setup on HAL DGX #14

Open matthewfeickert opened 2 years ago

matthewfeickert commented 2 years ago

After the NCSA team setup a login node for the HAL DGX box (c.f. Access hal-dgx and overdrive with hal-login3 Node) the .bash_profile based setup workflow failed as

When invoked as an interactive login shell, Bash looks for the /etc/profile file, and if the file exists, it runs the commands listed in the file. Then Bash searches for ~/.bash_profile, ~/.bash_login, and ~/.profile files, in the listed order, and executes commands from the first readable file found.

When Bash is invoked as an interactive non-login shell, it reads and executes commands from ~/.bashrc, if that file exists, and it is readable.

So as the NCSA team

... have prepared a hal-login3 machine as a login node so that users can request computational resources from hal-dgx and overdrive.

then when an interactive session on HAL DGX is requested it will not be a login shell and so ~/.bash_profile will never be sourced.

The solution then is to move all the components that were in ~.bash_profile into ~/.basrc_user. So this will require rewrites of migrate_home.sh and pyenv_setup.sh.

matthewfeickert commented 2 years ago

So this is what a .bashrc_user that works would look like

#!/usr/bin/env bash

export __HOME="/home/${USER}"
export HOME="/raid/projects/${USER}"

# Enable .pythonrc.py
if [ -f "${HOME}/.pythonrc.py" ]; then
    export PYTHONSTARTUP="${HOME}/.pythonrc.py"
fi

# Ensure local virtualenv setup
if [ ! -f "${HOME}/opt/venv/bin/virtualenv" ]; then
    curl -sL --location --output /tmp/virtualenv.pyz https://bootstrap.pypa.io/virtualenv.pyz
    python3 /tmp/virtualenv.pyz ~/opt/venv
    ~/opt/venv/bin/pip install --upgrade pip
    ~/opt/venv/bin/pip install virtualenv
    mkdir -p ~/bin  # Ensure exists if new machine
    ln -s ~/opt/venv/bin/virtualenv ~/bin/virtualenv
fi

# pyenv setup
export PYENV_ROOT="${HOME}/.pyenv"
export PATH="${PYENV_ROOT}/bin:${PATH}"

eval "$(pyenv init -)"

# Place pyenv shims on path
if [[ ":${PATH}:" != *":$(pyenv root)/shims:"* ]]; then
  eval "$(pyenv init --path)"
fi
# Place pyenv-virtualenv shims on path
if [[ ":${PATH}:" != *":$(pyenv root)/plugins/pyenv-virtualenv/shims:"* ]]; then
  eval "$(pyenv virtualenv-init -)"
fi

# default venv
if [ -d "${HOME}/.pyenv/versions/base" ]; then
    pyenv activate base
fi

# Add GPG key
export GPG_TTY=$(tty)

# User specific environment and startup programs
cd "${HOME}"

PATH="${PATH}:${HOME}/.local/bin:${HOME}/bin"
export PATH