forked from cri-o/cri-o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget
executable file
·299 lines (259 loc) · 9.61 KB
/
get
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/usr/bin/env bash
set -euo pipefail
ARCH_AMD64=amd64
ARCH_ARM64=arm64
ARCH_PPC64LE=ppc64le
ARCH=
VERSION=
GITHUB_TOKEN=${GITHUB_TOKEN:-}
GCB_URL=https://storage.googleapis.com/cri-o
usage() {
printf "Usage: %s [-a ARCH] [ -t TAG|SHA ] [ -b BUCKET ] [ -h ]\n\n" "$(basename "$0")"
echo "Possible arguments:"
printf " -a\tArchitecture to retrieve (defaults to the local system)\n"
printf " -t\tVersion tag or full length SHA to be used (defaults to the latest available main)\n"
printf " -b\tName of the GCS bucket for downloading artifacts (defaults to 'cri-o')\n"
printf " -h\tShow this help message\n"
}
parse_args() {
echo "Welcome to the CRI-O install script!"
while getopts 'a:b:t:h' OPTION; do
case "$OPTION" in
a)
ARCH="$OPTARG"
echo "Using architecture: $ARCH"
;;
t)
VERSION="$OPTARG"
echo "Using version: $VERSION"
;;
b)
GCB_URL="https://storage.googleapis.com/$OPTARG"
echo "Using GCS bucket: gs://$OPTARG"
;;
h)
usage
exit 0
;;
?)
usage
exit 1
;;
esac
done
if [[ $ARCH == "" ]]; then
LOCAL_ARCH=$(uname -m)
if [[ "$LOCAL_ARCH" == x86_64 ]]; then
ARCH=$ARCH_AMD64
elif [[ "$LOCAL_ARCH" == aarch64 ]]; then
ARCH=$ARCH_ARM64
elif [[ "$LOCAL_ARCH" == "$ARCH_PPC64LE" ]]; then
ARCH=$ARCH_PPC64LE
else
echo "Unsupported local architecture: $LOCAL_ARCH"
exit 1
fi
echo "No architecture provided, using: $ARCH"
fi
}
verify_requirements() {
CMDS=(curl jq tar)
echo "Checking if all commands are available: ${CMDS[*]}"
for CMD in "${CMDS[@]}"; do
if ! command -v "$CMD" >/dev/null; then
echo "Command $CMD not available but required"
exit 1
fi
done
}
curl_retry() {
curl -sSfL --retry 5 --retry-delay 3 "$@"
}
latest_version() {
GH_API_URL="https://api.github.com/repos/cri-o/cri-o/actions/runs?per_page=100"
GH_HEADERS=(-H "Accept: application/vnd.github.v3+json")
if [[ $GITHUB_TOKEN != "" ]]; then
GH_HEADERS+=(-H "Authorization: token $GITHUB_TOKEN")
fi
if [[ $VERSION == "" ]]; then
echo Searching for latest version via marker file
COMMIT=$(curl_retry "$GCB_URL/latest-main.txt")
if [[ "$COMMIT" != "" ]]; then
VERSION=$COMMIT
echo "Found latest version $VERSION"
return
fi
echo No version marker found, trying latest successful GitHub actions run
echo Export a GITHUB_TOKEN environment variable to avoid GitHub API rate limits
PAGE=0
while true; do
PAGE=$((PAGE + 1))
echo Searching GitHub actions page $PAGE
URL="${GH_API_URL}&page=$PAGE"
JSON=$(curl_retry "${GH_HEADERS[@]}" "$URL")
if echo "$JSON" | jq -e '.workflow_runs | length == 0' >/dev/null; then
echo No more GitHub action runs available to search
exit 1
fi
FOUND=$(echo "$JSON" |
jq -r '.workflow_runs | map(select(.name == "test" and .head_branch == "main" and .conclusion == "success")) | first | .head_sha')
if [[ $FOUND == null ]]; then
continue
fi
VERSION=$FOUND
echo "Using latest successful GitHub action main: $VERSION"
break
done
if [[ $VERSION == "" ]]; then
echo "Unable to find successful GitHub action"
exit 1
fi
fi
}
prepare() {
parse_args "$@"
verify_requirements
latest_version
}
prepare "$@"
TARBALL=cri-o.$ARCH.$VERSION.tar.gz
SPDX=$TARBALL.spdx
BASE_URL=$GCB_URL/artifacts
TMPDIR="$(mktemp -d)"
trap 'rm -rf -- "$TMPDIR"' EXIT
if command -v cosign >/dev/null; then
echo "Found cosign, verifying signatures"
pushd "$TMPDIR" >/dev/null
FILES=(
"$TARBALL"
"$TARBALL.sig"
"$TARBALL.cert"
"$SPDX"
"$SPDX.sig"
"$SPDX.cert"
)
for FILE in "${FILES[@]}"; do
echo "Downloading $FILE"
curl_retry "$BASE_URL/$FILE" -o "$FILE"
done
GIT_REF=refs/heads/main
if git ls-remote --exit-code --tags https://github.com/cri-o/cri-o "refs/tags/$VERSION" >/dev/null; then
GIT_REF="refs/tags/$VERSION"
fi
BLOBS=(
"$TARBALL"
"$SPDX"
)
for BLOB in "${BLOBS[@]}"; do
echo "Verifying blob $BLOB"
COSIGN_EXPERIMENTAL=1 cosign verify-blob "$BLOB" \
--certificate-identity "https://github.com/cri-o/cri-o/.github/workflows/test.yml@$GIT_REF" \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
--certificate-github-workflow-repository cri-o/cri-o \
--certificate-github-workflow-ref "$GIT_REF" \
--signature "$BLOB.sig" \
--certificate "$BLOB.cert"
done
tar xfz "$TARBALL"
TARBALL_DIR=cri-o
if command -v bom >/dev/null; then
echo "Found bom tool, verifying bill of materials"
bom validate -e "$SPDX" -d "$TARBALL_DIR"
fi
pushd "$TARBALL_DIR"
else
TARBALL_URL=$BASE_URL/$TARBALL
echo "Downloading $TARBALL_URL to $TMPDIR"
curl_retry "$TARBALL_URL" | tar xfz - --strip-components=1 -C "$TMPDIR"
pushd "$TMPDIR"
fi
echo Installing CRI-O
# In this section we include the contents of
# contrib/bundle/install-paths and contrib/bundle/install
# INCLUDE
DESTDIR=${DESTDIR:-}
PREFIX=${PREFIX:-/usr/local}
ETCDIR=${ETCDIR:-/etc}
CONTAINERS_DIR=${CONTAINERS_DIR:-$ETCDIR/containers}
CONTAINERS_REGISTRIES_CONFD_DIR=${CONTAINERS_REGISTRIES_CONFD_DIR:-$CONTAINERS_DIR/registries.conf.d}
CNIDIR=${CNIDIR:-$ETCDIR/cni/net.d}
BINDIR=${BINDIR:-$PREFIX/bin}
MANDIR=${MANDIR:-$PREFIX/share/man}
OCIDIR=${OCIDIR:-$PREFIX/share/oci-umount/oci-umount.d}
BASHINSTALLDIR=${BASHINSTALLDIR:-$PREFIX/share/bash-completion/completions}
FISHINSTALLDIR=${FISHINSTALLDIR:-$PREFIX/share/fish/completions}
ZSHINSTALLDIR=${ZSHINSTALLDIR:-$PREFIX/share/zsh/site-functions}
OPT_CNI_BIN_DIR=${OPT_CNI_BIN_DIR:-/opt/cni/bin}
# Update systemddir based on OS
source /etc/os-release
if { [[ "${ID}" == "fedora" ]] && [[ "${VARIANT_ID}" == "coreos" ]]; } ||
[[ "${ID}" == "rhcos" ]]; then
SYSTEMDDIR=${SYSTEMDDIR:-/etc/systemd/system}
else
SYSTEMDDIR=${SYSTEMDDIR:-$PREFIX/lib/systemd/system}
fi
SELINUX=
if selinuxenabled 2>/dev/null; then
SELINUX=-Z
fi
ARCH=${ARCH:-amd64}
set -x
install $SELINUX -d -m 755 "$DESTDIR$CNIDIR"
install $SELINUX -D -m 755 -t "$DESTDIR$OPT_CNI_BIN_DIR" cni-plugins/*
install $SELINUX -D -m 644 -t "$DESTDIR$CNIDIR" contrib/11-crio-ipv4-bridge.conflist
install $SELINUX -D -m 755 -t "$DESTDIR$BINDIR" bin/conmon
install $SELINUX -D -m 755 -t "$DESTDIR$BINDIR" bin/conmonrs
install $SELINUX -D -m 755 -t "$DESTDIR$BINDIR" bin/crictl
install $SELINUX -d -m 755 "$DESTDIR$BASHINSTALLDIR"
install $SELINUX -d -m 755 "$DESTDIR$FISHINSTALLDIR"
install $SELINUX -d -m 755 "$DESTDIR$ZSHINSTALLDIR"
install $SELINUX -d -m 755 "$DESTDIR$CONTAINERS_DIR"
install $SELINUX -d -m 755 "$DESTDIR$CONTAINERS_REGISTRIES_CONFD_DIR"
install $SELINUX -D -m 755 -t "$DESTDIR$BINDIR" bin/crio-status
install $SELINUX -D -m 755 -t "$DESTDIR$BINDIR" bin/crio
install $SELINUX -D -m 644 -t "$DESTDIR$ETCDIR" etc/crictl.yaml
install $SELINUX -D -m 644 -t "$DESTDIR$OCIDIR" etc/crio-umount.conf
install $SELINUX -D -m 644 -t "$DESTDIR$ETCDIR/crio" etc/crio.conf
install $SELINUX -D -m 644 -t "$DESTDIR$ETCDIR/crio/crio.conf.d" etc/10-crun.conf
install $SELINUX -D -m 644 -t "$DESTDIR$MANDIR/man5" man/crio.conf.5
install $SELINUX -D -m 644 -t "$DESTDIR$MANDIR/man5" man/crio.conf.d.5
install $SELINUX -D -m 644 -t "$DESTDIR$MANDIR/man8" man/crio-status.8
install $SELINUX -D -m 644 -t "$DESTDIR$MANDIR/man8" man/crio.8
install $SELINUX -D -m 644 -t "$DESTDIR$BASHINSTALLDIR" completions/bash/crio
install $SELINUX -D -m 644 -t "$DESTDIR$FISHINSTALLDIR" completions/fish/crio.fish
install $SELINUX -D -m 644 -t "$DESTDIR$ZSHINSTALLDIR" completions/zsh/_crio
install $SELINUX -D -m 644 -t "$DESTDIR$SYSTEMDDIR" contrib/crio.service
install $SELINUX -D -m 755 -t "$DESTDIR$BINDIR" bin/pinns
install $SELINUX -D -m 755 -t "$DESTDIR$BINDIR" bin/crun
install $SELINUX -D -m 644 -t "$DESTDIR$CONTAINERS_REGISTRIES_CONFD_DIR" contrib/crio-registries.conf
if [ ! -f "$DESTDIR$CONTAINERS_DIR/policy.json" ]; then
install $SELINUX -D -m 644 -t "$DESTDIR$CONTAINERS_DIR" contrib/policy.json
fi
# only install runc if it's not already in the path
if ! command -v runc; then
install $SELINUX -D -m 755 -t "$DESTDIR$BINDIR" bin/runc
fi
if [ -n "$SELINUX" ]; then
if command -v chcon >/dev/null; then
chcon -u system_u -r object_r -t container_runtime_exec_t \
"$DESTDIR$BINDIR/crio" \
"$DESTDIR$BINDIR/crio-status" \
"$DESTDIR$BINDIR/crun"
if [ "$ARCH" = amd64 ]; then
chcon -u system_u -r object_r -t container_runtime_exec_t \
"$DESTDIR$BINDIR/runc"
fi
chcon -u system_u -r object_r -t bin_t \
"$DESTDIR$BINDIR/conmon" \
"$DESTDIR$BINDIR/conmonrs" \
"$DESTDIR$BINDIR/crictl" \
"$DESTDIR$BINDIR/pinns"
chcon -R -u system_u -r object_r -t bin_t \
"$DESTDIR$OPT_CNI_BIN_DIR"
chcon -R -u system_u -r object_r -t container_config_t \
"$DESTDIR$ETCDIR/crio" \
"$DESTDIR$OCIDIR/crio-umount.conf"
chcon -R -u system_u -r object_r -t systemd_unit_file_t \
"$DESTDIR$SYSTEMDDIR/crio.service"
fi
fi