-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
211 lines (179 loc) · 7.21 KB
/
Copy pathinstall.sh
File metadata and controls
211 lines (179 loc) · 7.21 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
#!/bin/sh
# Liaison CLI installer.
#
# Usage:
# curl -fsSL https://liaison.cloud/install-cli.sh | sh
#
# Optional environment variables:
# LIAISON_CLI_VERSION pin a specific version (default: latest release)
# LIAISON_CLI_INSTALL_DIR where to put the binary (default: ~/.local/bin
# if writable, else /usr/local/bin via sudo)
# LIAISON_CLI_RELEASE_BASE override the release URL base (for staging)
#
# Designed to be safe to pipe into sh: it never sources untrusted code, never
# requires root unless installing into a system path, and verifies the SHA256
# checksum of the downloaded binary against the published SHA256SUMS file.
set -eu
GITHUB_BASE="https://github.com/liaisonio/cli/releases"
CHINA_MIRROR="https://liaison.cloud/releases"
RELEASE_BASE="${LIAISON_CLI_RELEASE_BASE:-${GITHUB_BASE}}"
VERSION="${LIAISON_CLI_VERSION:-latest}"
INSTALL_DIR="${LIAISON_CLI_INSTALL_DIR:-}"
BINARY_NAME="liaison"
# ─── helpers ─────────────────────────────────────────────────────────────────
err() { echo "error: $*" >&2; exit 1; }
info() { echo "→ $*"; }
have() { command -v "$1" >/dev/null 2>&1; }
require() {
for cmd in "$@"; do
have "$cmd" || err "required command not found: $cmd"
done
}
# ─── platform detection ──────────────────────────────────────────────────────
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
Darwin*) echo "darwin" ;;
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
*) err "unsupported OS: $(uname -s)" ;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "amd64" ;;
arm64|aarch64) echo "arm64" ;;
*) err "unsupported architecture: $(uname -m)" ;;
esac
}
# ─── install location ────────────────────────────────────────────────────────
resolve_install_dir() {
if [ -n "${INSTALL_DIR}" ]; then
# If the user explicitly chose a path, create it. Trust their decision —
# don't fall through to the sudo branch for an arbitrary user-supplied dir.
mkdir -p "${INSTALL_DIR}" 2>/dev/null || true
echo "${INSTALL_DIR}"
return
fi
# Prefer ~/.local/bin if the user can write to it (no sudo needed).
user_bin="${HOME}/.local/bin"
if [ -d "${user_bin}" ] && [ -w "${user_bin}" ]; then
echo "${user_bin}"
return
fi
if mkdir -p "${user_bin}" 2>/dev/null && [ -w "${user_bin}" ]; then
echo "${user_bin}"
return
fi
echo "/usr/local/bin"
}
needs_sudo() {
[ "$1" = "/usr/local/bin" ] || [ "$1" = "/usr/bin" ] || [ ! -w "$1" ]
}
# ─── download & verify ───────────────────────────────────────────────────────
download() {
url="$1"; out="$2"
if have curl; then
curl -fsSL "${url}" -o "${out}"
elif have wget; then
wget -q "${url}" -O "${out}"
else
err "need curl or wget"
fi
}
resolve_version() {
if [ "${VERSION}" = "latest" ]; then
# GitHub redirects /releases/latest to /releases/tag/<vN.N.N>; capture the tag
if have curl; then
curl -fsSLI "${RELEASE_BASE}/latest" \
| awk -F'/' '/^[Ll]ocation:/ { gsub(/[\r\n]+$/, "", $NF); print $NF }' \
| tail -1
else
err "need curl to resolve latest version"
fi
else
echo "${VERSION}"
fi
}
verify_sha256() {
file="$1"; expected="$2"
if have shasum; then
actual=$(shasum -a 256 "${file}" | awk '{print $1}')
elif have sha256sum; then
actual=$(sha256sum "${file}" | awk '{print $1}')
else
err "need shasum or sha256sum to verify download"
fi
if [ "${actual}" != "${expected}" ]; then
err "checksum mismatch for ${file} (expected ${expected}, got ${actual})"
fi
}
# ─── main ────────────────────────────────────────────────────────────────────
main() {
os=$(detect_os)
arch=$(detect_arch)
ext=""
[ "${os}" = "windows" ] && ext=".exe"
resolved_version=$(resolve_version)
[ -n "${resolved_version}" ] || err "could not resolve version (network?)"
info "version: ${resolved_version}"
info "platform: ${os}/${arch}"
artifact="${BINARY_NAME}-${resolved_version}-${os}-${arch}${ext}"
tmpdir=$(mktemp -d)
trap 'rm -rf "${tmpdir}"' EXIT
# Try liaison.cloud first; on failure try GitHub releases.
# Users can force a specific source via LIAISON_CLI_RELEASE_BASE.
fetch_from() {
_base="$1"; _label="$2"
_artifact_url="${_base}/download/${resolved_version}/${artifact}"
_sums_url="${_base}/download/${resolved_version}/SHA256SUMS"
# China mirror uses a flat layout: /releases/<version>/<file>
if echo "${_base}" | grep -q 'liaison.cloud'; then
_artifact_url="${_base}/${resolved_version}/${artifact}"
_sums_url="${_base}/${resolved_version}/SHA256SUMS"
fi
info "[${_label}] fetching ${_artifact_url}"
download "${_artifact_url}" "${tmpdir}/${artifact}" || return 1
info "[${_label}] fetching SHA256SUMS"
download "${_sums_url}" "${tmpdir}/SHA256SUMS" || return 1
expected=$(awk -v f="${artifact}" '$2 == f { print $1 }' "${tmpdir}/SHA256SUMS")
[ -n "${expected}" ] || { info "no SHA256 entry for ${artifact}"; return 1; }
info "[${_label}] verifying SHA256"
verify_sha256 "${tmpdir}/${artifact}" "${expected}"
}
if [ "${RELEASE_BASE}" != "${GITHUB_BASE}" ]; then
# User overrode the source — use only that.
fetch_from "${RELEASE_BASE}" "custom" || err "download failed from ${RELEASE_BASE}"
else
# Try liaison.cloud first (our own CDN), fall back to GitHub releases.
fetch_from "${CHINA_MIRROR}" "liaison.cloud" || {
info "liaison.cloud download failed, trying GitHub releases..."
fetch_from "${GITHUB_BASE}" "github" || err "download failed from both liaison.cloud and GitHub"
}
fi
install_dir=$(resolve_install_dir)
info "installing to ${install_dir}/${BINARY_NAME}${ext}"
chmod +x "${tmpdir}/${artifact}"
if needs_sudo "${install_dir}"; then
sudo mv "${tmpdir}/${artifact}" "${install_dir}/${BINARY_NAME}${ext}"
else
mv "${tmpdir}/${artifact}" "${install_dir}/${BINARY_NAME}${ext}"
fi
# Install the bundled agent skill files into ~/.claude/skills. Best-effort:
# failure just prints a hint, it doesn't fail the install. Opt out with
# LIAISON_CLI_SKIP_SKILLS=1.
if [ "${LIAISON_CLI_SKIP_SKILLS:-0}" != "1" ]; then
info "installing agent skills to ~/.claude/skills"
if ! "${install_dir}/${BINARY_NAME}${ext}" skills install -g >/dev/null 2>&1; then
info "skill install failed — run \`${BINARY_NAME} skills install -g\` manually to retry"
fi
fi
echo
echo "✓ Liaison CLI installed: ${install_dir}/${BINARY_NAME}${ext}"
case ":${PATH}:" in
*":${install_dir}:"*) ;;
*) echo " (note: ${install_dir} is not in your PATH — add it to your shell rc file)" ;;
esac
echo
echo "Next: liaison login"
}
main "$@"