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.

Code

527 commit(s) on main

Put job execution behind an interface Keenan Nemetz · 2h ago de3eec16
history blame raw 12.2 KiB
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
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.
11set -eu
12
13ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
14cd "$ROOT"
15
16tmp=$(mktemp -d)
17trap 'rm -rf "$tmp"' 0
18
19fail() {
20 printf 'check-install: %s\n' "$*" >&2
21 exit 1
22}
23
24note() {
25 printf 'check-install: %s\n' "$*"
26}
27
28sha256() {
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
42sh -n packaging/install.sh || fail "packaging/install.sh has a syntax error"
43
44pinned_sha=$(sed -n 's/^VOLE_KEY_SHA256=//p' packaging/install.sh)
45pinned_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
49actual_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
53if 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})"
59fi
60
61make_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
73run_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.
81debian=$(make_root debian debian "")
82run_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"
85grep -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"
87grep -q '/channels/stable/apt \./' "$debian/etc/apt/sources.list.d/vole.list" ||
88 fail "apt: source list does not name the stable apt tree"
89run_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
93ubuntu=$(make_root ubuntu ubuntu "debian")
94run_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.
98fedora=$(make_root fedora fedora "")
99run_install "$fedora"
100repo="$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"
103grep -q '^baseurl=.*/channels/stable/yum/$' "$repo" || fail "dnf: baseurl is wrong"
104grep -q '^gpgcheck=1$' "$repo" || fail "dnf: gpgcheck is not enabled"
105grep -q '^repo_gpgcheck=1$' "$repo" || fail "dnf: repo_gpgcheck is not enabled"
106grep -q '^gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-vole$' "$repo" || fail "dnf: gpgkey is wrong"
107run_install "$fedora"
108
109rocky=$(make_root rocky rocky "rhel centos fedora")
110run_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.
114arch=$(make_root arch arch "")
115run_install "$arch"
116conf="$arch/etc/pacman.conf"
117[ -f "$conf" ] || fail "pacman: pacman.conf was not written"
118grep -q '^\[vole\]$' "$conf" || fail "pacman: repository section is missing"
119grep -Fq 'Server = https://rodent.software/vole/channels/stable/pacman/$arch' "$conf" ||
120 fail "pacman: Server line is wrong"
121grep -q '^SigLevel = Required DatabaseRequired$' "$conf" || fail "pacman: SigLevel is wrong"
122run_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.
127pinned=$(make_root pinned debian "")
128run_install "$pinned" --version v0.2.0
129grep -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.
133plan=$(sh packaging/install.sh --dry-run)
134printf '%s\n' "$plan" | grep -q 'would run:' || fail "dry-run: no install command in the plan"
135printf '%s\n' "$plan" | grep -q 'detected ' || fail "dry-run: no detected distribution in the plan"
136printf '%s\n' "$plan" | grep -q 'would follow channel stable' ||
137 fail "dry-run: no channel in the plan"
138
139plan=$(sh packaging/install.sh --dry-run --version v0.2.0)
140printf '%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.
144bad=$(make_root bad debian "")
145: >"$tmp/wrong-key.asc"
146if 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"
149fi
150grep -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
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.
156fakebin="$tmp/fakebin"
157fixtures="$tmp/fixtures"
158mkdir -p "$fakebin" "$fixtures"
159cat >"$fakebin/uname" <<'EOF'
160#!/bin/sh
161case "$1" in
162-m) printf '%s\n' "${FAKE_ARCH:-arm64}" ;;
163-s) printf '%s\n' "${FAKE_OS:-Darwin}" ;;
164*) exec /usr/bin/uname "$@" ;;
165esac
166EOF
167cat >"$fakebin/curl" <<'EOF'
168#!/bin/sh
169out=
170url=
171while [ "$#" -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
178done
179printf '%s\n' "$url" >>"$FAKE_LOG"
180name=$(printf '%s' "$url" | sed 's|.*/||')
181if [ -z "$out" ] || [ ! -f "$FAKE_FIXTURES/$name" ]; then
182 exit 22
183fi
184cp "$FAKE_FIXTURES/$name" "$out"
185EOF
186cat >"$fakebin/brew" <<'EOF'
187#!/bin/sh
188exit "${FAKE_BREW_STATUS:-1}"
189EOF
190chmod +x "$fakebin/uname" "$fakebin/curl" "$fakebin/brew"
191
192printf '#!/bin/sh\necho 0.0.0\n' >"$fixtures/vole-darwin-arm64"
193printf '#!/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
199FAKE_LOG="$tmp/curl.log"
200FAKE_FIXTURES="$fixtures"
201export FAKE_LOG FAKE_FIXTURES
202mac_path=$PATH
203PATH="$fakebin:$PATH"
204
205# An --root install puts the arm64 asset where the root says, unchanged.
206: >"$tmp/curl.log"
207sh 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"
209cmp -s "$fixtures/vole-darwin-arm64" "$tmp/mac/usr/local/bin/vole" ||
210 fail "macOS: the installed binary is not the release asset"
211grep -Fq '/channels/stable/vole-darwin-arm64' "$tmp/curl.log" ||
212 fail "macOS: the arm64 asset was not downloaded"
213grep -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"
218FAKE_ARCH=x86_64 sh packaging/install.sh --root "$tmp/macintel" >/dev/null
219grep -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"
224sh packaging/install.sh --root "$tmp/macpin" --version v0.2.0 >/dev/null
225grep -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.
229plan=$(sh packaging/install.sh --dry-run)
230printf '%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"
232printf '%s\n' "$plan" | grep -q 'would check it against' ||
233 fail "macOS dry-run: the checksum check is missing from the plan"
234plan=$(sh packaging/install.sh --dry-run --repo-only)
235printf '%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.
239badfixtures="$tmp/badfixtures"
240mkdir -p "$badfixtures"
241cp "$fixtures/vole-darwin-arm64" "$badfixtures/"
242printf '%064d vole-darwin-arm64\n' 0 >"$badfixtures/SHA256SUMS"
243if 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"
246fi
247grep -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.
251if sh packaging/install.sh --root "$tmp/macrepo" --repo-only \
252 >"$tmp/macrepo.log" 2>&1; then
253 fail "macOS: --repo-only was accepted"
254fi
255grep -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.
259plan=$(FAKE_BREW_STATUS=0 sh packaging/install.sh --dry-run)
260printf '%s\n' "$plan" | grep -q 'leave the Homebrew installation alone' ||
261 fail "macOS: a Homebrew copy is missing from the plan"
262if [ "$(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"
277fi
278
279# Unsupported operating systems are refused rather than guessed at.
280if FAKE_OS=FreeBSD sh packaging/install.sh --dry-run >"$tmp/os.log" 2>&1; then
281 fail "an unsupported operating system was accepted"
282fi
283grep -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.
287PATH=$mac_path
288
289# Unsupported distributions and invalid options fail with a clear message.
290other=$(make_root other gentoo "")
291if 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"
294fi
295grep -q 'unsupported distribution' "$tmp/other.log" || fail "an unsupported distribution did not say so"
296
297if sh packaging/install.sh --dry-run --channel '../bad' >"$tmp/channel.log" 2>&1; then
298 fail "an invalid channel name was accepted"
299fi
300grep -q 'invalid channel name' "$tmp/channel.log" || fail "an invalid channel name did not say so"
301
302sh packaging/install.sh --help >/dev/null || fail "--help failed"
303
304note "install script checks passed"
305