summaryrefslogtreecommitdiff
path: root/report-installed-packages.in
blob: bb63a73c816091c9f1b1700b530fbf36b0a2d80d (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
#!/bin/bash

if [ $# -eq 2 ]; then
  from="$1"
  to="$2"
elif [ $# -ne 0 ]; then
  >&2 echo 'usage: report-installed-packages [from to]'
  exit 1
fi

content=$(
  (
    find '/var/lib/pacman/sync' -mindepth 1 -maxdepth 1 \
      -name '*testing.db' \
      -exec bsdtar -tf {} \; | \
      sed -n '
        /\/$/{
          s|/$||
          p
        }
      '
    pacman -Q | \
      tr ' ' '-'
  ) | \
    sort | \
    uniq -d
)

content=$(
  cd '/var/cache/pacman/pkg'
  ls | \
    sed 's|^\(.*\)-|\1 \0|' | \
    sort -k1,1 | \
    join -1 1 -2 1 -o 1.2 - <(echo "${content}") | \
    xargs -r sha512sum
)

if [ -z "${to}" ] || [ -z "${from}" ]; then
  echo "${content}"
elif [ -n "${content}" ]; then
  gpg --list-keys --with-colons "${to}" \
  | awk -F: '$1 == "fpr" {print $10}' \
  | while read -r fpr; do
    curl -Ss 'https://archlinux32.org/keys.php?k='"${fpr}"
  done \
  | gpg --import \
  >/dev/null 2>&1

  printf '%s\n' \
    "From: ${from}" \
    "To: ${to}" \
    "Subject: $(uname -n) - report about installed i686 packages" \
    "" \
    "$(
      printf '%s\n' "${content}" | \
        sed 's|^|stabilize: |'
    )" | \
    sendmailadvanced -e -s
fi