#!/bin/sh
set -e
binfmt_update() {
  test upgrade = "$1" || return 0
  dpkg --compare-versions "$2" le "1:5.2+dfsg-3~" || return 0
  command -v update-binfmts >/dev/null || return 0
  for fmt in ppc64abi32; do
    if [ -f /var/lib/binfmts/qemu-$fmt ]; then
      [ -f /usr/bin/qemu-$fmt-static ] ||
        echo "qemu-user-static.preinst: note: the warning from update-binfmts about missing qemu-$fmt-static is okay" >&2
      update-binfmts --package qemu-user-static --remove qemu-$fmt /usr/bin/qemu-$fmt-static
    fi
  done
}
binfmt_update "$1" "$2"
