Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Blame · scripts/check-install.sh

Line attribution on main · 304 line(s)

16a8be36
Keenan Nemetz
13d ago
1 #!/bin/sh
2 # Check the one-command installer without a package manager.
3 #
4 # The script pins the release key's SHA-256 and fingerprint, so this check fails
5 # when either constant disagrees with packaging/keys/vole-release.asc. It then
a4a6d1e9
Keenan Nemetz
12d ago
6 # runs install.sh against temporary roots for the three Linux families and for
7 # macOS, and asserts the files it writes, that a second run changes nothing, and
8 # that bad input is refused. No network, root, or package manager is needed: the
9 # key is supplied with --key, --root implies --repo-only, and the macOS case fakes
10 # uname, curl, and brew with fixtures under a temporary directory.
16a8be36
Keenan Nemetz
13d ago
11 set -eu
12
13 ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
14 cd "$ROOT"
15
16 tmp=$(mktemp -d)
17 trap 'rm -rf "$tmp"' 0
18
19 fail() {
20 printf 'check-install: %s\n' "$*" >&2
21 exit 1
22 }
23
24 note() {
25 printf 'check-install: %s\n' "$*"
26 }
27
28 sha256() {
29 if command -v sha256sum >/dev/null 2>&1; then
30 sha256sum "$1" | awk '{print $1}'
31 elif command -v shasum >/dev/null 2>&1; then
32 shasum -a 256 "$1" | awk '{print $1}'
33 else
34 fail "sha256sum or shasum is required"
35 fi
36 }
37
38 [ -f packaging/install.sh ] || fail "packaging/install.sh is missing"
39 [ -x packaging/install.sh ] || fail "packaging/install.sh is not executable"
40 [ -f packaging/keys/vole-release.asc ] || fail "packaging/keys/vole-release.asc is missing"
41
42 sh -n packaging/install.sh || fail "packaging/install.sh has a syntax error"
43
44 pinned_sha=$(sed -n 's/^VOLE_KEY_SHA256=//p' packaging/install.sh)
45 pinned_fpr=$(sed -n 's/^VOLE_KEY_FPR=//p' packaging/install.sh)
46 [ -n "$pinned_sha" ] || fail "VOLE_KEY_SHA256 is missing from packaging/install.sh"
47 [ -n "$pinned_fpr" ] || fail "VOLE_KEY_FPR is missing from packaging/install.sh"
48
49 actual_sha=$(sha256 packaging/keys/vole-release.asc)
50 [ "$pinned_sha" = "$actual_sha" ] ||
51 fail "VOLE_KEY_SHA256 ($pinned_sha) does not match packaging/keys/vole-release.asc ($actual_sha)"
52
53 if command -v gpg >/dev/null 2>&1; then
54 actual_fpr=$(gpg --batch --with-colons --import-options show-only \
55 --import packaging/keys/vole-release.asc 2>/dev/null |
56 awk -F: '$1 == "fpr" {print $10; exit}')
57 [ "$pinned_fpr" = "$actual_fpr" ] ||
58 fail "VOLE_KEY_FPR ($pinned_fpr) does not match packaging/keys/vole-release.asc (${actual_fpr:-none})"
59 fi
60
61 make_root() { # name ID ID_LIKE
62 root="$tmp/$1"
63 mkdir -p "$root/etc"
64 {
65 printf 'ID=%s\n' "$2"
66 if [ -n "${3:-}" ]; then
67 printf 'ID_LIKE="%s"\n' "$3"
68 fi
69 } >"$root/etc/os-release"
70 printf '%s\n' "$root"
71 }
72
73 run_install() { # root [extra arguments...]
74 root=$1
75 shift
76 sh packaging/install.sh --root "$root" --key packaging/keys/vole-release.asc \
77 --repo-only --yes "$@" >/dev/null
78 }
79
80 # Debian and Ubuntu use a signed-by keyring and a one-line source.
81 debian=$(make_root debian debian "")
82 run_install "$debian"
83 [ -f "$debian/etc/apt/keyrings/vole.asc" ] || fail "apt: keyring was not written"
84 [ -f "$debian/etc/apt/sources.list.d/vole.list" ] || fail "apt: source list was not written"
85 grep -q 'signed-by=/etc/apt/keyrings/vole.asc' "$debian/etc/apt/sources.list.d/vole.list" ||
86 fail "apt: source list does not name the keyring"
87 grep -q '/channels/stable/apt \./' "$debian/etc/apt/sources.list.d/vole.list" ||
88 fail "apt: source list does not name the stable apt tree"
89 run_install "$debian"
90 [ "$(wc -l <"$debian/etc/apt/sources.list.d/vole.list")" -eq 1 ] ||
91 fail "apt: a second run rewrote the source list more than once"
92
93 ubuntu=$(make_root ubuntu ubuntu "debian")
94 run_install "$ubuntu"
95 [ -f "$ubuntu/etc/apt/sources.list.d/vole.list" ] || fail "ubuntu: apt was not detected from ID_LIKE"
96
97 # Fedora and its derivatives use an RPM repository file with both checks on.
98 fedora=$(make_root fedora fedora "")
99 run_install "$fedora"
100 repo="$fedora/etc/yum.repos.d/vole.repo"
101 [ -f "$repo" ] || fail "dnf: repository file was not written"
102 [ -f "$fedora/etc/pki/rpm-gpg/RPM-GPG-KEY-vole" ] || fail "dnf: key was not written"
103 grep -q '^baseurl=.*/channels/stable/yum/$' "$repo" || fail "dnf: baseurl is wrong"
104 grep -q '^gpgcheck=1$' "$repo" || fail "dnf: gpgcheck is not enabled"
105 grep -q '^repo_gpgcheck=1$' "$repo" || fail "dnf: repo_gpgcheck is not enabled"
106 grep -q '^gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-vole$' "$repo" || fail "dnf: gpgkey is wrong"
107 run_install "$fedora"
108
109 rocky=$(make_root rocky rocky "rhel centos fedora")
110 run_install "$rocky"
111 [ -f "$rocky/etc/yum.repos.d/vole.repo" ] || fail "rocky: dnf was not detected from ID_LIKE"
112
113 # Arch reads a section in pacman.conf and a keyring that was marked trusted.
114 arch=$(make_root arch arch "")
115 run_install "$arch"
116 conf="$arch/etc/pacman.conf"
117 [ -f "$conf" ] || fail "pacman: pacman.conf was not written"
118 grep -q '^\[vole\]$' "$conf" || fail "pacman: repository section is missing"
119 grep -Fq 'Server = https://rodent.software/vole/channels/stable/pacman/$arch' "$conf" ||
120 fail "pacman: Server line is wrong"
121 grep -q '^SigLevel = Required DatabaseRequired$' "$conf" || fail "pacman: SigLevel is wrong"
122 run_install "$arch"
123 [ "$(grep -c '^\[vole\]$' "$conf" || true)" -eq 1 ] ||
124 fail "pacman: a second run duplicated the repository section"
125
126 # --version replaces the channel with one release's artifact tree.
127 pinned=$(make_root pinned debian "")
128 run_install "$pinned" --version v0.2.0
129 grep -q '/releases/v0.2.0/artifacts/apt \./' "$pinned/etc/apt/sources.list.d/vole.list" ||
130 fail "version: the pinned apt tree is wrong"
131
132 # --dry-run works without root and writes nothing.
133 plan=$(sh packaging/install.sh --dry-run)
134 printf '%s\n' "$plan" | grep -q 'would run:' || fail "dry-run: no install command in the plan"
135 printf '%s\n' "$plan" | grep -q 'detected ' || fail "dry-run: no detected distribution in the plan"
136 printf '%s\n' "$plan" | grep -q 'would follow channel stable' ||
137 fail "dry-run: no channel in the plan"
138
139 plan=$(sh packaging/install.sh --dry-run --version v0.2.0)
140 printf '%s\n' "$plan" | grep -q 'would install release v0.2.0' ||
141 fail "dry-run: the pinned release was not reported"
142
143 # A key that is not the release key is refused before anything is written.
144 bad=$(make_root bad debian "")
145 : >"$tmp/wrong-key.asc"
146 if sh packaging/install.sh --root "$bad" --key "$tmp/wrong-key.asc" --repo-only \
147 >"$tmp/wrong-key.log" 2>&1; then
148 fail "an empty key was accepted"
149 fi
150 grep -q 'checksum mismatch' "$tmp/wrong-key.log" || fail "a bad key did not report a checksum mismatch"
151 [ ! -e "$bad/etc/apt" ] || fail "a bad key still wrote apt configuration"
152
a4a6d1e9
Keenan Nemetz
12d ago
153 # macOS has no package manager, so the script installs the release binary itself
154 # after checking it against the release's SHA256SUMS. uname, curl and brew are
155 # faked from fixtures here, so the macOS path is exercised on Linux.
156 fakebin="$tmp/fakebin"
157 fixtures="$tmp/fixtures"
158 mkdir -p "$fakebin" "$fixtures"
159 cat >"$fakebin/uname" <<'EOF'
160 #!/bin/sh
161 case "$1" in
162 -m) printf '%s\n' "${FAKE_ARCH:-arm64}" ;;
163 -s) printf '%s\n' "${FAKE_OS:-Darwin}" ;;
164 *) exec /usr/bin/uname "$@" ;;
165 esac
166 EOF
167 cat >"$fakebin/curl" <<'EOF'
168 #!/bin/sh
169 out=
170 url=
171 while [ "$#" -gt 0 ]; do
172 case "$1" in
173 -o) out=$2; shift 2 ;;
174 --retry | --retry-delay) shift 2 ;;
175 -*) shift ;;
176 *) url=$1; shift ;;
177 esac
178 done
179 printf '%s\n' "$url" >>"$FAKE_LOG"
180 name=$(printf '%s' "$url" | sed 's|.*/||')
181 if [ -z "$out" ] || [ ! -f "$FAKE_FIXTURES/$name" ]; then
182 exit 22
183 fi
184 cp "$FAKE_FIXTURES/$name" "$out"
185 EOF
186 cat >"$fakebin/brew" <<'EOF'
187 #!/bin/sh
188 exit "${FAKE_BREW_STATUS:-1}"
189 EOF
190 chmod +x "$fakebin/uname" "$fakebin/curl" "$fakebin/brew"
191
192 printf '#!/bin/sh\necho 0.0.0\n' >"$fixtures/vole-darwin-arm64"
193 printf '#!/bin/sh\necho 0.0.0\n' >"$fixtures/vole-darwin-amd64"
194 {
195 printf '%s %s\n' "$(sha256 "$fixtures/vole-darwin-arm64")" vole-darwin-arm64
196 printf '%s %s\n' "$(sha256 "$fixtures/vole-darwin-amd64")" vole-darwin-amd64
197 } >"$fixtures/SHA256SUMS"
198
199 FAKE_LOG="$tmp/curl.log"
200 FAKE_FIXTURES="$fixtures"
201 export FAKE_LOG FAKE_FIXTURES
202 mac_path=$PATH
203 PATH="$fakebin:$PATH"
204
205 # An --root install puts the arm64 asset where the root says, unchanged.
206 : >"$tmp/curl.log"
207 sh packaging/install.sh --root "$tmp/mac" >/dev/null
208 [ -x "$tmp/mac/usr/local/bin/vole" ] || fail "macOS: the binary was not installed under --root"
209 cmp -s "$fixtures/vole-darwin-arm64" "$tmp/mac/usr/local/bin/vole" ||
210 fail "macOS: the installed binary is not the release asset"
211 grep -Fq '/channels/stable/vole-darwin-arm64' "$tmp/curl.log" ||
212 fail "macOS: the arm64 asset was not downloaded"
213 grep -Fq '/channels/stable/SHA256SUMS' "$tmp/curl.log" ||
214 fail "macOS: SHA256SUMS was not downloaded"
215
216 # uname spells Intel's architecture x86_64; the asset is named amd64.
217 : >"$tmp/curl.log"
218 FAKE_ARCH=x86_64 sh packaging/install.sh --root "$tmp/macintel" >/dev/null
219 grep -Fq '/channels/stable/vole-darwin-amd64' "$tmp/curl.log" ||
220 fail "macOS: an Intel Mac did not get the amd64 asset"
221
222 # --version replaces the channel with one release's artifact tree.
223 : >"$tmp/curl.log"
224 sh packaging/install.sh --root "$tmp/macpin" --version v0.2.0 >/dev/null
225 grep -Fq '/releases/v0.2.0/artifacts/vole-darwin-arm64' "$tmp/curl.log" ||
226 fail "macOS: the pinned release asset URL is wrong"
227
228 # --dry-run names the asset and the destination, and writes nothing.
229 plan=$(sh packaging/install.sh --dry-run)
230 printf '%s\n' "$plan" | grep -q 'would install vole-darwin-arm64 into' ||
231 fail "macOS dry-run: the asset and destination are missing from the plan"
232 printf '%s\n' "$plan" | grep -q 'would check it against' ||
233 fail "macOS dry-run: the checksum check is missing from the plan"
234 plan=$(sh packaging/install.sh --dry-run --repo-only)
235 printf '%s\n' "$plan" | grep -q 'would refuse --repo-only' ||
236 fail "macOS dry-run: --repo-only was not reported as refused"
237
238 # A release that serves a different binary is refused before it is installed.
239 badfixtures="$tmp/badfixtures"
240 mkdir -p "$badfixtures"
241 cp "$fixtures/vole-darwin-arm64" "$badfixtures/"
242 printf '%064d vole-darwin-arm64\n' 0 >"$badfixtures/SHA256SUMS"
243 if FAKE_FIXTURES=$badfixtures sh packaging/install.sh --root "$tmp/macbad" \
244 >"$tmp/macbad.log" 2>&1; then
245 fail "macOS: a mismatched checksum was accepted"
246 fi
247 grep -q 'checksum mismatch' "$tmp/macbad.log" || fail "macOS: a bad checksum did not say so"
248 [ ! -e "$tmp/macbad/usr/local/bin/vole" ] || fail "macOS: a bad checksum still installed the binary"
249
250 # There is no repository to configure on macOS.
251 if sh packaging/install.sh --root "$tmp/macrepo" --repo-only \
252 >"$tmp/macrepo.log" 2>&1; then
253 fail "macOS: --repo-only was accepted"
254 fi
255 grep -q 'configures a package manager' "$tmp/macrepo.log" ||
256 fail "macOS: --repo-only did not explain itself"
257
258 # A Homebrew copy owns the binary; the plan says so and an install refuses.
259 plan=$(FAKE_BREW_STATUS=0 sh packaging/install.sh --dry-run)
260 printf '%s\n' "$plan" | grep -q 'leave the Homebrew installation alone' ||
261 fail "macOS: a Homebrew copy is missing from the plan"
262 if [ "$(id -u)" -ne 0 ]; then
263 home="$tmp/home"
264 mkdir -p "$home"
265 if HOME=$home FAKE_BREW_STATUS=0 sh packaging/install.sh \
266 >"$tmp/brew.log" 2>&1; then
267 fail "macOS: a Homebrew-managed vole was installed over"
268 fi
269 grep -q 'installed by Homebrew' "$tmp/brew.log" ||
270 fail "macOS: a Homebrew-managed vole did not say so"
271 [ ! -e "$home/.local/bin/vole" ] || fail "macOS: a Homebrew-managed vole still wrote a binary"
272
273 # Without root and without Homebrew, the install is for that account.
274 : >"$tmp/curl.log"
275 HOME=$home sh packaging/install.sh >/dev/null
276 [ -x "$home/.local/bin/vole" ] || fail "macOS: a user install did not land in ~/.local/bin"
277 fi
278
279 # Unsupported operating systems are refused rather than guessed at.
280 if FAKE_OS=FreeBSD sh packaging/install.sh --dry-run >"$tmp/os.log" 2>&1; then
281 fail "an unsupported operating system was accepted"
282 fi
283 grep -q 'unsupported operating system' "$tmp/os.log" ||
284 fail "an unsupported operating system did not say so"
285
286 # Back to the real uname for the Linux cases below.
287 PATH=$mac_path
288
16a8be36
Keenan Nemetz
13d ago
289 # Unsupported distributions and invalid options fail with a clear message.
290 other=$(make_root other gentoo "")
291 if sh packaging/install.sh --root "$other" --key packaging/keys/vole-release.asc \
292 --repo-only >"$tmp/other.log" 2>&1; then
293 fail "an unsupported distribution was accepted"
294 fi
295 grep -q 'unsupported distribution' "$tmp/other.log" || fail "an unsupported distribution did not say so"
296
297 if sh packaging/install.sh --dry-run --channel '../bad' >"$tmp/channel.log" 2>&1; then
298 fail "an invalid channel name was accepted"
299 fi
300 grep -q 'invalid channel name' "$tmp/channel.log" || fail "an invalid channel name did not say so"
301
302 sh packaging/install.sh --help >/dev/null || fail "--help failed"
303
304 note "install script checks passed"