Last active
August 29, 2015 13:56
-
-
Save nomius/9196206 to your computer and use it in GitHub Desktop.
Small grub installer for Kwort 4.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
PARTITION_TABLE=${1} | |
error() { | |
tput setaf 1 | |
echo "${1}" | |
tput sgr0 | |
} | |
create_conf() { | |
grub-mkconfig -o ${1} | |
[ $? -ne 0 ] && { error "Failed to run grub-mkconfig... That's odd"; return 1; } | |
return 0 | |
} | |
install_efi() { | |
# Sanity checks: Check for EFI partition, and efivars | |
EFI_PART=$(fdisk -l | awk '/EFI System/ {print $1}') | |
[ -z "${EFI_PART}" ] && { error "No EFI partition found"; return 1; } | |
lsmod | grep -q efivars || modprobe efivars || { error "Can't load efivars module"; return 1; } | |
mount ${EFI_PART} -t vfat /boot/efi | |
[ $? -ne 0 ] && { error "Error mounting EFI partition"; return 1; } | |
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=grub --boot-directory=/boot/efi/EFI --recheck --debug | |
[ $? -ne 0 ] && { error "Error running grub-install on /boot/efi"; return 1; } | |
create_conf /boot/efi/EFI/grub/grub.cfg | |
[ $? -ne 0 ] && { error "Failed to configure grub"; return 1; } | |
umount /boot/efi | |
sync | |
return 0 | |
} | |
install_bios() { | |
grub-install --target=i386-pc --recheck --debug "${PARTITION_TABLE}" | |
[ $? -ne 0 ] && { error "Failed to run grub-install for BIOS setup"; return 1; } | |
create_conf /boot/grub/grub.cfg | |
[ $? -ne 0 ] && { error "Failed to configure grub"; return 1; } | |
return 0 | |
} | |
main() { | |
method=$(dialog --stdout --backtitle "kwort 4.1" --menu "GRUB installation options" 9 40 2 1 "Install GRUB2 for BIOS setup" 2 "Install GRUB2 for EFI setup") | |
if [ "${method}" = "1" ]; then | |
install_bios | |
return $? | |
elif [ "${method}" = "2" ]; then | |
install_efi | |
return $? | |
fi | |
return 0 | |
} | |
if [ -z "${PARTITION_TABLE}" ]; then | |
echo "No partition table given as argument, trying to figure that out on my own" | |
sleep 1 | |
PARTITION_TABLE=$(fdisk -l | grep "Disk /" | awk -F '[ :]' '{print $2}') | |
dialog --yesno "Use ${PARTITION_TABLE} as partition table?" 6 37 || exit 1 | |
fi | |
main "${PARTITION_TABLE}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment