#!/usr/bin/env sh # RigDoctor user-local installer (no root). Creates a private venv, links the # `rigdoctor` / `rigdoctor-gui` commands into ~/.local/bin, and adds a desktop # entry. Installs from a bundled wheel (the .run installer) or from a source # checkout. Re-run to upgrade; `./install.sh --uninstall` to remove. set -eu APP_NAME=rigdoctor DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" VENV="$DATA_HOME/$APP_NAME/venv" BIN_DIR="$HOME/.local/bin" DESKTOP_DIR="$DATA_HOME/applications" DESKTOP_FILE="$DESKTOP_DIR/rigdoctor.desktop" SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) uninstall() { echo "Removing RigDoctor user-local install…" rm -rf "$VENV" rm -f "$BIN_DIR/rigdoctor" "$BIN_DIR/rigdoctor-gui" "$DESKTOP_FILE" \ "$DATA_HOME/icons/hicolor/scalable/apps/rigdoctor.svg" echo "Done. (Config and logs under ~/.config/rigdoctor and ~/.local/share/rigdoctor were kept.)" } REF="" while [ $# -gt 0 ]; do case "$1" in --uninstall) uninstall; exit 0 ;; --ref) REF="${2:-}"; [ -n "$REF" ] || { echo "--ref needs a tag"; exit 1; }; shift 2 ;; -h|--help) echo "Usage: install.sh [--ref ] [--uninstall]"; exit 0 ;; *) echo "Unknown option: $1"; exit 1 ;; esac done PY=python3 command -v "$PY" >/dev/null 2>&1 || { echo "python3 not found — install Python 3.11+."; exit 1; } "$PY" - <<'EOF' || { echo "Python 3.11+ is required."; exit 1; } import sys sys.exit(0 if sys.version_info >= (3, 11) else 1) EOF # venv support (ensurepip) is required; install python3-venv if it's missing. if ! "$PY" -c "import ensurepip" >/dev/null 2>&1; then PYVER=$("$PY" -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')") PKGS="python3-venv python${PYVER}-venv" echo "Python venv support is missing — needs: $PKGS" if command -v pkexec >/dev/null 2>&1; then ESC=pkexec elif command -v sudo >/dev/null 2>&1; then ESC=sudo else ESC=""; fi if [ -n "$ESC" ] && command -v apt-get >/dev/null 2>&1; then echo "Installing $PKGS (you may be prompted for your password)…" "$ESC" sh -c "apt-get update && apt-get install -y $PKGS" \ || { echo "Failed. Install manually: sudo apt install $PKGS"; exit 1; } else echo "Install it manually, then re-run: sudo apt install $PKGS" exit 1 fi fi # Where to install from: a specific released tag (--ref), a bundled wheel, or source. WHEEL=$(ls "$SCRIPT_DIR"/rigdoctor-*.whl 2>/dev/null | head -n1 || true) if [ -n "$REF" ]; then CONF="${XDG_CONFIG_HOME:-$HOME/.config}/rigdoctor/token" TOKEN="${RIGDOCTOR_TOKEN:-$(cat "$CONF" 2>/dev/null || true)}" [ -n "$TOKEN" ] || { echo "--ref needs a token (run 'rigdoctor login' or set RIGDOCTOR_TOKEN)."; exit 1; } SRC="rigdoctor[gui] @ git+https://oauth2:$TOKEN@git.jesseyvanofferen.com/jessey/rigdoctor.git@$REF" elif [ -n "$WHEEL" ]; then SRC="$WHEEL[gui]" elif [ -f "$SCRIPT_DIR/pyproject.toml" ]; then SRC="$SCRIPT_DIR[gui]" else echo "No bundled wheel or source found next to the installer." exit 1 fi echo "Creating venv at $VENV…" "$PY" -m venv "$VENV" "$VENV/bin/pip" install --upgrade pip >/dev/null echo "Installing RigDoctor (pulls in PySide6 — this can take a minute)…" "$VENV/bin/pip" install "$SRC" mkdir -p "$BIN_DIR" ln -sf "$VENV/bin/rigdoctor" "$BIN_DIR/rigdoctor" ln -sf "$VENV/bin/rigdoctor-gui" "$BIN_DIR/rigdoctor-gui" # Install the app icon (for the dock/launcher); fall back to a stock icon. ICON_NAME=utilities-system-monitor ICON_SRC=$("$VENV/bin/python" -c "import os, rigdoctor.gui as g; print(os.path.join(os.path.dirname(g.__file__), 'assets', 'rigdoctor.svg'))" 2>/dev/null || true) if [ -n "$ICON_SRC" ] && [ -f "$ICON_SRC" ]; then ICON_DST="$DATA_HOME/icons/hicolor/scalable/apps/rigdoctor.svg" mkdir -p "$(dirname "$ICON_DST")" cp "$ICON_SRC" "$ICON_DST" ICON_NAME=rigdoctor command -v gtk-update-icon-cache >/dev/null 2>&1 && gtk-update-icon-cache -qtf "$DATA_HOME/icons/hicolor" 2>/dev/null || true fi mkdir -p "$DESKTOP_DIR" cat > "$DESKTOP_FILE" </dev/null 2>&1 && update-desktop-database "$DESKTOP_DIR" 2>/dev/null || true echo echo "RigDoctor $("$VENV/bin/rigdoctor" --version 2>/dev/null | awk '{print $2}') installed." echo " GUI: rigdoctor-gui (or find 'RigDoctor' in your app menu)" echo " CLI: rigdoctor --help" case ":$PATH:" in *":$BIN_DIR:"*) ;; *) echo " Note: add $BIN_DIR to your PATH (a fresh login usually does this).";; esac