#!/bin/bash # Path: scripts/python.sh set -e BLUE='\033[1;34m' YELLOW='\033[1;33m' GREEN='\033[1;32m' RED='\033[1;31m' NC='\033[0m' # OS Detection if [ -f /etc/os-release ]; then . /etc/os-release OS=$ID fi # 1. Install Build Dependencies if [ "$OS" == "arch" ] || [ "$OS" == "manjaro" ]; then echo -e "${BLUE} LOG:${YELLOW} Installing Arch build dependencies...${NC}" sudo pacman -S --noconfirm --needed base-devel openssl zlib xz tk libffi bzip2 git elif [ "$OS" == "ubuntu" ] || [ "$OS" == "debian" ]; then echo -e "${BLUE} LOG:${YELLOW} Installing Debian build dependencies...${NC}" sudo DEBIAN_FRONTEND=noninteractive apt-get update sudo DEBIAN_FRONTEND=noninteractive apt-get install -y make build-essential libssl-dev zlib1g-dev \ libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \ libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev git fi # 2. Define the Black Box Location export PYENV_ROOT="$HOME/.programming/python/pyenv" export PATH="$PYENV_ROOT/bin:$PATH" echo -e "${BLUE} LOG:${YELLOW} Setting up Pyenv in ${PYENV_ROOT}...${NC}" # 3. Install Pyenv if [ ! -d "$PYENV_ROOT" ]; then echo -e "${BLUE} LOG:${YELLOW} Cloning Pyenv...${NC}" git clone https://github.com/pyenv/pyenv.git "$PYENV_ROOT" echo -e "${BLUE} LOG:${YELLOW} Compiling Pyenv dynamic bash extension...${NC}" cd "$PYENV_ROOT" && src/configure && make -C src echo -e "${GREEN} SUCCESS:${NC} Pyenv installed." else echo -e "${GREEN} SKIP:${NC} Pyenv already installed." fi # Initialize Pyenv for this script session eval "$(pyenv init -)" # 4. Install Miniforge (The Community Standard) TARGET_VER="miniforge3-latest" if ! pyenv versions | grep -q "$TARGET_VER"; then echo -e "${BLUE} LOG:${YELLOW} Installing ${TARGET_VER}...${NC}" echo -e "${YELLOW} NOTE: This avoids Anaconda licensing issues and uses conda-forge default.${NC}" pyenv install "$TARGET_VER" echo -e "${GREEN} SUCCESS:${NC} Miniforge installed." else echo -e "${GREEN} SKIP:${NC} Miniforge already installed." fi # 5. Set Global Default pyenv global "$TARGET_VER" echo -e "${GREEN} SUCCESS:${NC} Python setup completed. Default is now Miniforge (Conda)."