-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·234 lines (204 loc) · 8.35 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·234 lines (204 loc) · 8.35 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
#!/usr/bin/env bash
# amplifier-agent installer
#
# Recommended usage:
# curl -fsSL https://raw.githubusercontent.com/microsoft/amplifier-agent/main/install.sh | bash
#
# Pin a specific version:
# curl -fsSL https://raw.githubusercontent.com/microsoft/amplifier-agent/main/install.sh | bash -s -- --tag v0.9.0
#
# Review first (recommended for production):
# curl -fsSL https://raw.githubusercontent.com/microsoft/amplifier-agent/main/install.sh -o install.sh
# less install.sh
# bash install.sh
#
# Flags: --tag <ref> | --no-prime | --yes | --help
set -euo pipefail
IFS=$'\n\t'
# ---------------------------------------------------------------------------
# Constants
# ---------------------------------------------------------------------------
REPO_SLUG="microsoft/amplifier-agent"
RELEASES_URL="https://api.github.com/repos/${REPO_SLUG}/releases/latest"
GIT_URL="https://github.com/${REPO_SLUG}"
PACKAGE_NAME="amplifier-agent"
# ---------------------------------------------------------------------------
# Usage
# ---------------------------------------------------------------------------
usage() {
cat <<'USAGE'
amplifier-agent installer
Usage:
curl -fsSL https://raw.githubusercontent.com/microsoft/amplifier-agent/main/install.sh | bash
Flags:
--tag <ref> Install a specific tag, branch, or commit (default: latest release)
--no-prime Skip the bundle cache priming step
--yes Skip the confirmation prompt (for CI/automation)
--help Print this help and exit
Examples:
# Pin to a specific version
curl -fsSL https://raw.githubusercontent.com/microsoft/amplifier-agent/main/install.sh | bash -s -- --tag v0.9.0
# Skip bundle priming (faster install, but first run will be 30-60s slower)
curl -fsSL https://raw.githubusercontent.com/microsoft/amplifier-agent/main/install.sh | bash -s -- --no-prime
# Non-interactive (CI/automation)
curl -fsSL https://raw.githubusercontent.com/microsoft/amplifier-agent/main/install.sh | bash -s -- --yes
USAGE
}
# ---------------------------------------------------------------------------
# Parse flags
# ---------------------------------------------------------------------------
TAG=""
NO_PRIME=0
YES=0
while [[ $# -gt 0 ]]; do
case "$1" in
--tag)
if [[ "$#" -lt 2 ]] || [[ -z "$2" ]]; then
printf 'error: --tag requires a non-empty argument\n' >&2
exit 1
fi
TAG="$2"
shift 2
;;
--tag=*)
TAG="${1#--tag=}"
if [[ -z "${TAG}" ]]; then
printf 'error: --tag= requires a non-empty value\n' >&2
exit 1
fi
shift
;;
--no-prime)
NO_PRIME=1
shift
;;
--yes)
YES=1
shift
;;
--help | -h)
usage
exit 0
;;
*)
printf 'error: unknown flag: %s\n' "$1" >&2
printf 'Run with --help for usage.\n' >&2
exit 1
;;
esac
done
# ---------------------------------------------------------------------------
# Pre-flight checks
# ---------------------------------------------------------------------------
# Require bash 3.2+ (macOS ships with 3.2; this script uses bash-specific syntax).
BASH_MAJOR="${BASH_VERSION%%.*}"
BASH_MINOR="${BASH_VERSION#*.}"
BASH_MINOR="${BASH_MINOR%%.*}"
if [[ "${BASH_MAJOR}" -lt 3 ]]; then
printf 'error: bash 3.2 or later is required (found bash %s)\n' "${BASH_VERSION}" >&2
exit 1
fi
if [[ "${BASH_MAJOR}" -eq 3 ]] && [[ "${BASH_MINOR}" -lt 2 ]]; then
printf 'error: bash 3.2 or later is required (found bash %s)\n' "${BASH_VERSION}" >&2
exit 1
fi
# Require curl.
if ! command -v curl > /dev/null 2>&1; then
printf 'error: curl is required but not found on PATH.\n' >&2
printf 'Install curl with your package manager and re-run this script.\n' >&2
exit 1
fi
# Require git -- the bundle system clones module and bundle repositories, both
# while priming the cache below and every time a bundle is mounted at run time.
if ! command -v git > /dev/null 2>&1; then
printf 'error: git is required but not found on PATH.\n\n' >&2
printf 'amplifier-agent fetches modules and bundles by cloning git repositories,\n' >&2
printf 'both while priming the cache during this install and every time a bundle\n' >&2
printf 'is mounted at run time. It is a runtime dependency, not just a build one.\n\n' >&2
printf 'Install git:\n' >&2
printf ' macOS: xcode-select --install\n' >&2
printf ' Linux: your package manager, e.g. apt install git\n' >&2
printf ' Windows: https://git-scm.com/download/win (Git for Windows)\n\n' >&2
printf 'Then re-run this script.\n' >&2
exit 1
fi
# Require uv — never silently bootstrap it; direct the user instead.
if ! command -v uv > /dev/null 2>&1; then
printf 'error: uv is required but not found on PATH.\n\n' >&2
printf 'Install uv first:\n' >&2
printf ' curl -LsSf https://astral.sh/uv/install.sh | sh\n\n' >&2
printf 'Then open a new shell (or run: source ~/.local/bin/env) and re-run this script.\n' >&2
exit 1
fi
# ---------------------------------------------------------------------------
# Resolve the target tag
# ---------------------------------------------------------------------------
if [[ -z "${TAG}" ]]; then
printf 'Resolving latest amplifier-agent release...\n'
TAG="$(
curl -fsSL "${RELEASES_URL}" \
| grep -m1 '"tag_name":' \
| sed -E 's/.*"tag_name": *"([^"]+)".*/\1/'
)"
if [[ -z "${TAG}" ]]; then
printf 'error: could not determine the latest release tag.\n' >&2
printf 'Pass --tag <ref> explicitly, or browse releases at:\n' >&2
printf ' https://github.com/%s/releases\n' "${REPO_SLUG}" >&2
exit 1
fi
fi
# ---------------------------------------------------------------------------
# Confirmation gate
# ---------------------------------------------------------------------------
printf '\n'
if [[ "${NO_PRIME}" -eq 1 ]]; then
printf 'Will install %s@%s via uv tool install (bundle priming skipped).\n' \
"${PACKAGE_NAME}" "${TAG}"
else
printf 'Will install %s@%s via uv tool install, then prime bundle cache.\n' \
"${PACKAGE_NAME}" "${TAG}"
fi
printf '\n'
# Skip the prompt when stdin is not a TTY (piped) or --yes was passed.
if [[ "${YES}" -eq 0 ]] && [[ -t 0 ]]; then
printf 'Press Enter to continue, Ctrl+C to abort... '
read -r _confirm
printf '\n'
fi
# ---------------------------------------------------------------------------
# Install via uv tool
# ---------------------------------------------------------------------------
printf 'Installing %s@%s...\n' "${PACKAGE_NAME}" "${TAG}"
if ! uv tool install --reinstall --force \
--from "git+${GIT_URL}@${TAG}" \
"${PACKAGE_NAME}"; then
printf '\nerror: uv tool install failed.\n' >&2
printf 'You can retry manually:\n' >&2
printf ' uv tool install --reinstall --force "git+%s@%s"\n' "${GIT_URL}" "${TAG}" >&2
exit 1
fi
# ---------------------------------------------------------------------------
# Prime bundle cache (optional but strongly recommended)
# ---------------------------------------------------------------------------
if [[ "${NO_PRIME}" -eq 0 ]]; then
printf '\nPriming bundle cache (this prevents a 30-60s delay on first run)...\n'
if ! amplifier-agent-post-install; then
printf 'warning: bundle priming failed — continuing anyway.\n' >&2
printf 'You can retry priming with: amplifier-agent prepare\n' >&2
fi
fi
# ---------------------------------------------------------------------------
# Success
# ---------------------------------------------------------------------------
TOOL_DIR="$(uv tool dir)"
printf '\n'
printf '=======================================================================\n'
printf ' amplifier-agent %s installed successfully!\n' "${TAG}"
printf '=======================================================================\n'
printf '\n'
printf ' Install location: %s/%s\n' "${TOOL_DIR}" "${PACKAGE_NAME}"
printf ' Run: amplifier-agent --help\n'
printf ' Update: amplifier-agent update\n'
printf ' Uninstall: uv tool uninstall %s\n' "${PACKAGE_NAME}"
printf ' rm -rf ~/.amplifier-agent # optional: removes cached data\n'
printf '\n'