Welcome to mirror list, hosted at ThFree Co, Russian Federation.

status.sh « poudriere « share « src - github.com/freebsd/poudriere.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 18e4e655427f239293ddacdc93d736b8681667f4 (plain)
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
#!/bin/sh
# 
# Copyright (c) 2014 Bryan Drewery <bdrewery@FreeBSD.org>
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

. ${SCRIPTPREFIX}/common.sh

usage() {
	cat << EOF
poudriere status [options]

Options:
    -a          -- Show all builds, not just latest. This implies -f.
    -f          -- Show finished builds as well. This is default
                   if -a, -B or -r are specified.
    -b          -- Display status of each builder for the matched build.
    -B name     -- What buildname to use (must be unique, defaults to
                   "latest"). This implies -f.
    -c          -- Compact output (shorter headers and no logs/url)
    -H          -- Script mode. Do not print headers and separate fields by a
                   single tab instead of arbitrary white space.
    -j name     -- Run on the given jail
    -p tree     -- Specify on which ports tree to match for the build.
    -l          -- Show logs instead of URL.
    -r          -- Show results. This implies -f.
    -z set      -- Specify which SET to match for the build. Use '0' to only
                   match on empty sets.
EOF
	exit ${EX_USAGE}
}

PTNAME=
SETNAME=
SCRIPT_MODE=0
ALL=0
SHOW_FINISHED=0
COMPACT=0
URL=1
BUILDER_INFO=0
BUILDNAME=
RESULTS=0
SUMMARY=0

while getopts "abB:cfHj:lp:rz:" FLAG; do
	case "${FLAG}" in
		a)
			ALL=1
			SHOW_FINISHED=1
			BUILDNAME_GLOB="*"
			;;
		b)
			BUILDER_INFO=1
			;;
		B)
			BUILDNAME_GLOB="${OPTARG}"
			SHOW_FINISHED=1
			;;
		c)
			COMPACT=1
			;;
		f)
			SHOW_FINISHED=1
			;;
		j)
			JAILNAME=${OPTARG}
			;;
		l)
			URL=0
			;;
		p)
			PTNAME=${OPTARG}
			;;
		H)
			SCRIPT_MODE=1
			;;
		r)
			RESULTS=1
			SHOW_FINISHED=1
			;;
		z)
			SETNAME="${OPTARG}"
			;;
		*)
			usage
			;;
	esac
done

shift $((OPTIND-1))
post_getopts

[ ${BUILDER_INFO} -eq 0 -a ${RESULTS} -eq 0 ] && \
    SUMMARY=1

# Default to "latest" if not using -a and no -B specified
[ ${ALL} -eq 0 ] && : ${BUILDNAME_GLOB:=latest}

POUDRIERE_BUILD_TYPE=bulk
now="$(clock -epoch)"

output_builder_info() {
	local builders

	_bget builders builders || :

	_mastermnt MASTERMNT
	JOBS="${builders}" siginfo_handler
}

add_summary_build() {
	local status nbqueued nbfailed nbignored nbskipped nbbuilt nbtobuild
	local nbfetched
	local elapsed time url save_status

	_bget status status || :
	_bget nbqueued stats_queued || :
	_bget nbbuilt stats_built || :
	_bget nbfailed stats_failed || :
	_bget nbignored stats_ignored || :
	_bget nbskipped stats_skipped || :
	_bget nbfetched stats_fetched || stats_fetched=0
	nbtobuild=$((nbqueued - (nbbuilt + nbfailed + nbskipped + nbignored + \
	    nbfetched)))

	calculate_elapsed_from_log ${now} ${log}
	elapsed=${_elapsed_time}
	calculate_duration time "${elapsed}"

	url=
	if [ ${COMPACT} -eq 0 ]; then
		if [ ${URL} -eq 0 ] || ! build_url url; then
			url="${PWD}/${log}"
		fi
	fi
	status="${status#stopped:}"
	# This mess is to pull the first 2 fields: and remove trailing
	# ':'
	save_status="${status%%:*}"
	status="${status#*:}"
	status="${save_status}:${status%%:*}"
	status="${status%:}"

	display_add "${setname:--}" "${ptname}" "${jailname}" \
	    "${BUILDNAME}" "${status:-?}" "${nbqueued:-?}" \
	    "${nbbuilt:-?}" "${nbfailed:-?}" "${nbskipped:-?}" \
	    "${nbignored:-?}" "${nbfetched:-?}" "${nbtobuild:-?}" "${time:-?}" ${url}
}

status_for_each_build() {
	[ ${SCRIPT_MODE} -eq 0 -a -n "${BUILDNAME_GLOB}" -a \
	    "${BUILDNAME_GLOB}" != "latest" -a \
	    "${BUILDNAME_GLOB}" != "latest-done" ] && \
	    msg_warn "Looking up all matching builds. This may take a while."
	for_each_build "$@"
}

show_summary() {
	if [ ${COMPACT} -eq 0 ]; then
		columns=13
	else
		columns=12
	fi
	if [ ${SCRIPT_MODE} -eq 0 ]; then
		format="%%-%ds %%-%ds %%-%ds %%-%ds %%-%ds %%%ds %%%ds %%%ds %%%ds %%%ds %%%ds %%%ds %%-%ds"
		[ ${COMPACT} -eq 0 ] && format="${format} %%s"
	else
		#format="%%s\t%%s\t%%s\t%%s\t%%s\t%%s\t%%s\t%%s\t%%s\t%%s\t%%s\t%%s"
		#[ ${COMPACT} -eq 0 ] && format="${format}\t%%s"
		format="%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s"
		[ ${COMPACT} -eq 0 ] && format="${format}\t%s"
	fi

	display_setup "${format}" "${columns}" "-d -k1,1 -k2,2 -k3,3n -k4,4n"

	if [ ${COMPACT} -eq 0 ]; then
		if [ -n "${URL_BASE}" ] && [ ${URL} -eq 1 ]; then
			url_logs="URL"
		else
			url_logs="LOGS"
		fi
		display_add "SET" "PORTS" "JAIL" "BUILD" "STATUS" \
		    "QUEUE" "BUILT" "FAIL" "SKIP" "IGNORE" "FETCH" "REMAIN" \
		    "TIME" "${url_logs}"
	else
		display_add "SET" "PORTS" "JAIL" "BUILD" "STATUS" \
		    "Q" "B" "F" "S" "I" "P" "R" "TIME"
	fi

	status_for_each_build add_summary_build

	if [ ${SCRIPT_MODE} -eq 0 ]; then
		if [ ${found_jobs} -eq 0 ]; then
			if [ ${SHOW_FINISHED} -eq 0 ]; then
				msg "No running builds. Use -a or -f to show finished builds."
			else
				msg "No matching builds found."
			fi
			exit 0
		fi

		display_output

		[ -t 0 ] && [ -n "${JAILNAME}" ] && \
		    msg "Use -b to show detailed builder output."
	else
		display_output -q
	fi

	return 0
}

show_builder_info() {
	status_for_each_build output_builder_info

	return 0
}

show_results() {
	status_for_each_build show_build_results

	return 0
}

case "${SUMMARY}${BUILDER_INFO}${RESULTS}" in
	100)
		show_summary
		;;
	010)
		show_builder_info
		;;
	001)
		show_results
		;;
	*)
		usage
		;;
esac