-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·119 lines (108 loc) · 3.9 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·119 lines (108 loc) · 3.9 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
#!/usr/bin/env bash
# Gravity Town - Deploy script
# Usage: bash deploy.sh [RPC_URL]
# RPC_URL defaults to http://127.0.0.1:8545
set -euo pipefail
REPO="https://github.com/Galxe/gravity-town.git"
GAME_DIR="$HOME/game"
RPC_URL="${1:-http://127.0.0.1:8545}"
# Prompt for operator private key (never stored to disk)
read -r -s -p "Enter operator private key (0x...): " DEPLOY_PK
echo
[[ "$DEPLOY_PK" == 0x* ]] || { echo "ERROR: private key must start with 0x"; exit 1; }
# -- [0] RPC connectivity check ------------------------------------------------
echo "=== [0/6] Check RPC: $RPC_URL ==="
RPC_RESP=$(curl -s --max-time 5 -X POST "$RPC_URL" \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' 2>&1) || true
if echo "$RPC_RESP" | grep -q '"result"'; then
BLOCK=$(echo "$RPC_RESP" | grep -o '"result":"0x[^"]*"' | head -1 | cut -d'"' -f4)
echo "OK - latest block: $BLOCK"
else
echo "ERROR: cannot reach RPC at $RPC_URL"
echo " response: $RPC_RESP"
exit 1
fi
# -- [1] Node.js ---------------------------------------------------------------
echo "=== [1/6] Check Node.js ==="
if command -v node &>/dev/null; then
echo "OK - $(node -v) already installed"
else
echo "Installing Node.js 20..."
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
fi
# -- [2] Foundry ---------------------------------------------------------------
echo "=== [2/6] Check Foundry ==="
if command -v forge &>/dev/null; then
echo "OK - $(forge --version | head -1)"
else
echo "Installing Foundry..."
curl -L https://foundry.paradigm.xyz | bash
export PATH="$HOME/.foundry/bin:$PATH"
foundryup
fi
# -- [3] Clone / update repo ---------------------------------------------------
echo "=== [3/6] Clone / update repo ==="
if [ -d "$GAME_DIR/.git" ]; then
git -C "$GAME_DIR" pull
else
git clone "$REPO" "$GAME_DIR"
fi
echo " Installing Foundry dependencies (contracts/lib/)..."
(cd "$GAME_DIR/contracts" && \
url="" && \
while IFS= read -r line; do \
if [[ "$line" =~ url\ =\ (.*) ]]; then url="${BASH_REMATCH[1]}"; fi; \
if [[ "$line" =~ path\ =\ (.*) ]]; then \
path="${BASH_REMATCH[1]}"; \
if [ -n "$url" ] && [ ! -d "$path/.git" ]; then \
echo " Cloning $url -> $path"; \
git clone --depth=1 --quiet "$url" "$path"; \
else \
echo " Already present: $path"; \
fi; \
url=""; \
fi; \
done < .gitmodules \
)
# -- [4] Install Node dependencies ---------------------------------------------
echo "=== [4/6] Install Node dependencies ==="
(cd "$GAME_DIR/mcp-server" && npm install --silent)
(cd "$GAME_DIR/agent-runner" && npm install --silent)
# -- [5] Deploy contracts ------------------------------------------------------
echo "=== [5/6] Deploy contracts to $RPC_URL ==="
OPERATOR_ADDR=$(cast wallet address "$DEPLOY_PK")
(cd "$GAME_DIR/contracts" && \
PRIVATE_KEY="$DEPLOY_PK" \
OPERATOR_ADDRESS="$OPERATOR_ADDR" \
forge script script/Deploy.s.sol \
--rpc-url "$RPC_URL" \
--broadcast)
echo ""
echo "Contract addresses:"
cat "$GAME_DIR/deployed-addresses.json"
# -- [6] Config & agent-runner -------------------------------------------------
echo ""
echo "=== [6/6] Config & agent-runner ==="
CONFIG="$GAME_DIR/agent-runner/config.toml"
if [ ! -f "$CONFIG" ]; then
cp "$GAME_DIR/agent-runner/config.example.toml" "$CONFIG"
echo "config.toml created from template."
echo "Edit $CONFIG (fill in api_key), then run:"
echo " cd $GAME_DIR/agent-runner && npm run dev"
else
echo "config.toml already exists."
if command -v pm2 &>/dev/null; then
if pm2 show agent-runner &>/dev/null 2>&1; then
pm2 restart agent-runner
else
pm2 start --name agent-runner -- npm run dev --prefix "$GAME_DIR/agent-runner"
fi
pm2 save
echo "Done. Use: pm2 logs agent-runner"
else
echo "Ready. Run:"
echo " cd $GAME_DIR/agent-runner && npm run dev"
fi
fi