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

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

shutdownasap_progress=$(shutdownasap -g || echo 'none')
if [ "${shutdownasap_progress}" != 'none' ]; then
  >&2 printf 'shutdownasap in progress: %s\n' "${shutdownasap_state}"
  exit 1
fi

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

pkill -x keyboxd

for distro in arch artix; do
  for arch in x86_64 i486 i686 pentium4; do
    unset pkgs
    declare -A pkgs
    [ "${arch}" != 'x86_64' ] && [ "${distro}" != 'arch' ] && continue
    upkgs=$(
      ssh ${distro}linuxewe@eckner.net '
        bsdtar -Oxf os/'"${arch}"'/'"${distro}"'linuxewe.db.tar.gz \
        | sed -n '"'"'
          /^%FILENAME%$/ {
            N
            s/^.*\n//
            p
          }
        '"'"' \
        | while read -r f; do
          [ -f "os/'"${arch}"'/${f}" ] \
          || continue
          [ -f "os/'"${arch}"'/${f}.sig" ] \
          || continue
          echo "${f}"
        done
      '
    )
    for pkg in */${distro}*-${arch}/*.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
      parch="${pkg##*-}"
      parch="${parch%%.*}"
      pkgs["${parch}"]+=" ${pkg}"
    done
    for archdir in "${!pkgs[@]}"; do
      rsync -av --progress \
        ${pkgs["${archdir}"]} \
        $(printf '%s.sig\n' "${pkgs["${archdir}"]}") \
        ${distro}linuxewe@eckner.net:os/${archdir}/
      if [ "${archdir}" = 'any' ]; then
        ssh ${distro}linuxewe@eckner.net '
          cd os
          for arch in */; do
            [ "${arch}" = '"'"'any/'"'"' ] && continue
            cd ${arch}
            for pkg in '"${pkgs["${archdir}"]##*/}"'; do
              ln -s ../any/${pkg}
              ln -s ../any/${pkg}.sig
            done
            repo-add -s -k 0x3CFB0AD8F60030F8 '"${distro}"'linuxewe.db.tar.gz '"${pkgs["${archdir}"]##*/}"'
            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 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 rm -f
        '
      else
        ssh ${distro}linuxewe@eckner.net '
          cd os/'"${archdir}"'
          repo-add -s -k 0x3CFB0AD8F60030F8 '"${distro}"'linuxewe.db.tar.gz '"${pkgs["${archdir}"]##*/}"'
          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 rm -f
        '
      fi
    done
  done
done