-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·91 lines (78 loc) · 1.95 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·91 lines (78 loc) · 1.95 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
#!/usr/bin/env bash
set -eu
repo=kjanat/envctl
dir=${ENVCTL_INSTALL_DIR:-${HOME}/.local/bin}
version=${ENVCTL_VERSION:-latest}
sys=$(uname -s)
machine=$(uname -m)
case ${sys} in
Linux) os=linux ;;
Darwin) os=darwin ;;
MINGW* | MSYS* | CYGWIN*) os=windows ;;
*)
echo "unsupported OS: ${sys}" >&2
exit 1
;;
esac
case ${machine} in
x86_64 | amd64) arch=amd64 ;;
aarch64 | arm64) arch=arm64 ;;
*)
echo "unsupported architecture: ${machine}" >&2
exit 1
;;
esac
ext=
[[ ${os} == windows ]] && ext=.exe
asset="envctl-${os}-${arch}${ext}"
if [[ ${version} == latest ]]; then
base="https://github.com/${repo}/releases/latest/download"
else
base="https://github.com/${repo}/releases/download/${version}"
fi
tmp=$(mktemp -d)
trap 'rm -rf "${tmp}"' EXIT INT TERM
fetch() {
if command -v curl >/dev/null; then
curl -fsSL -o "$2" "$1"
elif command -v wget >/dev/null; then
wget -qO "$2" "$1"
else
echo "need curl or wget" >&2
exit 1
fi
}
fetch "${base}/${asset}" "${tmp}/${asset}"
fetch "${base}/SHA256SUMS" "${tmp}/SHA256SUMS"
grep " ${asset}\$" "${tmp}/SHA256SUMS" >"${tmp}/expected"
(
cd "${tmp}"
if command -v sha256sum >/dev/null; then
sha256sum -c expected >/dev/null
elif command -v shasum >/dev/null; then
shasum -a 256 -c expected >/dev/null
else
echo "note: no sha256 tool, skipping checksum verification" >&2
fi
) || {
echo "checksum verification failed for ${asset}" >&2
exit 1
}
if [[ -n ${ENVCTL_ATTEST:-} ]]; then
if ! command -v gh >/dev/null; then
echo "ENVCTL_ATTEST is set but gh is not installed" >&2
exit 1
fi
if ! gh attestation verify "${tmp}/${asset}" -R "${repo}" >/dev/null; then
echo "attestation verification failed for ${asset}" >&2
exit 1
fi
echo "attestation verified: built by ${repo} CI"
fi
mkdir -p "${dir}"
install -m 755 "${tmp}/${asset}" "${dir}/envctl${ext}"
echo "installed ${asset} ${version} -> ${dir}/envctl${ext}"
case :${PATH}: in
*:${dir}:*) ;;
*) echo "note: ${dir} is not in PATH" >&2 ;;
esac