From e7fec6b427b84f41eb46d5eef60458f359af5117 Mon Sep 17 00:00:00 2001 From: B4S3D Date: Thu, 16 Dec 2021 22:50:53 -0600 Subject: [PATCH 1/2] Rewrite build scripts in POSIX shell. Merge sync_repo.sh and sync_vm.sh into one script. Remove old build scripts. --- build/build-iso.sh | 53 +++++++++++++++++++++++++++++++ build/build_iso.sh | 50 ----------------------------- build/old/export.ps1 | 4 --- build/old/just_mnt.sh | 9 ------ build/old/just_umnt.sh | 12 ------- build/old/mnt.sh | 37 ---------------------- build/sync.sh | 71 ++++++++++++++++++++++++++++++++++++++++++ build/sync_repo.sh | 39 ----------------------- build/sync_vm.sh | 29 ----------------- 9 files changed, 124 insertions(+), 180 deletions(-) create mode 100755 build/build-iso.sh delete mode 100755 build/build_iso.sh delete mode 100644 build/old/export.ps1 delete mode 100755 build/old/just_mnt.sh delete mode 100755 build/old/just_umnt.sh delete mode 100755 build/old/mnt.sh create mode 100755 build/sync.sh delete mode 100755 build/sync_repo.sh delete mode 100755 build/sync_vm.sh diff --git a/build/build-iso.sh b/build/build-iso.sh new file mode 100755 index 00000000..9d967824 --- /dev/null +++ b/build/build-iso.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# Build Distro ISO using AUTO.ISO minimal auto-install as bootstrap to merge codebase, recompile system, and export ISO + +# Run this script inside build/ directory + +# 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 + +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 512M -rtc base=localtime -cdrom AUTO.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 +umount_tempdisk + +echo "Generating ISO..." +qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 512M -rtc base=localtime -device isa-debug-exit + +echo "Extracting ISO from vdisk..." +rm ./ZealOS-*.iso 2> /dev/null # comment this line if you want lingering old ISOs +mount_tempdisk +cp $TMPMOUNT/Tmp/MyDistro.ISO.C ./ZealOS-$(date +%Y-%m-%d-%H_%M_%S).iso +umount_tempdisk + +echo "Deleting temp folder..." +rm -rf $TMPDIR +echo "Finished." +ls -lh ZealOS-*.iso + diff --git a/build/build_iso.sh b/build/build_iso.sh deleted file mode 100755 index 87cc2489..00000000 --- a/build/build_iso.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -# Build Distro ISO using AUTO.ISO minimal auto-install as bootstrap to merge codebase, recompile system, and export ISO - -# Run this script inside build/ directory - -echo "Making temp HDD, running auto-install" -qemu-img create -f raw ZealOS.raw 192M -qemu-system-x86_64 -machine q35,kernel_irqchip=off,accel=kvm -drive format=raw,file=ZealOS.raw -m 2G -smp $(nproc) -rtc base=localtime -cdrom AUTO.ISO -device isa-debug-exit -echo "Mounting" -sudo mkdir /tmp/zealtmp/ -sudo rm /tmp/zealtmp/* -r -sudo sync -sudo modprobe nbd -sudo qemu-nbd -c dev/nbd0 -f raw ./ZealOS.raw -sudo partprobe /dev/nbd0 -echo "Merging with src/" -sudo mount /dev/nbd0p1 /tmp/zealtmp -rm ../src/Home/Registry.ZC # we use Registry for auto-iso process, don't want to overwrite -rm ../src/Home/MakeHome.ZC # unneeded file -sudo cp -r ../src/* /tmp/zealtmp/ -sudo sync -echo "Files copied, unmounting" -sudo umount /tmp/zealtmp -sudo qemu-nbd -d /dev/nbd0 -sudo rm /tmp/zealtmp/* -r -sudo sync -qemu-system-x86_64 -machine q35,kernel_irqchip=off,accel=kvm -drive format=raw,file=ZealOS.raw -m 2G -smp $(nproc) -rtc base=localtime -device isa-debug-exit -echo "Mounting" -sudo rm /tmp/zealtmp/* -r -sudo sync -sudo modprobe nbd -sudo qemu-nbd -c dev/nbd0 -f raw ./ZealOS.raw -sudo partprobe /dev/nbd0 -sudo mount /dev/nbd0p1 /tmp/zealtmp -echo "Extracting Distro ISO" -sudo rm ./ZealOS-*.iso # comment this line if you want lingering old ISOs -sudo cp /tmp/zealtmp/Tmp/MyDistro.ISO.C ./ZealOS-$(date +%Y-%m-%d-%H_%M_%S).iso -sudo chown -R $USER:$USER ./ZealOS-*.iso -echo "Files copied, unmounting" -sudo umount /tmp/zealtmp -sudo qemu-nbd -d /dev/nbd0 -sudo rm /tmp/zealtmp/* -r -sudo sync -echo "Deleting temp HDD" -rm ./ZealOS.raw -echo "Deleting temp mount folder" -sudo rm -rf /tmp/zealtmp -echo "Done, build/ contents:" -ls diff --git a/build/old/export.ps1 b/build/old/export.ps1 deleted file mode 100644 index 76eb58c1..00000000 --- a/build/old/export.ps1 +++ /dev/null @@ -1,4 +0,0 @@ -Remove-Item -Recurse -Force .\src\* -Copy-Item -Recurse -Force Z:\* .\src\ -Remove-Item .\ZealOS-*.iso -Move-Item .\src\Tmp\MyDistro.ISO.C .\ZealOS-$(Get-Date -Format "yyyy-MM-dd-HH_mm_ss").iso diff --git a/build/old/just_mnt.sh b/build/old/just_mnt.sh deleted file mode 100755 index 1d897110..00000000 --- a/build/old/just_mnt.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -echo "mounting..." -sudo modprobe nbd -sudo qemu-nbd -c dev/nbd0 ~/VirtualBox\ VMs/ZealOS/ZealOS.vdi #Replace with path to disk -#sudo qemu-nbd -c dev/nbd0 ~/vmware/ZealOS/ZealOS.vmdk #Replace with path to disk -sudo partprobe /dev/nbd0 -sudo mount /dev/nbd0p1 /mnt -echo "mounted .vdi" - diff --git a/build/old/just_umnt.sh b/build/old/just_umnt.sh deleted file mode 100755 index 3edb80c8..00000000 --- a/build/old/just_umnt.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -echo "unmounting..." -sudo umount /mnt -sudo qemu-nbd -d /dev/nbd0 -echo "unmounted .vdi" -echo "not copying/updating ISO." -#echo "set perms, update ISO." -#sudo chown -R $USER:$USER src/* -#rm ZealOS-* -#mv src/Tmp/MyDistro.ISO.C ./ZealOS-$(date +%Y-%m-%d-%H_%M_%S).iso -echo "finished." diff --git a/build/old/mnt.sh b/build/old/mnt.sh deleted file mode 100755 index e1a6231f..00000000 --- a/build/old/mnt.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -echo "mounting..." -sudo modprobe nbd -sudo qemu-nbd -c dev/nbd0 ~/VirtualBox\ VMs/ZealOS/ZealOS.vdi #Replace with path to disk -#sudo qemu-nbd -c dev/nbd0 ~/vmware/ZealOS/ZealOS.vmdk #Replace with path to disk -sudo partprobe /dev/nbd0 -sudo mount /dev/nbd0p1 /mnt -echo "mounted .vdi" - -echo "removing src/ files" -rm -rf src/* -echo "copying src/ files from root of mounted .vdi" -sudo cp -r /mnt/* src/ -echo "src/ files copied" - -echo "removing doc/ files" -rm -rf docs/* -echo "copying docs/ files from HTML/ folder of mounted .vdi" -sudo cp -r /mnt/HTML/* docs/ -echo "docs/ files copied" - -echo "unmounting..." -sudo umount /mnt -sudo qemu-nbd -d /dev/nbd0 -echo "unmounted .vdi" -echo "set perms, update ISO." -sudo chown -R $USER:$USER src/* -sudo chown -R $USER:$USER docs/* -rm ZealOS-* -mv src/Tmp/MyDistro.ISO.C ./ZealOS-$(date +%Y-%m-%d-%H_%M_%S).iso -mv src/Tmp/AUTO.ISO.C ./build/AUTO.ISO - -echo "removing duplicates" -rm -rf ./src/HTML/* - -echo "finished." -git status diff --git a/build/sync.sh b/build/sync.sh new file mode 100755 index 00000000..854155a9 --- /dev/null +++ b/build/sync.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# Sync VM <--> Repo. +# Run this script inside build/ directory. + +# On copying from virtual disk to src/, the directory is emptied before copy. Comment out "rm -rf ../src/*" to copy onto src. + +# Uncomment if you use doas instead of sudo +#alias sudo=doas + +# Set this +ZEALDISK="" + +[ -z $ZEALDISK ] && echo "Please edit this script with the full path to your ZealOS virtual disk." && exit 1 + +TMPMOUNT=/tmp/zealtmp +USAGE="Usage: $0 [ repo | vm ]" + +mount_vdisk() { + echo "Mounting virtual disk..." + sudo qemu-nbd -c /dev/nbd0 $ZEALDISK + sudo partprobe /dev/nbd0 + sudo mount /dev/nbd0p1 $TMPMOUNT +} + +umount_vdisk() { + echo "Unmounting virtual disk..." + sync + sudo umount $TMPMOUNT + sudo qemu-nbd -d /dev/nbd0 +} + +if [ -z $1 ] +then + echo $USAGE +else + sudo modprobe nbd + [ ! -d $TMPMOUNT ] && mkdir $TMPMOUNT + case $1 in + repo) + echo "Emptying src..." + rm -rf ../src/* + mount_vdisk + echo "Copying vdisk root to src..." + cp -r $TMPMOUNT/* ../src + rm ../src/Boot/BootMHD2.BIN.C + if [ -d $TMPMOUNT/HTML ] + then + echo "Copying HTML docs to docs/..." + cp -r $TMPMOUNT/HTML/* ../docs + else + echo "No HTML docs to copy." + fi + umount_vdisk + [ -f ../src/Tmp/AUTO.ISO.C ] && mv ../src/Tmp/AUTO.ISO.C ./AUTO.ISO + echo "Finished." + git status + ;; + vm) + mount_vdisk + echo "Copying src to vdisk..." + sudo cp -r ../src/* $TMPMOUNT + umount_vdisk + echo "Finished." + ;; + *) + echo "Unknown action." + echo $USAGE + ;; + esac +fi diff --git a/build/sync_repo.sh b/build/sync_repo.sh deleted file mode 100755 index f324467f..00000000 --- a/build/sync_repo.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -# Sync VM --> repo -# (wipe src/, copy VM to src/. To copy over src/ in-place, comment out the `rm -rf ../src/*` line.) - -sudo modprobe nbd - -echo "Edit this script first to pick your VM path & file!" -exit # Comment this line out - -# Uncomment ONE of the next lines and edit it to point to your VM HDD -# sudo qemu-nbd -c dev/nbd0 ~/VirtualBox\ VMs/ZealOS/ZealOS.vdi -# sudo qemu-nbd -c dev/nbd0 ~/vmware/ZealOS/ZealOS.vmdk -# sudo qemu-nbd -c dev/nbd0 ZealOS.qcow2 - -sudo partprobe /dev/nbd0 -sudo mkdir /tmp/zealtmp -sudo mount /dev/nbd0p1 /tmp/zealtmp -echo "removing src/ files" -rm -rf ../src/* -echo "copying src/ files from root of mounted hdd" -sudo cp -r /tmp/zealtmp/* ../src/ -sudo rm ../src/Boot/BootMHD2.BIN.C -echo "src/ files copied" - -echo "copying docs/ files from HTML/ folder of mounted .vdi" -sudo cp -r /tmp/zealtmp/HTML/* ../docs/ -echo "docs/ files copied" - -echo "unmounting..." -sudo umount /tmp/zealtmp -sudo rm -rf /tmp/zealtmp -sudo qemu-nbd -d /dev/nbd0 -echo "unmounted hdd" -echo "set perms" -sudo chown -R $USER:$USER ../src/* -mv ../src/Tmp/AUTO.ISO.C ./AUTO.ISO -echo "finished." -git status diff --git a/build/sync_vm.sh b/build/sync_vm.sh deleted file mode 100755 index 0071fa88..00000000 --- a/build/sync_vm.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -# Sync repo --> VM -# (copy src/ to VM. Kernel code changes won't be reflected in VM until running BootHDIns; to recompile kernel.) - -# Run this script inside build/ directory - -sudo modprobe nbd - -echo "Edit this script first to pick your VM path & file!" -exit # Comment this line out - -# Uncomment ONE of the next lines and edit it to point to your VM HDD -# sudo qemu-nbd -c dev/nbd0 ~/VirtualBox\ VMs/ZealOS/ZealOS.vdi -# sudo qemu-nbd -c dev/nbd0 ~/vmware/ZealOS/ZealOS.vmdk -# sudo qemu-nbd -c dev/nbd0 ZealOS.qcow2 - -sudo partprobe /dev/nbd0 -sudo mkdir /tmp/zealtmp -sudo mount /dev/nbd0p1 /tmp/zealtmp -echo "Merging with src/" -sudo cp -r ../src/* /tmp/zealtmp -sudo sync -echo "Files copied, unmounting" -sudo umount /tmp/zealtmp -sudo qemu-nbd -d /dev/nbd0 -sudo rm -rf /tmp/zealtmp -sudo sync -echo "finished." From 93d81670e0a6791ce7b9f037a7589fdf698d24cb Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Fri, 17 Dec 2021 12:50:03 -0500 Subject: [PATCH 2/2] Clean-up new build scripts. Thanks to B4S3D for helpful tips on bash no-quote tilde expansion! --- build/build-iso.sh | 4 ++-- build/sync.sh | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/build/build-iso.sh b/build/build-iso.sh index 9d967824..c5900179 100755 --- a/build/build-iso.sh +++ b/build/build-iso.sh @@ -28,7 +28,7 @@ umount_tempdisk() { 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 512M -rtc base=localtime -cdrom AUTO.ISO -device isa-debug-exit +qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -cdrom AUTO.ISO -device isa-debug-exit echo "Mounting vdisk and copying src/..." rm ../src/Home/Registry.ZC 2> /dev/null @@ -38,7 +38,7 @@ sudo cp -r ../src/* $TMPMOUNT umount_tempdisk echo "Generating ISO..." -qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 512M -rtc base=localtime -device isa-debug-exit +qemu-system-x86_64 -machine q35,accel=kvm -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -device isa-debug-exit echo "Extracting ISO from vdisk..." rm ./ZealOS-*.iso 2> /dev/null # comment this line if you want lingering old ISOs diff --git a/build/sync.sh b/build/sync.sh index 854155a9..0ff672fe 100755 --- a/build/sync.sh +++ b/build/sync.sh @@ -9,16 +9,21 @@ #alias sudo=doas # Set this -ZEALDISK="" +ZEALDISK= +# Examples: +#ZEALDISK=~/VirtualBox\ VMs/ZealOS/ZealOS.vdi +#ZEALDISK=~/vmware/ZealOS/ZealOS.vmdk +#ZEALDISK=ZealOS.qcow2 -[ -z $ZEALDISK ] && echo "Please edit this script with the full path to your ZealOS virtual disk." && exit 1 +[ -z "$ZEALDISK" ] && echo "Please edit this script with the full path to your ZealOS virtual disk." && exit 1 +[ ! -f "$ZEALDISK" ] && echo "\$ZEALDISK is not a path to a file." && exit 1 TMPMOUNT=/tmp/zealtmp -USAGE="Usage: $0 [ repo | vm ]" +USAGE="Usage: $0 [ repo | vm ] \n\n repo - overwrites src/ with virtual disk contents.\n vm - overwrites virtual disk with src/ contents.\n" mount_vdisk() { echo "Mounting virtual disk..." - sudo qemu-nbd -c /dev/nbd0 $ZEALDISK + sudo qemu-nbd -c /dev/nbd0 "$ZEALDISK" sudo partprobe /dev/nbd0 sudo mount /dev/nbd0p1 $TMPMOUNT } @@ -28,6 +33,7 @@ umount_vdisk() { sync sudo umount $TMPMOUNT sudo qemu-nbd -d /dev/nbd0 + sudo rm -rf $TMPMOUNT } if [ -z $1 ]