forked from opensquilla/opensquilla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·260 lines (229 loc) · 7.95 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·260 lines (229 loc) · 7.95 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
#!/usr/bin/env bash
# install.sh - OpenSquilla release installer for Linux and macOS.
#
# This script is safe to pipe from the public install URL. It installs uv if
# needed, installs a release wheel with uv tool, then prints the explicit next
# steps. It does not run onboarding or start the gateway.
set -euo pipefail
default_version="v0.2.1"
repo_slug="${OPENSQUILLA_REPOSITORY:-opensquilla/opensquilla}"
python_version="${OPENSQUILLA_PYTHON_VERSION:-3.12}"
original_path="${PATH:-}"
cli_version=""
cli_profile=""
cli_extras=""
usage() {
cat <<HELP
Usage: bash install.sh [--version v0.2.1|latest] [--profile recommended|core] [--extras name[,name]]
Environment equivalents:
OPENSQUILLA_VERSION=v0.2.1
OPENSQUILLA_INSTALL_PROFILE=recommended|core
OPENSQUILLA_INSTALL_EXTRAS=matrix
OPENSQUILLA_INSTALL_DRY_RUN=1
HELP
}
while [[ $# -gt 0 ]]; do
case "$1" in
--version)
cli_version="${2:?install.sh: --version requires a value}"
shift 2
;;
--version=*)
cli_version="${1#*=}"
shift
;;
--profile)
cli_profile="${2:?install.sh: --profile requires a value}"
shift 2
;;
--profile=*)
cli_profile="${1#*=}"
shift
;;
--extras)
cli_extras="${2:?install.sh: --extras requires a value}"
shift 2
;;
--extras=*)
cli_extras="${1#*=}"
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "install.sh: unknown argument '$1'." >&2
usage >&2
exit 1
;;
esac
done
release_selector="${cli_version:-${OPENSQUILLA_VERSION:-${default_version}}}"
profile="${cli_profile:-${OPENSQUILLA_INSTALL_PROFILE:-recommended}}"
dry_run="${OPENSQUILLA_INSTALL_DRY_RUN:-0}"
is_release_version() {
[[ "$1" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?$ ]]
}
valid_extras=" feishu telegram dingtalk wecom qq matrix matrix-e2e document-extras "
extras_csv="${OPENSQUILLA_INSTALL_EXTRAS:-}"
if [[ -n "${cli_extras}" ]]; then
extras_csv="${extras_csv}${extras_csv:+,}${cli_extras}"
fi
extras_csv="${extras_csv// /,}"
raw_extras=()
if [[ -n "${extras_csv}" ]]; then
IFS=',' read -r -a raw_extras <<< "${extras_csv}"
fi
install_extras=()
for extra in "${raw_extras[@]}"; do
[[ -n "${extra}" ]] || continue
if [[ "${valid_extras}" != *" ${extra} "* ]]; then
echo "install.sh: unsupported extra '${extra}'." >&2
echo "install.sh: supported extras:${valid_extras}" >&2
exit 1
fi
duplicate=0
for existing in "${install_extras[@]}"; do
if [[ "${existing}" == "${extra}" ]]; then
duplicate=1
break
fi
done
if [[ "${duplicate}" -eq 0 ]]; then
install_extras+=("${extra}")
fi
done
case "${profile}" in
core|minimal)
profile="core"
target_extras=()
;;
recommended)
target_extras=(recommended)
;;
*)
echo "install.sh: unsupported OPENSQUILLA_INSTALL_PROFILE='${profile}'." >&2
echo "install.sh: supported profiles: core, recommended" >&2
exit 1
;;
esac
if (( ${#install_extras[@]} > 0 )); then
target_extras+=("${install_extras[@]}")
fi
if (( ${#target_extras[@]} > 0 )); then
package_name="opensquilla[$(IFS=,; echo "${target_extras[*]}")]"
else
package_name="opensquilla"
fi
if [[ "${release_selector}" != "latest" && "${release_selector}" != "stable" ]] && ! is_release_version "${release_selector}"; then
echo "install.sh: unsupported OPENSQUILLA_VERSION='${release_selector}'." >&2
echo "install.sh: the release installer only supports latest, stable, or release versions like v0.2.1." >&2
echo "install.sh: use git clone plus scripts/install_source.sh for main, dev, branch, or source installs." >&2
exit 1
fi
case "${release_selector}" in
latest|stable)
latest_tag=""
if command -v curl >/dev/null 2>&1; then
latest_tag="$(
curl -fsSL "https://api.github.com/repos/${repo_slug}/releases/latest" \
| sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' \
| head -n 1
)"
elif command -v wget >/dev/null 2>&1; then
latest_tag="$(
wget -qO- "https://api.github.com/repos/${repo_slug}/releases/latest" \
| sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' \
| head -n 1
)"
else
echo "install.sh: curl or wget is required to resolve the latest release." >&2
exit 1
fi
if ! is_release_version "${latest_tag}"; then
echo "install.sh: failed to resolve latest release tag for ${repo_slug}." >&2
exit 1
fi
release_version="${latest_tag#v}"
wheel_url="https://github.com/${repo_slug}/releases/download/${latest_tag}/opensquilla-${release_version}-py3-none-any.whl"
display_version="${latest_tag}"
;;
v*)
release_version="${release_selector#v}"
wheel_url="https://github.com/${repo_slug}/releases/download/${release_selector}/opensquilla-${release_version}-py3-none-any.whl"
display_version="${release_selector}"
;;
*)
release_version="${release_selector}"
release_tag="v${release_version}"
wheel_url="https://github.com/${repo_slug}/releases/download/${release_tag}/opensquilla-${release_version}-py3-none-any.whl"
display_version="${release_tag}"
;;
esac
install_spec="${package_name} @ ${wheel_url}"
install_uv() {
if command -v curl >/dev/null 2>&1; then
curl -LsSf https://astral.sh/uv/install.sh | sh
elif command -v wget >/dev/null 2>&1; then
wget -qO- https://astral.sh/uv/install.sh | sh
else
echo "install.sh: curl or wget is required to install uv." >&2
exit 1
fi
}
resolve_uv() {
if command -v uv >/dev/null 2>&1; then
command -v uv
return 0
fi
if [[ -f "${HOME}/.local/bin/env" ]]; then
# shellcheck disable=SC1091
. "${HOME}/.local/bin/env"
fi
export PATH="${HOME}/.local/bin:${HOME}/.cargo/bin:${PATH:-}"
if command -v uv >/dev/null 2>&1; then
command -v uv
return 0
fi
return 1
}
if [[ "${dry_run}" == "1" ]]; then
echo "install.sh: dry-run - would install OpenSquilla ${display_version}"
echo "install.sh: dry-run - would run: uv tool install --python ${python_version} --force --reinstall-package opensquilla \"${install_spec}\""
exit 0
fi
uv_bin="$(resolve_uv || true)"
if [[ -z "${uv_bin}" ]]; then
echo "install.sh: uv not found; installing uv first."
install_uv
uv_bin="$(resolve_uv || true)"
fi
if [[ -z "${uv_bin}" ]]; then
echo "install.sh: uv was not found after installation." >&2
echo "install.sh: restart your terminal or run '. \"\$HOME/.local/bin/env\"', then retry." >&2
exit 1
fi
echo "install.sh: installing OpenSquilla ${display_version} (${profile})"
"${uv_bin}" tool install --python "${python_version}" --force --reinstall-package opensquilla "${install_spec}"
tool_bin_dir="$("${uv_bin}" tool dir --bin 2>/dev/null || true)"
cat <<DONE
----------------------------------------------------------------------------
OpenSquilla installed from ${display_version}.
Next steps:
opensquilla onboard
opensquilla gateway run
Default gateway bind: 127.0.0.1:18791 (loopback only).
Do not expose the gateway on 0.0.0.0 unless it is behind a trusted reverse
proxy or VPN.
----------------------------------------------------------------------------
DONE
if [[ -n "${tool_bin_dir}" && ":${original_path}:" != *":${tool_bin_dir}:"* ]]; then
cat <<PATHNOTE
PATH note:
Your current shell may not find 'opensquilla' until PATH is refreshed.
Run one of these, then retry the next steps:
. "\$HOME/.local/bin/env"
# or open a new terminal
PATHNOTE
fi