#!/bin/sh

# Avoid executing multiple times.
if [ -n "$DEB_MAINT_PARAMS" ];then
    eval set -- "$DEB_MAINT_PARAMS"
    if [ -z "$1" ] || [ "$1" != "remove" ]
    then
        case "$1" in
            remove|configure)
                ;;
            *)
                exit 0
        esac
    fi
fi

which zipl >/dev/null 2>&1 || exit 0

if [ -f /etc/zipl.conf ]
then
    for initrd in $(awk '
      function emit() {
        if (optional == "0" && ramdisk != "") {
          print(ramdisk);
        };
        ramdisk="";
        optional="0";
      }
      /^optional[ 	]*=/	{ optional=$0; sub("^optional[ 	]*=[ 	]*", "", optional); }
      /^ramdisk[ 	]*=/	{ ramdisk=$0; sub("^ramdisk[ 	]*=[ 	]*", "", ramdisk); }
      /^\[/			{ emit(); }
      END			{ emit(); }
      ' < /etc/zipl.conf); do
        if [ ! -f "$initrd" ]; then
            echo "Not invoking zipl: initrd doesn't exist yet" >&2
            exit 0
        fi
    done
    zipl </dev/null >&2
else
    echo "WARNING, not invoking zipl: /etc/zipl.conf not found" >&2
fi
