-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·187 lines (167 loc) · 7.66 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·187 lines (167 loc) · 7.66 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
#!/bin/sh
# install.sh — One-line installer for the openclaw shell wrapper and autocomplete
#
# Run directly from the internet:
# curl -fsSL https://raw.githubusercontent.com/stritti/clawmetry-docker/main/install.sh | bash
#
# What it installs:
# 1. openclaw.sh → /usr/local/bin/openclaw (or ~/.local/bin/openclaw as fallback)
# 2. openclaw_completion.sh → shell-specific location (Bash or Zsh)
#
# Override defaults with environment variables:
# OPENCLAW_INSTALL_DIR — directory to install the binary (default: /usr/local/bin)
# OPENCLAW_REPO — GitHub repo slug (default: stritti/clawmetry-docker)
# OPENCLAW_BRANCH — branch/tag to download from (default: main)
set -e
OPENCLAW_REPO="${OPENCLAW_REPO:-stritti/clawmetry-docker}"
OPENCLAW_BRANCH="${OPENCLAW_BRANCH:-main}"
BASE_URL="https://raw.githubusercontent.com/${OPENCLAW_REPO}/${OPENCLAW_BRANCH}"
# ── Helpers ───────────────────────────────────────────────────────────────────
info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
ok() { printf '\033[1;32m ✓\033[0m %s\n' "$*"; }
warn() { printf '\033[1;33mWARN\033[0m %s\n' "$*" >&2; }
die() { printf '\033[1;31mERROR\033[0m %s\n' "$*" >&2; exit 1; }
# Download a URL to a file (supports curl and wget)
download() {
url="$1"; dest="$2"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$dest"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$dest" "$url"
else
die "Neither curl nor wget found. Install one and re-run."
fi
}
# ── Preflight ─────────────────────────────────────────────────────────────────
if ! command -v docker >/dev/null 2>&1; then
warn "Docker is not installed. The openclaw wrapper requires Docker to run."
warn "Install Docker from https://docs.docker.com/get-docker/ before using openclaw."
fi
# ── Choose install directory ──────────────────────────────────────────────────
if [ -n "$OPENCLAW_INSTALL_DIR" ]; then
INSTALL_DIR="$OPENCLAW_INSTALL_DIR"
elif [ -w /usr/local/bin ]; then
INSTALL_DIR="/usr/local/bin"
elif command -v sudo >/dev/null 2>&1; then
INSTALL_DIR="/usr/local/bin"
USE_SUDO=1
else
INSTALL_DIR="$HOME/.local/bin"
warn "No write access to /usr/local/bin and sudo not found."
warn "Installing to $INSTALL_DIR — make sure it is in your PATH."
fi
# Ensure install directory exists and is writable
if [ ! -d "$INSTALL_DIR" ]; then
if [ -n "$USE_SUDO" ]; then
info "Creating install directory $INSTALL_DIR with sudo …"
if ! sudo mkdir -p "$INSTALL_DIR"; then
die "Failed to create install directory $INSTALL_DIR with sudo."
fi
else
if ! mkdir -p "$INSTALL_DIR" 2>/dev/null; then
if command -v sudo >/dev/null 2>&1; then
info "Creating install directory $INSTALL_DIR with sudo …"
if ! sudo mkdir -p "$INSTALL_DIR"; then
die "Failed to create install directory $INSTALL_DIR with sudo."
fi
USE_SUDO=1
else
die "Cannot create install directory $INSTALL_DIR; check permissions."
fi
fi
fi
fi
if [ ! -w "$INSTALL_DIR" ]; then
if command -v sudo >/dev/null 2>&1; then
USE_SUDO=1
else
die "Install directory $INSTALL_DIR is not writable and sudo is not available."
fi
fi
# ── Install openclaw wrapper ──────────────────────────────────────────────────
info "Downloading openclaw wrapper …"
TMP_WRAPPER="$(mktemp "${TMPDIR:-/tmp}/openclaw.XXXXXX")"
download "${BASE_URL}/openclaw.sh" "$TMP_WRAPPER"
chmod 755 "$TMP_WRAPPER"
WRAPPER_DEST="${INSTALL_DIR}/openclaw"
if [ -n "$USE_SUDO" ]; then
sudo mv "$TMP_WRAPPER" "$WRAPPER_DEST"
sudo chmod 755 "$WRAPPER_DEST"
else
mv "$TMP_WRAPPER" "$WRAPPER_DEST"
chmod 755 "$WRAPPER_DEST"
fi
ok "Installed wrapper → $WRAPPER_DEST"
# ── Install shell completion ──────────────────────────────────────────────────
info "Downloading shell completion script …"
TMP_COMP="$(mktemp)"
download "${BASE_URL}/openclaw_completion.sh" "$TMP_COMP"
# Detect the current shell from the parent process
DETECTED_SHELL="$(basename "${SHELL:-sh}")"
case "$DETECTED_SHELL" in
zsh)
# Per-user Zsh install: copy to ~/.local/share and source from ~/.zshrc
COMP_DEST="$HOME/.local/share/openclaw_completion.sh"
mkdir -p "$(dirname "$COMP_DEST")"
cp "$TMP_COMP" "$COMP_DEST"
if ! grep -qF "openclaw_completion.sh" "$HOME/.zshrc" 2>/dev/null; then
printf '\n# openclaw shell completion\nsource %s\n' "$COMP_DEST" >> "$HOME/.zshrc"
ok "Added completion source line to ~/.zshrc"
else
ok "Completion already sourced in ~/.zshrc — skipped"
fi
ok "Installed completion → $COMP_DEST"
;;
bash)
# Try system-wide Bash completion directory first, then per-user fallback
if [ -d /etc/bash_completion.d ] && { [ -w /etc/bash_completion.d ] || [ -n "$USE_SUDO" ]; }; then
COMP_DEST="/etc/bash_completion.d/openclaw"
if [ -n "$USE_SUDO" ]; then
sudo mv "$TMP_COMP" "$COMP_DEST"
sudo chmod 644 "$COMP_DEST"
else
mv "$TMP_COMP" "$COMP_DEST"
chmod 644 "$COMP_DEST"
fi
ok "Installed completion → $COMP_DEST (open a new shell to activate)"
else
# Per-user fallback: source from ~/.bashrc
COMP_DEST="$HOME/.local/share/openclaw_completion.sh"
mkdir -p "$(dirname "$COMP_DEST")"
cp "$TMP_COMP" "$COMP_DEST"
if ! grep -qF "openclaw_completion.sh" "$HOME/.bashrc" 2>/dev/null; then
printf '\n# openclaw shell completion\nsource %s\n' "$COMP_DEST" >> "$HOME/.bashrc"
ok "Added completion source line to ~/.bashrc"
else
ok "Completion already sourced in ~/.bashrc — skipped"
fi
ok "Installed completion → $COMP_DEST"
fi
;;
*)
# Unknown shell: install to ~/.local/share and print instructions
COMP_DEST="$HOME/.local/share/openclaw_completion.sh"
mkdir -p "$(dirname "$COMP_DEST")"
cp "$TMP_COMP" "$COMP_DEST"
ok "Installed completion → $COMP_DEST"
warn "Unknown shell '$DETECTED_SHELL'. Add the following line to your shell RC file to enable completion:"
warn " source $COMP_DEST"
;;
esac
rm -f "$TMP_COMP"
# ── Done ──────────────────────────────────────────────────────────────────────
printf '\n'
info "Installation complete!"
printf '\n'
printf ' Run the onboarding wizard:\n'
printf ' openclaw setup\n'
printf '\n'
printf ' Check gateway status:\n'
printf ' openclaw status\n'
printf '\n'
if [ -n "$USE_SUDO" ] || [ "$INSTALL_DIR" != "$HOME/.local/bin" ]; then
printf ' Reload your shell or open a new terminal to use the openclaw command.\n'
else
printf ' Make sure %s is in your PATH, then reload your shell.\n' "$INSTALL_DIR"
fi
printf '\n'