-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcbd-cli
More file actions
executable file
·204 lines (170 loc) · 4.27 KB
/
cbd-cli
File metadata and controls
executable file
·204 lines (170 loc) · 4.27 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
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
#!/bin/bash -eu
#
# CLI for the CBD build system
#
function out()
{
local rc=${?}
if [ -n "${TMP_DIR}" ] ; then
rm -rf "${TMP_DIR}"
fi
if [ -n "${CBD_BRANCH}" ] ; then
git branch -D "${CBD_BRANCH}" >/dev/null
fi
if [ "${rc}" -ne 0 ] ; then
echo "-- Script failed" >&2
fi
exit "${rc}"
}
function cbd_build()
{
local opts commit logfile
if [ -z "${SERIES}" ] ; then
echo "-- Not an Ubuntu kernel repository" >&2
exit 1
fi
if ! [ -d "${HOME}"/.cache/cbd ] ; then
mkdir "${HOME}"/.cache/cbd
fi
# Assemble git push options
opts=("cbd:${SERIES}.git")
if [ "$(git cat-file -t "${1:-}" 2>/dev/null)" = "commit" ] ; then
# Create a temporary branch to push if the first argument is a
# commitish
commit=${1}
shift
CBD_BRANCH=cbd-${commit}
git branch "${CBD_BRANCH}" "${commit}"
opts+=("${CBD_BRANCH}")
fi
opts+=("${@}" "-o" "vars")
echo "-- git push ${opts[*]}"
# Kick off the build
logfile=${HOME}/.cache/cbd/${SERIES}--${SOURCE}.log
{
time git push "${opts[@]}" || echo "FAILED"
} 2>&1 | tee "${logfile}"
if [ "${NO_DOWNLOAD}" -eq 1 ] && ! grep -q FAILED "${logfile}" ; then
return
fi
# Source the CBD variables
eval "$(sed -n 's/^remote: CBD/CBD/p' "${logfile}")"
if [ -z "${CBD_JOB:-}" ] ; then
echo "-- Failed to source CBD variables" >&2
exit 1
fi
# Download the build artifacts
cbd_download "${CBD_JOB}"
}
function cbd_download()
{
if [ ${#} -ne 1 ] ; then
usage
exit 2
fi
local cbd_job=${1}
local cbd_hash log arch
if [ -z "${OUT_DIR}" ] ; then
cbd_hash=${cbd_job%-*}
cbd_hash=${cbd_hash##*-}
OUT_DIR=../cbd.d/${cbd_hash}
rm -rf "${OUT_DIR}"
fi
mkdir -p "${OUT_DIR}"
echo "-- Download build artifacts to ${OUT_DIR}"
TMP_DIR=$(mktemp -d)
# shellcheck disable=SC2029
ssh cbd tarball "${cbd_job}" | ( cd "${TMP_DIR}" && tar -xzvf - )
# Move the debs to the provided output directory
find "${TMP_DIR}" -name '*.deb' -print0 | xargs -0 -I{} mv '{}' "${OUT_DIR}"
# Copy the build logs
if [ -e "${TMP_DIR}"/build.log ] ; then
cp "${TMP_DIR}"/build.log "${OUT_DIR}"
fi
for log in "${TMP_DIR}"/*/build.log ; do
if [ -e "${log}" ] ; then
arch=${log%/build.log}
arch=${arch##*/}
cp "${log}" "${OUT_DIR}"/build_"${arch}".log
fi
done
# Save the job ID
echo "${cbd_job}" > "${OUT_DIR}"/cbd_job.id
}
function cbd_help() { ssh cbd help ; }
function cbd_list() { ssh cbd list ; }
function cbd_queue() { ssh cbd queue ; }
function cbd_status() { ssh cbd status ; }
function usage()
{
cat <<EOF
Usage: cbd-cli [-h] [-d DIR] [-n] [-s SERIES] build [COMMIT] [CBD_OPTS]
cbd-cli [-h] [-d DIR] download CBD_JOB
cbd-cli [-h] help|list|queue|status
Commandline interface for the CBD kernel builder.
Supported commands:
build Build (and download) kernel packages.
download Download kernel packages.
help Show CBD help.
list Show supported <series>.git.
queue Show currently queued jobs.
status Show CBD server status summary.
Optional arguments:
-h, --help Show this help text and exit.
-d, --directory DIR Directory to download the Debian packages to. If not
provided, defaults to '../cbd.d/<git_hash>'.
-n, --no-download Don't download packages after the build.
-s, --series SERIES Use series SERIES instead of reading it from the
changelog.
EOF
}
OUT_DIR=
NO_DOWNLOAD=0
SERIES=
SOURCE=
cmd=
while [ $# -gt 0 ] ; do
case "${1}" in
-d|--directory)
shift
OUT_DIR=${1}
;;
-h|--help)
usage
exit
;;
-n|--no-download)
NO_DOWNLOAD=1
;;
-s|--series)
shift
SERIES=${1}
;;
build|download|help|list|queue|status)
cmd=${1}
shift
break
;;
esac
shift
done
if [ -z "${cmd}" ] ; then
usage
exit 2
fi
CBD_BRANCH=
TMP_DIR=
trap out EXIT INT TERM HUP
if [ -e debian/debian.env ] ; then
# shellcheck disable=SC1091
. debian/debian.env
SOURCE=$(dpkg-parsechangelog -l "${DEBIAN}"/changelog -S Source)
if [ -z "${SERIES}" ] ; then
SERIES=$(dpkg-parsechangelog -l "${DEBIAN}"/changelog -S Distribution)
if [ "${SERIES}" = "UNRELEASED" ] ; then
SERIES=$(dpkg-parsechangelog -l "${DEBIAN}"/changelog -S Distribution \
-o 1 -c 1)
fi
fi
fi
cbd_"${cmd}" "${@}"