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

# shellcheck disable=SC2119,SC2120

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

if [ $# -eq 0 ]; then
  dummynator='sudo'
elif [ $# -eq 1 ] && [ "x$1" = 'x-n' ]; then
  dummynator='echo'
else
  >&2 echo 'usage: clean-cache [-n]'
  >&2 echo '  cleans /var/cache/archbuild32'
  >&2 echo '  (or prints what would be cleaned)'
  exit 1
fi

repos='build-support community-staging community-testing community core extra gnome-unstable kde-unstable staging testing'

mirror=$(
  grep -m1 '^Server = ' '/etc/pacman.d/mirrorlist32' | \
    cut -d= -f2 | \
    sed 's|^\s*||'
)

tmp_dir=$(mktemp -d 'tmp.clean-cache.XXXXXXXXXX' --tmpdir)
trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT

for repo in ${repos}; do
  mkdir "${tmp_dir}/${repo}"
  wget -qO - "$(
    # shellcheck disable=SC2016
    echo "${mirror}" | \
      sed "$(
        printf 's|%s|%s|\n' \
          '\$repo' "${repo}" \
          '\$arch' 'i686' \
          '$' "/${repo}.db.tar.gz"
      )"
  )" | \
    tar -xzC "${tmp_dir}/${repo}"
done

find "${tmp_dir}" -type f -name desc \
  -printf '%h ' \
  -exec grep -xFA1 '%SHA256SUM%' {} \; | \
  sed '
    N
    s|^.\+/\([^/]\+\) %SHA256SUM%\n\(.\+\)$|\2  /var/cache/archbuild32/\1|
  ' | \
  sort -k2,2 | \
  uniq -uf1 | \
  sed -n '
    h
  '"$(
    # shellcheck disable=SC2016
    {
      printf 'SELECT'
      printf ' CONCAT('
        printf '"g;s@$@-",'
        printf '`architectures`.`name`,'
        printf '".pkg.",'
        printf '`compressions`.`suffix`,'
        printf '"@;p"'
      printf ')'
      printf ' FROM `compressions`'
      printf ' JOIN `architectures`;\n'
    } \
    | mysql_run_query
  )" \
  sha256sum -c --ignore-missing --quiet 2> /dev/null | \
  sed -n '
    s|: FAILED$||
    T
    p
    s/$/.sig/
  ' | \
  xargs -r ${dummynator} rm -f