Evidence

Archive-related identifier text lines 1–48
1#!/usr/bin/env sh
2
3set -eu
4
5readonly repository='devantler-tech/ksail'
6readonly release_base_url="${KSAIL_RELEASE_BASE_URL:-https://github.com/${repository}/releases}"
7
8fail() {
9 printf '%s\n' "$1" >&2
10 exit 1
11}
12
13sha256() {
14 if command -v sha256sum >/dev/null 2>&1; then
15 checksum_output="$(sha256sum "$1")" || return 1
16 elif command -v shasum >/dev/null 2>&1; then
17 checksum_output="$(shasum -a 256 "$1")" || return 1
18 else
19 fail 'sha256sum or shasum is required to verify the KSail release'
20 fi
21 printf '%s\n' "${checksum_output}" | awk '{print $1}'
22}
23
24version="${KSAIL_VERSION:-latest}"
25if [ "${version}" = 'latest' ]; then
26 latest_url="$(
27 curl --fail --silent --show-error --location --head \
28 --output /dev/null --write-out '%{url_effective}' \
29 "${release_base_url}/latest"
30 )"
31 version="${latest_url##*/}"
32fi
33
34if ! printf '%s\n' "${version}" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$'; then
35 printf 'invalid KSail release version: %s\n' "${version}" >&2
36 exit 1
37fi
38
39case "$(uname -s)" in
40Darwin) operating_system='darwin' ;;
41Linux) operating_system='linux' ;;
42*)
43 printf 'unsupported operating system: %s\n' "$(uname -s)" >&2
44 exit 1
45 ;;
46esac
47
48case "$(uname -m)" in
Shell command-substitution syntax lines 86–100
86:19… sums_path}" "${download_base}/${checksums}"
87
88expected_checksum="$(
89 awk -v target="${asset}" '
90 {
⋯10 lines
Reports a hash, checksum or digest mismatch lines 100–112
100:29… o not contain %s\n' "${asset}" >&2
101 exit 1
102fi
103
104actual_checksum="$(sha256 "${archive_path}")"
105
106if [ "${actual_checksum}" != "${expected_checksum}" ]; then
107 printf 'checksum mismatch for %s\n' "${asset}" >&2
108 exit 1
109fi
110
111# Never extract archive paths onto the filesystem. Admit each exact member once,
112# verify …
Command text invokes mkdir lines 114–119
114:65… mbers"; then
115 fail 'release archive contains an unsafe path'
116fi
117mkdir "${tmp_dir}/GoNotices"
118for member in ksail GoNotices/THIRD_PARTY_NOTICES.txt GoNotices/manifest.json GoNotices/release.txt; do
119 if ! awk -v member="${ …
tar extraction command usage lines 124–128
124:5… il 'release archive required member is not a regular file'
125 fi
126 tar -xOzf "${archive_path}" -- "${member}" >"${tmp_dir}/${member}"
127 if [ ! -s "${tmp_dir}/${member}" ]; then
128 fail "release archive required member is emp …

Keyboard shortcuts on this page: j for the next sample, k for the previous one, x to go back to the feed, d to download the original bytes, r to re-queue the sample for analysis.