#!/bin/sh
#the script is being executed in chroot_local-includes/usr/share/ubuntu/scripts/success-general.sh
#after ubiquity finished 2nd stage installation successfully.
#WARNING: Be careful, the TARGET filesystem is being mounted on /target

set -x

. /target/usr/share/volatile/common.sh

if [ ! -d /sys/firmware/efi ] ; then
    #For HP F11 recovery hotkey, only available in Legacy BIOS.
    SYSTEM_ONLY=$(mount | grep "target" | grep -o "sda1")
    if [ -z "$SYSTEM_ONLY" ] ; then
        #If /target at sda1, there's no recovery and it will break grub stage2. (LP: #1337722)
        echo "POS=[2048]" | dd of=/dev/sda bs=512 seek=5
        echo "POS=[2048]" | dd of=/dev/sda bs=512 seek=10
    fi
fi

#blacklist opensource graphics modules in OOBE.
cat > /target/etc/modprobe.d/blacklist-opensource-graphics.conf <<EOF
blacklist nouveau
blacklist radeon 
blacklist lbm-nouveau
blacklist lbm-radeon 
alias radeon off
alias lbm-radeon off
EOF

# Remove vga=791 in OOBE (LP: #1057933)
sed -i 's/vga=791//' /target/etc/default/grub

mount --bind /dev /target/dev
mount --bind /proc /target/proc
chroot /target update-grub
umount -l /target/dev
umount -l /target/proc

chroot /target depmod -ae
chroot /target update-initramfs -u

exit 0
