-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_clawchain.sh
More file actions
123 lines (112 loc) · 3.44 KB
/
Copy pathsetup_clawchain.sh
File metadata and controls
123 lines (112 loc) · 3.44 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
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PORT="${1:-${PORT:-8888}}"
ACCOUNT_ID="${CLAWCHAIN_ACCOUNT_ID:-local-operator}"
PASSWORD="${CLAWCHAIN_PASSWORD:-local-operator}"
WORKSPACE="${CLAWCHAIN_WORKSPACE:-$ROOT_DIR}"
ROOT_PARENT="${CLAWCHAIN_ROOT_PARENT:-}"
REQUIRE_CHAIN="${CLAWCHAIN_REQUIRE_CHAIN:-0}"
SKIP_CHAIN="${CLAWCHAIN_SKIP_CHAIN_BOOTSTRAP:-0}"
AUTO_INSTALL_FOUNDRY="${CLAWCHAIN_AUTO_INSTALL_FOUNDRY:-1}"
ANVIL_PATH="${CLAWCHAIN_ANVIL_PATH:-}"
FORGE_PATH="${CLAWCHAIN_FORGE_PATH:-}"
DEPLOYER_PRIVATE_KEY="${CLAWCHAIN_DEPLOYER_PRIVATE_KEY:-}"
is_truthy() {
local value="${1:-}"
case "${value,,}" in
1|true|yes|on) return 0 ;;
*) return 1 ;;
esac
}
if command -v python >/dev/null 2>&1; then
PYTHON_BIN="python"
elif command -v python3 >/dev/null 2>&1; then
PYTHON_BIN="python3"
else
echo "[setup] neither python nor python3 is available on PATH" >&2
exit 1
fi
if [[ -n "$ROOT_PARENT" ]]; then
ACCOUNT_ROOT="$ROOT_PARENT/$ACCOUNT_ID"
else
ACCOUNT_ROOT="$HOME/.clawchain-agent/$ACCOUNT_ID"
fi
CONFIG_PATH="$ACCOUNT_ROOT/agent-proxy.config.json"
WORKSPACE="$(cd "$WORKSPACE" && pwd)"
cd "$ROOT_DIR"
export PYTHONPATH="$ROOT_DIR${PYTHONPATH:+:$PYTHONPATH}"
run_cmd() {
printf '[setup]'
for token in "$@"; do
printf ' %q' "$token"
done
printf '\n'
"$@"
}
if [[ -f "$CONFIG_PATH" ]]; then
run_cmd "$PYTHON_BIN" -m clawchain.agent_proxy_cli service-stop "$CONFIG_PATH" || true
fi
deploy_args=(
"$PYTHON_BIN" -m clawchain.agent_proxy_cli deploy
"$ACCOUNT_ID" "$PASSWORD"
--workspace "$WORKSPACE"
--no-start-service
)
if [[ -n "$ROOT_PARENT" ]]; then
deploy_args+=(--root-dir "$ROOT_PARENT")
fi
if ! is_truthy "$AUTO_INSTALL_FOUNDRY"; then
deploy_args+=(--no-auto-install-foundry)
fi
if [[ -n "$ANVIL_PATH" ]]; then
deploy_args+=(--anvil-path "$ANVIL_PATH")
fi
if [[ -n "$FORGE_PATH" ]]; then
deploy_args+=(--forge-path "$FORGE_PATH")
fi
run_cmd "${deploy_args[@]}"
chain_ok=0
if ! is_truthy "$SKIP_CHAIN"; then
chain_args=(
"$PYTHON_BIN" -m clawchain.agent_proxy_cli chain-connect
"$ACCOUNT_ID"
--bootstrap-local-evm
)
if [[ -n "$ROOT_PARENT" ]]; then
chain_args+=(--root-dir "$ROOT_PARENT")
fi
if [[ -n "$DEPLOYER_PRIVATE_KEY" ]]; then
chain_args+=(--deployer-private-key "$DEPLOYER_PRIVATE_KEY")
fi
if run_cmd "${chain_args[@]}"; then
chain_ok=1
elif is_truthy "$REQUIRE_CHAIN"; then
echo "[setup] chain bootstrap failed and CLAWCHAIN_REQUIRE_CHAIN is enabled" >&2
exit 1
else
echo "[setup] chain bootstrap failed; continuing with local setup and UI startup" >&2
fi
fi
run_cmd "$PYTHON_BIN" -m clawchain.agent_proxy_cli service-start "$CONFIG_PATH"
run_cmd "$PYTHON_BIN" -m clawchain.agent_proxy_cli service-status "$CONFIG_PATH"
if [[ "$chain_ok" == "1" ]]; then
chain_status_args=("$PYTHON_BIN" -m clawchain.agent_proxy_cli chain-status "$ACCOUNT_ID")
if [[ -n "$ROOT_PARENT" ]]; then
chain_status_args+=(--root-dir "$ROOT_PARENT")
fi
run_cmd "${chain_status_args[@]}" || true
fi
echo "[setup] account: $ACCOUNT_ID"
echo "[setup] account root: $ACCOUNT_ROOT"
echo "[setup] config path: $CONFIG_PATH"
echo "[setup] workspace: $WORKSPACE"
if is_truthy "$SKIP_CHAIN"; then
echo "[setup] chain bootstrap: skipped"
elif [[ "$chain_ok" == "1" ]]; then
echo "[setup] chain bootstrap: ok"
else
echo "[setup] chain bootstrap: warning"
fi
echo "[setup] launching UI on port $PORT"
exec bash "$ROOT_DIR/run_clawchain_ui.sh" "$PORT"