summaryrefslogtreecommitdiff
path: root/bin/manage-fail-reasons
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2019-08-10 18:41:31 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2019-08-10 18:41:31 +0200
commitd6a60390b4ce8ea3bd9a995ef54089b3bcf2ed26 (patch)
tree1420e7876897aa4b9f54e29137c49db0a49bde64 /bin/manage-fail-reasons
parent23512eacd8be92c89dbee688903550f09b16c3b9 (diff)
downloadbuilder-d6a60390b4ce8ea3bd9a995ef54089b3bcf2ed26.tar.xz
added a manage-fail-reasons to improve failure detection
Diffstat (limited to 'bin/manage-fail-reasons')
-rwxr-xr-xbin/manage-fail-reasons68
1 files changed, 68 insertions, 0 deletions
diff --git a/bin/manage-fail-reasons b/bin/manage-fail-reasons
new file mode 100755
index 0000000..bc7c5bc
--- /dev/null
+++ b/bin/manage-fail-reasons
@@ -0,0 +1,68 @@
+#!/bin/sh
+
+# shellcheck source=../lib/load-configuration
+. "${0%/*}/../lib/load-configuration"
+
+# shellcheck disable=SC2016
+usage() {
+ >&2 echo ''
+ >&2 echo 'manage-fail-reasons $action [parameters]: manage the list of fail reasons'
+ >&2 echo ''
+ >&2 echo 'possible actions:'
+ >&2 echo ' list list installed fail reasons'
+ >&2 echo ' check <build-log> check a build log for fail reasons'
+ exit 1
+}
+
+if [ $# -eq 0 ]; then
+ usage
+fi
+
+case "$1" in
+ 'list')
+ # shellcheck disable=SC2016
+ fail_reason_identifiers=$(
+ {
+ printf 'SELECT `fail_reasons`.`id`,`fail_reasons`.`severity`,replace(to_base64(`fail_reasons`.`identifier`),"\\n","")'
+ printf ' FROM `fail_reasons` ORDER BY `fail_reasons`.`severity` ASC, `fail_reasons`.id ASC'
+ } | \
+ mysql_run_query
+ )
+ printf '%s\n' "${fail_reason_identifiers}" | \
+ while read -r reason_id severity identifier; do
+ ident=$(printf '%s' "${identifier}" | base64 -d -)
+ printf "%02s %03s %s\n" "$reason_id" "$severity" "$ident"
+ done
+ ;;
+ 'check')
+ shift
+ filelog="$1"
+ if [ $# -ne 1 ]; then
+ >&2 printf '"check" expects 1 parameter (a path to a build log), %s were given\n' "$#"
+ usage
+ fi
+ fail_reason_identifiers=$(
+ {
+ printf 'SELECT id,severity,replace(to_base64(`fail_reasons`.`identifier`),"\\n","")'
+ printf ' FROM `fail_reasons` ORDER BY `fail_reasons`.`severity` ASC, `fail_reasons`.id ASC'
+ } | \
+ mysql_run_query
+ )
+ printf '%s\n' "${fail_reason_identifiers}" | \
+ while read -r id severity identifier; do
+ if zgrep -qx "\s*$(
+ printf '%s' "${identifier}" | \
+ base64 -d
+ )\s*" \
+ "$filelog"; then
+ echo 'match'
+ ident=$(printf '%s' "${identifier}" | base64 -d -)
+ printf "$id ($ident) matches with severity $severity\n"
+ fi
+ done
+ ;;
+ *)
+ >&2 printf 'unknown action "%s"\n' "$1"
+ usage
+ ;;
+esac