#!/bin/bash
post_install() {
	# Detect distro and set GRUB location and update method
	GRUB_DIR='grub'
	UPDATE_GRUB=''
	BOOT_MODE='legacy'
	GRUB_THEME="Fallout"
	if [[ -d /boot/efi && -d /sys/firmware/efi ]]; then
		BOOT_MODE='UEFI'
	fi

	echo "Boot mode: ${BOOT_MODE}"
	echo 'Removing other themes from GRUB config'
	sed -i '/^GRUB_THEME=/d' /etc/default/grub
	echo 'Making sure GRUB uses graphical output'
	sed -i 's/^\(GRUB_TERMINAL\w*=.*\)/#\1/' /etc/default/grub
	echo 'Removing empty lines at the end of GRUB config' # optional
	sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' /etc/default/grub
	echo 'Adding new line to GRUB config just in case' # optional
	echo | tee -a /etc/default/grub
	if [[ -f "/usr/share/${GRUB_DIR}/themes/${GRUB_THEME}/theme.txt" ]]; then
		echo 'Adding theme to GRUB config'
		echo "GRUB_THEME=/usr/share/${GRUB_DIR}/themes/${GRUB_THEME}/theme.txt" | tee -a /etc/default/grub
	fi
	if which update-initramfs >/dev/null 2>&1
	then
	    update-initramfs -u
	fi
	if which grub-mkconfig >/dev/null 2>&1;	then
	    grub-mkconfig -o /boot/grub/grub.cfg
	fi
}
post_upgrade() {
post_install
}
