From b992dcebb244941c310808461ca217a39c246de0 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Fri, 11 Mar 2022 03:22:01 -0500 Subject: [PATCH] Create Windows build scripts. --- README.md | 5 +- build/build-iso.ps1 | 66 +++++++++++++++++++++++++++ build/sync.ps1 | 108 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+), 2 deletions(-) create mode 100755 build/build-iso.ps1 create mode 100755 build/sync.ps1 diff --git a/README.md b/README.md index b21259f8..eaec2f3b 100644 --- a/README.md +++ b/README.md @@ -30,13 +30,14 @@ Features in development include: ### Prerequisites - For running in a VM: Intel VT-x/AMD-V acceleration enabled in your BIOS settings. (Required to virtualize any 64-bit operating system properly.) + * If using Windows, [Hyper-V must be enabled.](https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v#enable-the-hyper-v-role-through-settings) - Working knowledge of the C programming language. -To create a Distro ISO, run `build-iso.sh` in the `build/` directory. Check the Wiki guide for details on [building an ISO](https://github.com/Zeal-Operating-System/ZealOS/wiki/Building-an-ISO). After creating an ISO, see the Wiki guides on installing in [VirtualBox](https://github.com/Zeal-Operating-System/ZealOS/wiki/Installing-(Virtualbox)), [VMWare](https://github.com/Zeal-Operating-System/ZealOS/wiki/Installing-(VMWare)), and [bare-metal](https://github.com/Zeal-Operating-System/ZealOS/wiki/Installing-(Bare%E2%80%90metal)). +To create a Distro ISO, run the `build-iso` script in the `build` directory. Check the Wiki guide for details on [building an ISO](https://github.com/Zeal-Operating-System/ZealOS/wiki/Building-an-ISO). After creating an ISO, see the Wiki guides on installing in [VirtualBox](https://github.com/Zeal-Operating-System/ZealOS/wiki/Installing-(Virtualbox)), [VMWare](https://github.com/Zeal-Operating-System/ZealOS/wiki/Installing-(VMWare)), and [bare-metal](https://github.com/Zeal-Operating-System/ZealOS/wiki/Installing-(Bare%E2%80%90metal)). ### Contributing -There are two ways to contribute. The first way involves everything happening inside the OS, as intended by Terry. After you've built the latest ISO, installed to a VM, made your changes, and powered off the VM, you can run the `sync.sh` script to merge your changes to the repo. +There are two ways to contribute. The first way involves everything happening inside the OS, as intended by Terry. After you've built the latest ISO, installed to a VM, made your changes, and powered off the VM, you can run the `sync` script to merge your changes to the repo. Alternatively, you can edit repo files using an external editor, outside of the OS. diff --git a/build/build-iso.ps1 b/build/build-iso.ps1 new file mode 100755 index 00000000..dea56ad5 --- /dev/null +++ b/build/build-iso.ps1 @@ -0,0 +1,66 @@ +if (!((Split-Path -Path (Get-Location) -Leaf) -eq "build")) +{ + Write-Output "This script must be run inside the build folder. Press ENTER to exit."; Read-Host; exit +} + +if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) +{ + Write-Output "This script must be run as Adminstrator. Press ENTER to exit."; Read-Host; exit +} + +if (!(Get-Command qemu-system-x86_64.exe -errorAction SilentlyContinue)) +{ + $env:Path += ";C:\Program Files\qemu;" + if (!(Get-Command qemu-system-x86_64.exe -errorAction SilentlyContinue)) + { + Write-Output "QEMU is not installed, or not set in \$PATH. Press ENTER to exit."; Read-Host; exit + } +} +Write-Output "QEMU installation found." + +$hyperv = Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online +if (!($hyperv.State -eq "Enabled")) +{ + Write-Host "Hyper-V is disabled. Enable Hyper-V and reboot before running this script. Press ENTER to exit."; Read-Host; exit +} + +$TMPDISK = "$env:TEMP\ZealOS.vhdx" + +function Mount-TempDisk +{ + $global:QEMULETTER = ((Mount-DiskImage -ImagePath $TMPDISK -Access ReadWrite) | Get-Disk | Get-Partition).DriveLetter +} + +function Unmount-TempDisk +{ + $be_quiet = Dismount-DiskImage -ImagePath $TMPDISK +} + +Write-Output "Making temp vdisk, running auto-install..." + +qemu-img create -f vhdx $TMPDISK 512M +fsutil sparse setflag $TMPDISK 0 +fsutil sparse queryflag $TMPDISK +qemu-system-x86_64 -machine q35,accel=whpx,kernel-irqchip=off -drive format=vhdx,file=$TMPDISK -m 2G -rtc base=localtime -cdrom AUTO.ISO -device isa-debug-exit + +Remove-Item "..\src\Home\Registry.ZC" -errorAction SilentlyContinue +Remove-Item "..\src\Home\MakeHome.ZC" -errorAction SilentlyContinue +Mount-TempDisk + +Copy-Item -Path "..\src\*" -Destination "${QEMULETTER}:\" -Recurse -Force +Unmount-TempDisk + +Write-Output "Generating ISO..." +qemu-system-x86_64 -machine q35,accel=whpx,kernel-irqchip=off -drive format=vhdx,file=$TMPDISK -m 2G -rtc base=localtime -device isa-debug-exit +Write-Output "Extracting ISO from vdisk..." +Remove-Item "ZealOS-*.iso" -errorAction SilentlyContinue +Mount-TempDisk + +$ZEALISO = "ZealOS-" + (Get-Date -Format "yyyy-MM-dd-HH_mm_ss").toString() + ".iso" + +Copy-Item "${QEMULETTER}:\Tmp\MyDistro.ISO.C" -Destination $ZEALISO +Unmount-TempDisk + +Remove-Item $TMPDISK +Write-Output "Finished." +Get-ChildItem "ZealOS*.iso" \ No newline at end of file diff --git a/build/sync.ps1 b/build/sync.ps1 new file mode 100755 index 00000000..1338aee7 --- /dev/null +++ b/build/sync.ps1 @@ -0,0 +1,108 @@ +$choice = $args[0] + +function print_usage() +{ + Write-Output "Usage: sync.ps1 [ repo | vm ]" + Write-Output "" + Write-Output " repo - overwrites src/ with virtual disk contents." + Write-Output " vm - overwrites virtual disk with src/ contents." + Write-Output "" + exit +} + +if ($args.count -eq 0) +{ + print_usage +} +if ($choice -ne 'repo' -and $choice -ne "vm") +{ + print_usage +} + +if (!((Split-Path -Path (Get-Location) -Leaf) -eq "build")) +{ + Write-Output "This script must be run inside the build folder. Press ENTER to exit."; Read-Host; exit +} + +if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) +{ + Write-Output "This script must be run as Adminstrator. Press ENTER to exit."; Read-Host; exit +} + +if (!(Get-Command qemu-system-x86_64.exe -errorAction SilentlyContinue)) +{ + $env:Path += ";C:\Program Files\qemu;" + if (!(Get-Command qemu-system-x86_64.exe -errorAction SilentlyContinue)) + { + Write-Output "QEMU is not installed, or not set in \$PATH. Press ENTER to exit."; Read-Host; exit + } +} +Write-Output "QEMU installation found." + +# Set this +$ZEALDISK="" +# Examples: +#$ZEALDISK = "$HOME\VirtualBox VMs\ZEAL\ZEAL.vdi" +#$ZEALDISK="$HOME\vmware\ZealOS\ZealOS.vmdk" +#$ZEALDISK="ZealOS.qcow2" + +if ($ZEALDISK -eq "") +{ + Write-Output "Please edit this script with the full path to your ZealOS virtual disk. Press ENTER to exit."; Read-Host; exit +} +if (!(Test-Path -Path $ZEALDISK)) +{ + Write-Output "$ZEALDISK is not a path to a file. Press ENTER to exit."; Read-Host; exit +} + +$TEMPZEALDISK = "$env:TEMP\TempZealDisk.vhd" +qemu-img convert -O vpc $ZEALDISK $TEMPZEALDISK +fsutil sparse setflag $TEMPZEALDISK 0 +fsutil sparse queryflag $TEMPZEALDISK + +function Mount-ZealDisk +{ + $global:ZEALLETTER = ((Mount-DiskImage -ImagePath $TEMPZEALDISK -Access ReadWrite) | Get-Disk | Get-Partition -PartitionNumber 1).DriveLetter +} + +function Unmount-ZealDisk +{ + $be_quiet = Dismount-DiskImage -ImagePath $TEMPZEALDISK +} + +switch ($choice) +{ + "repo" + { + Write-Output "Emptying src..." + Remove-Item "..\src\*" -Recurse -Force + Mount-ZealDisk + Write-Output "Copying vdisk root to src..." + Copy-Item -Path "${ZEALLETTER}:\*" -Destination "..\src\" -Recurse -Force + Remove-Item "..\src\Boot\BootMHD2.BIN" + Remove-Item "..\src\Boot\KERNEL.ZXE" + Unmount-ZealDisk + Remove-Item $TEMPZEALDISK + Write-Output "Finished." + } + + "vm" + { + Write-Output "" + Write-Output "TODO: Windows sync.ps1 vm" + Write-Output "since this is not implemented yet, you can instead use build-iso.ps1" + Write-Output "to make a Distro ISO, and use that to install changes over your existing VM." + Write-Output "" + <# + Mount-ZealDisk + Write-Output "Copying src to vdisk..." + Copy-Item -Path "..\src\*" -Destination "${ZEALLETTER}:\" -Recurse -Force + Unmount-ZealDisk + switch ([System.IO.Path]::GetExtension($ZEALDISK)) + { + ".vdi" {qemu-img convert -O vdi $TEMPZEALDISK $ZEALDISK} # Non-working... re-building a HDD changes file UUID, which confuses Virtualbox... + } + Write-Output "Finished." + #> + } +} \ No newline at end of file