Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/scrub-for-gpg-keys
blob: d4d6f6972a31c5d0e9eb6e96388330a080389ca2 (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
#!/bin/bash

archlinux=true
archlinux_arm=true
archlinux_git=true
local=false
parabola=true
wishlist=true

while [ $# -gt 0 ]; do

  case "x$1" in
    'x-l')
      local=true
    ;;
    'x--no-archlinux')
      archlinux=false
    ;;
    'x--no-archlinux-arm')
      archlinux_arm=false
    ;;
    'x--no-archlinux-git')
      archlinux_git=false
    ;;
    'x--no-parabola')
      parabola=false
    ;;
    'x--no-wishlist')
      wishlist=false
    ;;
    *)
      >&2 printf 'unknown parameter %s\n' "$1"
      >&2 printf 'known parameters:\n'
      >&2 printf '  -%s  %s\n' \
        'l' 'update local keyring'
      >&2 printf '  --no-%s\n    do not update keys from/mentioned in\n    %s\n' \
        'archlinux' 'locally running archlinux keyring' \
        'archlinux-arm' 'archlinuxarm keyring package' \
        'archlinux-git' 'archlinux sources (PKGBUILDs) git repository' \
        'parabola' 'parabola keyring package sources' \
        'wishlist' 'our keyserver'"'"'s wishlist'
      exit 1
    ;;
  esac
  shift

done

if ${parabola}; then
  parabola_keyring_version=$(
    curl -Ss 'https://repo.parabola.nu/other/parabola-keyring/' \
    | sed '
      s@^.*<a href="parabola-keyring-\([0-9.]\+\)\.tar\.gz">.*$@\1@
      t
      d
    ' \
    | sort -V \
    | tail -n1
  )
  parabola_keyring="https://repo.parabola.nu/other/parabola-keyring/parabola-keyring-${parabola_keyring_version}.tar.gz"
fi

if ${archlinux_arm}; then
  archlinuxarm_keyring=$(
    curl -Ss 'https://arch.eckner.net/archlinuxarm/arm/core/' \
    | sed '
      s@^.*<a href="archlinuxarm-keyring-\([0-9.]\+-[0-9]\+\)-any\.pkg\.tar\.xz">.*$@\1@
      t
      d
    ' \
    | sort -V \
    | tail -n1 \
    | sed '
      s@^.*$@https://arch.eckner.net/archlinuxarm/arm/core/archlinuxarm-keyring-\0-any.pkg.tar.xz@
    '
  )
fi

{
  {
    if ${archlinux_git}; then
      find \
        /usr/src/archlinux/{packages,community}/ \
        /usr/src/archlinux32/packages/ \
        ~/eigeneSkripte/archPackages/ \
        -type f -name PKGBUILD \
        -exec sed -n '
          /^\s*validpgpkeys=.*)/p
          /^\s*validpgpkeys=[^)]\+$/,/)/p
        ' {} + 2>/dev/null \
      | sed '
        s/#.*$//
        s/^\s*validpgpkeys=(//
        s/).*$//
      ' \
      | tr -d '" \t'"'"
    fi
    curl -Ss 'https://archlinux32.org/key-wishlist'
    {
      if ${archlinux_arm}; then
        curl -Ss "${archlinuxarm_keyring}" \
        | bsdtar -Oxf - usr/share/pacman/keyrings/archlinuxarm-{trusted,revoked}
      fi
      if ${parabola}; then
        curl -Ss "${parabola_keyring}" \
        | bsdtar -Oxf - parabola-keyring-${parabola_keyring_version}/parabola-{trusted,revoked}
      fi
    } \
    | cut -d: -f1
  } \
  | sort -u \
  | grep -x '[0-9a-fA-F]\{16,40\}' \
  | while read -r key_id; do
    key=$(gpg -a --export "${key_id}" 2>/dev/null)
    if [ -z "${key}" ]; then
      /usr/src/skripte/gpg-safe-import/gpg-safe-import --recv-keys "${key_id}"
      key=$(gpg -a --export "${key_id}" 2>/dev/null)
    fi
    if [ -z "${key}" ]; then
      >&2 printf 'wish-list key "%s" is unknown\n' "${key_id}"
      continue
    fi
    printf '%s\n' "${key}"
  done
  if ${archlinux}; then
    gpg --homedir /etc/pacman.d/gnupg -a --export
  fi
  if ${archlinux_arm}; then
    curl -Ss "${archlinuxarm_keyring}" \
    | bsdtar -Oxf - usr/share/pacman/keyrings/archlinuxarm.gpg
  fi
  if ${parabola}; then
    curl -Ss "${parabola_keyring}" \
    | bsdtar -Oxf - parabola-keyring-${parabola_keyring_version}/parabola.gpg
  fi
} \
| if ${local}; then
  sudo su http -s /bin/bash -c 'gpg --import'
else
  ssh archlinux32 "sudo su http -s /bin/bash -c 'gpg --import'"
fi