Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/ping-from-slave
blob: 88b25efb6855f055b0ea330562a99b2f2420a15d (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
#!/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 disable=SC2119,SC2120

# shellcheck source=../lib/load-configuration
. "${0%/*}/../lib/load-configuration"

status=$(
  # shellcheck disable=SC2016,SC2154
  {
    printf 'SELECT'
    printf ' IF(`build_slaves`.`currently_building` IS NULL,0,1),'
    printf 'IF(`build_slaves`.`is_sane`,1,0)'
    printf ' FROM `build_slaves`'
    printf ' WHERE `build_slaves`.`name`=from_base64("%s");\n' \
      "$(printf '%s' "${slave}" | base64 -w0)"
  } | \
    mysql_run_query 'unimportant' | \
    tr '\t' ' '
)

# mysql errors are uncritical for us
if [ -z "${status}" ]; then
  exit
fi

if [ "${status% *}" != '1' ]; then
  # during upload and report of failure, the job might already have been
  # deleted from the database
  if [ 'uploading' != "$1" ] && \
    [ 'failure' != "$1" ]; then
    >&2 echo 'You do not build anything currently - abort whatever you are doing.'
    if [ "${status#* }" = '1' ]; then
      # shellcheck disable=SC2016
      {
        printf 'UPDATE `build_slaves`'
        printf ' SET `build_slaves`.`is_sane`=0'
        printf ' WHERE `build_slaves`.`name`=from_base64("%s");\n' \
          "$(printf '%s' "${slave}" | base64 -w0)"
      } | \
        mysql_run_query
      printf '/j %s Your buildslave "%s" builds some outdated package.\n' \
        "${operator}" "${slave}" | \
        sponge "${irc_dir}/in"
    fi
  fi
  exit 2
fi

log_lines=$(cat)


# shellcheck disable=SC2016
{
  printf 'UPDATE `build_slaves`'
  printf ' SET'
  printf ' `build_slaves`.`last_action`=from_base64("%s")' \
    "$(
      printf '%s' "$1" | \
        base64 -w0
    )"

  printf ', `build_slaves`.`logged_lines`='
  if [ -n "${log_lines}" ]; then
    printf 'from_base64("%s")' \
      "$(
        printf '%s' "$((
          $(
            printf '%s' "${log_lines}" | \
              cut -d' ' -f1 | \
              tr '\n' '+'
          )0))" | \
          base64 -w0
      )"
  else
    printf 'NULL'
  fi

  printf ', `build_slaves`.`trials`='
  if [ -n "${log_lines}" ]; then
    printf 'from_base64("%s")' \
      "$(
        printf '%s\n' "${log_lines}" | \
          wc -l | \
          tr -d '\n' | \
          base64 -w0
      )"
  else
    printf 'NULL'
  fi

  printf ' WHERE `build_slaves`.`id`=from_base64("%s");\n' \
    "$(
      # shellcheck disable=SC2154
      printf '%s' "${slave_id}" | \
        base64 -w0
    )"
} | \
  mysql_run_query 'unimportant'