-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·119 lines (104 loc) · 4.24 KB
/
install.sh
File metadata and controls
executable file
·119 lines (104 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
#
# Claude Code Hooks Daemon - One-Line Installer (Layer 1)
#
# Usage:
# curl -sSL https://raw.githubusercontent.com/Edmonds-Commerce-Limited/claude-code-hooks-daemon/main/install.sh -o /tmp/hooks-daemon-install.sh && bash /tmp/hooks-daemon-install.sh
#
# This is a minimal Layer 1 script that:
# 1. Validates project root (.claude and .git must exist)
# 2. Clones daemon repository to .claude/hooks-daemon/
# 3. Delegates to Layer 2 (scripts/install_version.sh) for full setup
# 4. Falls back to legacy install.py if Layer 2 not available
#
# Environment variables:
# DAEMON_BRANCH - Git branch/tag to install (default: main)
# FORCE - Set to "true" to reinstall over existing installation
#
set -euo pipefail
# Configuration
DAEMON_REPO="https://github.com/Edmonds-Commerce-Limited/claude-code-hooks-daemon.git"
DAEMON_BRANCH="${DAEMON_BRANCH:-main}"
FORCE="${FORCE:-false}"
# Minimal output functions (can't source library before clone)
if [ -t 1 ]; then
_RED='\033[0;31m'; _GREEN='\033[0;32m'; _YELLOW='\033[1;33m'
_BLUE='\033[0;34m'; _NC='\033[0m'
else
_RED=''; _GREEN=''; _YELLOW=''; _BLUE=''; _NC=''
fi
_ok() { echo -e "${_GREEN}OK${_NC} $1"; }
_err() { echo -e "${_RED}ERR${_NC} $1" >&2; }
_warn() { echo -e "${_YELLOW}WARN${_NC} $1"; }
_info() { echo -e "${_BLUE}>>>${_NC} $1"; }
_fail() { _err "$1"; echo ""; echo "Installation aborted."; exit 1; }
# ============================================================
# Main
# ============================================================
echo ""
echo "============================================================"
echo " Claude Code Hooks Daemon - Installer"
echo "============================================================"
echo ""
PROJECT_ROOT="$(pwd)"
DAEMON_DIR="$PROJECT_ROOT/.claude/hooks-daemon"
# Step 1: Minimal prerequisites (git required for clone)
_info "Checking prerequisites..."
command -v git &>/dev/null || _fail "git is not installed. Please install git first."
_ok "git found"
# Step 2: Validate project root
_info "Validating project root..."
[ -d ".claude" ] || _fail "No .claude directory found. Run from a Claude Code project root."
[ -d ".git" ] || _fail "No .git directory found. Run from a git repository root."
git remote get-url origin 2>/dev/null || _fail "No git remote 'origin' configured.
The daemon requires a remote named 'origin'.
Fix: git remote add origin <your-repo-url>"
_ok "Project root: $PROJECT_ROOT"
# Step 3: Clone daemon repository
_info "Checking daemon installation..."
if [ -d "$DAEMON_DIR" ]; then
if [ "$FORCE" = "true" ]; then
_warn "Removing existing installation (FORCE=true)..."
rm -rf "$DAEMON_DIR"
else
_err "Daemon already installed at $DAEMON_DIR"
echo ""
echo "To reinstall: curl -sSL <url> | FORCE=true bash"
echo "Or remove: rm -rf $DAEMON_DIR"
exit 1
fi
fi
_info "Cloning from $DAEMON_REPO (branch: $DAEMON_BRANCH)..."
if ! git clone --branch "$DAEMON_BRANCH" --depth 1 "$DAEMON_REPO" "$DAEMON_DIR" >/dev/null 2>&1; then
_fail "Failed to clone daemon repository"
fi
_ok "Daemon cloned to $DAEMON_DIR"
# Step 4: Delegate to Layer 2 (with fallback to legacy)
LAYER2_SCRIPT="$DAEMON_DIR/scripts/install_version.sh"
if [ -f "$LAYER2_SCRIPT" ]; then
_info "Delegating to version-specific installer..."
exec bash "$LAYER2_SCRIPT" "$PROJECT_ROOT" "$DAEMON_DIR"
else
# Fallback: legacy install flow for older tags without Layer 2
_warn "Layer 2 installer not found (older version). Using legacy flow..."
# Legacy: install dependencies
_info "Installing dependencies with uv..."
if command -v uv &>/dev/null || {
curl -LsSf https://astral.sh/uv/install.sh | sh >/dev/null 2>&1
export PATH="$HOME/.local/bin:$PATH"
command -v uv &>/dev/null
}; then
cd "$DAEMON_DIR"
mkdir -p untracked
echo "/untracked/" > untracked/.gitignore
UV_PROJECT_ENVIRONMENT="$(pwd)/untracked/venv" uv sync --project . >/dev/null 2>&1 || true
cd - >/dev/null
fi
# Legacy: run install.py
if [ -f "$DAEMON_DIR/install.py" ]; then
_info "Running legacy installer (install.py)..."
python3 "$DAEMON_DIR/install.py" --force
else
_fail "No installer found in cloned repository"
fi
fi