-
Notifications
You must be signed in to change notification settings - Fork 18
/
install-slsa-provenance.sh
executable file
·109 lines (89 loc) · 2.79 KB
/
install-slsa-provenance.sh
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
#!/usr/bin/env bash
shopt -s expand_aliases
if [ -z "$NO_COLOR" ]; then
alias log_info="echo -e \"\033[1;32mINFO\033[0m:\""
alias log_error="echo -e \"\033[1;31mERROR\033[0m:\""
alias log_warning="echo -e \"\033[1;33mWARN\033[0m:\""
else
alias log_info="echo \"INFO:\""
alias log_error="echo \"ERROR:\""
alias log_warning="echo \"WARN:\""
fi
set -e
GITHUB_API=${GITHUB_API:-'https://api.github.com'}
# default to relative path if INSTALL_PATH is not set
INSTALL_PATH=${INSTALL_PATH:-$(realpath ./.slsa-provenance)}
mkdir -p "${INSTALL_PATH}"
VERSION=v0.7.2
RELEASE="https://github.com/philips-labs/slsa-provenance-action/releases/download/${VERSION}"
if [[ "$VERSION" == *-draft ]] ; then
curl_args=(-H "Authorization: token $GITHUB_TOKEN")
assets=$(curl "${curl_args[@]}" -s "${GITHUB_API}/repos/philips-labs/slsa-provenance-action/releases?per_page=10" | jq "map(select(.name == \"${VERSION}\"))" | jq -r '.[0].assets')
fi
function download {
url="${2}"
if [[ "$VERSION" == *-draft ]] ; then
url="$(echo "${assets}" | jq "map(select(.name == \"$1\"))" | jq -r '.[0].url')"
curl_args+=(-H 'Accept: application/octet-stream')
fi
log_info "Downloading ${1} from ${url}…"
curl -sLo "${1}" --show-error "${curl_args[@]}" "${url}"
echo
}
OS=${RUNNER_OS:-Linux}
ARCH=${RUNNER_ARCH:-X64}
case "${ARCH}" in
X64)
ARCH=amd64
;;
ARM64)
ARCH=arm64
;;
*)
log_error "unsupported ARCH ${ARCH}"
exit 1
;;
esac
BINARY=slsa-provenance
case "${OS}" in
Linux)
OS=linux
ARCHIVE="slsa-provenance_${VERSION/v}_${OS}_${ARCH}.tar.gz"
;;
macOS)
ARCHIVE="slsa-provenance_${VERSION/v}_${OS}_${ARCH}.tar.gz"
;;
Windows)
OS=windows
ARCHIVE="slsa-provenance_${VERSION/v}_${OS}_${ARCH}.zip"
BINARY="${BINARY}.exe"
;;
*)
log_error "unsupported OS ${OS}"
exit 1
;;
esac
DOWNLOAD="${RELEASE}/${ARCHIVE}"
log_info "Installing ${BINARY} (${OS}/${ARCH}) at ${INSTALL_PATH}"
mkdir -p "$INSTALL_PATH"
trap "popd >/dev/null" EXIT
pushd "$INSTALL_PATH" > /dev/null || exit
download "${ARCHIVE}" "${DOWNLOAD}"
if [ -x "$(command -v cosign)" ] ; then
download ${ARCHIVE}.sig "${DOWNLOAD}.sig"
download cosign.pub "$RELEASE/cosign.pub"
log_info "Verifying signature…"
cosign verify-blob --key cosign.pub --signature "${ARCHIVE}.sig" "${ARCHIVE}"
rm "${ARCHIVE}.sig" cosign.pub
else
log_warning >&2
log_warning " cosign binary not installed in PATH. Unable to verify signature!" >&2
log_warning >&2
log_warning " Consider installing cosign first, to be able to verify the signature!" >&2
log_warning >&2
fi
log_info "extracting ${BINARY} from ${ARCHIVE}"
tar -xzf "${ARCHIVE}" "${BINARY}"
rm "${ARCHIVE}"
# for testing purposes fall back to "$INSTALL_PATH/GITHUB_PATH"
echo "$INSTALL_PATH" >> "${GITHUB_PATH:-"$INSTALL_PATH/GITHUB_PATH"}"