ZealOS/build/build-temp-vm-uefi-1.sh

79 lines
2.1 KiB
Bash
Raw Normal View History

#!/bin/sh
# Build OS using AUTO.ISO minimal auto-install as bootstrap to merge codebase, recompile system, and start temporary VM
# make sure we are in the correct directory
SCRIPT_DIR=$(realpath "$(dirname "$0")")
SCRIPT_NAME=$(basename "$0")
EXPECTED_DIR=$(realpath "$PWD")
if test "${EXPECTED_DIR}" != "${SCRIPT_DIR}"
then
( cd "$SCRIPT_DIR" || exit ; "./$SCRIPT_NAME" "$@" );
exit
fi
# Uncomment if you use doas instead of sudo
#alias sudo=doas
TMPDIR="/tmp/zealtmp"
TMPDISK="$TMPDIR/ZealOS.raw"
TMPMOUNT="$TMPDIR/mnt"
mount_tempdisk() {
sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd0 -f raw $TMPDISK
sudo partprobe /dev/nbd0
sudo mount /dev/nbd0p1 $TMPMOUNT
}
umount_tempdisk() {
sync
sudo umount $TMPMOUNT
sudo qemu-nbd -d /dev/nbd0
}
[ ! -d $TMPMOUNT ] && mkdir -p $TMPMOUNT
2022-08-20 15:13:06 +01:00
set -e
2022-08-20 00:54:34 +01:00
echo "Building ZealBooter..."
( cd ../zealbooter && make clean all )
2022-08-20 15:13:06 +01:00
set +e
echo "Making temp vdisk, running auto-install..."
qemu-img create -f raw $TMPDISK 192M
qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -cdrom AUTO-VM-1.ISO -device isa-debug-exit
echo "Mounting vdisk and copying src/..."
rm ../src/Home/Registry.ZC 2> /dev/null
rm ../src/Home/MakeHome.ZC 2> /dev/null
mount_tempdisk
sudo cp -r ../src/* $TMPMOUNT
[ ! -d "limine" ] && git clone https://github.com/limine-bootloader/limine.git --branch=v3.0-branch-binary --depth=1
sudo mkdir -p $TMPMOUNT/EFI/BOOT
sudo cp limine/BOOTX64.EFI $TMPMOUNT/EFI/BOOT/BOOTX64.EFI
2022-08-20 00:54:34 +01:00
sudo cp ../zealbooter/zealbooter.elf $TMPMOUNT/Boot/ZealBooter.ELF
umount_tempdisk
2022-08-20 00:54:34 +01:00
echo "Rebuilding kernel..."
qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -device isa-debug-exit
2022-08-20 00:54:34 +01:00
if [ ! -d "ovmf" ]; then
echo "Downloading OVMF..."
mkdir ovmf
cd ovmf
curl -o OVMF-X64.zip https://efi.akeo.ie/OVMF/OVMF-X64.zip
7z x OVMF-X64.zip
cd ..
fi
echo "Testing..."
2022-08-21 09:27:19 +01:00
qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -bios ovmf/OVMF.fd -no-reboot -no-shutdown
echo "Deleting temp folder..."
rm -rf $TMPDIR
echo "Finished."