-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·310 lines (286 loc) · 9.39 KB
/
setup.sh
File metadata and controls
executable file
·310 lines (286 loc) · 9.39 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/bin/bash
#
# wp-coding-agents setup script
# Bootstrap WordPress + Data Machine + a coding agent on a VPS or local machine
# with a pluggable chat interface layer and auto-discovered runtime modules.
#
# Usage:
# Fresh VPS: SITE_DOMAIN=example.com ./setup.sh
# Existing WP: EXISTING_WP=/var/www/mysite ./setup.sh --existing
# Local (macOS): EXISTING_WP=/path/to/wordpress ./setup.sh --local
# Claude Code: ./setup.sh --runtime claude-code
# Without Discord: ./setup.sh --no-chat
#
# Data Machine is the substrate wp-coding-agents composes on top of — memory
# files (SOUL/MEMORY/USER/RULES/SITE), auto-composed AGENTS.md, skills,
# workspace primitive, MCP surface. It is not optional. Uninstall the plugin
# later if you don't want it.
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Source shared modules
for lib in common detect wordpress infrastructure data-machine skills chat-bridge summary; do
source "$SCRIPT_DIR/lib/${lib}.sh"
done
# Discover available runtimes from runtimes/ directory
AVAILABLE_RUNTIMES=()
for runtime_file in "$SCRIPT_DIR"/runtimes/*.sh; do
[ -f "$runtime_file" ] || continue
name=$(basename "$runtime_file" .sh)
AVAILABLE_RUNTIMES+=("$name")
done
# ============================================================================
# Parse arguments
# ============================================================================
MODE="fresh"
LOCAL_MODE=false
SKIP_DEPS=false
SKIP_SSL=false
INSTALL_CHAT=true
CHAT_BRIDGE=""
SHOW_HELP=false
DRY_RUN=false
RUN_AS_ROOT=true
MULTISITE=false
MULTISITE_TYPE="subdirectory"
INSTALL_SKILLS=true
SKILLS_ONLY=false
RUNTIME_ONLY=false
RUNTIME=""
DETECTED_RUNTIMES=()
IS_STUDIO=false
while [[ $# -gt 0 ]]; do
case $1 in
--skills-only)
SKILLS_ONLY=true
shift
;;
--existing)
MODE="existing"
shift
;;
--wp-path)
MODE="existing"
EXISTING_WP="$2"
shift 2
;;
--local)
LOCAL_MODE=true
MODE="existing"
SKIP_DEPS=true
SKIP_SSL=true
RUN_AS_ROOT=false
shift
;;
--skip-deps)
SKIP_DEPS=true
shift
;;
--no-chat)
INSTALL_CHAT=false
shift
;;
--chat)
CHAT_BRIDGE="$2"
shift 2
;;
--skip-ssl)
SKIP_SSL=true
shift
;;
--root)
RUN_AS_ROOT=true
shift
;;
--non-root)
RUN_AS_ROOT=false
shift
;;
--dry-run)
DRY_RUN=true
shift
;;
--multisite)
MULTISITE=true
shift
;;
--subdomain)
MULTISITE_TYPE="subdomain"
shift
;;
--no-skills)
INSTALL_SKILLS=false
shift
;;
--runtime-only)
RUNTIME_ONLY=true
MODE="existing"
shift
;;
--runtime)
RUNTIME="$2"
shift 2
;;
--agent-slug)
AGENT_SLUG="$2"
shift 2
;;
--agent-name)
AGENT_NAME="$2"
shift 2
;;
--help|-h)
SHOW_HELP=true
shift
;;
*)
shift
;;
esac
done
if [ "$SHOW_HELP" = true ]; then
cat << HELP
wp-coding-agents setup script
Bootstrap WordPress + Data Machine + a coding agent on a VPS or local machine,
with a pluggable chat bridge for talking to your agent.
Available runtimes: ${AVAILABLE_RUNTIMES[*]}
USAGE:
Fresh VPS: SITE_DOMAIN=example.com ./setup.sh
Existing WordPress: EXISTING_WP=/var/www/mysite ./setup.sh --existing
Local (macOS/Linux): EXISTING_WP=/path/to/wordpress ./setup.sh --local
With Claude Code: ./setup.sh --runtime claude-code --existing
With Studio Code: ./setup.sh --runtime studio-code --local
OPTIONS:
--existing Add agent to existing WordPress (skip WP install)
--wp-path <path> Path to WordPress root (implies --existing)
--local Local machine mode (skip infrastructure: no apt, nginx,
systemd, SSL, service users). Works with any local
WordPress install (Studio, MAMP, manual, etc.)
--runtime <name> Coding agent runtime (auto-detected if omitted)
Available: ${AVAILABLE_RUNTIMES[*]}
--agent-slug <s> Override Data Machine agent slug (default: derived from domain)
--agent-name <n> Override Data Machine agent display name (default: blogname)
--no-chat Skip chat bridge installation
--chat <bridge> Chat bridge to install (default: kimaki for opencode,
cc-connect for claude-code)
Supported: kimaki (Discord), cc-connect, telegram
--skip-deps Skip apt package installation
--multisite Convert to WordPress Multisite (subdirectory by default)
--subdomain Use subdomain multisite (requires wildcard DNS; use with --multisite)
--no-skills Skip WordPress agent skills installation
--skills-only Only run skills installation on existing site
--skip-ssl Skip SSL/HTTPS configuration
--root Run agent as root (default)
--non-root Run agent as dedicated service user (opencode)
--dry-run Print commands without executing
--help, -h Show this help
ENVIRONMENT VARIABLES:
SITE_DOMAIN Domain for fresh install (required)
SITE_PATH WordPress path (default: /var/www/\$SITE_DOMAIN)
EXISTING_WP Path to existing WordPress (required with --existing)
DB_NAME Database name (fresh install only)
DB_USER Database user (fresh install only)
DB_PASS Database password (auto-generated if not set)
AGENT_SLUG Override agent slug (default: derived from domain)
AGENT_NAME Override agent display name (default: blogname)
OPENCODE_MODEL Override default model (e.g., anthropic/claude-sonnet-4-20250514)
OPENCODE_SMALL_MODEL Override small model (e.g., anthropic/claude-haiku-4-5)
KIMAKI_BOT_TOKEN Discord bot token (skip interactive setup)
TELEGRAM_BOT_TOKEN Telegram bot token from @BotFather (--chat telegram)
TELEGRAM_ALLOWED_USER_ID Numeric Telegram user ID (--chat telegram)
OPENCODE_MODEL_PROVIDER Default model provider for Telegram bot (default: opencode)
OPENCODE_MODEL_ID Default model ID for Telegram bot (default: big-pickle)
EXTRA_PLUGINS Space-separated slug:url pairs for additional plugins
MCP_SERVERS JSON object merged into runtime config (requires jq)
WP_CMD Override WP-CLI command (default: wp; e.g., "studio wp")
MIGRATION WORKFLOW:
1. On old server: Export database and wp-content
mysqldump dbname > backup.sql
tar -czf wp-content.tar.gz wp-content/
2. On new VPS: Import and run setup
mysql dbname < backup.sql
tar -xzf wp-content.tar.gz -C /var/www/mysite/
EXISTING_WP=/var/www/mysite ./setup.sh --existing
HELP
exit 0
fi
# ============================================================================
# Runtime resolution
# ============================================================================
# Auto-detect runtime(s).
#
# RUNTIME is the "primary" runtime — the one that drives runtime_install,
# runtime_generate_config, runtime_install_hooks, and the chat-bridge default.
# First-match cascade: studio-code > claude-code > opencode.
#
# DETECTED_RUNTIMES is the list of ALL runtimes whose binary is present. On a
# machine with both claude and opencode installed, skills get installed into
# every detected runtime's skills dir (see install_skills in lib/skills.sh).
# Explicit --runtime <name> narrows both lists to that single runtime.
if [ -n "$RUNTIME" ]; then
# User passed --runtime explicitly — respect it, single-runtime mode.
DETECTED_RUNTIMES=("$RUNTIME")
else
if command -v studio &>/dev/null && [ "${IS_STUDIO:-false}" = true ]; then
DETECTED_RUNTIMES+=("studio-code")
fi
if command -v claude &>/dev/null; then
DETECTED_RUNTIMES+=("claude-code")
fi
if command -v opencode &>/dev/null; then
DETECTED_RUNTIMES+=("opencode")
fi
if [ ${#DETECTED_RUNTIMES[@]} -eq 0 ]; then
# Nothing installed yet — default to opencode (will be installed).
DETECTED_RUNTIMES=("opencode")
fi
# Primary = first match in the cascade above.
RUNTIME="${DETECTED_RUNTIMES[0]}"
fi
# Source the selected runtime
RUNTIME_FILE="$SCRIPT_DIR/runtimes/${RUNTIME}.sh"
if [ ! -f "$RUNTIME_FILE" ]; then
error "Unknown runtime: $RUNTIME. Available: ${AVAILABLE_RUNTIMES[*]}"
fi
source "$RUNTIME_FILE"
# Set default chat bridge based on runtime
if [ -z "$CHAT_BRIDGE" ]; then
case "$RUNTIME" in
claude-code|studio-code) CHAT_BRIDGE="cc-connect" ;;
*) CHAT_BRIDGE="kimaki" ;;
esac
fi
# ============================================================================
# Execute
# ============================================================================
detect_environment
# --skills-only early exit
if [ "$SKILLS_ONLY" = true ]; then
install_skills
print_skills_summary
exit 0
fi
# --runtime-only skips infrastructure phases (plugins, database, agent creation).
# Use when adding a runtime to an existing agent that already has plugins installed.
if [ "$RUNTIME_ONLY" != true ]; then
install_system_deps
setup_database
install_wordpress
setup_multisite
create_service_user
install_data_machine
create_dm_agent
install_extra_plugins
setup_nginx
setup_ssl
setup_service_permissions
fi
runtime_install
runtime_discover_dm_paths
runtime_generate_config
runtime_install_hooks
runtime_generate_instructions
runtime_merge_mcp_servers
install_skills
install_chat_bridge
print_summary