summaryrefslogtreecommitdiff
path: root/bin/ping-from-slave
blob: e16364970fd061e350b5a5168f0058cf36c48807 (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
#!/bin/sh

# should be called periodically on the build-master from the slaves to
#  - report any update on the build process
#  - show that the build is still running
#  - get notified by the build master if the build is not necessary anymore

# shellcheck source=../conf/default.conf
. "${0%/*}/../conf/default.conf"

# TODO: receive/save some statistics about current build

if [ "$(
  # shellcheck disable=SC2016,SC2154
  {
    printf 'SELECT count(*) FROM `build_slaves`'
    mysql_join_build_slaves_build_assignments
    printf ' WHERE `build_slaves`.`name`=from_base64("%s");\n' \
      "$(printf '%s' "${slave}" | base64 -w0)"
  } | \
    mysql_run_query
  )" -ne 1 ]; then
  >&2 echo 'You do not build anything currently - abort whatever you are doing.'
  exit 2
fi

log_lines=$(cat)

if [ -n "${log_lines}" ]; then

  # shellcheck disable=SC2016
  {
    printf 'UPDATE `build_slaves`'
    printf ' SET `build_slaves`.`logged_lines`=from_base64("%s")' \
      "$(
        printf '%s' "$((
          $(
            printf '%s' "${log_lines}" | \
              cut -d' ' -f1 | \
              tr '\n' '+'
          )0))" | \
          base64 -w0
      )"
    printf ' WHERE `build_slaves`.`name`=from_base64("%s");\n' \
      "$(
        printf '%s' "${slave}" | \
          base64 -w0
      )"
  } | \
    tee /tmp/ping-from-slave.query | \
    mysql_run_query

fi