Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·204 lines (175 loc) · 6.86 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·204 lines (175 loc) · 6.86 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
#!/usr/bin/env sh
#
# Install the Dimo Host family (dimo-server, dimo-mcp, dimo-workflow-mcp
# and the web bundle) from a GitHub Release.
#
# The desktop app is not installed by this script; it ships as an Electron
# installer with its own updater. Coding agents are not installed either —
# they live in your own environment (ADR-0060).
#
# curl -fsSL https://raw.githubusercontent.com/DimoADE/Dimo/master/install.sh | sh
#
# Environment:
# DIMO_VERSION Install this version instead of the latest release.
# DIMO_PLATFORM Override platform detection (e.g. linux-x86_64).
# DIMO_GITHUB_REPO Source repository. Default DimoADE/Dimo.
# DIMO_HOST_FAMILY_BASE Override the download origin (no trailing slash).
# DIMO_INSTALL_DIR Where the `dimo` launcher goes. Default ~/.local/bin.
# DIMO_PRINT_PLAN Print the resolved platform and URLs, then exit.
set -eu
DEFAULT_REPO="DimoADE/Dimo"
REPO="${DIMO_GITHUB_REPO:-$DEFAULT_REPO}"
CACHE_ROOT="${HOME}/.dimo/host-family"
INSTALL_DIR="${DIMO_INSTALL_DIR:-${HOME}/.local/bin}"
# Kept in step with npx-cli/bin/release-assets.js by scripts/release-assets.test.js.
SUPPORTED_PLATFORMS="linux-x86_64 linux-aarch64 darwin-aarch64 windows-x86_64 windows-aarch64"
TEMP_DIR=""
fail() {
printf 'error: %s\n' "$1" >&2
exit 1
}
cleanup() {
if [ -n "$TEMP_DIR" ]; then
rm -rf "$TEMP_DIR"
fi
}
trap cleanup EXIT INT TERM
require_command() {
command -v "$1" >/dev/null 2>&1 || fail "$1 is required but was not found"
}
detect_platform() {
if [ -n "${DIMO_PLATFORM:-}" ]; then
printf '%s' "$DIMO_PLATFORM"
return
fi
os=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$os" in
linux) os="linux" ;;
darwin) os="darwin" ;;
*) fail "unsupported operating system: $(uname -s). Supported: ${SUPPORTED_PLATFORMS}" ;;
esac
machine=$(uname -m | tr '[:upper:]' '[:lower:]')
case "$machine" in
x86_64 | amd64) arch="x86_64" ;;
arm64 | aarch64) arch="aarch64" ;;
*) fail "unsupported architecture: $(uname -m). Supported: ${SUPPORTED_PLATFORMS}" ;;
esac
printf '%s-%s' "$os" "$arch"
}
assert_supported_platform() {
for candidate in $SUPPORTED_PLATFORMS; do
[ "$candidate" = "$1" ] && return 0
done
fail "unsupported platform: $1. Supported: ${SUPPORTED_PLATFORMS}"
}
latest_tag() {
curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" |
sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' |
head -n 1
}
# Both the archive digest and the per-file SHA256SUMS inside it are checked.
# There is deliberately no flag to skip either: a mismatch means the bytes are
# not the published release, and installing them anyway defers the problem to
# runtime.
verify_digest() {
file="$1"
expected="$2"
if command -v sha256sum >/dev/null 2>&1; then
actual=$(sha256sum "$file" | cut -d' ' -f1)
else
actual=$(shasum -a 256 "$file" | cut -d' ' -f1)
fi
[ "$actual" = "$expected" ] ||
fail "checksum mismatch for $(basename "$file"): expected ${expected}, got ${actual}"
}
verify_sha256sums() {
root="$1"
( cd "$root" && grep -v ' SHA256SUMS$' SHA256SUMS > .dimo-verify-list || true )
if [ ! -s "${root}/.dimo-verify-list" ]; then
rm -f "${root}/.dimo-verify-list"
fail "SHA256SUMS in the archive contained no checksums"
fi
if command -v sha256sum >/dev/null 2>&1; then
( cd "$root" && sha256sum --quiet --check .dimo-verify-list ) ||
fail "the extracted Host family failed per-file verification"
else
( cd "$root" && shasum -a 256 --status --check .dimo-verify-list ) ||
fail "the extracted Host family failed per-file verification"
fi
rm -f "${root}/.dimo-verify-list"
}
write_launcher() {
family_root="$1"
mkdir -p "$INSTALL_DIR"
launcher="${INSTALL_DIR}/dimo"
cat > "$launcher" <<LAUNCHER
#!/usr/bin/env sh
exec "${family_root}/dimo-server" "\$@"
LAUNCHER
chmod +x "$launcher"
printf '%s' "$launcher"
}
main() {
require_command curl
require_command tar
platform=$(detect_platform)
assert_supported_platform "$platform"
if [ -n "${DIMO_VERSION:-}" ]; then
tag="v${DIMO_VERSION#v}"
else
tag=$(latest_tag)
[ -n "$tag" ] || fail "could not resolve the latest release of ${REPO}"
fi
version="${tag#v}"
archive="Dimo-${version}-${platform}-server.tar.gz"
if [ -n "${DIMO_HOST_FAMILY_BASE:-}" ]; then
base_url="${DIMO_HOST_FAMILY_BASE%/}"
else
base_url="https://github.com/${REPO}/releases/download/${tag}"
fi
family_root="${CACHE_ROOT}/${tag}/${platform}/family"
if [ -n "${DIMO_PRINT_PLAN:-}" ]; then
printf 'platform=%s\n' "$platform"
printf 'tag=%s\n' "$tag"
printf 'archive=%s\n' "$archive"
printf 'archive_url=%s/%s\n' "$base_url" "$archive"
printf 'checksum_url=%s/%s.sha256\n' "$base_url" "$archive"
printf 'family_root=%s\n' "$family_root"
return 0
fi
if [ -f "${family_root}/SHA256SUMS" ]; then
printf 'Dimo Host family %s is already installed for %s.\n' "$tag" "$platform"
verify_sha256sums "$family_root"
else
TEMP_DIR=$(mktemp -d)
printf 'Downloading Dimo Host family %s for %s...\n' "$tag" "$platform"
curl -fSL --progress-bar "${base_url}/${archive}" -o "${TEMP_DIR}/${archive}" ||
fail "could not download ${base_url}/${archive}"
curl -fsSL "${base_url}/${archive}.sha256" -o "${TEMP_DIR}/${archive}.sha256" ||
fail "could not download the checksum for ${archive}"
expected=$(cut -d' ' -f1 < "${TEMP_DIR}/${archive}.sha256")
[ -n "$expected" ] || fail "the published checksum file for ${archive} was empty"
verify_digest "${TEMP_DIR}/${archive}" "$expected"
mkdir -p "${TEMP_DIR}/extract"
tar -xzf "${TEMP_DIR}/${archive}" -C "${TEMP_DIR}/extract"
unpacked="${TEMP_DIR}/extract/${platform}"
[ -f "${unpacked}/SHA256SUMS" ] || unpacked="${TEMP_DIR}/extract"
[ -f "${unpacked}/SHA256SUMS" ] ||
fail "the archive did not contain SHA256SUMS"
verify_sha256sums "$unpacked"
rm -rf "$family_root"
mkdir -p "$(dirname "$family_root")"
mv "$unpacked" "$family_root"
fi
chmod +x "${family_root}/dimo-server" "${family_root}/dimo-mcp" \
"${family_root}/dimo-workflow-mcp" 2>/dev/null || true
launcher=$(write_launcher "$family_root")
printf '\nInstalled Dimo Host family %s to %s\n' "$tag" "$family_root"
printf 'Launcher: %s\n' "$launcher"
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) printf '\nRun `dimo` to start the server on http://127.0.0.1:17891\n' ;;
*) printf '\nAdd %s to your PATH, then run `dimo`:\n export PATH="%s:$PATH"\n' \
"$INSTALL_DIR" "$INSTALL_DIR" ;;
esac
}
main "$@"