#!/usr/bin/env bash

# The bios for a dell D830, M4300 requires a bios disk for grub-imageboot
cd /tmp || exit

git clone http://github.com/dell/biosdisk

cd biosdisk || exit
# dch -i --create

cat >debian/changelog <<EOF
biosdisk (1.0) UNRELEASED; urgency=medium

  * Initial release. 

 -- MAINTAINER <default@devuan>  Tue, 22 Dec 2026 14:51:23 +0000
EOF

dpkg-buildpackage -us -uc -b
sudo dpkg -i ../biosdisk_1.0_all.deb

# The dell bios download pages for  D830 and M4300
# https://www.dell.com/support/home/en-uk/drivers/driversdetails?driverid=nkwv6
# https://www.dell.com/support/home/en-uk/drivers/driversdetails?driverid=hw8kt

# CURL_UAS="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"
DL_LINK="https://dl.dell.com/FOLDER06318034M/1/M4300A17.exe"
DL_LINK="https://dl.dell.com/FOLDER01556726M/1/D830_A17.exe"
BASENAME="$(basename $DL_LINK .exe)"
curl -fsSLo "${BASENAME}.exe" "${DL_LINK}" -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"

sudo mkdir -p /boot/images

# load exe into an image, configure GRUB2 boot entry, set boot flag
sudo biosdisk install -o "/nopause" ./"${BASENAME}.exe"

sudo cp /boot/"${BASENAME}.iso" /boot/images

sudo biosdisk uninstall ./"${BASENAME}.exe"

sudo apt-get install -y grub-imageboot
