2021-12-17 04:50:53 +00:00
|
|
|
#!/bin/sh
|
2022-03-04 19:48:45 +00:00
|
|
|
#
|
2021-12-17 04:50:53 +00:00
|
|
|
# Sync VM <--> Repo.
|
2022-03-04 19:48:45 +00:00
|
|
|
#
|
2021-12-17 04:50:53 +00:00
|
|
|
# On copying from virtual disk to src/, the directory is emptied before copy. Comment out "rm -rf ../src/*" to copy onto src.
|
2022-03-04 19:48:45 +00:00
|
|
|
#
|
|
|
|
#
|
2021-12-17 04:50:53 +00:00
|
|
|
|
2022-04-29 08:33:51 +01:00
|
|
|
# make sure we are in the correct directory
|
|
|
|
SCRIPT_DIR=$(realpath "$(dirname "$0")")
|
|
|
|
SCRIPT_NAME=$(basename "$0")
|
|
|
|
EXPECTED_DIR=$(realpath "$PWD")
|
|
|
|
|
2022-12-12 01:06:40 +00:00
|
|
|
# Change this if your default QEMU version does not work and you have installed a different version elsewhere.
|
|
|
|
QEMU_BIN_PATH=$(dirname "$(which qemu-system-x86_64)")
|
|
|
|
|
2022-04-29 08:33:51 +01:00
|
|
|
if test "${EXPECTED_DIR}" != "${SCRIPT_DIR}"
|
|
|
|
then
|
2022-05-02 10:10:49 +01:00
|
|
|
( cd "$SCRIPT_DIR" || exit ; "./$SCRIPT_NAME" "$@" );
|
2022-04-29 08:33:51 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2021-12-17 04:50:53 +00:00
|
|
|
# Uncomment if you use doas instead of sudo
|
|
|
|
#alias sudo=doas
|
|
|
|
|
|
|
|
# Set this
|
2021-12-17 17:50:03 +00:00
|
|
|
ZEALDISK=
|
|
|
|
# Examples:
|
|
|
|
#ZEALDISK=~/VirtualBox\ VMs/ZealOS/ZealOS.vdi
|
|
|
|
#ZEALDISK=~/vmware/ZealOS/ZealOS.vmdk
|
|
|
|
#ZEALDISK=ZealOS.qcow2
|
2021-12-17 04:50:53 +00:00
|
|
|
|
2021-12-17 17:50:03 +00:00
|
|
|
[ -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
|
2021-12-17 04:50:53 +00:00
|
|
|
|
2022-03-04 19:48:45 +00:00
|
|
|
# Set this if updating organization homepage github.io docs
|
|
|
|
DOCS_DIR=
|
|
|
|
# Example:
|
|
|
|
#DOCS_DIR=../../zeal-operating-system.github.io/
|
|
|
|
|
|
|
|
[ ! -z "$DOCS_DIR" ] && [ ! -d "$DOCS_DIR" ] && echo "\$DOCS_DIR ($DOCS_DIR) does not exist!" && exit 1
|
|
|
|
|
2021-12-17 04:50:53 +00:00
|
|
|
TMPMOUNT=/tmp/zealtmp
|
2021-12-17 18:06:00 +00:00
|
|
|
|
|
|
|
print_usage() {
|
|
|
|
echo "Usage: $0 [ repo | vm ]"
|
|
|
|
echo
|
2021-12-17 18:13:44 +00:00
|
|
|
echo " repo - overwrites src/ with virtual disk contents."
|
|
|
|
echo " vm - overwrites virtual disk with src/ contents."
|
2021-12-17 18:06:00 +00:00
|
|
|
echo
|
|
|
|
}
|
2021-12-17 04:50:53 +00:00
|
|
|
|
|
|
|
mount_vdisk() {
|
|
|
|
echo "Mounting virtual disk..."
|
2022-12-12 01:06:40 +00:00
|
|
|
sudo $QEMU_BIN_PATH/qemu-nbd -c /dev/nbd0 "$ZEALDISK"
|
2021-12-17 04:50:53 +00:00
|
|
|
sudo partprobe /dev/nbd0
|
|
|
|
sudo mount /dev/nbd0p1 $TMPMOUNT
|
|
|
|
}
|
|
|
|
|
|
|
|
umount_vdisk() {
|
|
|
|
echo "Unmounting virtual disk..."
|
|
|
|
sync
|
|
|
|
sudo umount $TMPMOUNT
|
2022-12-12 01:06:40 +00:00
|
|
|
sudo $QEMU_BIN_PATH/qemu-nbd -d /dev/nbd0
|
2021-12-17 17:50:03 +00:00
|
|
|
sudo rm -rf $TMPMOUNT
|
2021-12-17 04:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ -z $1 ]
|
|
|
|
then
|
2021-12-17 18:06:00 +00:00
|
|
|
print_usage
|
2021-12-17 04:50:53 +00:00
|
|
|
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
|
2022-02-14 03:11:46 +00:00
|
|
|
rm ../src/Boot/BootMHD2.BIN
|
2022-03-04 19:48:45 +00:00
|
|
|
if [ -d $TMPMOUNT/HTML ] && [ ! -z $DOCS_DIR ]
|
2021-12-17 04:50:53 +00:00
|
|
|
then
|
2022-03-04 19:48:45 +00:00
|
|
|
echo "Copying HTML docs to \$DOCS_DIR ($DOCS_DIR)..."
|
|
|
|
rm -rf $DOCS_DIR/*
|
|
|
|
cp -r $TMPMOUNT/HTML/* $DOCS_DIR
|
2021-12-30 22:37:35 +00:00
|
|
|
rm -rf ../src/HTML/
|
2021-12-17 04:50:53 +00:00
|
|
|
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."
|
2021-12-17 18:06:00 +00:00
|
|
|
print_usage
|
2021-12-17 04:50:53 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|