Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·449 lines (393 loc) · 13.7 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·449 lines (393 loc) · 13.7 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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
#!/usr/bin/env sh
#
# issy installer — downloads a verified prebuilt binary (Linux, OpenBSD)
# or builds from source (macOS, or any platform without a prebuilt), then
# seeds ~/.issyrc and prints a PATH hint if needed.
#
# Usage:
# curl -sSL https://raw.githubusercontent.com/davidemerson/issy/main/install.sh | sh
# sh install.sh --prefix ~/bin
# sh install.sh --version latest --no-rc
#
# Flags:
# --prefix DIR Install dir (default: $HOME/.local/bin)
# --version VER Release tag; default "latest"
# --no-rc Do not seed ~/.issyrc
# --help / -h Show this help
set -eu
DEFAULT_PREFIX="$HOME/.local/bin"
PREFIX="$DEFAULT_PREFIX"
VERSION="latest"
SEED_RC=1
REPO_URL="https://github.com/davidemerson/issy"
# Ed25519 public key that matches src/update_key.zig. Regenerate with
# `sh tools/dump_pubkey.sh` after rotating UPDATE_SIGNING_KEY.
PUBKEY_PEM='-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEA0+BfQpAYpL6E8Yqnn4ND6xGu3qHG4UZ1eWZ0TCTstbE=
-----END PUBLIC KEY-----'
die() {
printf 'error: %s\n' "$*" >&2
exit 1
}
info() {
printf '%s\n' "$*"
}
usage() {
sed -n '3,16p' "$0" | sed 's/^# \{0,1\}//'
exit 0
}
need_cmd() {
command -v "$1" >/dev/null 2>&1 || die "required command not found: $1"
}
parse_args() {
while [ $# -gt 0 ]; do
case "$1" in
--prefix)
[ $# -ge 2 ] || die "--prefix requires an argument"
PREFIX="$2"
shift 2
;;
--prefix=*)
PREFIX="${1#--prefix=}"
shift
;;
--version)
[ $# -ge 2 ] || die "--version requires an argument"
VERSION="$2"
shift 2
;;
--version=*)
VERSION="${1#--version=}"
shift
;;
--no-rc)
SEED_RC=0
shift
;;
-h|--help)
usage
;;
*)
die "unknown argument: $1"
;;
esac
done
}
detect_platform() {
uname_s="$(uname -s 2>/dev/null || echo unknown)"
uname_m="$(uname -m 2>/dev/null || echo unknown)"
case "$uname_s" in
Linux) OS=linux ;;
Darwin) OS=macos ;;
OpenBSD) OS=openbsd ;;
*) die "unsupported OS: $uname_s (issy supports Linux, macOS, OpenBSD)" ;;
esac
case "$uname_m" in
x86_64|amd64) ARCH=amd64 ;;
aarch64|arm64) ARCH=arm64 ;;
*) die "unsupported architecture: $uname_m (issy supports amd64, arm64)" ;;
esac
}
asset_name_for() {
# Prebuilt asset names produced by .github/workflows/ci.yml. Keep in
# sync with src/update.zig `currentAssetName()` — the auto-update path
# depends on the same filenames.
case "$1/$2" in
linux/amd64) echo "issy-linux-amd64" ;;
linux/arm64) echo "issy-linux-arm64" ;;
openbsd/amd64) echo "issy-openbsd-amd64" ;;
*) echo "" ;; # empty = no prebuilt, fall through to source build
esac
}
choose_fetcher() {
if command -v curl >/dev/null 2>&1; then
FETCH="curl -fsSL --retry 3 --max-time 120 -o"
elif command -v wget >/dev/null 2>&1; then
FETCH="wget -q -O"
else
die "neither curl nor wget found; install one and retry"
fi
}
choose_sha256() {
if command -v sha256sum >/dev/null 2>&1; then
SHA256="sha256sum"
elif command -v shasum >/dev/null 2>&1; then
SHA256="shasum -a 256"
else
die "neither sha256sum nor shasum found; install one and retry"
fi
}
release_url() {
# Build GitHub release download URL. "latest" maps to the /latest/download
# redirect, anything else uses /download/<tag>/.
asset="$1"
if [ "$VERSION" = "latest" ]; then
echo "$REPO_URL/releases/latest/download/$asset"
else
echo "$REPO_URL/releases/download/$VERSION/$asset"
fi
}
fetch() {
url="$1"
dest="$2"
# shellcheck disable=SC2086
$FETCH "$dest" "$url" || die "failed to download: $url"
}
verify_signature() {
manifest="$1"
signature="$2"
need_cmd openssl
pub_tmp="$TMPDIR_/pubkey.pem"
printf '%s\n' "$PUBKEY_PEM" > "$pub_tmp"
if ! openssl pkeyutl -verify -pubin -inkey "$pub_tmp" \
-rawin -sigfile "$signature" -in "$manifest" >/dev/null 2>&1; then
die "signature verification FAILED for sha256sums.txt — refusing to install"
fi
}
verify_binary_hash() {
manifest="$1"
asset="$2"
binary="$3"
# Manifest lines look like: "<hex> <name>" (sha256sum / shasum format).
expected="$(awk -v a="$asset" '$2 == a || $2 == "*" a || $2 == "./" a { print $1 }' "$manifest")"
if [ -z "$expected" ]; then
die "sha256sums.txt does not list $asset"
fi
actual="$($SHA256 "$binary" | awk '{print $1}')"
if [ "$expected" != "$actual" ]; then
die "sha256 mismatch for $asset: expected $expected, got $actual"
fi
}
ensure_prefix_dir() {
mkdir -p "$PREFIX" || die "failed to create $PREFIX"
if [ ! -w "$PREFIX" ]; then
die "$PREFIX is not writable. Use --prefix to pick a different directory, or chmod the target."
fi
}
install_prebuilt() {
asset="$1"
info "downloading $asset from $VERSION release..."
fetch "$(release_url "$asset")" "$TMPDIR_/$asset"
fetch "$(release_url "sha256sums.txt")" "$TMPDIR_/sha256sums.txt"
fetch "$(release_url "sha256sums.txt.sig")" "$TMPDIR_/sha256sums.txt.sig"
info "verifying Ed25519 signature..."
verify_signature "$TMPDIR_/sha256sums.txt" "$TMPDIR_/sha256sums.txt.sig"
info "verifying sha256..."
verify_binary_hash "$TMPDIR_/sha256sums.txt" "$asset" "$TMPDIR_/$asset"
info "installing to $PREFIX/issy..."
install -m 0755 "$TMPDIR_/$asset" "$PREFIX/issy" \
|| die "install failed (check permissions on $PREFIX)"
INSTALLED_SHA="$($SHA256 "$PREFIX/issy" | awk '{print $1}')"
# The release publishes the commit it was cut from; reuse it rather
# than guessing. Format is "<sha>[ <epoch>]".
if fetch "$(release_url "commit.txt")" "$TMPDIR_/commit.txt" 2>/dev/null; then
_rel="$(tr -d '\r' < "$TMPDIR_/commit.txt" | head -1)"
seed_update_cache "${_rel%% *}" "$(printf '%s' "$_rel" | cut -s -d' ' -f2)"
fi
}
install_from_source() {
info "no prebuilt binary for $OS/$ARCH — building from source."
if ! command -v zig >/dev/null 2>&1; then
cat >&2 <<EOF
error: zig is required to build from source on $OS/$ARCH.
1. Install Zig 0.15.x or 0.16.x from https://ziglang.org/download/
2. Ensure 'zig' is on your PATH
3. Re-run this installer
On macOS you can also use Homebrew:
brew tap davidemerson/issy https://github.com/davidemerson/issy
brew install issy
EOF
exit 1
fi
zig_version="$(zig version 2>/dev/null || echo 0.0.0)"
# issy supports the 0.15.x and 0.16.x series (src/fsx.zig papers
# over the std.fs → std.Io move). Anything else: build.zig rejects
# it at comptime, so this gate simply fails earlier with a clearer
# message than the compile error would give.
case "$zig_version" in
0.15.*|0.16.*)
;;
*)
die "zig $zig_version is unsupported; issy requires Zig 0.15.x or 0.16.x"
;;
esac
src_dir="$TMPDIR_/src"
if command -v git >/dev/null 2>&1; then
info "cloning $REPO_URL..."
git clone --depth 1 "$REPO_URL" "$src_dir" >/dev/null 2>&1 \
|| die "git clone failed"
else
info "git not found — fetching source tarball..."
tarball="$TMPDIR_/issy.tar.gz"
fetch "$REPO_URL/archive/refs/heads/main.tar.gz" "$tarball"
mkdir -p "$src_dir"
tar -xzf "$tarball" -C "$src_dir" --strip-components=1 \
|| die "failed to extract source tarball"
fi
info "building (zig build -Doptimize=ReleaseSafe)..."
( cd "$src_dir" && zig build -Doptimize=ReleaseSafe >/dev/null ) \
|| die "zig build failed"
info "installing to $PREFIX/issy..."
install -m 0755 "$src_dir/zig-out/bin/issy" "$PREFIX/issy" \
|| die "install failed (check permissions on $PREFIX)"
INSTALLED_SHA="$($SHA256 "$PREFIX/issy" | awk '{print $1}')"
# %ct reads the commit object, so this works in the --depth 1 clone
# above. A tarball build has no .git and simply seeds nothing.
if [ -d "$src_dir/.git" ] && command -v git >/dev/null 2>&1; then
seed_update_cache \
"$(git -C "$src_dir" rev-parse HEAD 2>/dev/null)" \
"$(git -C "$src_dir" show -s --format=%ct HEAD 2>/dev/null)"
fi
}
seed_update_cache() {
# Record the release we just installed in ~/.cache/issy/commit.txt.
#
# Without this the editor's first launch compares its own commit
# against whatever the cache last saw — the release you just upgraded
# AWAY from — and (before the strictly-newer check landed) advertised
# a downgrade. Seeding it makes a fresh install quiet immediately
# instead of waiting for the first background worker run.
#
# Only commit.txt. NEVER seed manifest_epoch.txt: that is the
# anti-rollback high-water mark, and a wrong value written here would
# silently refuse every future update for that user.
#
# Entirely best-effort — a failure here must never fail an install.
[ -n "${HOME:-}" ] || return 0
[ -d "$HOME" ] && [ -w "$HOME" ] || return 0
_sha="$1"
_epoch="$2"
[ -n "$_sha" ] || return 0
_cache="$HOME/.cache/issy"
mkdir -p "$_cache" 2>/dev/null || return 0
if [ -n "$_epoch" ]; then
printf '%s %s\n' "$_sha" "$_epoch" > "$_cache/commit.txt" 2>/dev/null || true
else
printf '%s\n' "$_sha" > "$_cache/commit.txt" 2>/dev/null || true
fi
}
seed_rc() {
[ "$SEED_RC" -eq 1 ] || return 0
rc="$HOME/.issyrc"
if [ -e "$rc" ]; then
info "$rc already exists — leaving it alone."
return 0
fi
cat > "$rc" <<'EOF'
# issy configuration
#
# Every setting is commented out. Uncomment a line to override the
# compiled-in default. Lines starting with # are comments. Unknown keys
# are ignored.
# ── Editing ──
# tab_width = 4
# expand_tabs = true
# auto_indent = true
# auto_close_brackets = false
# auto_detect_indent = true
# scroll_margin = 5
#
# swap_files: while a buffer has unsaved changes, periodically write them
# to a sibling .<name>.swp file (removed on save/clean exit); a leftover
# swap from a crash is reported on open.
# swap_files = true
# ── Clipboard ──
#
# system_clipboard: when on (the default), Ctrl+V and middle-click read the
# system clipboard / primary selection via OSC 52, so text copied in any
# other application pastes in. Falls back to issy's internal clipboard if the
# terminal has OSC 52 read disabled. Set false to keep Ctrl+V internal-only.
# (Pasting via the terminal's own key — Ctrl+Shift+V / Shift+Insert — always
# works regardless of this setting.)
# system_clipboard = true
# ── Display ──
# line_numbers = true
# left_padding = 2
# gutter_padding = 3
# word_wrap = true
# wrap_indent = false # hang wrap continuations under the line's indent
# right_margin = 100
# cursor_line_bg = true
# cursor_style = bar # bar, block, or underline
# trailing_whitespace = true
# indent_mismatch = true
# ── Auto-update ──
#
# Release builds check the latest GitHub release on startup. If the
# binary is not writable by you (e.g. a root-owned install), the check
# still runs but nothing is downloaded and no apply is attempted —
# notify-only, with no recurring failure notice.
# notify_updates = true # status-bar "update available" hint
# autoupdate = false # opt-in: auto-download + verify + in-session re-exec
# # Rollback any time with: issy --rollback
# ── PDF / Print ──
# font_file = "/Library/Fonts/Berkeley Mono Variable.ttf"
# font_size = 10.0
# print_margin_top = 72.0
# print_margin_bottom = 72.0
# print_margin_left = 108.0
# print_margin_right = 72.0
# ── Theme ──
#
# Uncomment one of:
# [theme.default] — black background (compiled-in default)
# [theme.paper] — Solarized Light
#
# Individual colors (any theme) use #rrggbb:
# bg = "#000000"
# fg = "#b0b8c8"
# keyword = "#c4a0f7"
# string_color = "#a0d06e"
# comment = "#444c5e"
EOF
info "seeded $rc with commented defaults."
}
print_path_hint() {
# Only warn if $PREFIX is not already in PATH.
case ":$PATH:" in
*":$PREFIX:"*) return 0 ;;
esac
# Guess the user's shell rc for a targeted hint. These are display
# strings, not paths we read — keep the literal "~" so the user sees
# something they can copy-paste.
# shellcheck disable=SC2088
{
shell_rc='~/.profile'
case "${SHELL:-}" in
*/zsh) shell_rc='~/.zshrc' ;;
*/bash) shell_rc='~/.bashrc' ;;
*/fish) shell_rc='~/.config/fish/config.fish' ;;
esac
}
info ""
info "note: $PREFIX is not in your PATH. Add it with:"
if [ "${SHELL##*/}" = "fish" ]; then
info " fish_add_path $PREFIX"
else
info " echo 'export PATH=\"$PREFIX:\$PATH\"' >> $shell_rc"
info " # then restart your shell, or: source $shell_rc"
fi
}
main() {
parse_args "$@"
detect_platform
choose_fetcher
choose_sha256
ensure_prefix_dir
TMPDIR_="$(mktemp -d 2>/dev/null || mktemp -d -t issy-install)"
trap 'rm -rf "$TMPDIR_"' EXIT INT TERM
asset="$(asset_name_for "$OS" "$ARCH")"
if [ -n "$asset" ]; then
install_prebuilt "$asset"
else
install_from_source
fi
seed_rc
info ""
info "installed issy to $PREFIX/issy"
info " sha256: $INSTALLED_SHA"
print_path_hint
info ""
info "Run 'issy --help' to see options."
}
main "$@"