summaryrefslogtreecommitdiff
path: root/bin/build-master-status-from-mysql
blob: d1ee9ffe49a5db9d358d959f697e187fc548b216 (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

# report about status of build master - according to mysql database

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

# TODO: add all (necessary) features from build-master-status

tmp_dir=$(mktemp -d 'tmp.build-master-status-from-mysql.XXXXXXXXXX' --tmpdir)
trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT

# always block if locked
exec 9> "${build_list_lock_file}"
if ! flock -n -s 9; then
  >&2 echo 'Mysql-Sanity check skipped, cannot acquire lock.'
  exit
fi

# shellcheck disable=SC2016
{
  printf 'SELECT DISTINCT `package_sources`.`pkgbase`,`package_sources`.`git_revision`,`package_sources`.`mod_git_revision`,`upstream_repositories`.`name`'
  printf ' FROM `package_sources`'
  printf ' JOIN `%s` ON `%s`.`%s`=`%s`.`id`' \
    'upstream_repositories' 'package_sources' 'upstream_package_repository' 'upstream_repositories' \
    'build_assignments' 'build_assignments' 'package_source' 'package_sources' \
    'binary_packages' 'binary_packages' 'build_assignment' 'build_assignments' \
    'repositories' 'binary_packages' 'repository' 'repositories'
  printf ' WHERE `repositories`.`name`="build-list"'
} | \
  ${mysql_command} --batch | \
  sed '
    1d
    y/\t/ /
  ' | \
  sort > \
  "${tmp_dir}/build-list.mysql"
sort "${work_dir}/build-list" > \
  "${tmp_dir}/build-list.file"

# shellcheck disable=SC2016
{
  printf 'SELECT '
  printf '`package_sources`.`%s`,' \
    'pkgbase' 'git_revision' 'mod_git_revision'
  printf '`upstream_repositories`.`name`'
  printf ' FROM `build_slaves`'
  printf ' JOIN `%s` ON `%s`.`id`=`%s`.`%s`' \
    'build_assignments' 'build_assignments' 'build_slaves' 'currently_building' \
    'package_sources' 'package_sources' 'build_assignments' 'package_source' \
    'upstream_repositories' 'upstream_repositories' 'package_sources' 'upstream_package_repository'
} | \
  ${mysql_command} --raw --batch | \
  sed '
    1d
    y/\t/ /
  ' | \
  sort > \
  "${tmp_dir}/locked.mysql"
find "${work_dir}/package-states" -mindepth 1 -maxdepth 1 -name '*.locked' -printf '%f\n' | \
  sed '
    s/\.\([^.]\+\)\.\([^.]\+\)\.\([^.]\+\)\.[^.]\+$/ \1 \2 \3/
  ' | \
  sort > \
  "${tmp_dir}/locked.file"

# shellcheck disable=SC2016
{
  printf 'SELECT DISTINCT `package_sources`.`pkgbase`'
  printf ' FROM `package_sources`'
  printf ' JOIN `%s` ON `%s`.`%s`=`%s`.`id`' \
    'build_assignments' 'build_assignments' 'package_source' 'package_sources' \
    'binary_packages' 'binary_packages' 'build_assignment' 'build_assignments' \
    'repositories' 'binary_packages' 'repository' 'repositories'
  printf ' WHERE `repositories`.`name`="deletion-list"'
  printf ' OR `binary_packages`.`is_to_be_deleted`;\n'
} | \
  ${mysql_command} --batch | \
  sed '
    1d
    y/\t/ /
  ' | \
  sort > \
  "${tmp_dir}/deletion-list.mysql"
sort "${work_dir}/deletion-list" > \
  "${tmp_dir}/deletion-list.file"

# shellcheck disable=SC2016
{
  printf 'SELECT `package_sources`.`pkgbase`'
  printf ' FROM `package_sources`'
  printf ' JOIN `%s` ON `%s`.`%s`=`%s`.`id`' \
    'build_assignments' 'build_assignments' 'package_source' 'package_sources' \
    'build_dependency_loops' 'build_dependency_loops' 'build_assignment' 'build_assignments'
  printf ';\n'
} | \
  ${mysql_command} --batch | \
  sed '
    1d
    y/\t/ /
  ' | \
  sort > \
  "${tmp_dir}/loops.mysql"
find "${work_dir}/build-list.loops" -regextype grep -mindepth 1 -maxdepth 1 \
  -regex '.*/loop_[0-9]\+' \
  -exec 'cat' '{}' \; | \
  sort > \
  "${tmp_dir}/loops.file"

# shellcheck disable=SC2016
{
  printf 'SELECT '
  printf '`binary_packages`.`%s`,' \
    'pkgname' \
    'epoch' \
    'pkgver' \
    'pkgrel' \
    'sub_pkgrel'
  printf '`architectures`.`name`'
  printf ' FROM `binary_packages`'
  printf ' JOIN `%s` ON `%s`.`id`=`%s`.`%s`' \
    'repositories'           'repositories'           'binary_packages' 'repository' \
    'architectures'          'architectures'          'binary_packages' 'architecture' \
    'repository_stabilities' 'repository_stabilities' 'repositories'    'stability'
  printf ' WHERE `binary_packages`.`is_tested`'
  printf ' AND NOT `binary_packages`.`has_issues`'
  printf ' AND `repository_stabilities`.`name`="testing"'
} | \
  ${mysql_command} --batch | \
  sed '
    1d
    s/^\(\S\+\)\s\(\S\+\)\s\(\S\+\)\s\(\S\+\)\s\(\S\+\)\s\(\S\+\)$/\1-\2:\3-\4.\5-\6.pkg.tar.xz/
  ' | \
  sort -u > \
  "${tmp_dir}/tested.mysql"
find "${work_dir}/package-states" -mindepth 1 -maxdepth 1 \
  -name '*.tested' \
  -exec cat '{}' \; | \
  sed '
    s/-\([^-.]\+\)\(-[^-]\+\)$/-\1.0-\2/
    s/-\([^-:]\+\)\(\(-[^-]\+\)\{2\}\)$/-0:\1\2/
  ' | \
  sort -u > \
  "${tmp_dir}/tested.file"

# shellcheck disable=SC2016
{
  printf 'SELECT '
  printf '`binary_packages`.`%s`,' \
    'pkgname' \
    'epoch' \
    'pkgver' \
    'pkgrel' \
    'sub_pkgrel'
  printf '`architectures`.`name`'
  printf ' FROM `binary_packages`'
  printf ' JOIN `%s` ON `%s`.`id`=`%s`.`%s`' \
    'repositories'           'repositories'           'binary_packages' 'repository' \
    'architectures'          'architectures'          'binary_packages' 'architecture' \
    'repository_stabilities' 'repository_stabilities' 'repositories'    'stability'
  printf ' WHERE NOT `binary_packages`.`is_tested`'
  printf ' AND NOT `binary_packages`.`has_issues`'
  printf ' AND `repository_stabilities`.`name`="testing"'
} | \
  ${mysql_command} --batch | \
  sed '
    1d
    s/^\(\S\+\)\s\(\S\+\)\s\(\S\+\)\s\(\S\+\)\s\(\S\+\)\s\(\S\+\)$/\1-\2:\3-\4.\5-\6.pkg.tar.xz/
  ' | \
  sort -u > \
  "${tmp_dir}/testing.mysql"
find "${work_dir}/package-states" -mindepth 1 -maxdepth 1 \
  -name '*.testing' \
  -exec cat '{}' \; | \
  sed '
    s/-\([^-.]\+\)\(-[^-]\+\)$/-\1.0-\2/
    s/-\([^-:]\+\)\(\(-[^-]\+\)\{2\}\)$/-0:\1\2/
  ' | \
  sort -u > \
  "${tmp_dir}/testing.file"

# shellcheck disable=SC2016
{
  printf 'SELECT '
  printf '`package_sources`.`%s`,' \
    'pkgbase' \
    'git_revision' \
    'mod_git_revision'
  printf '`upstream_repositories`.`name`,`install_targets`.`name`'
  printf ' FROM `binary_packages`'
  printf ' JOIN `%s` ON `%s`.`id`=`%s`.`%s`' \
    'dependencies'     'binary_packages'  'dependencies' 'dependent' \
    'dependency_types' 'dependency_types' 'dependencies' 'dependency_type'
  printf ' AND `dependency_types`.`relevant_for_building`'
  printf ' JOIN `%s` ON `%s`.`id`=`%s`.`%s`' \
    'install_targets'       'install_targets'       'dependencies'      'depending_on' \
    'build_assignments'     'build_assignments'     'binary_packages'   'build_assignment' \
    'package_sources'       'package_sources'       'build_assignments' 'package_source' \
    'upstream_repositories' 'upstream_repositories' 'package_sources'   'upstream_package_repository'
} | \
  ${mysql_command} --raw --batch | \
  sed '
    1d
    y/\t/ /
  ' | \
  sort -u > \
  "${tmp_dir}/build-dependencies.mysql"
{
  cat "${tmp_dir}/build-dependencies.mysql"
  find "${work_dir}/package-infos" -name '*.build-depends' \
    -exec grep -HF '' {} \; | \
    sed '
      s,^.*/,,
      s/\.\([^.]\+\)\.\([^.]\+\)\.\([^.:]\+\)\.build-depends:\([^:]\+\)$/ \1 \2 \3 \4/
    '
} | \
  sort -u > \
  "${tmp_dir}/build-dependencies.file"

{
  diff -u \
    "${tmp_dir}/locked.file" \
    "${tmp_dir}/locked.mysql" || \
    true
  mysql_sanity_check || true
  diff -u \
    "${tmp_dir}/build-list.file" \
    "${tmp_dir}/build-list.mysql" || \
    true
  diff -u \
    "${tmp_dir}/deletion-list.file" \
    "${tmp_dir}/deletion-list.mysql" || \
    true
  diff -u \
    "${tmp_dir}/loops.file" \
    "${tmp_dir}/loops.mysql" || \
    true
  diff -u \
    "${tmp_dir}/tested.file" \
    "${tmp_dir}/tested.mysql" || \
    true
  diff -u \
    "${tmp_dir}/testing.file" \
    "${tmp_dir}/testing.mysql" || \
    true
  diff -u \
    "${tmp_dir}/build-dependencies.file" \
    "${tmp_dir}/build-dependencies.mysql" || \
    true
} | \
  sed '
    s,^-.*$,<font color="#FF0000">\0</font>,
    s,^+.*$,<font color="#00FF00">\0</font>,
    s/$/<br>/
    1 i <html><head><title>sanity of the buildmaster'"'"'s mysql database</title></head><body>
    $ a </body></html>
  ' | \
  sponge "${webserver_directory}/mysql-sanity.html"