#!/bin/sh
# postinst script for #PACKAGE#

set -e

case "$1" in
    configure)
    if [ ! -z $(dmidecode|grep -m1 -i tuxedo| awk '{print $2}') ]; then
        if [ -z "$(grep cryptomount /boot/grub/grub.cfg)" ]; then
	    grub_dev=$(grub-probe --target=fs_uuid /boot/grub)
	    if [ "$(grep linux /boot/grub/grub.cfg | grep -m1 \/boot\/)" ]; then
	    cp -af /usr/share/tuxedo/44_custom /etc/grub.d
	    sed -i "s/grub_dev/$grub_dev/g" /etc/grub.d/44_custom
	    else
	    cp -af /usr/share/tuxedo/42_custom /etc/grub.d
	    sed -i "s/grub_dev/$grub_dev/g" /etc/grub.d/42_custom
	    fi
	else
	    grub_dev=$(grub-probe --target=cryptodisk_uuid /boot/grub)
	    cp -af /usr/share/tuxedo/43_custom /etc/grub.d
	    sed -i "s/cryptuuid/$grub_dev/g" /etc/grub.d/43_custom
	fi
	update-grub
    else
	if [ -f /etc/grub.d/43_custom ]; then
	    rm -f /etc/grub.d/43_custom
	fi
	if [ -f /etc/grub.d/42_custom ]; then
	    rm -f /etc/grub.d/42_custom
	fi
	if [ -f /etc/grub.d/43_custom ]; then
	    rm -f /etc/grub.d/43_custom
	fi
	update-grub
    fi
    ;;

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

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

#DEBHELPER#

exit 0
