-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·262 lines (236 loc) · 10 KB
/
install.sh
File metadata and controls
executable file
·262 lines (236 loc) · 10 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
#!/usr/bin/env bash
# CloseClaw Installer — the one-liner bootstrap
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/BitmapAsset/CloseClaw/main/install.sh | sh
#
# Options (environment variables):
# CLOSECLAW_DIR — install directory (default: ~/.closeclaw/src)
# CLOSECLAW_REPO — git repo URL to clone (default: GitHub HTTPS)
# CLOSECLAW_BRANCH — branch to clone (default: main)
# CLOSECLAW_PIP_EXTRAS — optional pip extras, e.g. voice or dev
# SKIP_GENESIS — set to 1 to skip first-boot genesis after install
# QUIET — set to 1 for non-interactive install
#
# What this does:
# 1. Detects OS and package manager
# 2. Installs system dependencies (git, python3, pip)
# 3. Clones (or updates) the CloseClaw repository
# 4. Installs Python package with pip
# 5. Runs `closeclaw genesis` for the first-life experience
#
set -euo pipefail
# ── Colours ────────────────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
RESET='\033[0m'
say() { printf "${BOLD} ◈ %s${RESET}\n" "$*"; }
ok() { printf "${GREEN} ✓ %s${RESET}\n" "$*"; }
warn() { printf "${YELLOW} ⚠ %s${RESET}\n" "$*"; }
die() { printf "${RED} ✗ %s${RESET}\n" "$*" >&2; exit 1; }
# ── Config ──────────────────────────────────────────────────────────────────
CLOSECLAW_REPO="${CLOSECLAW_REPO:-https://github.com/BitmapAsset/CloseClaw.git}"
CLOSECLAW_BRANCH="${CLOSECLAW_BRANCH:-main}"
CLOSECLAW_DIR="${CLOSECLAW_DIR:-$HOME/.closeclaw/src}"
CLOSECLAW_PIP_EXTRAS="${CLOSECLAW_PIP_EXTRAS:-}"
SKIP_GENESIS="${SKIP_GENESIS:-0}"
QUIET="${QUIET:-0}"
# ── Banner ──────────────────────────────────────────────────────────────────
echo ""
printf "${BOLD} ░░ CloseClaw Installer ░░${RESET}\n"
printf " Any robot. Any chip. Any OS. Your AI.\n\n"
# ── OS & arch detection ───────────────────────────────────────────────────────
OS="$(uname -s)"
ARCH="$(uname -m)"
# Normalize arch labels
case "$ARCH" in
aarch64|arm64) ARCH_LABEL="arm64" ;;
armv7l|armhf|arm) ARCH_LABEL="arm32" ;;
x86_64|amd64) ARCH_LABEL="x86_64" ;;
i386|i686) ARCH_LABEL="x86" ;;
riscv64) ARCH_LABEL="riscv64" ;;
*) ARCH_LABEL="$ARCH" ;;
esac
say "Detected: $OS / $ARCH ($ARCH_LABEL)"
# Detect board
BOARD="generic"
if [ -f /proc/device-tree/model ]; then
MODEL=$(cat /proc/device-tree/model 2>/dev/null || echo "")
if echo "$MODEL" | grep -qi "Raspberry Pi"; then
BOARD="raspberry-pi"
ok "Board: Raspberry Pi detected"
elif echo "$MODEL" | grep -qi "Jetson"; then
BOARD="jetson"
ok "Board: NVIDIA Jetson detected"
fi
elif [ -f /proc/cpuinfo ]; then
if grep -qi "raspberry pi\|bcm2" /proc/cpuinfo 2>/dev/null; then
BOARD="raspberry-pi"
ok "Board: Raspberry Pi (cpuinfo)"
fi
fi
# ── Dependency checks ────────────────────────────────────────────────────────
need_cmd() {
command -v "$1" >/dev/null 2>&1 || return 1
}
install_pkg() {
local pkg="$1"
if need_cmd apt-get; then
sudo apt-get install -y "$pkg" >/dev/null 2>&1
elif need_cmd dnf; then
sudo dnf install -y "$pkg" >/dev/null 2>&1
elif need_cmd yum; then
sudo yum install -y "$pkg" >/dev/null 2>&1
elif need_cmd pacman; then
sudo pacman -Sy --noconfirm "$pkg" >/dev/null 2>&1
elif need_cmd zypper; then
sudo zypper install -y "$pkg" >/dev/null 2>&1
elif need_cmd brew; then
brew install "$pkg" >/dev/null 2>&1
elif need_cmd apk; then
sudo apk add --no-cache "$pkg" >/dev/null 2>&1
elif need_cmd opkg; then
opkg install "$pkg" >/dev/null 2>&1
else
warn "Cannot auto-install $pkg — please install it manually"
return 1
fi
}
say "Checking dependencies..."
if ! need_cmd git; then
say "Installing git..."
install_pkg git || die "git is required but could not be installed"
fi
ok "git: $(git --version)"
# Python 3.10+ (CloseClaw requires 3.10 for match-case and union types)
PYTHON=""
for py in python3.13 python3.12 python3.11 python3.10 python3; do
if need_cmd "$py"; then
major=$("$py" -c "import sys; print(sys.version_info[0])" 2>/dev/null || echo 0)
minor=$("$py" -c "import sys; print(sys.version_info[1])" 2>/dev/null || echo 0)
if [ "$major" -ge 3 ] && [ "$minor" -ge 10 ]; then
PYTHON="$py"
break
fi
fi
done
if [ -z "$PYTHON" ]; then
say "Python 3.10+ not found. Attempting installation..."
if need_cmd apt-get; then
sudo apt-get update -qq
sudo apt-get install -y python3 python3-pip python3-venv >/dev/null 2>&1 || true
# Try deadsnakes PPA on Ubuntu if default is too old
if ! python3 -c "import sys; assert sys.version_info >= (3,10)" 2>/dev/null; then
if need_cmd add-apt-repository; then
sudo add-apt-repository -y ppa:deadsnakes/ppa >/dev/null 2>&1 || true
sudo apt-get update -qq
sudo apt-get install -y python3.11 python3.11-venv >/dev/null 2>&1 || true
fi
fi
elif need_cmd brew; then
brew install python@3.12 >/dev/null 2>&1 || true
elif need_cmd dnf; then
sudo dnf install -y python3.11 >/dev/null 2>&1 || true
fi
# Re-check
for py in python3.13 python3.12 python3.11 python3.10 python3; do
if need_cmd "$py"; then
major=$("$py" -c "import sys; print(sys.version_info[0])" 2>/dev/null || echo 0)
minor=$("$py" -c "import sys; print(sys.version_info[1])" 2>/dev/null || echo 0)
if [ "$major" -ge 3 ] && [ "$minor" -ge 10 ]; then
PYTHON="$py"
break
fi
fi
done
[ -z "$PYTHON" ] && die "Python 3.10+ is required. Install it: https://python.org"
fi
ok "Python: $PYTHON ($($PYTHON --version))"
# Raspberry Pi specific: enable I2C, SPI, camera if not done
if [ "$BOARD" = "raspberry-pi" ] && need_cmd raspi-config; then
say "Enabling RPi interfaces (I2C, SPI, camera)..."
sudo raspi-config nonint do_i2c 0 2>/dev/null || true
sudo raspi-config nonint do_spi 0 2>/dev/null || true
sudo raspi-config nonint do_camera 0 2>/dev/null || true
ok "RPi interfaces enabled."
fi
if ! need_cmd pip3 && ! "$PYTHON" -m pip --version >/dev/null 2>&1; then
say "Installing pip..."
install_pkg python3-pip || true
fi
# ── Clone / update repo ─────────────────────────────────────────────────────
if [ -d "$CLOSECLAW_DIR/.git" ]; then
say "Updating existing CloseClaw repo at $CLOSECLAW_DIR..."
git -C "$CLOSECLAW_DIR" fetch --quiet origin
git -C "$CLOSECLAW_DIR" checkout "$CLOSECLAW_BRANCH" --quiet
git -C "$CLOSECLAW_DIR" pull --quiet origin "$CLOSECLAW_BRANCH"
ok "Repo updated."
else
say "Cloning CloseClaw to $CLOSECLAW_DIR..."
mkdir -p "$(dirname "$CLOSECLAW_DIR")"
git clone --quiet --branch "$CLOSECLAW_BRANCH" "$CLOSECLAW_REPO" "$CLOSECLAW_DIR"
ok "Repo cloned."
fi
# ── Install Python package ──────────────────────────────────────────────────
say "Installing CloseClaw Python package..."
cd "$CLOSECLAW_DIR"
PIP_TARGET="."
if [ -n "$CLOSECLAW_PIP_EXTRAS" ]; then
PIP_TARGET=".[$CLOSECLAW_PIP_EXTRAS]"
fi
# Try with venv first to avoid "externally managed" errors on modern Debian/Ubuntu
VENV_DIR="$HOME/.closeclaw/venv"
if "$PYTHON" -m venv --help >/dev/null 2>&1; then
if [ ! -d "$VENV_DIR" ]; then
"$PYTHON" -m venv "$VENV_DIR"
fi
VENV_PYTHON="$VENV_DIR/bin/python"
"$VENV_PYTHON" -m pip install --quiet --upgrade pip
"$VENV_PYTHON" -m pip install --quiet -e "$PIP_TARGET"
# Create wrapper scripts
INSTALL_BIN="$HOME/.local/bin"
mkdir -p "$INSTALL_BIN"
for cmd in closeclaw clawd; do
cat > "$INSTALL_BIN/$cmd" <<WRAPPER
#!/usr/bin/env bash
exec "$VENV_PYTHON" -m closeclaw.cli "\$@"
WRAPPER
chmod +x "$INSTALL_BIN/$cmd"
done
ok "Installed via venv at $VENV_DIR"
else
# Fallback: user install
"$PYTHON" -m pip install --quiet --user -e "$PIP_TARGET"
ok "Installed via pip --user"
fi
# ── PATH hint ───────────────────────────────────────────────────────────────
if ! need_cmd closeclaw; then
warn "closeclaw not in PATH yet."
echo ""
echo " Add this to your shell profile (~/.bashrc or ~/.zshrc):"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
echo ""
echo " Then reload: source ~/.bashrc"
echo ""
export PATH="$HOME/.local/bin:$VENV_DIR/bin:$PATH"
fi
ok "CloseClaw installed."
echo ""
# ── Genesis ─────────────────────────────────────────────────────────────────
if [ "$SKIP_GENESIS" = "1" ]; then
say "Skipping genesis (SKIP_GENESIS=1)."
echo ""
echo " Run when ready: closeclaw genesis"
echo ""
exit 0
fi
say "Starting genesis — first-boot sequence..."
echo ""
if [ "$QUIET" = "1" ]; then
closeclaw genesis --quiet || "$VENV_PYTHON" -m closeclaw.genesis --quiet
else
closeclaw genesis || "$VENV_PYTHON" -m closeclaw.genesis
fi