-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·254 lines (209 loc) · 6.09 KB
/
install.sh
File metadata and controls
executable file
·254 lines (209 loc) · 6.09 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
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GITHUB_REPO="Yeachan-Heo/clawhip"
INSTALLER_URL="${CLAWHIP_INSTALLER_URL:-https://github.com/${GITHUB_REPO}/releases/latest/download/clawhip-installer.sh}"
CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
export CARGO_HOME
SYSTEMD=0
SKIP_STAR_PROMPT=0
usage() {
cat <<'EOF'
Usage: ./install.sh [--systemd] [--skip-star-prompt]
Options:
--systemd Install and start the bundled systemd service.
--skip-star-prompt Disable the optional post-install GitHub star prompt.
-h, --help Show this help text.
Environment:
CLAWHIP_SKIP_STAR_PROMPT=1
Disable the optional post-install GitHub star prompt.
EOF
}
parse_args() {
for arg in "$@"; do
case "$arg" in
--systemd) SYSTEMD=1 ;;
--skip-star-prompt) SKIP_STAR_PROMPT=1 ;;
-h|--help)
usage
exit 0
;;
*)
echo "unknown arg: $arg" >&2
usage >&2
exit 1
;;
esac
done
}
log() {
echo "[clawhip] $*"
}
is_truthy() {
case "${1:-}" in
1|true|TRUE|yes|YES|on|ON) return 0 ;;
*) return 1 ;;
esac
}
star_prompt_disabled() {
is_truthy "${CLAWHIP_SKIP_STAR_PROMPT:-}" || is_truthy "${SKIP_STAR_PROMPT:-}"
}
is_interactive_install() {
[[ -t 0 && -t 1 ]]
}
can_use_github_cli_for_star() {
command -v gh >/dev/null 2>&1 && gh auth status &>/dev/null
}
star_repo_with_gh() {
gh api --method PUT "/user/starred/${GITHUB_REPO}" --silent &>/dev/null
}
prompt_to_star_repo() {
local response
printf '[clawhip] Would you like to star %s on GitHub with gh? [y/N]: ' "$GITHUB_REPO"
read -r response || return 0
case "$response" in
[yY]|[yY][eE][sS])
if star_repo_with_gh; then
log "thanks for starring ${GITHUB_REPO}"
else
log "unable to star ${GITHUB_REPO} with gh; continuing without it"
fi
;;
*)
log "skipping GitHub star step"
;;
esac
}
maybe_prompt_to_star_repo() {
if star_prompt_disabled; then
log "skipping GitHub star prompt (--skip-star-prompt or CLAWHIP_SKIP_STAR_PROMPT)"
return 0
fi
if ! is_interactive_install; then
return 0
fi
if ! can_use_github_cli_for_star; then
return 0
fi
log "optional: star ${GITHUB_REPO} on GitHub to support the project"
prompt_to_star_repo
}
install_prebuilt_binary() {
if ! command -v curl >/dev/null 2>&1; then
log "curl is not installed; skipping prebuilt binary download"
return 1
fi
mkdir -p "$CARGO_HOME/bin"
log "attempting prebuilt binary install from ${INSTALLER_URL}"
local installer
installer="$(mktemp)"
if ! curl --proto '=https' --tlsv1.2 -LsSf "$INSTALLER_URL" -o "$installer"; then
log "no downloadable release installer found; falling back to cargo install"
rm -f "$installer"
return 1
fi
if sh "$installer"; then
rm -f "$installer"
return 0
else
local status=$?
log "prebuilt installer failed with status ${status}; falling back to cargo install"
rm -f "$installer"
return 1
fi
}
install_from_source() {
if ! command -v cargo >/dev/null 2>&1; then
cat >&2 <<'MSG'
[clawhip] A prebuilt binary was not available and Cargo is not installed.
[clawhip] Install Rust with rustup, then rerun this installer:
[clawhip] curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
[clawhip] source "$HOME/.cargo/env"
MSG
exit 1
fi
log "building from source with cargo install --path . --force"
cd "$REPO_ROOT"
cargo install --path . --force
}
sync_plugins() {
local source_dir="$REPO_ROOT/plugins"
local target_dir="$HOME/.clawhip/plugins"
if [[ ! -d "$source_dir" ]]; then
return 0
fi
rm -rf "$target_dir"
mkdir -p "$(dirname "$target_dir")"
cp -R "$source_dir" "$target_dir"
log "synced plugins to $target_dir"
}
installed_binary_path() {
if [[ -x "$CARGO_HOME/bin/clawhip" ]]; then
printf '%s\n' "$CARGO_HOME/bin/clawhip"
return 0
fi
if command -v clawhip >/dev/null 2>&1; then
command -v clawhip
return 0
fi
return 1
}
setup_quick_start() {
local binary_path
binary_path="$(installed_binary_path)" || return 0
local config_path="$HOME/.clawhip/config.toml"
if [[ -f "$config_path" ]]; then
log "existing config found at $config_path; skipping quick-start scaffold"
return 0
fi
local webhook_url="${CLAWHIP_WEBHOOK_URL:-}"
if [[ -z "${webhook_url// }" && -t 0 ]]; then
printf '[clawhip] Discord webhook URL (recommended quick start; press Enter to skip): '
read -r webhook_url || true
fi
if [[ -n "${webhook_url// }" ]]; then
log "scaffolding webhook quick-start config"
"$binary_path" setup --webhook "$webhook_url"
log "webhook config scaffolded at $config_path"
else
log "recommended quick start: clawhip setup --webhook 'https://discord.com/api/webhooks/...'"
log "bot-token mode is still supported via ~/.clawhip/config.toml"
fi
}
install_systemd_binary() {
local binary_path
binary_path="$(installed_binary_path)" || {
log "unable to find installed clawhip binary for systemd setup"
exit 1
}
log "installing $binary_path to /usr/local/bin/clawhip for systemd"
sudo install -m 755 "$binary_path" /usr/local/bin/clawhip
}
main() {
parse_args "$@"
log "install flow: prebuilt binary -> cargo fallback -> SKILL attach -> config scaffold -> optional post-install GitHub star prompt -> verification"
log "repo root: $REPO_ROOT"
if install_prebuilt_binary; then
log "prebuilt binary installed successfully"
else
install_from_source
fi
mkdir -p "$HOME/.clawhip"
log "ensured config dir $HOME/.clawhip"
sync_plugins
log "next: read SKILL.md and attach the skill surface"
setup_quick_start
if [[ "$SYSTEMD" == "1" ]]; then
install_systemd_binary
sudo cp deploy/clawhip.service /etc/systemd/system/clawhip.service
sudo systemctl daemon-reload
sudo systemctl enable --now clawhip
log "systemd unit installed and started"
fi
maybe_prompt_to_star_repo
log "recommended verification: scripts/live-verify-default-presets.sh <mode>"
log "install complete"
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
fi