Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/sync-any-packages
blob: 7c8fb1aeafd773be7a82978ae9c009b226d45bb1 (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
#!/bin/bash

set -e

if [ $# -eq 2 ]; then
  >&2 echo curl -Lo "$1" "$2"
  curl -Lo "$1" "$2"
  exit
fi

if [ $# -ne 1 ] || [ ! -d "$1" ]; then
  >&2 echo 'usage:'
  >&2 printf '%s /path/to/mirror\n' "$0"
  exit 1
fi

if [ "$(whoami)" != 'mirror' ]; then
  exec su mirror -c "$0 $*"
fi

exec 9> /tmp/sync-any-packages.lock
if ! flock -n 9; then
  >&2 echo 'cannot obtain lock'
  exit
fi

dir="$(readlink -e "$1")"

for repo in core extra; do
  mirrors=(
    $(
      sed -n '
        s/^Server = //
        T
        s/\$arch/x86_64/
        s/\$repo/'"${repo}"'/
        p
      ' '/etc/pacman.d/mirrorlist'
    )
  )

  bsdtar -Oxf "/var/lib/pacman/sync/${repo}.db" \
  | sed -n '
    /^%\(FILENAME\|CSIZE\|PGPSIG\)%/ {
      N
      s/^.*\n//
      p
    }
  ' \
  | sed '
    /-any\.pkg\.tar\.zst$/ !d
    N
    s/\n/ /
    N
    s/\n/ /
  ' \
  | while read -r pkg size sig; do
    [ -f "${dir}/pool-any/${pkg}" ] \
    && [ -f "${dir}/pool-any/${pkg}.sig" ] \
    && [ $(stat -c%s "${dir}/pool-any/${pkg}") -eq "${size}" ] \
    && continue

    printf '%s\n' "${sig}" \
    | base64 -d \
    > "${dir}/pool-any/${pkg}.sig"
    printf '%s/pool-any/%s\n%s/%s\n' "${dir}" "${pkg}" "$(printf '%s\n' "${mirrors[@]}" | shuf -n1)" "${pkg}"
  done \
  | parallel -N 2 -j 20 "$0"
done

tmp_dir=$(mktemp -d)
trap 'cd / && rm -rf --one-file-system "${tmp_dir:?}"' EXIT

for repo in core extra; do
  bsdtar -C "${tmp_dir}" -xf "/var/lib/pacman/sync/${repo}.db"
done

for desc_file in "${tmp_dir}/"*"/desc"; do
  sed '
    /^%ARCH%$/ !d
    N
    s/^.*\n//
  ' "${desc_file}" \
  | grep -qxF any \
  && continue
  rm "${desc_file}"
  rmdir "${desc_file%/*}"
done

cd "${tmp_dir}"
bsdtar -czf "${dir}/pool-any/build-support-any.db.tar.gz" --strip-components=1 .