-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
303 lines (254 loc) · 7.87 KB
/
install.sh
File metadata and controls
303 lines (254 loc) · 7.87 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/usr/bin/env sh
set -eu
# minisign public key (ONLY the base64 key, without the comment line)
MINISIGN_PUBKEY="RWSIfpPSznK9A1gWUc8Eg2iXXQwU5d9BYuQNKGOcoujAF2stPu5rKFjQ"
REPO="${VIX_REPO:-vixcpp/vix}"
VERSION="${VIX_VERSION:-latest}" # "latest" or "vX.Y.Z"
# install kind: sdk or cli
INSTALL_KIND="${VIX_INSTALL_KIND:-sdk}"
# SDK installs a full prefix, CLI installs only the binary
PREFIX_DIR="${VIX_INSTALL_PREFIX:-$HOME/.local}"
BIN_DIR="${VIX_INSTALL_BIN_DIR:-$HOME/.local/bin}"
BIN_NAME="vix"
# --------------------------------------------------
# Styling
# --------------------------------------------------
if [ -t 2 ] && [ "${NO_COLOR:-}" = "" ]; then
C_RESET="$(printf '\033[0m')"
C_BOLD="$(printf '\033[1m')"
C_DIM="$(printf '\033[2m')"
C_RED="$(printf '\033[31m')"
C_GREEN="$(printf '\033[32m')"
C_YELLOW="$(printf '\033[33m')"
C_BLUE="$(printf '\033[34m')"
C_CYAN="$(printf '\033[36m')"
else
C_RESET=""
C_BOLD=""
C_DIM=""
C_RED=""
C_GREEN=""
C_YELLOW=""
C_BLUE=""
C_CYAN=""
fi
die() {
printf "%s✖%s vix install: %s\n" "$C_RED" "$C_RESET" "$*" >&2
exit 1
}
info() {
printf "%s›%s vix install: %s\n" "$C_CYAN" "$C_RESET" "$*" >&2
}
ok() {
printf "%s✔%s vix install: %s\n" "$C_GREEN" "$C_RESET" "$*" >&2
}
warn() {
printf "%s!%s vix install: %s\n" "$C_YELLOW" "$C_RESET" "$*" >&2
}
step() {
printf "\n%s==>%s %s\n" "$C_BOLD$C_BLUE" "$C_RESET" "$*" >&2
}
banner() {
printf '\n' >&2
printf "%sVix.cpp installer%s\n" "$C_BOLD" "$C_RESET" >&2
printf "%sNative runtime and SDK installer%s\n" "$C_DIM" "$C_RESET" >&2
}
# --------------------------------------------------
# Helpers
# --------------------------------------------------
have() { command -v "$1" >/dev/null 2>&1; }
need_cmd() { have "$1" || die "missing dependency: $1"; }
fetch() {
url="$1"
out="$2"
if have curl; then
curl -fsSL "$url" -o "$out" >/dev/null 2>&1
elif have wget; then
wget -qO "$out" "$url" >/dev/null 2>&1
else
die "need curl or wget"
fi
}
need_cmd uname
need_cmd mktemp
need_cmd tar
banner
# --------------------------------------------------
# Detect platform
# --------------------------------------------------
step "Detecting platform"
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
case "$os" in
linux) OS="linux" ;;
darwin) OS="macos" ;;
*) die "unsupported OS: $os (only Linux/macOS supported by install.sh)" ;;
esac
case "$arch" in
x86_64|amd64) ARCH="x86_64" ;;
arm64|aarch64) ARCH="aarch64" ;;
*) die "unsupported CPU arch: $arch" ;;
esac
ok "platform detected: os=$OS arch=$ARCH"
TMP_DIR="$(mktemp -d 2>/dev/null || mktemp -d -t vix)"
cleanup() { rm -rf "$TMP_DIR"; }
trap cleanup EXIT INT TERM
# --------------------------------------------------
# Resolve version
# --------------------------------------------------
resolve_version() {
if [ "$VERSION" = "latest" ]; then
have curl || die "curl is required to resolve latest (or set VIX_VERSION=vX.Y.Z)"
final="$(curl -fsSLI -o /dev/null -w '%{url_effective}' "https://github.com/$REPO/releases/latest")"
tag="${final##*/}"
[ -n "$tag" ] || die "could not resolve latest version"
printf "%s" "$tag"
else
printf "%s" "$VERSION"
fi
}
step "Resolving release version"
TAG="$(resolve_version)"
ok "repo=$REPO version=$TAG os=$OS arch=$ARCH kind=$INSTALL_KIND"
case "$INSTALL_KIND" in
sdk)
ASSET="vix-sdk-${OS}-${ARCH}.tar.gz"
;;
cli)
ASSET="vix-${OS}-${ARCH}.tar.gz"
;;
*)
die "unsupported VIX_INSTALL_KIND='$INSTALL_KIND' (expected sdk or cli)"
;;
esac
BASE_URL="https://github.com/${REPO}/releases/download/${TAG}"
URL_BIN="${BASE_URL}/${ASSET}"
URL_SHA="${URL_BIN}.sha256"
URL_MINISIG="${URL_BIN}.minisig"
ARCHIVE_PATH="${TMP_DIR}/${ASSET}"
SHA_PATH="${TMP_DIR}/${ASSET}.sha256"
SIG_PATH="${TMP_DIR}/${ASSET}.minisig"
EXTRACT_DIR="${TMP_DIR}/extract"
# --------------------------------------------------
# Download
# --------------------------------------------------
step "Downloading archive"
info "asset: $ASSET"
info "url: $URL_BIN"
fetch "$URL_BIN" "$ARCHIVE_PATH" || die "download failed"
ok "archive downloaded"
# --------------------------------------------------
# SHA256 verification
# --------------------------------------------------
step "Verifying checksum"
if fetch "$URL_SHA" "$SHA_PATH"; then
if ! have sha256sum && ! have shasum; then
die "need sha256sum (Linux) or shasum (macOS) for verification"
fi
expected="$(
awk '
/^[0-9a-fA-F]{64}/ { print $1; exit }
/^SHA256 \(/ { print $NF; exit }
' "$SHA_PATH"
)"
[ -n "$expected" ] || die "invalid sha256 file"
if have sha256sum; then
actual="$(sha256sum "$ARCHIVE_PATH" | awk '{print $1}')"
else
actual="$(shasum -a 256 "$ARCHIVE_PATH" | awk '{print $1}')"
fi
[ "$expected" = "$actual" ] || die "sha256 mismatch"
ok "sha256 ok"
else
warn "sha256 file not found"
fi
# --------------------------------------------------
# Minisign verification
# --------------------------------------------------
step "Verifying signature"
if fetch "$URL_MINISIG" "$SIG_PATH"; then
if have minisign; then
if minisign -Vm "$ARCHIVE_PATH" -P "$MINISIGN_PUBKEY" >/dev/null 2>&1; then
ok "minisign ok"
else
die "minisign verification failed"
fi
else
warn "minisig is published but minisign is not installed"
warn "continuing because checksum verification already succeeded"
fi
else
warn "minisig not found"
fi
# --------------------------------------------------
# Extract
# --------------------------------------------------
step "Extracting archive"
mkdir -p "$EXTRACT_DIR"
tar -xzf "$ARCHIVE_PATH" -C "$EXTRACT_DIR"
ok "archive extracted"
# --------------------------------------------------
# Install
# --------------------------------------------------
step "Installing"
if [ "$INSTALL_KIND" = "cli" ]; then
mkdir -p "$BIN_DIR"
[ -f "${EXTRACT_DIR}/${BIN_NAME}" ] || die "archive does not contain '${BIN_NAME}'"
chmod +x "${EXTRACT_DIR}/${BIN_NAME}"
dest="${BIN_DIR}/${BIN_NAME}"
info "installing CLI to: $dest"
mv -f "${EXTRACT_DIR}/${BIN_NAME}" "$dest"
ok "CLI installed"
else
mkdir -p "$PREFIX_DIR" "$BIN_DIR"
info "installing SDK to: $PREFIX_DIR"
cp -R "${EXTRACT_DIR}/." "$PREFIX_DIR/"
if [ -f "${PREFIX_DIR}/bin/${BIN_NAME}" ]; then
target="${PREFIX_DIR}/bin/${BIN_NAME}"
elif [ -f "${PREFIX_DIR}/install/bin/${BIN_NAME}" ]; then
target="${PREFIX_DIR}/install/bin/${BIN_NAME}"
else
target="$(find "$PREFIX_DIR" -type f -path "*/bin/${BIN_NAME}" 2>/dev/null | head -n 1 || true)"
fi
[ -n "$target" ] || die "could not find installed '${BIN_NAME}' in SDK"
chmod +x "$target"
dest="${BIN_DIR}/${BIN_NAME}"
if [ "$target" = "$dest" ]; then
info "CLI already installed at: $dest"
else
ln -sf "$target" "$dest"
info "linked CLI to: $dest"
fi
ok "SDK installed"
fi
# --------------------------------------------------
# Validate install
# --------------------------------------------------
step "Validating installation"
if "$dest" --version >/dev/null 2>&1; then
INSTALLED_VERSION="$("$dest" --version 2>/dev/null || true)"
ok "installed: $INSTALLED_VERSION"
else
warn "installed, but running 'vix --version' failed"
fi
# --------------------------------------------------
# PATH hint
# --------------------------------------------------
step "Checking PATH"
case ":$PATH:" in
*":$BIN_DIR:"*)
ok "'$BIN_DIR' is already in PATH"
;;
*)
warn "'$BIN_DIR' is not in your PATH"
info "Add this to your shell config:"
printf " export PATH=\"%s:\$PATH\"\n" "$BIN_DIR" >&2
;;
esac
# --------------------------------------------------
# Final summary
# --------------------------------------------------
printf "\n%sDone.%s\n" "$C_BOLD$C_GREEN" "$C_RESET" >&2
printf "%sLocation:%s %s\n" "$C_BOLD" "$C_RESET" "$dest" >&2
printf "%sVersion:%s %s\n" "$C_BOLD" "$C_RESET" "$TAG" >&2
printf "%sKind:%s %s\n" "$C_BOLD" "$C_RESET" "$INSTALL_KIND" >&2