#!/usr/bin/env bash set -euo pipefail # install.sh — Peeta Tools installer (small & strict, no sudo) # # Usage: # curl -fsSL https://xxx.com/install.sh | bash # # Notes: # - Installs CLI entrypoints into ~/.local/bin (no sudo) # - Appends PATH export to ~/.zshrc / ~/.bashrc (idempotent) # - For curl|bash: prints 2 lines to make current shell work immediately REPO_URL="https://github.com/peeta-ai/peeta-tools.git" INSTALL_ROOT="${HOME}/.peeta" TOOLS_DIR="${INSTALL_ROOT}/tools" BIN_DIR="${HOME}/.local/bin" PATH_LINE='export PATH="$HOME/.local/bin:$PATH"' log() { echo "[peeta-tools] $*"; } log "Installing Peeta tools..." mkdir -p "$INSTALL_ROOT" mkdir -p "$BIN_DIR" # clone / update if [ -d "$TOOLS_DIR/.git" ]; then log "Repo already exists, updating..." git -C "$TOOLS_DIR" pull --ff-only else log "Cloning repo..." git clone "$REPO_URL" "$TOOLS_DIR" fi # install bin/* log "Installing CLI tools to $BIN_DIR" for f in "$TOOLS_DIR/bin/"*; do [ -e "$f" ] || continue name="$(basename "$f")" ln -sf "$f" "$BIN_DIR/$name" chmod +x "$f" log " - installed: $name" done # append PATH to rc files (idempotent by substring) append_if_missing() { local rc="$1" [ -f "$rc" ] || touch "$rc" if grep -Fqs "$HOME/.local/bin" "$rc"; then return 0 fi { echo echo "# Added by peeta-tools installer ($(date '+%Y-%m-%d %H:%M:%S'))" echo "$PATH_LINE" } >> "$rc" } # prefer current shell rc, but keep it simple: update both if present if [ -f "$HOME/.zshrc" ]; then append_if_missing "$HOME/.zshrc"; fi if [ -f "$HOME/.bashrc" ]; then append_if_missing "$HOME/.bashrc"; fi # if neither exists, default to ~/.zshrc (your environment is zsh) if [ ! -f "$HOME/.zshrc" ] && [ ! -f "$HOME/.bashrc" ]; then append_if_missing "$HOME/.zshrc" log "Updated: $HOME/.zshrc" else log "Updated shell rc (if present): ~/.zshrc ~/.bashrc" fi log "Installation complete." echo echo "Available commands:" for f in "$TOOLS_DIR/bin/"*; do [ -e "$f" ] || continue echo " - $(basename "$f")" done echo echo "Next steps:" echo " - Ensure Python 3.11, Poetry, and gcloud are installed" echo " - Run: peeta-agent-release -h" # IMPORTANT: curl|bash cannot modify parent shell, always print this echo log "Current terminal not updated (expected for curl | bash)." log "Run these in your current shell to use commands immediately:" echo " export PATH=\"\$HOME/.local/bin:\$PATH\"" echo " hash -r"