-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
路175 lines (145 loc) 路 4.25 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
路175 lines (145 loc) 路 4.25 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
#!/bin/bash
set -euo pipefail
OWNER="${CLAWMAX_GITHUB_OWNER:-Maximilien-ai}"
REPO="${CLAWMAX_GITHUB_REPO:-clawmax}"
DEFAULT_TARGET_DIR="${CLAWMAX_INSTALL_DIR:-clawmax}"
usage() {
cat <<'EOF'
ClawMax bootstrap installer
Usage:
./install.sh [latest|vX.Y.Z] [--dir PATH] [--force] [setup.sh args...]
Examples:
./install.sh
./install.sh v1.5.6
./install.sh v1.5.6 --dir /opt/clawmax --non-interactive
EOF
}
print() { printf '%s\n' "$*"; }
print_info() { printf '\033[0;34m鈩筡033[0m %s\n' "$*"; }
print_ok() { printf '\033[0;32m鉁揬033[0m %s\n' "$*"; }
print_warn() { printf '\033[1;33m鈿燶033[0m %s\n' "$*"; }
print_error() { printf '\033[0;31m鉁梊033[0m %s\n' "$*" >&2; }
require_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
print_error "Required command not found: $1"
exit 1
fi
}
resolve_latest_version() {
curl -fsSL -o /dev/null -w '%{url_effective}' "https://github.com/${OWNER}/${REPO}/releases/latest" | awk -F/ '{print $NF}'
}
checksum_verify() {
local checksum_file="$1"
local asset_file="$2"
if command -v shasum >/dev/null 2>&1; then
(cd "$(dirname "$asset_file")" && shasum -a 256 -c "$(basename "$checksum_file")")
return
fi
if command -v sha256sum >/dev/null 2>&1; then
(cd "$(dirname "$asset_file")" && sha256sum -c "$(basename "$checksum_file")")
return
fi
print_error "Neither shasum nor sha256sum is available for checksum verification"
exit 1
}
VERSION=""
TARGET_DIR="$DEFAULT_TARGET_DIR"
FORCE_INSTALL=false
SETUP_ARGS=()
while [ "$#" -gt 0 ]; do
case "$1" in
-h|--help)
usage
exit 0
;;
--dir)
shift
[ "$#" -gt 0 ] || { print_error "--dir requires a path"; exit 1; }
TARGET_DIR="$1"
;;
--force)
FORCE_INSTALL=true
;;
latest|v[0-9]*)
if [ -z "$VERSION" ]; then
VERSION="$1"
else
SETUP_ARGS+=("$1")
fi
;;
*)
SETUP_ARGS+=("$1")
;;
esac
shift
done
require_cmd curl
require_cmd tar
if [ -z "$VERSION" ] || [ "$VERSION" = "latest" ]; then
print_info "Resolving latest ClawMax release..."
VERSION="$(resolve_latest_version)"
fi
case "$VERSION" in
v[0-9]*)
;;
*)
print_error "Version must look like vX.Y.Z or 'latest' (got: $VERSION)"
exit 1
;;
esac
ASSET_BASENAME="clawmax-${VERSION}.tar.gz"
CHECKSUM_BASENAME="clawmax-${VERSION}.sha256"
BASE_URL="https://github.com/${OWNER}/${REPO}/releases/download/${VERSION}"
ASSET_URL="${BASE_URL}/${ASSET_BASENAME}"
CHECKSUM_URL="${BASE_URL}/${CHECKSUM_BASENAME}"
TARGET_DIR_ABS="$(python3 - <<'PY' "$TARGET_DIR"
import os, sys
print(os.path.abspath(sys.argv[1]))
PY
)"
TARGET_PARENT="$(dirname "$TARGET_DIR_ABS")"
TARGET_NAME="$(basename "$TARGET_DIR_ABS")"
if [ -e "$TARGET_DIR_ABS" ] && [ "$FORCE_INSTALL" != true ]; then
print_error "Target directory already exists: $TARGET_DIR_ABS"
print_info "Use --force to replace it or choose --dir PATH"
exit 1
fi
if [ -e "$TARGET_DIR_ABS" ] && [ "$FORCE_INSTALL" = true ]; then
print_warn "Removing existing target directory: $TARGET_DIR_ABS"
rm -rf "$TARGET_DIR_ABS"
fi
TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/clawmax-install.XXXXXX")"
cleanup() {
rm -rf "$TMP_DIR"
}
trap cleanup EXIT
ARCHIVE_PATH="${TMP_DIR}/${ASSET_BASENAME}"
CHECKSUM_PATH="${TMP_DIR}/${CHECKSUM_BASENAME}"
print_info "Downloading ${VERSION} release bundle..."
curl -fsSL "$ASSET_URL" -o "$ARCHIVE_PATH"
curl -fsSL "$CHECKSUM_URL" -o "$CHECKSUM_PATH"
print_ok "Downloaded release assets"
print_info "Verifying checksum..."
checksum_verify "$CHECKSUM_PATH" "$ARCHIVE_PATH"
print_ok "Checksum verified"
mkdir -p "$TARGET_PARENT"
EXTRACT_DIR="${TMP_DIR}/extract"
mkdir -p "$EXTRACT_DIR"
print_info "Extracting ${ASSET_BASENAME}..."
tar -xzf "$ARCHIVE_PATH" -C "$EXTRACT_DIR"
EXTRACTED_ROOT="$(find "$EXTRACT_DIR" -mindepth 1 -maxdepth 1 -type d | head -1)"
if [ -z "$EXTRACTED_ROOT" ] || [ ! -f "$EXTRACTED_ROOT/setup.sh" ]; then
print_error "Release bundle did not contain a valid ClawMax root with setup.sh"
exit 1
fi
mv "$EXTRACTED_ROOT" "$TARGET_DIR_ABS"
print_ok "Installed release bundle to $TARGET_DIR_ABS"
print_info "Starting setup..."
cd "$TARGET_DIR_ABS"
if [ -z "${AUTH_MODE:-}" ]; then
export AUTH_MODE="bypass"
fi
if [ "${#SETUP_ARGS[@]}" -gt 0 ]; then
exec ./setup.sh "${SETUP_ARGS[@]}"
fi
exec ./setup.sh