#!/bin/sh

set -xe

rm -f disk.hdd

dd if=/dev/zero of=disk.hdd bs=1M count=128

parted disk.hdd --script mklabel msdos
parted disk.hdd --script mkpart primary fat32 1MiB 63MiB
parted disk.hdd --script set 1 boot on
parted disk.hdd --script mkpart primary 64MiB 127MiB

LOOP=$(sudo losetup --find --show --partscan disk.hdd)
sudo mkfs.fat -F32 ${LOOP}p1
sudo mklittlefs -c uhome -b 512 -s $(((127*1024*1024)-(64*1024*1024))) ${LOOP}p2

mkdir mnt
sudo mount ${LOOP}p1 mnt
sudo cp -r iso_root/* mnt/

sudo ./limine/limine bios-install ${LOOP}

sudo umount mnt
sudo losetup -d ${LOOP}
rm -rf mnt
