-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall
More file actions
executable file
·299 lines (272 loc) · 9.87 KB
/
install
File metadata and controls
executable file
·299 lines (272 loc) · 9.87 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
#!/usr/bin/env bash
# hum installer.
#
# Builds + registers humd as a user service. Pulls orch + orchd binaries
# (bee supervisor). After this, `hum hive install <kind>` brings up bees
# via orchd; no per-bee bash scripts.
#
# Idempotent — re-running upgrades in place.
#
# Usage:
# ./install # from a cloned repo
# ./install status # humd state + paths
# ./install logs # tail humd logs
# ./install uninstall # stop + remove humd unit (state preserved)
# ./install purge # remove everything INCLUDING state
set -euo pipefail
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
HUM_CONFIG="$XDG_CONFIG_HOME/hum"
HUM_DATA="$XDG_DATA_HOME/hum"
HUM_STATE="$XDG_STATE_HOME/hum"
HUM_BIN_ROOT="$HOME/.local"
HUMD_BIN="$HUM_BIN_ROOT/bin/humd"
HUMCTL_BIN="$HUM_BIN_ROOT/bin/humctl"
HUM_CLI_BIN="$HUM_BIN_ROOT/bin/hum"
ORCH_BIN="$HUM_BIN_ROOT/bin/orch"
ORCHD_BIN="$HUM_BIN_ROOT/bin/orchd"
HUM_REPO_URL="${HUM_REPO_URL:-https://github.com/adiled/hum.git}"
HUM_SRC="$HUM_DATA/src"
MIN_CLAUDE="2.1.86"
CMD="${1:-install}"
OS="$(uname -s)"
log() { printf '\033[1m[hum]\033[0m %s\n' "$*"; }
warn() { printf '\033[1;33m[hum]\033[0m %s\n' "$*" >&2; }
fail() { printf '\033[1;31m[hum]\033[0m %s\n' "$*" >&2; exit 1; }
version_gte() { printf '%s\n%s\n' "$2" "$1" | sort -V -C; }
read_version() { "$1" --version 2>/dev/null | sed -n 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' | head -1; }
ensure_min_version() {
local NAME="$1" BIN="$2" MIN="$3"
if ! command -v "$BIN" >/dev/null 2>&1; then fail "$NAME not found on PATH."; fi
local CUR; CUR="$(read_version "$BIN" || true)"
if [ -z "$CUR" ]; then fail "$NAME found but couldn't read version."; fi
if version_gte "$CUR" "$MIN"; then log "$NAME ${CUR} ≥ ${MIN} ✓"
else fail "$NAME ${CUR} < ${MIN} — upgrade and re-run."; fi
}
ensure_prereqs() {
ensure_min_version "claude CLI" "claude" "$MIN_CLAUDE"
if ! command -v cargo >/dev/null 2>&1; then
if [ -x "$HUMD_BIN" ] && [ -x "$HUMCTL_BIN" ] && [ -x "$HUM_CLI_BIN" ] && [ -x "$ORCHD_BIN" ]; then
warn "cargo not found; using pre-built binaries in $HUM_BIN_ROOT/bin"
SKIP_BUILD=1
else
fail "cargo (rustup) not found. Install rustup: https://rustup.rs"
fi
fi
}
ensure_identity() {
mkdir -p "$HUM_STATE"
local KEY="$HUM_STATE/humd.key"
if [ -s "$KEY" ]; then log "humd identity: $KEY ✓"; return 0; fi
log "minting humd identity at $KEY"
if command -v openssl >/dev/null 2>&1; then
openssl genpkey -algorithm Ed25519 -outform DER -out "$KEY.tmp" 2>/dev/null
tail -c 32 "$KEY.tmp" > "$KEY"
rm -f "$KEY.tmp"
else
dd if=/dev/urandom of="$KEY" bs=32 count=1 2>/dev/null
fi
chmod 600 "$KEY"
}
ensure_peers_config() {
mkdir -p "$HUM_CONFIG"
local PEERS="$HUM_CONFIG/peers.json"
if [ -s "$PEERS" ]; then log "peers.json: $PEERS ✓"; return 0; fi
echo "[]" > "$PEERS"
log "wrote empty peers.json at $PEERS"
}
ensure_hum_config() {
mkdir -p "$HUM_CONFIG"
local CFG="$HUM_CONFIG/hum.json"
if [ -s "$CFG" ]; then log "hum.json: $CFG ✓"; return 0; fi
cat > "$CFG" <<JSON
{
"\$schema": "https://adiled.github.io/hum/hum.schema.json",
"humd": { "permissionDuskMs": 60000, "driftRetentionDays": 30 },
"fs": {
"roots": [
{ "path": "~/code", "mode": "rw" },
{ "path": "/tmp", "mode": "rw" }
],
"denied": ["~/.ssh", "~/.aws", "~/.gnupg", "~/.config/hum"]
},
"nest": { "maxActiveCells": 4, "cellIdlePruneThresholdMs": 300000, "default": "claude-cli" }
}
JSON
log "wrote default hum.json at $CFG"
}
ensure_orch_overlay_dir() {
mkdir -p "$HUM_CONFIG/orch.d"
: > "$HUM_CONFIG/Orchfile"
log "orch overlay dir: $HUM_CONFIG/orch.d/"
}
build_binaries() {
local SRC
if [ -f "$(dirname "$0")/Cargo.toml" ] && grep -q '"humd"' "$(dirname "$0")/Cargo.toml"; then
SRC="$(dirname "$0")"
else
if [ ! -d "$HUM_SRC/.git" ]; then
log "cloning $HUM_REPO_URL into $HUM_SRC"
mkdir -p "$HUM_DATA"
git clone --depth 1 "$HUM_REPO_URL" "$HUM_SRC"
else
log "updating $HUM_SRC"
(cd "$HUM_SRC" && git pull --ff-only --quiet)
fi
SRC="$HUM_SRC"
fi
log "building Rust binaries"
cargo install --quiet --locked --path "$SRC/humd" --root "$HUM_BIN_ROOT" --force
cargo install --quiet --locked --path "$SRC/humctl" --root "$HUM_BIN_ROOT" --force
cargo install --quiet --locked --path "$SRC/hum" --root "$HUM_BIN_ROOT" --force
log "installing orch + orchd (bee supervisor) from git"
cargo install --quiet --git https://github.com/adiled/orch.git --root "$HUM_BIN_ROOT" --force
cargo install --quiet --git https://github.com/adiled/orchd.git --root "$HUM_BIN_ROOT" --force
[ -x "$HUMD_BIN" ] || fail "humd not at $HUMD_BIN after build"
[ -x "$HUMCTL_BIN" ] || fail "humctl not at $HUMCTL_BIN after build"
[ -x "$HUM_CLI_BIN" ] || fail "hum not at $HUM_CLI_BIN after build"
[ -x "$ORCH_BIN" ] || fail "orch not at $ORCH_BIN after build"
[ -x "$ORCHD_BIN" ] || fail "orchd not at $ORCHD_BIN after build"
log "humd $HUMD_BIN ; humctl $HUMCTL_BIN ; hum $HUM_CLI_BIN ; orch $ORCH_BIN ; orchd $ORCHD_BIN"
}
linux_unit_dir="${XDG_CONFIG_HOME}/systemd/user"
darwin_unit_dir="$HOME/Library/LaunchAgents"
write_linux_unit() {
mkdir -p "$linux_unit_dir"
cat > "$linux_unit_dir/humd.service" <<EOF
[Unit]
Description=hum router daemon
[Service]
Type=simple
ExecStart=$HUMD_BIN
Restart=always
RestartSec=2
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable humd.service >/dev/null 2>&1 || true
systemctl --user restart humd.service
}
write_darwin_unit() {
mkdir -p "$darwin_unit_dir"
cat > "$darwin_unit_dir/humd.plist" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Label</key><string>humd</string>
<key>Program</key><string>$HUMD_BIN</string>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
<key>StandardOutPath</key><string>$HOME/Library/Logs/sh.hum.humd.out.log</string>
<key>StandardErrorPath</key><string>$HOME/Library/Logs/sh.hum.humd.err.log</string>
</dict></plist>
EOF
local uid; uid="$(id -u)"
launchctl bootout "gui/$uid/humd" 2>/dev/null || true
launchctl bootstrap "gui/$uid" "$darwin_unit_dir/humd.plist"
}
start_daemons() {
case "$OS" in
Linux) write_linux_unit ;;
Darwin) write_darwin_unit ;;
*) warn "service install not supported on $OS — run '$HUMD_BIN' manually"; return 0 ;;
esac
log "humd registered + started ($OS)"
sleep 1
}
print_next_steps() {
log ""
log "humd is up. Add a bee:"
log " hum hive install claude-cli # claude worker (cargo build + register)"
log " hum hive install humfs # filesystem forager"
log " hum hive install paid-oracle # x402 paid price oracle"
log ""
log "Bee state: hum bee --list / hum nest"
log "humd state: hum status / hum doctor / humctl logs"
check_path_hint
}
# Warn loudly when ~/.local/bin isn't on $PATH. Without it,
# `hum`/`humd`/`humctl`/`orch`/`orchd` aren't reachable by bare name
# from a fresh shell, and `hum hive install` fails late with confusing
# errors. hum's own orchd lookup now prefers the absolute path, but
# the user still needs `hum` itself on PATH.
check_path_hint() {
case ":$PATH:" in
*":$HUM_BIN_ROOT/bin:"*) return 0 ;;
esac
log ""
warn "$HUM_BIN_ROOT/bin is not on \$PATH."
warn "Add this to your shell config (\$HOME/.bashrc, \$HOME/.zshrc, \$HOME/.profile):"
warn " export PATH=\"\$HOME/.local/bin:\$PATH\""
warn "Then open a new shell. Until then, invoke binaries by absolute path:"
warn " $HUM_CLI_BIN status"
}
show_status() {
echo "humd binary: $HUMD_BIN"
echo " version: $($HUMD_BIN --version 2>&1 || echo 'not installed')"
echo "orchd binary: $ORCHD_BIN"
echo " version: $($ORCHD_BIN --version 2>&1 || echo 'not installed')"
echo "identity: $HUM_STATE/humd.key $([ -s "$HUM_STATE/humd.key" ] && echo ✓ || echo MISSING)"
echo "peers.json: $HUM_CONFIG/peers.json $([ -s "$HUM_CONFIG/peers.json" ] && echo ✓ || echo MISSING)"
echo "hum.json: $HUM_CONFIG/hum.json $([ -s "$HUM_CONFIG/hum.json" ] && echo ✓ || echo MISSING)"
case "$OS" in
Linux) systemctl --user status humd --no-pager 2>&1 | head -6 || true ;;
Darwin) launchctl print "gui/$(id -u)/humd" 2>&1 | head -6 || true ;;
esac
if [ -x "$ORCHD_BIN" ]; then
echo "--- bees ---"
"$ORCHD_BIN" --orchfile "$HUM_CONFIG/Orchfile" --user --namespace hum status 2>&1 || true
fi
}
show_logs() {
if [ -x "$HUMCTL_BIN" ]; then
"$HUMCTL_BIN" logs -n 100
else
warn "humctl not installed"
fi
}
uninstall() {
case "$OS" in
Linux)
systemctl --user stop humd.service 2>/dev/null || true
systemctl --user disable humd.service 2>/dev/null || true
rm -f "$linux_unit_dir/humd.service"
systemctl --user daemon-reload 2>/dev/null || true
;;
Darwin)
local uid; uid="$(id -u)"
launchctl bootout "gui/$uid/humd" 2>/dev/null || true
rm -f "$darwin_unit_dir/humd.plist"
;;
esac
rm -f "$HUMD_BIN" "$HUMCTL_BIN" "$HUM_CLI_BIN"
log "uninstalled humd. orch/orchd left in place. State preserved in $HUM_STATE + $HUM_CONFIG."
log " run \`./install purge\` to remove state too."
}
purge() {
uninstall
rm -rf "$HUM_STATE" "$HUM_CONFIG" "$HUM_DATA"
log "purged."
}
do_install() {
log "hum installer"
ensure_prereqs
if [ "${SKIP_BUILD:-0}" != "1" ]; then build_binaries; fi
ensure_identity
ensure_peers_config
ensure_hum_config
ensure_orch_overlay_dir
start_daemons
log ""
print_next_steps
}
case "$CMD" in
install|"") do_install ;;
status) show_status ;;
logs) show_logs ;;
uninstall) uninstall ;;
purge) purge ;;
*) fail "unknown command: $CMD (try: install, status, logs, uninstall, purge)" ;;
esac