summaryrefslogtreecommitdiff
path: root/sign-and-upload-all
blob: fe202a3335a601f639fcf7e9bba12e5e327c9cdc (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
#!/bin/bash

cd "$(dirname "$(readlink -e "$0")")"

exec 9> sign-and-upload-all.lock
if ! flock -n 9; then
  >&2 echo 'another sign-and-upload-all still holds the lock'
  exit 1
fi

for distro in arch artix; do
  upkgs=$(
    ssh ${distro}linuxewe@eckner.net '
      bsdtar -Oxf os/'"$(pacman-conf Architecture)"'/'"${distro}"'linuxewe.db.tar.gz \
      | sed -n '"'"'
        /^%FILENAME%$/ {
          N
          s/^.*\n//
          p
        }
      '"'"'
    '
  )
  unset archs
  declare -A archs
  for pkg in */${distro}/*.pkg.tar.zst; do
    [ -f "${pkg}" ] \
    || continue
    printf '%s\n' "${pkg##*/}" \
    | grep -qxF "${upkgs}" \
    && continue
    [ -f "${pkg}.sig" ] \
    || gpg --detach-sign -u 5FDCA472AB93292BC678FD59255A76DB9A12601A "${pkg}" \
    || exit 1
    arch="${pkg##*-}"
    arch="${arch%%.*}"
    archs["${arch}"]=1
  done

  for arch in "${!archs[@]}"; do
    rsync -av --progress --ignore-existing */${distro}/*-${arch}.pkg.tar.zst{,.sig} ${distro}linuxewe@eckner.net:os/${arch}/
    pkgs=$(
      printf '%s\n' */${distro}/*-${arch}.pkg.tar.zst \
      | sed 's@^.*/@@' \
      | tr '\n' ' '
    )

    if [ "${arch}" = 'any' ]; then
      ssh ${distro}linuxewe@eckner.net '
        cd os
        for arch in */; do
          [ "${arch}" = 'any/' ] && continue
          cd ${arch}
          for pkg in '"${pkgs}"'; do
            ln -s ../any/${pkg}
            ln -s ../any/${pkg}.sig
          done
          repo-add -s -k 0x3CFB0AD8F60030F8 '"${distro}"'linuxewe.db.tar.gz '"${pkgs}"'
          find -maxdepth 1 -mindepth 1 -not -type d -printf '"'"'%f\n'"'"' \
          | grep -vxFf <(
            ls '"${distro}"'linuxewe.{db,files}*
            bsdtar -Oxf '"${distro}"'linuxewe.db.tar.gz \
            | sed -n '"'"'
              /^%FILENAME%$/ {
                N
                s/^.*\n//
                p
                s/$/.sig/
                p
              }
            '"'"'
          ) \
          | xargs -r echo rm -f
          cd ..
        done
        cd any
        find -maxdepth 1 -mindepth 1 -not -type d -printf '"'"'%f\n'"'"' \
        | grep -vxFf <(
          for db in ../*/'"${distro}"'linuxewe.db.tar.gz; do
            bsdtar -Oxf "${db}"
          done \
          | sed -n '"'"'
            /^%FILENAME%$/ {
              N
              s/^.*\n//
              p
              s/$/.sig/
              p
            }
          '"'"'
        ) \
        | xargs -r echo rm -f
      '
    else
      ssh ${distro}linuxewe@eckner.net '
        cd os/'"${arch}"'
        repo-add -s -k 0x3CFB0AD8F60030F8 '"${distro}"'linuxewe.db.tar.gz '"${pkgs}"'
        find -maxdepth 1 -mindepth 1 -not -type d -printf '"'"'%f\n'"'"' \
        | grep -vxFf <(
          ls '"${distro}"'linuxewe.{db,files}*
          bsdtar -Oxf '"${distro}"'linuxewe.db.tar.gz \
          | sed -n '"'"'
            /^%FILENAME%$/ {
              N
              s/^.*\n//
              p
              s/$/.sig/
              p
            }
          '"'"'
        ) \
        | xargs -r echo rm -f
      '
    fi
  done
done