Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/seed-build-list
blob: cf147c6301b6687507992d54e276b4897cac1a2b (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
286
#!/bin/sh

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

. "${0%/*}/../conf/default.conf"

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)"
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}/delta_pkgbases"
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='core community extra gnome-unstable kde-unstable'

for repo in ${repo_names}; do
  if [ "${repo_names}" = 'archlinux32' ]; then
    continue
  fi
  eval 'repo_path="${repo_paths__'"${repo}"'}"'
  git -C "${repo_path}" archive origin/master | \
    tar -t | \
    grep '^[^/]\+/repos/[^/]\+/PKGBUILD$' | \
    grep -v -- '-i686/PKGBUILD$' | \
    grep -v -- '[-/]\(staging\|testing\)-[^/]\+/PKGBUILD$' | \
    sed '
      s|^\([^/]\+\)/repos/\([^/]\+\)-[^/-]\+/PKGBUILD$|\1 \2|
    '
done | \
  sort -k1,1 > \
  "${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 $1}' "${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|
      '
    ) | \
    sort -k4,4 -k3Vr,3 -k1,1 | \
    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"

join -j1 "${tmp_dir}/delta_packages" "${tmp_dir}/known_packages" >> \
  "${tmp_dir}/append_packages"

(
  awk '{print $1}' "${tmp_dir}/append_packages"
  cat "${tmp_dir}/delta_packages"
) | \
  sort | \
  uniq -u | \
  sponge "${tmp_dir}/delta_packages"

while read -r pkg; do
  if [ -z "${pkg}" ]; then
    continue
  fi
  success=false
  for arch in x86_64 any; do
    pkgbase="$(
      curl -sS "https://www.archlinux.org/packages/community/x86_64/${pkg}/" | \
        sed -n '
          /Base Package:/{
            :a
            N
            s|</tr>.*$||
            Ta
            p
          }
        ' | \
        tr '<>' '\n' | \
        grep '^a href="' | \
        sed '
          s|^a href="||
          s|".*||
          s|/$||
          s|^.*/||
        '
    )"
    if [ -n "${pkgbase}" ]; then
      echo "${pkgbase}" >> \
        "${tmp_dir}/delta_pkgbases"
      success=true
      break
    fi
  done
  if ! ${sucess}; then
    echo "${pkg}"
  fi
done < \
  "${tmp_dir}/delta_packages" | \
  sponge "${tmp_dir}/delta_packages"

sort -u "${tmp_dir}/delta_pkgbases" | \
  sponge "${tmp_dir}/delta_pkgbases"

join -j1 "${tmp_dir}/delta_pkgbases" "${tmp_dir}/known_packages" >> \
  "${tmp_dir}/append_packages"

sort -u "${tmp_dir}/append_packages" | \
  sponge "${tmp_dir}/append_packages"

rm "${tmp_dir}/delta_pkgbases"

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

rm "${tmp_dir}/delta_packages"

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

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 < \
  "${tmp_dir}/append_packages" | \
  awk '{print "append " $1 " " $2 " " $3 " " $4 " " $1}' > \
  "${tmp_dir}/build-list.append"

# Create a lock file for build list.

if ${update}; then
  exec 9> "${build_list_lock_file}"
  flock 9
fi

# ignore packages already on the build list
awk '{print "old " $1 " " $2 " " $3 " " $4 " " $1}' "${work_dir}/build-list" > \
  "${tmp_dir}/build-list.old"

# ignore packages on the deletion-list
awk '{print "delete " $1 " X X X " $1}' "${work_dir}/deletion-list" >> \
  "${tmp_dir}/build-list.old"

# ignore packages on the blacklist
git -C "${repo_paths__archlinux32}" archive HEAD -- blacklist | \
  tar -Ox blacklist | \
  awk '{print "blacklist " $1 " X X X " $1}' >> \
  "${tmp_dir}/build-list.old"

# ignore explicitely ignored packages
awk '{print "ignore " $1 " X X X " $1}' "${tmp_dir}/ignore_packages" >> \
  "${tmp_dir}/build-list.old"

if ${update}; then
  cat "${tmp_dir}/build-list.append" "${tmp_dir}/build-list.old" | \
    sort -k6,6 -k1,1 | \
    uniq -uf5 | \
    grep '^append ' | \
    awk '{print $2 " " $3 " " $4 " " $5}' >> \
    "${work_dir}/build-list"

  # Remove the lock file

  rm -f "${build_list_lock_file}"
else
  cat "${tmp_dir}/build-list.append" "${tmp_dir}/build-list.old" | \
    sort -k6,6 | \
    uniq -uf5 | \
    grep '^append ' | \
    awk '{print $2 " " $3 " " $4 " " $5}'
fi