#!/bin/sh
# vim:set expandtab tabstop=2 shiftwidth=2:
# shellcheck disable=SC2086
set -e -u

cd ~phahn/REPOS/ucs
for srv in */*/debian/*.univention-service
do
  [ -e "$srv" ] || continue
  bin="$(basename "$srv" .univention-service)"
  src="$(basename "${srv%/debian/*}")"
  for err in "doc/errata/published/"2019-0[89]-??-"$src.yaml"
  do
    [ -e "$err" ] ||
      continue
    fix="$(sed -ne 's/fix: //p;T;q' "$err")"
    cfg="etc/univention/service.info/services/${bin}.cfg"
    for deb in "/var/univention/buildsystem2/mirror/ftp/4.4/maintained/component/4.4-1-errata/"*"/${bin}_${fix}_"*".deb"
    do
      [ -e "$deb" ] ||
        continue
      printf '%s\t%s\t' "$src" "$deb"
      dpkg -c $deb | grep -Fo --color "$cfg" ||
        echo FAIL
    done
  done
done
