-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·229 lines (187 loc) · 8.86 KB
/
install.sh
File metadata and controls
executable file
·229 lines (187 loc) · 8.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
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
#!/bin/sh
# Installer for sortie — spec-first agent orchestrator.
#
# Usage:
# curl -sSL https://get.sortie-ai.com/install.sh | sh
#
# Environment:
# SORTIE_VERSION Pin a specific release tag (e.g. v1.0.0 or 0.0.7).
# SORTIE_INSTALL_DIR Override install directory
# (default: /usr/local/bin as root, ~/.local/bin otherwise).
# SORTIE_NO_VERIFY Set to 1 to skip checksum verification.
set -eu
REPO="sortie-ai/sortie"
BIN="sortie"
# ── Formatting ────────────────────────────────────────────────────────────────
setup_colors() {
if [ -t 1 ] && [ "${TERM-}" != "dumb" ]; then
BOLD='\033[1m' DIM='\033[2m'
RED='\033[31m' GREEN='\033[32m' YELLOW='\033[33m' CYAN='\033[36m'
RESET='\033[0m'
else
BOLD='' DIM='' RED='' GREEN='' YELLOW='' CYAN='' RESET=''
fi
}
info() { printf '%b%s\n' "${BOLD}${CYAN}:: ${RESET}" "$*"; }
ok() { printf '%b%s\n' "${BOLD}${GREEN}:: ${RESET}" "$*"; }
err() { printf '%b%s\n' "${BOLD}${RED}error: ${RESET}" "$*" >&2; }
die() { err "$@"; exit 1; }
# ── Platform detection ────────────────────────────────────────────────────────
detect_platform() {
OS=$(uname -s)
case "$OS" in
Linux*) OS=linux ;;
Darwin*) OS=darwin ;;
*) die "unsupported OS: $OS" ;;
esac
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH=amd64 ;;
aarch64|arm64) ARCH=arm64 ;;
*) die "unsupported architecture: $ARCH" ;;
esac
# On macOS, detect Rosetta 2: if the shell runs as x86_64 under translation
# on an Apple Silicon Mac, prefer the native arm64 binary.
if [ "$OS" = "darwin" ] && [ "$ARCH" = "amd64" ]; then
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then
ARCH=arm64
fi
fi
}
# ── HTTP abstraction ──────────────────────────────────────────────────────────
need_cmd() { command -v "$1" >/dev/null 2>&1 || die "required command not found: $1"; }
fetch() {
_url=$1 _out=${2:-}
if command -v curl >/dev/null 2>&1; then
if [ -n "$_out" ]; then curl -fsSL -o "$_out" "$_url"
else curl -fsSL "$_url"; fi
elif command -v wget >/dev/null 2>&1; then
if [ -n "$_out" ]; then wget -qO "$_out" "$_url"
else wget -qO- "$_url"; fi
else
die "curl or wget is required"
fi
}
# ── Version resolution ────────────────────────────────────────────────────────
resolve_tag() {
if [ -n "${SORTIE_VERSION-}" ]; then
printf '%s' "$SORTIE_VERSION"
return
fi
_json=$(fetch "https://api.github.com/repos/${REPO}/releases/latest") \
|| die "GitHub API request failed (rate-limited? set SORTIE_VERSION to skip)"
printf '%s' "$_json" \
| sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' \
| head -n1
}
# ── Checksum verification ────────────────────────────────────────────────────
verify_checksum() {
_file=$1 _sums=$2
_want=$(awk -v f="$(basename "$_file")" '$2 == f {print $1}' "$_sums")
[ -n "$_want" ] || die "no checksum entry for $(basename "$_file")"
if command -v sha256sum >/dev/null 2>&1; then
_got=$(sha256sum "$_file" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
_got=$(shasum -a 256 "$_file" | awk '{print $1}')
else
die "sha256sum or shasum is required"
fi
[ "$_want" = "$_got" ] \
|| die "checksum mismatch (expected ${_want}, got ${_got})"
}
# ── Install directory resolution ──────────────────────────────────────────────
resolve_install_dir() {
if [ -n "${SORTIE_INSTALL_DIR-}" ]; then
printf '%s' "$SORTIE_INSTALL_DIR"
return
fi
# Root (e.g. Docker) → /usr/local/bin, the FHS standard for local binaries.
if [ "$(id -u)" -eq 0 ]; then
printf '%s' "/usr/local/bin"
return
fi
# Non-root → ~/.local/bin (XDG convention, same as pip, mise, pipx).
printf '%s' "${HOME}/.local/bin"
}
# Detect rc file for the current shell so PATH hint is copy-pasteable.
shell_rc() {
case "${SHELL-}" in
*/zsh) printf '%s' "${ZDOTDIR:-$HOME}/.zshrc" ;;
*/bash) printf '%s' "${HOME}/.bashrc" ;;
*/fish) printf '%s' "${HOME}/.config/fish/config.fish" ;;
*) printf '%s' "${HOME}/.profile" ;;
esac
}
# ── Cleanup ───────────────────────────────────────────────────────────────────
cleanup() { [ -d "${TMPDIR_INSTALL-}" ] && rm -rf "$TMPDIR_INSTALL"; }
# ── Main ──────────────────────────────────────────────────────────────────────
main() {
setup_colors
need_cmd uname
need_cmd tar
detect_platform
info "Platform: ${OS}/${ARCH}"
_tag=$(resolve_tag)
[ -n "$_tag" ] || die "could not determine latest release"
_version=$(printf '%s' "$_tag" | sed 's/^v//')
info "Release: ${_tag}"
_archive="${BIN}_${_version}_${OS}_${ARCH}.tar.gz"
_base="https://github.com/${REPO}/releases/download/${_tag}"
TMPDIR_INSTALL=$(mktemp -d)
trap cleanup EXIT
trap 'exit 1' INT TERM
info "Downloading ${_archive}"
fetch "${_base}/${_archive}" "${TMPDIR_INSTALL}/${_archive}" \
|| die "download failed — verify release ${_tag} has asset for ${OS}/${ARCH}"
if [ "${SORTIE_NO_VERIFY-}" != "1" ]; then
fetch "${_base}/checksums.txt" "${TMPDIR_INSTALL}/checksums.txt" \
|| die "failed to download checksums"
verify_checksum "${TMPDIR_INSTALL}/${_archive}" "${TMPDIR_INSTALL}/checksums.txt"
info "Checksum verified"
fi
tar -xzf "${TMPDIR_INSTALL}/${_archive}" -C "${TMPDIR_INSTALL}"
_dir=$(resolve_install_dir)
mkdir -p "$_dir"
install -m 755 "${TMPDIR_INSTALL}/${BIN}" "${_dir}/${BIN}"
ok "Installed ${BIN} ${_tag} to ${_dir}/${BIN}"
case ":${PATH}:" in
*":${_dir}:"*) ;;
*)
_rc=$(shell_rc)
printf '\n'
info "Add to your PATH to get started:"
# shellcheck disable=SC2016
printf ' %becho '\''export PATH="%s:$PATH"'\'' >> %s%b\n\n' \
"${DIM}" "$_dir" "$_rc" "${RESET}"
;;
esac
printf '\n'
_utf8=false
case "${LC_ALL:-${LC_CTYPE:-${LANG:-}}}" in
*[Uu][Tt][Ff]8*|*[Uu][Tt][Ff]-8*) _utf8=true ;;
esac
# Skip decorative art in CI pipelines and non-interactive terminals.
printf '\n'
if [ -z "${CI-}" ] && [ -t 1 ] && [ "${TERM-}" != "dumb" ]; then
if [ "$_utf8" = "true" ]; then
printf '\033[36m ███████╗ ██████╗ ██████╗ ████████╗██╗███████╗\n'
printf ' ██╔════╝██╔═══██╗██╔══██╗╚══██╔══╝██║██╔════╝\n'
printf ' ███████╗██║ ██║██████╔╝ ██║ ██║█████╗\n'
printf ' ╚════██║██║ ██║██╔══██╗ ██║ ██║██╔══╝\n'
printf ' ███████║╚██████╔╝██║ ██║ ██║ ██║███████╗\n'
printf ' ╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝\033[0m\n'
else
printf ' Sortie\n'
fi
fi
printf ' %bTurns issue tickets into autonomous sessions%b\n\n' "${DIM}" "${RESET}"
printf '\n %bDocs:%b https://docs.sortie-ai.com\n' "${BOLD}${YELLOW}" "${RESET}"
printf ' %bChangelog:%b https://docs.sortie-ai.com/changelog/#%s\n' "${BOLD}${YELLOW}" "${RESET}" "$_version"
printf ' %bGitHub:%b https://github.com/%s\n' "${BOLD}${YELLOW}" "${RESET}" "$REPO"
if [ "$_utf8" = "true" ]; then
printf '\n Happy hacking! %b♠%b\n\n' "${CYAN}" "${RESET}"
else
printf '\n Happy hacking!\n\n'
fi
}
main "$@"