#!/bin/sh

log() {
    logger -t finish-install "$@"
}

# If both cryptsetup and console-setup are installed, run update-initramfs to
# make sure one can type the passphrase (see #694156, workaround for #696773):
if /bin/in-target /bin/sh -c "dpkg-query -s console-setup >/dev/null 2>&1"; then
    log "refresh initramfs for cryptsetup"
    # Fix bug keyboard not using the selected layout. --Trisquel
    /bin/in-target /bin/sh -c "dpkg-reconfigure -f noninteractive keyboard-configuration"
    refresh=yes
fi

# If bochs or cirrus are loaded, we might get into troubles within the installed
# system if they aren't included in the initramfs (see #1036019). Work around by
# adding detection here (#1036788), before a better and long-term solution is
# implemented (see #1036779 and #1036780).
for module in bochs cirrus; do
    if lsmod | grep -qs "^$module "; then
        echo $module >> /target/etc/initramfs-tools/modules
        log "refresh initramfs for $module.ko"
        refresh=yes
    fi
done

if [ "$refresh" = yes ]; then
    /bin/in-target update-initramfs -u -k all
fi
