diff --git a/.zshrc b/.zshrc index d688fe1..068e934 100644 --- a/.zshrc +++ b/.zshrc @@ -51,6 +51,12 @@ if command -v conda >/dev/null 2>&1; then [ -f "$CONDA_BASE/etc/profile.d/conda.sh" ] && source "$CONDA_BASE/etc/profile.d/conda.sh" fi +# 5. R and Rig +export RIG_HOME="$PROG_DIR/r" +if [ -d "$RIG_HOME/bin" ]; then + export PATH="$RIG_HOME/bin:$PATH" +fi + # Zoxide eval "$(zoxide init --cmd cd zsh)" diff --git a/Makefile b/Makefile index d8ffea9..692bb42 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ setup: bash ./scripts/go.sh bash ./scripts/rust.sh bash ./scripts/python.sh + bash ./scripts/r.sh make clean make stow @echo "Full setup completed." @@ -45,6 +46,12 @@ rust: python: bash ./scripts/python.sh +r: + bash ./scripts/r.sh + +cpp: + bash ./scripts/cpp.sh + storagebox: bash ./scripts/storagebox.sh diff --git a/scripts/cpp.sh b/scripts/cpp.sh new file mode 100644 index 0000000..b2d0c9f --- /dev/null +++ b/scripts/cpp.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Path: scripts/cpp.sh + +set -e + +BLUE='\033[1;34m' +YELLOW='\033[1;33m' +GREEN='\033[1;32m' +NC='\033[0m' + +# OS Detection +if [ -f /etc/os-release ]; then + . /etc/os-release + OS=$ID +fi + +echo -e "${BLUE} LOG:${YELLOW} Setting up C++ Tooling (LLVM/Clang)...${NC}" + +if [ "$OS" == "arch" ] || [ "$OS" == "manjaro" ]; then + sudo pacman -S --noconfirm --needed clang cmake ninja lldb gdb +elif [ "$OS" == "ubuntu" ] || [ "$OS" == "debian" ]; then + sudo DEBIAN_FRONTEND=noninteractive apt-get update + sudo DEBIAN_FRONTEND=noninteractive apt-get install -y clang cmake ninja-build lldb gdb +fi + +echo -e "${GREEN} SUCCESS:${NC} C++ Environment Ready." +echo -e " - Compiler: $(clang --version | head -n 1)" +echo -e " - Builder: $(cmake --version | head -n 1)" +echo -e " - Debugger: $(lldb --version | head -n 1)" \ No newline at end of file diff --git a/scripts/node.sh b/scripts/node.sh index 7b29f47..0051d27 100644 --- a/scripts/node.sh +++ b/scripts/node.sh @@ -1,43 +1,45 @@ #!/bin/bash -set -e + # Path: scripts/node.sh +set -e + BLUE='\033[1;34m' YELLOW='\033[1;33m' GREEN='\033[1;32m' NC='\033[0m' -# 1. Define Custom Path +# 1. Define Custom Path (The Black Box) export NVM_DIR="$HOME/.programming/node" -echo -e "${BLUE} LOG:${YELLOW} Setting up Node.js (NVM)...${NC}" +echo -e "${BLUE} LOG:${YELLOW} Setting up Node.js (NVM) in ${NVM_DIR}...${NC}" # 2. Install NVM (if missing) if [ ! -d "$NVM_DIR" ]; then mkdir -p "$NVM_DIR" echo -e "${BLUE} LOG:${YELLOW} Installing NVM to custom path...${NC}" - # PROFILE=/dev/null prevents the installer from editing your .zshrc/.bashrc + # NVM_DIR is exported above, so the install script picks it up automatically. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | PROFILE=/dev/null bash fi # 3. Source NVM (Load it into current shell) -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # 4. Install Node if command -v nvm &> /dev/null; then - echo -e "${BLUE} LOG:${YELLOW} Installing LTS...${NC}" - nvm install --lts + echo -e "${BLUE} LOG:${YELLOW} Installing Node LTS...${NC}" + + # --no-progress suppresses the progress bar spam in logs + nvm install --lts --no-progress nvm use --lts - echo -e "${BLUE} LOG:${YELLOW} Installing Global Tools...${NC}" + echo -e "${BLUE} LOG:${YELLOW} Enabling Corepack (pnpm/yarn)...${NC}" - # Disable strict error checking for npm global installs (they are noisy) - set +e - npm install -g pnpm yarn || true - set -e + corepack enable echo -e "${GREEN} LOG: Node setup complete. $(node -v)${NC}" + echo -e "${GREEN} LOG: Package Managers: pnpm $(pnpm -v), yarn $(yarn -v)${NC}" else echo -e "${RED} ERROR: NVM failed to load from $NVM_DIR${NC}" exit 1 diff --git a/scripts/r.sh b/scripts/r.sh new file mode 100644 index 0000000..539eece --- /dev/null +++ b/scripts/r.sh @@ -0,0 +1,104 @@ +#!/bin/bash + +# Path: scripts/r.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 + +echo -e "${BLUE} LOG:${YELLOW} Detecting R installation strategy for $OS...${NC}" + +# ------------------------------------------------------------------ +# STRATEGY A: ARCH LINUX (Native Pacman) +# Arch always has the latest R kernel. We don't need Rig. +# ------------------------------------------------------------------ +if [ "$OS" == "arch" ] || [ "$OS" == "manjaro" ]; then + + echo -e "${BLUE} LOG:${YELLOW} Arch Linux detected. Using system R (Pacman)...${NC}" + + # 1. Install R + Build Tools + # gcc-fortran is critical for compiling R packages + sudo pacman -S --noconfirm --needed r gcc-fortran curl tar + + echo -e "${GREEN} SUCCESS:${NC} R installed via Pacman." + + # Define R binary path for the renv step later + R_BIN="R" + +# ------------------------------------------------------------------ +# STRATEGY B: UBUNTU/DEBIAN (Rig Version Manager) +# These distros have old R versions. We need Rig to get the latest. +# ------------------------------------------------------------------ +elif [ "$OS" == "ubuntu" ] || [ "$OS" == "debian" ]; then + + # 1. Install Deps + 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 gfortran curl tar + + # 2. Setup Rig Paths + export RIG_HOME="$HOME/.programming/r" + export RIG_BIN="$RIG_HOME/bin" + export PATH="$RIG_BIN:$PATH" + + # 3. Install Rig Binary + if [ ! -f "$RIG_BIN/rig" ]; then + echo -e "${BLUE} LOG:${YELLOW} Downloading Rig binary...${NC}" + mkdir -p "$RIG_BIN" + + # Robust URL Fetching + LATEST_REL_DATA=$(curl -s https://api.github.com/repos/r-lib/rig/releases/latest) + RIG_URL=$(echo "$LATEST_REL_DATA" | grep -o 'https://[^"]*rig-linux-[^"]*\.tar\.gz' | head -n 1) + + if [ -z "$RIG_URL" ]; then + echo -e "${RED} ERROR:${NC} Could not find Rig download URL." + exit 1 + fi + + # Extract to temp + TEMP_EXTRACT=$(mktemp -d) + curl -L -s "$RIG_URL" | tar -xz -C "$TEMP_EXTRACT" + FOUND_BIN=$(find "$TEMP_EXTRACT" -name "rig" -type f | head -n 1) + + if [ -f "$FOUND_BIN" ]; then + mv "$FOUND_BIN" "$RIG_BIN/rig" + chmod +x "$RIG_BIN/rig" + else + rm -rf "$TEMP_EXTRACT"; exit 1 + fi + rm -rf "$TEMP_EXTRACT" + fi + + # 4. Install R via Rig + TARGET_VER="release" + if ! "$RIG_BIN/rig" list | grep -q "release"; then + echo -e "${BLUE} LOG:${YELLOW} Installing R (${TARGET_VER})...${NC}" + sudo "$RIG_BIN/rig" add "$TARGET_VER" --without-cran-mirror + sudo "$RIG_BIN/rig" default "$TARGET_VER" + fi + + # Define R binary path for the renv step + R_BIN="$RIG_BIN/rig run" +fi + +# ------------------------------------------------------------------ +# COMMON: RENV (Dependency Management) +# This works the same on both systems. +# ------------------------------------------------------------------ + +echo -e "${BLUE} LOG:${YELLOW} Installing 'renv' package globally...${NC}" + +# We use a small R script to install renv if missing +# Note: On Arch, $R_BIN is just "R". On Ubuntu, it might be "rig run". +$R_BIN -e 'if (!require("renv", quietly=TRUE)) install.packages("renv", repos="https://cloud.r-project.org")' + +echo -e "${GREEN} SUCCESS:${NC} R setup completed." \ No newline at end of file diff --git a/scripts/rust.sh b/scripts/rust.sh index fa0a22f..e6c954c 100644 --- a/scripts/rust.sh +++ b/scripts/rust.sh @@ -7,21 +7,27 @@ YELLOW='\033[1;33m' GREEN='\033[1;32m' NC='\033[0m' -# 1. Define Custom Paths +# 1. Define Custom Paths (The Black Box) export RUSTUP_HOME="$HOME/.programming/rust/multirust" export CARGO_HOME="$HOME/.programming/rust/cargo" -echo -e "${BLUE} LOG:${YELLOW} Setting up Rust (Rustup)...${NC}" +echo -e "${BLUE} LOG:${YELLOW} Setting up Rust (Rustup) in ${CARGO_HOME}...${NC}" # 2. Install Rustup (if missing) if [ ! -f "$CARGO_HOME/bin/rustup" ]; then echo -e "${BLUE} LOG:${YELLOW} Installing Rustup to custom path...${NC}" + + # Create parent dirs to be safe + mkdir -p "$RUSTUP_HOME" "$CARGO_HOME" + + # Install: --no-modify-path keeps your .zshrc clean (we manage it manually) curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path else echo -e "${GREEN} LOG: Rustup already installed in custom path.${NC}" fi # 3. Source Environment +# This loads cargo into the PATH for the rest of this script if [ -f "$CARGO_HOME/env" ]; then source "$CARGO_HOME/env" fi @@ -31,7 +37,13 @@ if command -v cargo &> /dev/null; then echo -e "${BLUE} LOG:${YELLOW} Updating toolchain...${NC}" rustup default stable rustup update - echo -e "${GREEN} LOG: Rust setup complete.$(cargo --version)${NC}" + + # CRITICAL FOR LEARNING: Install source code for the standard library + # This allows you to inspect 'std' code in your IDE (VS Code/Neovim) + echo -e "${BLUE} LOG:${YELLOW} Installing rust-src for 'Go to Definition'...${NC}" + rustup component add rust-src + + echo -e "${GREEN} LOG: Rust setup complete. $(cargo --version)${NC}" else echo -e "${RED} ERROR: Cargo not found in PATH. Check CARGO_HOME.${NC}" exit 1