-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·217 lines (187 loc) · 6.14 KB
/
install.sh
File metadata and controls
executable file
·217 lines (187 loc) · 6.14 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
#!/usr/bin/env bash
set -euo pipefail
LOG_FILE="/tmp/zync-install.log"
exec > >(tee -a "$LOG_FILE") 2>&1
INSTALL_DIR="${ZYNC_DIR:-$HOME/.zync}"
RAW_BASE="https://raw.githubusercontent.com/Lawndlwd/zync/main"
COMPOSE_URL="$RAW_BASE/docker-compose.prod.yml"
SCRIPT_URL="$RAW_BASE/install.sh"
OPENCODE_INSTALL_URL="https://opencode.ai/install"
ZYNC_PORT="${ZYNC_PORT:-8080}"
# --- Helpers ---
info() { printf "\033[1;34m[info]\033[0m %s\n" "$*"; }
ok() { printf "\033[1;32m[ok]\033[0m %s\n" "$*"; }
warn() { printf "\033[1;33m[warn]\033[0m %s\n" "$*"; }
err() { printf "\033[1;31m[error]\033[0m %s\n" "$*" >&2; }
check_cmd() {
if ! command -v "$1" &>/dev/null; then
err "$1 is required but not installed."
exit 1
fi
}
# --- Parse flags ---
DO_UPDATE=false
for arg in "$@"; do
case "$arg" in
--update) DO_UPDATE=true ;;
*) ;;
esac
done
# --- Detect platform ---
OS="$(uname -s)"
ARCH="$(uname -m)"
info "Detected platform: $OS $ARCH"
# --- Check prerequisites ---
info "Checking prerequisites..."
check_cmd docker
check_cmd curl
if docker compose version &>/dev/null; then
ok "Docker Compose v2 found ($(docker compose version --short 2>/dev/null || echo "unknown"))"
else
err "Docker Compose v2 is required. Install it: https://docs.docker.com/compose/install/"
exit 1
fi
if ! docker info &>/dev/null; then
err "Docker daemon is not running. Please start Docker and try again."
exit 1
fi
# --- Install OpenCode (required) ---
install_opencode() {
if command -v opencode &>/dev/null; then
ok "OpenCode already installed ($(opencode --version 2>/dev/null || echo "unknown"))"
return 0
fi
info "Installing OpenCode..."
local INSTALL_EXIT=0
curl -fsSL "$OPENCODE_INSTALL_URL" | bash || INSTALL_EXIT=$?
if [[ "$INSTALL_EXIT" -ne 0 ]]; then
err "OpenCode installation failed (exit code: $INSTALL_EXIT)"
case "$OS" in
Linux)
err "Try: snap install opencode"
;;
Darwin)
err "Try: brew install opencode-ai/tap/opencode"
;;
esac
err "Zync requires OpenCode. Install it manually and re-run this script."
exit 1
fi
# Reload shell config so opencode is on PATH
local SHELL_NAME
SHELL_NAME="$(basename "${SHELL:-/bin/bash}")"
case "$SHELL_NAME" in
zsh) [[ -f "$HOME/.zshrc" ]] && source "$HOME/.zshrc" 2>/dev/null || true ;;
bash) [[ -f "$HOME/.bashrc" ]] && source "$HOME/.bashrc" 2>/dev/null || true ;;
fish) info "Fish shell — run 'source ~/.config/fish/config.fish' to refresh PATH" ;;
esac
if command -v opencode &>/dev/null; then
ok "OpenCode installed successfully"
else
for CANDIDATE in "$HOME/.opencode/bin/opencode" "$HOME/.local/bin/opencode" "/usr/local/bin/opencode"; do
if [[ -x "$CANDIDATE" ]]; then
ok "OpenCode installed at $CANDIDATE (add to PATH or open new terminal)"
return 0
fi
done
err "OpenCode installed but not on PATH. Add it to PATH and re-run."
exit 1
fi
}
install_opencode
# --- Setup install directory ---
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
# --- Download compose + install script ---
download_files() {
info "Downloading Zync configuration..."
curl -fsSL "$COMPOSE_URL" -o docker-compose.yml
curl -fsSL "$SCRIPT_URL" -o install.sh && chmod +x install.sh
}
# --- Write/update .env without nuking existing values ---
set_env() {
local key="$1" val="$2"
touch .env
if grep -q "^${key}=" .env; then
local tmp; tmp="$(mktemp)"
sed "s|^${key}=.*|${key}=${val}|" .env > "$tmp" && mv "$tmp" .env
else
echo "${key}=${val}" >> .env
fi
}
# --- Handle --update ---
if [[ "$DO_UPDATE" == "true" ]]; then
info "Updating Zync..."
download_files
set_env "ZYNC_PORT" "$ZYNC_PORT"
docker compose --profile voice pull
docker compose --profile voice up -d
ok "Zync containers updated!"
else
# --- Fresh install ---
download_files
set_env "ZYNC_PORT" "$ZYNC_PORT"
info "Pulling images (this may take a minute on first install)..."
docker compose --profile voice pull
docker compose --profile voice up -d
fi
# --- Wait for backend health ---
info "Waiting for backend to become healthy..."
HEALTHY=false
for i in $(seq 1 30); do
if curl -sf http://localhost:3001/api/health &>/dev/null; then
HEALTHY=true
break
fi
sleep 2
done
if $HEALTHY; then
VERSION=$(curl -sf http://localhost:3001/api/health | grep -o '"version":"[^"]*"' | cut -d'"' -f4 || echo "unknown")
ok "Backend is healthy! (v$VERSION)"
else
err "Backend did not become healthy within 60s."
err "Check logs: cd $INSTALL_DIR && docker compose logs backend"
exit 1
fi
# --- Start OpenCode serve ---
start_opencode() {
# Kill any existing opencode serve process
pkill -f "opencode serve" 2>/dev/null || true
sleep 1
local CORS_ORIGIN="http://localhost:$ZYNC_PORT"
info "Starting OpenCode serve (CORS: $CORS_ORIGIN)..."
nohup opencode serve --cors "$CORS_ORIGIN" > "$INSTALL_DIR/opencode.log" 2>&1 &
local OC_PID=$!
sleep 2
if kill -0 "$OC_PID" 2>/dev/null; then
ok "OpenCode running (PID $OC_PID, log: $INSTALL_DIR/opencode.log)"
else
err "OpenCode failed to start. Check: $INSTALL_DIR/opencode.log"
exit 1
fi
}
start_opencode
# --- Summary ---
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
ok "Zync is running!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
info "Open http://localhost:$ZYNC_PORT to get started"
echo ""
info "Services:"
echo " Frontend: http://localhost:$ZYNC_PORT"
echo " Backend: http://localhost:3001"
echo " OpenCode: http://localhost:4096"
echo " Whisper: internal (voice transcription)"
echo " Wakeword: http://localhost:9000"
echo ""
info "Useful commands:"
echo " cd $INSTALL_DIR"
echo " docker compose logs -f # View logs"
echo " docker compose down # Stop Zync"
echo " docker compose up -d # Start Zync"
echo " ./install.sh --update # Update to latest"
echo ""
info "Install log: $LOG_FILE"
info "OpenCode log: $INSTALL_DIR/opencode.log"