#!/bin/sh
# postinst script for acrn-hypervisor
#
# see: dh_installdeb(1)

set -e

ACRNDIR=@acrndir@

. /usr/share/debconf/confmodule

db_get acrn-hypervisor/board
BOARD=${RET}
db_get acrn-hypervisor/scenario
SCENARIO=${RET}

ACRNCFG="${ACRNDIR}/${BOARD}/${SCENARIO}/acrn.${BOARD}.${SCENARIO}.config"
ACRNMAP="${ACRNDIR}/${BOARD}/${SCENARIO}/acrn.${BOARD}.${SCENARIO}.map"
ACRNBIN="${ACRNDIR}/${BOARD}/${SCENARIO}/acrn.${BOARD}.${SCENARIO}.bin"
ACRNACPI="${ACRNDIR}/${BOARD}/${SCENARIO}/acpi"
ACRNETC="${ACRNDIR}/${BOARD}/${SCENARIO}/etc"

case "$1" in
    configure)
        if [ -f ${ACRNCFG} ] && [ -f ${ACRNMAP} ] && [ -f ${ACRNBIN} ]; then
            cp ${ACRNCFG} /boot/acrn-@acrnversion@.config
            cp ${ACRNMAP} /boot/acrn-@acrnversion@.map
            cp ${ACRNBIN} /boot/acrn-@acrnversion@.bin
            if [ -d ${ACRNACPI} ]; then
                cp ${ACRNACPI}/ACPI_VM* /boot
            fi
            if [ -f ${ACRNETC}/serial.conf ]; then
                echo "# START - ACRN HYPERVISOR INSTALL" >> /etc/serial.conf
                cat ${ACRNETC}/serial.conf >> /etc/serial.conf
                echo "# END - ACRN HYPERVISOR INSTALL" >> /etc/serial.conf
            fi
        fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
