chamesle

chamesle.org: the site of Chamesle, a small Linux distribution
git clone https://github.com/tortr-rs/chamesle
Log | Files | Refs | README

merge-index.sh (2702B)


      1 #!/bin/bash
      2 # put packages in the published repo without having the whole repo here: the index on sourceforge is taken
      3 # as it is, the new packages replace their old versions in it, and it's signed with your key
      4 #   tools/repo/merge-index.sh work/repo/x86_64/foo-1.0-r1.apk ...   -> work/publish/x86_64/
      5 #   tools/repo/merge-index.sh                                        just re-sign the published index (a new key)
      6 # then upload work/publish/x86_64/ (tools/repo/upload.sh publish). packages already there stay as they are:
      7 # apk trusts them through the hashes in the signed index, their own signatures don't matter
      8 set -euo pipefail
      9 HERE=$(cd "$(dirname "$0")" && pwd)
     10 TOP=$HERE/../..
     11 APK=${APK:-apk}
     12 INDEX=${INDEX:-https://master.dl.sourceforge.net/project/chameslerepos/x86_64/Packages.adb}
     13 KEY=$(ls "$HOME"/.config/chamesle/chamesle-*.rsa | sort | tail -n1)
     14 OUT=${OUT:-$TOP/work/publish/x86_64}
     15 T=$TOP/work/merge-tmp; rm -rf "$T"; mkdir -p "$T"; trap 'rm -rf "$T"' EXIT
     16 
     17 curl -fsSL -o "$T/old.adb" "$INDEX"
     18 # only an index we signed: one of the keys in keys/apk has to check out
     19 "$APK" adbdump --keys-dir "$TOP/keys/apk" "$T/old.adb" > "$T/old.yaml"
     20 grep -q '^# sig .*: OK$' "$T/old.yaml" || { echo "merge-index: $INDEX isn't signed by a key in keys/apk" >&2; exit 1; }
     21 
     22 rm -rf "$OUT"; mkdir -p "$OUT"
     23 : > "$T/new.yaml"
     24 if [ $# -gt 0 ]; then
     25     cp "$@" "$OUT/"
     26     "$APK" mkndx --keys-dir "$TOP/keys/apk" --output "$T/new.adb" "$@"
     27     "$APK" adbdump "$T/new.adb" > "$T/new.yaml"
     28 fi
     29 
     30 python3 - "$T/old.yaml" "$T/new.yaml" "chamesle $(date +%Y-%m-%d)" > "$T/index.yaml" <<'EOF'
     31 import sys
     32 def entries(path):
     33     out, cur = {}, None
     34     for line in open(path):
     35         if line.startswith('  - name: '):
     36             cur = line[10:].strip()
     37             out[cur] = []
     38         elif not line.startswith('    ') and not line.startswith('  - '):
     39             cur = None
     40         if cur:
     41             out[cur].append(line)
     42     return out
     43 old, new = entries(sys.argv[1]), entries(sys.argv[2])
     44 for name in new:
     45     print(('replaced ' if name in old else 'added ') + name, file=sys.stderr)
     46 old.update(new)
     47 # adbgen needs to know what kind of file it's making
     48 print(next(l for l in open(sys.argv[1]) if l.startswith('#%SCHEMA')).strip())
     49 print('description: ' + sys.argv[3])
     50 print('packages: # %d items' % len(old))
     51 for name in sorted(old):
     52     sys.stdout.write(''.join(old[name]))
     53 EOF
     54 "$APK" adbgen "$T/index.yaml" > "$OUT/Packages.adb"
     55 "$APK" adbsign --allow-untrusted --reset-signatures --sign-key "$KEY" "$OUT/Packages.adb"
     56 "$APK" adbdump --keys-dir "$TOP/keys/apk" "$OUT/Packages.adb" | grep -q '^# sig .*: OK$'
     57 echo "$(grep -c '^  - name: ' "$T/index.yaml") packages, signed with $(basename "$KEY"): $OUT"