Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/seed-build-list
blob: 5392306ccb1cffd9c603f129e9b287ceb4268dff (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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/bin/sh

# seed the build list from differences between an x86_64 and our master mirror

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

# shellcheck disable=SC2016
usage() {
  >&2 echo ''
  >&2 echo 'seed-build-list [options]:'
  >&2 echo '  seed the build list from'
  >&2 echo '    - differences between an x86_64 and our master mirror'
  >&2 echo '    - a list of packages which need to be rebuilt'
  >&2 echo ''
  >&2 echo 'possible options:'
  >&2 echo '  -h|--help:'
  >&2 echo '    Show this help and exit.'
  >&2 echo '  -i|--ignore $package:'
  >&2 echo '    Do not update $package.'
  >&2 echo '  -m|--mirror $url:'
  >&2 echo '    Get x86_64 packages from mirror at $url.'
  >&2 echo '  -n|--no-action:'
  >&2 echo '    Do not actually update build-list, just print it.'
  >&2 echo '  -p|--package $pkg_regex:'
  >&2 echo '    Update packages matching $pkg_regex.'
  [ -z "$1" ] && exit 1 || exit "$1"
}

tmp_dir=$(mktemp -d)
# shellcheck disable=SC2064
trap "rm -rf --one-file-system '${tmp_dir:?}'" EXIT

eval set -- "$(
  getopt -o hi:m:np: \
    --long help \
    --long ignore: \
    --long mirror: \
    --long no-action \
    --long package: \
    -n "$(basename "$0")" -- "$@" || \
    echo usage
  )"

touch "${tmp_dir}/mirrors"
touch "${tmp_dir}/delta-packages"
touch "${tmp_dir}/package-regexes"
touch "${tmp_dir}/ignore-packages"

update=true

while true
do
  case "$1" in
    -h|--help)
      usage 0
    ;;
    -i|--ignore)
      shift
      echo "$1" >> \
        "${tmp_dir}/ignore-packages"
    ;;
    -m|--mirror)
      shift
      echo "$1" >> \
        "${tmp_dir}/mirrors"
    ;;
    -n|--no-action)
      update=false
    ;;
    -p|--package)
      shift
      echo "$1" >> \
        "${tmp_dir}/package-regexes"
    ;;
    --)
      shift
      break
    ;;
    *)
      >&2 echo 'Whoops, forgot to implement option "'"$1"'" internally.'
      exit 42
    ;;
  esac
  shift
done

if [ $# -ne 0 ]; then
  usage 1
fi

repos="${stable_package_repositories}"

find "${work_dir}/package-infos" -maxdepth 1 -name '*.packages' -printf '%f\n' | \
  sed 's|\.\([^.]\+\)\.\([^.]\+\)\.\([^.]\+\)\.[^.]\+$| \1 \2 \3|' | \
  sort -k1,1 > \
  "${tmp_dir}/known-packages"

mod_repo_rev=$(cat "${work_dir}/archlinux32.revision")
{
  for repo in ${repo_names}; do
    if [ "${repo_names}" = 'archlinux32' ]; then
      continue
    fi
    eval 'repo_path="${repo_paths__'"${repo}"'}"'
    repo_rev=$(cat "${work_dir}/${repo}.revision")
    git -C "${repo_path}" archive "$(cat "${work_dir}/${repo}.revision")" | \
      tar -t | \
      grep '^[^/]\+/repos/[^/]\+/PKGBUILD$' | \
      grep -v -- '-i686/PKGBUILD$' | \
      grep -v -- '[-/]\(staging\|testing\|unstable\)-[^/]\+/PKGBUILD$' | \
      sed '
        s|^\([^/]\+\)/repos/\([^/]\+\)-[^/-]\+/PKGBUILD$|'"${repo_rev}"' \1 \2|
      '
  done | \
    sort -u | \
    sort -k1,1
  awk '{print "nothing " $1 " " $4}' "${tmp_dir}/known-packages" | \
    sort -u | \
    sed 'p'
} | \
  sort -k2,3 | \
  uniq -uf1 | \
  while read -r repo_rev pkg prepo; do
    generate_package_metadata "${pkg}" "${repo_rev}" "${mod_repo_rev}" "${prepo}"
  done

find "${work_dir}/package-infos" -maxdepth 1 -name '*.packages' -exec grep -HF '' "{}" \; | \
  sed '
    s|^.*/||
    s|\.\([^.]\+\)\.\([^.]\+\)\.\([^.]\+\)\.[^.]\+:| \1 \2 \3 |
  ' | \
  sort -k5,5 > \
  "${tmp_dir}/known-packages"

# generate delta-packages from package-regexes
while read -r pkg_regex; do
  if [ -z "${pkg_regex}" ]; then
    continue
  fi
  awk '{print $5}' "${tmp_dir}/known-packages" | \
    grep "${pkg_regex}" || \
    true
done < \
  "${tmp_dir}/package-regexes" >> \
  "${tmp_dir}/delta-packages"

# genereate delta_packages from mirror delta

while read -r mirror; do
  if [ -z "${mirror}" ]; then
    continue
  fi
  {
    # theirs
    for repo in ${repos}; do
      curl -sS "${mirror}/${repo}/os/x86_64/${repo}.db.tar.gz" | \
        tar -tz
    done | \
      grep '/$' | \
      sed '
        s|/$||
        s|^\(.*\)-\([^-]\+-[^-]\+\)|theirs \1-\2 \2 \1|
      '

    # ours
    for repo in $(ls_master_mirror 'i686'); do
      ls_master_mirror "i686/${repo}" | \
        grep '\.pkg\.tar\.xz$' | \
        sed 's|-[^-]\+$||'
    done | \
      sed '
        s|^\(.*\)-\([^-]\+-[^-]\+\)|ours \1-\2 \2 \1|
      '
  } | \
    expand_version 3 | \
    sort -k4,4 -k3Vr,3 -k1,1 | \
    shrink_version 3 | \
    uniq -f3 | \
    grep '^theirs ' | \
    awk '{print $4}' | \
    sort -k1,1 >> \
    "${tmp_dir}/delta-packages"
done < \
  "${tmp_dir}/mirrors"

sort -k1,1 -u "${tmp_dir}/delta-packages" | \
  sponge "${tmp_dir}/delta-packages"

cat \
  "${tmp_dir}/delta-packages" \
  "${tmp_dir}/ignore-packages" \
  "${tmp_dir}/ignore-packages" | \
  sort | \
  uniq -u | \
  sponge "${tmp_dir}/delta-packages"

join -1 1 -2 5 -o 2.1,2.2,2.3,2.4,2.5 "${tmp_dir}/delta-packages" "${tmp_dir}/known-packages" >> \
  "${tmp_dir}/append-packages"

{
  awk '{print $5}' "${tmp_dir}/append-packages"
  cat "${tmp_dir}/delta-packages"
} | \
  sort | \
  uniq -u | \
  sponge "${tmp_dir}/delta-packages"

if [ -s "${tmp_dir}/delta-packages" ]; then
  echo 'There are still packages newer for x86_64 which I cannot identify :-/'
  cat "${tmp_dir}/delta-packages"
  exit 2
fi

rm "${tmp_dir}/delta-packages"

# convert append-packages to build-list.new (add git hashes)

cut -d' ' -f1,4 < \
  "${tmp_dir}/append-packages" | \
  sort -u | \
  while read -r pkg repo; do
    git_repo=$(find_git_repository_to_package_repository "${repo}")
    printf '%s %s %s %s\n' \
      "${pkg}" \
      "$(cat "${work_dir}/${git_repo}.revision")" \
      "$(cat "${work_dir}/archlinux32.revision")" \
      "${repo}"
  done | \
  sort -u > \
  "${tmp_dir}/build-list.append"

# Create a lock file for build list.

if ${update}; then
  # always block if locked
  exec 9> "${build_list_lock_file}"
  flock 9

  exec 8> "${sanity_check_lock_file}"
  flock -s 8
fi

{
  awk '{print $2 " " $3 " " $4 " " $1}' "${tmp_dir}/build-list.append"

  # ignore packages on the build-list
  awk '{print $2 " " $3 " " $4 " " $1}' < \
    "${work_dir}/build-list" | \
    sed 'p'

  # ignore packages on the deletion-list
  awk '{print "X X X " $1}' "${work_dir}/deletion-list" | \
    sed 'p'

  # ignore packages on the blacklist
  git -C "${repo_paths__archlinux32}" archive "$(cat "${work_dir}/archlinux32.revision")" -- blacklist | \
    tar -Ox blacklist | \
    sed '
      s/\s*#.*$//
      /^\s*$/d
    ' | \
    awk '{print "X X X " $1}' | \
    sed 'p'

  # ignore explicitely ignored packages
  awk '{print "X X X " $1}' "${tmp_dir}/ignore-packages" | \
    sed 'p'
} | \
  sort -k4,4 | \
  uniq -uf3 > \
  "${tmp_dir}/build-list.new"

if ${update}; then
  awk '{print $4 " " $1 " " $2 " " $3}' \
    "${tmp_dir}/build-list.new" >> \
    "${work_dir}/build-list"

  # Remove the lock file

  rm -f "${build_list_lock_file}"
else
  awk '{print $4 " " $1 " " $2 " " $3}' \
    "${tmp_dir}/build-list.new"
fi