Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·154 lines (137 loc) · 6.6 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·154 lines (137 loc) · 6.6 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
#!/bin/sh
# Install mewkit on Linux or macOS.
#
# curl -fsSL https://raw.githubusercontent.com/ngocsangyem/MeowKit/main/install.sh | sh
#
# Every archive this script can install is pinned below by URL, SHA-256 and
# size. The pins are written by the release job and land on the default branch
# only through a reviewed pull request, so this script never trusts anything it
# downloads: a byte that differs from the pin stops the install before anything
# is written. There is no signature; see RELEASING.md for the trust model.
#
# Environment:
# MEWKIT_CHANNEL stable (default) or beta
# MEWKIT_INSTALL_DIR where the binary goes (default: $HOME/.local/bin)
# MEWKIT_VERSION refuse unless the pinned version is this one
#
# GENERATED by scripts/release/render-installers.mjs from install.sh.tmpl and
# installer-pins.json. Edit those, never this file.
set -eu
say() { printf 'mewkit install: %s\n' "$1"; }
die() { printf 'mewkit install: error: %s\n' "$1" >&2; exit 1; }
# The pinned archive for a channel and target: "version url sha256 size".
pin() {
case "$1:$2" in
stable:x86_64-unknown-linux-musl) echo "0.2.1 https://github.com/ngocsangyem/MeowKit/releases/download/mewkit-v0.2.1/mewkit-0.2.1-x86_64-unknown-linux-musl.tar.gz f5d63c55006c8172171b654fed2dd3bd88cf4e99d2ed5cd6dd2b8f76a9386122 5454147" ;;
stable:aarch64-unknown-linux-musl) echo "0.2.1 https://github.com/ngocsangyem/MeowKit/releases/download/mewkit-v0.2.1/mewkit-0.2.1-aarch64-unknown-linux-musl.tar.gz 3d8066aa3b89c8f91c4548fda9c8e39ab680e4ce15e2220575140481f46c11ec 4924501" ;;
stable:x86_64-apple-darwin) echo "0.2.1 https://github.com/ngocsangyem/MeowKit/releases/download/mewkit-v0.2.1/mewkit-0.2.1-x86_64-apple-darwin.tar.gz 523abd4c2da02f0687580f23e5edd5aa7583a860cb9770983f4f9ba89e203353 5195306" ;;
stable:aarch64-apple-darwin) echo "0.2.1 https://github.com/ngocsangyem/MeowKit/releases/download/mewkit-v0.2.1/mewkit-0.2.1-aarch64-apple-darwin.tar.gz c43539d03397f2243107eb476be44ab04ed7761ace2516a1c66de65781e1dfca 4741983" ;;
*) return 1 ;;
esac
}
target() {
os=$(uname -s)
arch=$(uname -m)
case "$arch" in
x86_64 | amd64) arch=x86_64 ;;
arm64 | aarch64) arch=aarch64 ;;
*) die "no mewkit build for the $arch processor" ;;
esac
case "$os" in
Linux) echo "$arch-unknown-linux-musl" ;;
Darwin)
# A shell under Rosetta reports x86_64 on Apple silicon; take the native build.
if [ "$arch" = x86_64 ] && [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" = 1 ]; then
arch=aarch64
fi
echo "$arch-apple-darwin"
;;
MINGW* | MSYS* | CYGWIN* | Windows_NT) die "on Windows, run install.ps1 in PowerShell instead" ;;
*) die "no mewkit build for $os" ;;
esac
}
sha256_of() {
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$1" | cut -d ' ' -f 1
elif command -v shasum >/dev/null 2>&1; then
shasum -a 256 "$1" | cut -d ' ' -f 1
elif command -v openssl >/dev/null 2>&1; then
openssl dgst -sha256 -r "$1" | cut -d ' ' -f 1
else
return 1
fi
}
download() {
if command -v curl >/dev/null 2>&1; then
curl -fsSL --retry 2 -o "$2" "$1"
elif command -v wget >/dev/null 2>&1; then
wget -q -O "$2" "$1"
else
die "neither curl nor wget is installed"
fi
}
main() {
channel=${MEWKIT_CHANNEL:-stable}
case "$channel" in
stable | beta) ;;
*) die "MEWKIT_CHANNEL must be stable or beta, not '$channel'" ;;
esac
install_dir=${MEWKIT_INSTALL_DIR:-${HOME:?HOME is not set}/.local/bin}
tgt=$(target)
pinned=$(pin "$channel" "$tgt") || die "this installer pins no $channel release for $tgt yet; see https://github.com/ngocsangyem/MeowKit/releases"
# shellcheck disable=SC2086 # the pin is four space-free words
set -- $pinned
version=$1 url=$2 want_sha=$3 want_size=$4
if [ -n "${MEWKIT_VERSION:-}" ] && [ "${MEWKIT_VERSION#v}" != "$version" ]; then
die "this installer pins mewkit $version on $channel, not ${MEWKIT_VERSION#v}.
To install another version by hand, verified:
1. download mewkit-<version>-$tgt.tar.gz and checksums.txt from
https://github.com/ngocsangyem/MeowKit/releases/tag/mewkit-v<version>
2. check it: sha256sum -c --ignore-missing checksums.txt (macOS: shasum -a 256 -c)
3. extract it and put mewkit in a directory on your PATH"
fi
tmp=$(mktemp -d 2>/dev/null || mktemp -d -t mewkit)
trap 'rm -rf "$tmp"' EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
archive=$tmp/mewkit.tar.gz
# Refuse before downloading when the result could not be checked.
sha256_of /dev/null >/dev/null 2>&1 || die "no SHA-256 tool (sha256sum, shasum or openssl); cannot verify the download, so nothing was installed"
say "downloading mewkit $version for $tgt"
download "$url" "$archive" || die "download failed: $url"
size=$(wc -c <"$archive" | tr -d ' ')
[ "$size" = "$want_size" ] || die "the download is $size bytes, the pin says $want_size; nothing was installed"
sha=$(sha256_of "$archive")
[ "$sha" = "$want_sha" ] || die "SHA-256 mismatch (got $sha, pinned $want_sha); nothing was installed"
mkdir "$tmp/x"
tar -xzf "$archive" -C "$tmp/x" || die "the archive did not extract; nothing was installed"
bin=$(find "$tmp/x" -maxdepth 2 -type f -name mewkit | head -n 1)
[ -n "$bin" ] || die "the archive holds no mewkit binary; nothing was installed"
mkdir -p "$install_dir" || die "cannot create $install_dir"
staged=$install_dir/.mewkit.install.$$
cp "$bin" "$staged" || { rm -f "$staged"; die "cannot write to $install_dir"; }
chmod 755 "$staged"
mv -f "$staged" "$install_dir/mewkit" || { rm -f "$staged"; die "cannot place $install_dir/mewkit"; }
say "installed $install_dir/mewkit ($version, $channel)"
# `mk` is the short name. A name already taken by something that is not a mewkit
# binary is left alone: `mk` is short enough that another tool may own it. The binary
# is installed either way.
link=$install_dir/mk
if { [ -e "$link" ] || [ -L "$link" ]; } && { [ -d "$link" ] || ! "$link" --version 2>/dev/null | grep -q '^mewkit '; }; then
say "$link exists and is not mewkit; left as it is (run mewkit directly)"
else
ln -sf mewkit "$link" && say "linked $link to mewkit" || say "could not link $link; run mewkit directly"
fi
# Installers for 0.1.0 and 0.1.1 also placed `mewkit-next`; remove it when it is mewkit.
retired=$install_dir/mewkit-next
if { [ -L "$retired" ] && [ "$(readlink "$retired")" = mewkit ]; } ||
{ [ -f "$retired" ] && "$retired" --version 2>/dev/null | grep -q '^mewkit '; }; then
rm -f "$retired" && say "removed $retired (the name is retired; run mewkit or mk)"
fi
case ":${PATH:-}:" in
*":$install_dir:"*) ;;
*) say "$install_dir is not on your PATH; add it, e.g.: export PATH=\"$install_dir:\$PATH\"" ;;
esac
say "later updates: mewkit self-update"
}
main "$@"