This repository was archived by the owner on Apr 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·182 lines (166 loc) · 6.57 KB
/
setup
File metadata and controls
executable file
·182 lines (166 loc) · 6.57 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env bash
# heygen-stack setup — first-time installation for Claude Code and OpenClaw users.
# Idempotent: safe to run multiple times.
set -euo pipefail
# ─── Colors (degrade gracefully) ─────────────────────────────
if [ -t 1 ] && command -v tput &>/dev/null && [ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]; then
GREEN=$(tput setaf 2) YELLOW=$(tput setaf 3) RED=$(tput setaf 1) BOLD=$(tput bold) RESET=$(tput sgr0)
else
GREEN="" YELLOW="" RED="" BOLD="" RESET=""
fi
ok() { echo "${GREEN}✓${RESET} $1"; }
warn() { echo "${YELLOW}!${RESET} $1"; }
err() { echo "${RED}✗${RESET} $1"; }
# ─── Locate repo root ────────────────────────────────────────
STACK_DIR="$(cd "$(dirname "$0")" && pwd)"
if [ ! -f "$STACK_DIR/SKILL.md" ]; then
err "Cannot find SKILL.md — run this script from the heygen-stack repo root."
exit 1
fi
# ─── Parse flags ────────────────────────────────────────────
HOST_OVERRIDE=""
while [ $# -gt 0 ]; do
case "$1" in
--host)
shift
if [ $# -eq 0 ]; then
err "--host requires a value: claude or openclaw"
exit 1
fi
case "$1" in
claude|claude-code) HOST_OVERRIDE="claude-code" ;;
openclaw) HOST_OVERRIDE="openclaw" ;;
*)
err "Unknown host agent: $1 (expected: claude or openclaw)"
exit 1
;;
esac
shift
;;
--host=*)
val="${1#--host=}"
case "$val" in
claude|claude-code) HOST_OVERRIDE="claude-code" ;;
openclaw) HOST_OVERRIDE="openclaw" ;;
*)
err "Unknown host agent: $val (expected: claude or openclaw)"
exit 1
;;
esac
shift
;;
*)
warn "Unknown flag: $1"
shift
;;
esac
done
# ─── Detect host agent ───────────────────────────────────────
# Priority: 1) --host flag, 2) script path, 3) directory existence fallback
AGENT="unknown"
SKILLS_DIR=""
if [ -n "$HOST_OVERRIDE" ]; then
# Explicit --host flag takes highest priority
AGENT="$HOST_OVERRIDE"
elif [[ "$STACK_DIR" == *"/.openclaw/workspace/skills/"* ]]; then
AGENT="openclaw"
elif [[ "$STACK_DIR" == *"/.claude/skills/"* ]]; then
AGENT="claude-code"
elif [ -d "$HOME/.openclaw" ] && [ -d "$HOME/.claude" ]; then
# Both installed — path was ambiguous, warn and ask for --host
warn "Both Claude Code and OpenClaw detected. Cannot auto-detect host agent."
warn "Re-run with: ./setup --host claude OR ./setup --host openclaw"
elif [ -d "$HOME/.claude" ]; then
AGENT="claude-code"
elif [ -d "$HOME/.openclaw" ]; then
AGENT="openclaw"
fi
# Set skills directory based on detected agent
case "$AGENT" in
claude-code) SKILLS_DIR="$HOME/.claude/skills" ;;
openclaw) SKILLS_DIR="$HOME/.openclaw/workspace/skills" ;;
esac
echo ""
echo "${BOLD}HeyGen Stack Setup${RESET}"
echo "─────────────────────────────"
if [ "$AGENT" = "unknown" ]; then
warn "Could not detect Claude Code or OpenClaw. See INSTALL.md for manual setup."
else
ok "Detected host agent: ${BOLD}${AGENT}${RESET}"
fi
# ─── Create skill symlinks ───────────────────────────────────
SKILLS=(heygen-avatar heygen-video)
if [ -n "$SKILLS_DIR" ]; then
STACK_SKILL_DIR="$SKILLS_DIR/heygen-stack"
mkdir -p "$STACK_SKILL_DIR"
for skill in "${SKILLS[@]}"; do
src="$STACK_DIR/$skill/SKILL.md"
[ ! -f "$src" ] && { warn "Skipping $skill — SKILL.md not found"; continue; }
mkdir -p "$STACK_SKILL_DIR/$skill" "$SKILLS_DIR/$skill"
ln -sf "$src" "$STACK_SKILL_DIR/$skill/SKILL.md"
ln -sf "$src" "$SKILLS_DIR/$skill/SKILL.md"
done
ln -sf "$STACK_DIR/SKILL.md" "$STACK_SKILL_DIR/SKILL.md"
[ -d "$STACK_DIR/references" ] && ln -sfn "$STACK_DIR/references" "$STACK_SKILL_DIR/references"
ok "Skill symlinks created in ${SKILLS_DIR}"
for skill in "${SKILLS[@]}"; do echo " ${skill}/SKILL.md"; done
fi
# ─── Persistent config ──────────────────────────────────────
HEYGEN_CONFIG_DIR="$HOME/.heygen"
HEYGEN_CONFIG="$HEYGEN_CONFIG_DIR/config"
# Load key from config file if env var is not set
if [ -z "${HEYGEN_API_KEY:-}" ] && [ -f "$HEYGEN_CONFIG" ]; then
# shellcheck source=/dev/null
source "$HEYGEN_CONFIG"
fi
# ─── Check HEYGEN_API_KEY ────────────────────────────────────
echo ""
if [ -z "${HEYGEN_API_KEY:-}" ]; then
echo " Get your key: ${BOLD}https://app.heygen.com/settings/api${RESET}"
echo ""
if [ -t 0 ]; then
printf " Enter your HeyGen API key: "
read -r HEYGEN_API_KEY
if [ -z "$HEYGEN_API_KEY" ]; then
warn "No key entered. You can set it later:"
echo " export HEYGEN_API_KEY=<your-key>"
echo " Or re-run ./setup"
fi
else
warn "HEYGEN_API_KEY is not set (non-interactive shell)."
echo " Set it manually: export HEYGEN_API_KEY=<your-key>"
echo " Or re-run ./setup in an interactive terminal."
fi
fi
if [ -n "${HEYGEN_API_KEY:-}" ]; then
echo -n "Validating API key... "
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://api.heygen.com/v3/users/me" \
-H "X-Api-Key: $HEYGEN_API_KEY" 2>/dev/null || echo "000")
if [ "$HTTP_CODE" = "200" ]; then
ok "API key is valid."
# Persist to ~/.heygen/config
mkdir -p "$HEYGEN_CONFIG_DIR"
echo "HEYGEN_API_KEY=$HEYGEN_API_KEY" > "$HEYGEN_CONFIG"
chmod 600 "$HEYGEN_CONFIG"
ok "Key saved to ${BOLD}~/.heygen/config${RESET} (persists across sessions)."
else
err "API key validation failed (HTTP $HTTP_CODE)."
echo " Check your key: https://app.heygen.com/settings/api"
fi
fi
# ─── Summary ─────────────────────────────────────────────────
echo ""
echo "${BOLD}Installed skills:${RESET}"
for skill in "${SKILLS[@]}"; do
echo " - $skill"
done
echo ""
echo "${BOLD}Next steps:${RESET}"
if [ -z "${HEYGEN_API_KEY:-}" ]; then
echo " 1. Re-run ./setup and enter your API key, or:"
echo " export HEYGEN_API_KEY=<your-key>"
echo " 2. Ask your agent: \"Create my HeyGen avatar\""
else
echo " Ask your agent: \"Create my HeyGen avatar\""
fi
echo ""