41 lines
1.7 KiB
Bash
41 lines
1.7 KiB
Bash
# ==============================================================================
|
|
# /etc/profile.d/pyenv.sh
|
|
# Global Pyenv Configuration for Multi-User Enterprise Environment
|
|
# ==============================================================================
|
|
|
|
# Add the globally compiled Pyenv core binaries to the system PATH
|
|
export PATH="/opt/pyenv/bin:$PATH"
|
|
|
|
# Isolate the Pyenv execution root to the current user's HOME directory
|
|
# This ensures that 'pyenv rehash' and shim generation have native write permissions
|
|
export PYENV_ROOT="$HOME/.pyenv"
|
|
|
|
# Bootstrap required directory structure inside the user's HOME if missing
|
|
if [ ! -d "$PYENV_ROOT/versions" ]; then
|
|
mkdir -p "$PYENV_ROOT/versions" "$PYENV_ROOT/shims"
|
|
fi
|
|
|
|
# Define the hook path required by Pyenv architecture plugins
|
|
export PYENV_HOOK_PATH="/opt/pyenv/hooks"
|
|
|
|
# SELF-HEALING: Detect and forcefully purge broken/orphaned symbolic links
|
|
# This prevents shell errors if an administrator uninstalls a global Python version
|
|
find "$PYENV_ROOT/versions/" -xtype l -delete 2>/dev/null
|
|
|
|
# SYNCHRONIZATION: Map globally available Python installations into the user's scope
|
|
# Individual symlinks are used so the user's Pyenv can correctly resolve each version
|
|
find /opt/pyenv/versions/ -type d -name '[23]*' | \
|
|
while read path; do
|
|
version=$(basename $path);
|
|
mkdir -p "$PYENV_ROOT/versions/$version/envs" 2>/dev/null
|
|
if [ -d "$PYENV_ROOT/versions/$version" ]; then
|
|
ln -snf /opt/pyenv/versions/$version/* \
|
|
"$PYENV_ROOT/versions/$version/" 2>/dev/null;
|
|
fi
|
|
done
|
|
|
|
# INITIALIZATION: Spawn the Pyenv environment and virtualenv managers
|
|
# into the shell session
|
|
eval "$(pyenv init -)"
|
|
eval "$(pyenv virtualenv-init -)"
|