Skip to content

Instantly share code, notes, and snippets.

@keyboard-slayer
Last active January 21, 2022 18:37
Show Gist options
  • Save keyboard-slayer/c6b23122da499078d6998b98b8a59d97 to your computer and use it in GitHub Desktop.
Save keyboard-slayer/c6b23122da499078d6998b98b8a59d97 to your computer and use it in GitHub Desktop.
Launch Cpcdos VM on GNU/Linux
#!/bin/bash
link="https://dl.cpcdos.net/PUBLIC/cpcdososx/binary/OS2.1__BETA1.5/[PUBLIC]%20Cpcdos%20OS2.1%20Beta%201.5%20[15-AUG-2021].zip"
if which doas &>/dev/null; then
sudo=$(which doas)
elif which sudo &>/dev/null; then
sudo=$(which sudo)
else
echo [-] Please install sudo or doas
exit 1
fi
function command_not_found
{
echo [-] Please install $1
exit 1
}
function download
{
wget $link -O cpcdos.zip || command_not_found wget
unzip cpcdos.zip || command_not_found unzip
find ./ -name "*.ova" -exec mv {} ./ \; 2>/dev/null
rm -rf \[PUBLIC\]*
tar -xvf *.ova
rm *.mf *.ova *.ovf
qemu-img convert -f vmdk -O qcow2 PUBLIC\ Cpcdos\ OSx-disk001.vmdk cpcdos.qcow2 || command_not_found qemu-img
rm *.vmdk *.zip
}
function umount-cpcdos
{
$sudo umount ./cpcdos
$sudo qemu-nbd --disconnect /dev/nbd0 || command_not_found qemu-nbd
$sudo rmmod nbd
rmdir ./cpcdos
}
function usage
{
echo "$0 [ -m / --mount | -r / --run | -u / --umount ]"
}
if [ ! -f cpcdos.qcow2 ]; then
download
fi
if [ $# -eq 0 ]; then
usage
exit 1
fi
case $1 in
-m | --mount)
if lsmod | grep qemu-nbd &>/dev/null ; then
echo [?] Qemu module loaded
else
$sudo modprobe nbd max_part=8 || command_not_found qemu-nbd
fi
$sudo qemu-nbd --connect=/dev/nbd0 ./cpcdos.qcow2 || command_not_found qemu-nbd
if [ ! -d ./cpcdos ]; then
mkdir ./cpcdos
fi
$sudo mount /dev/nbd0p1 ./cpcdos -o uid=$UID,gid=$(id -g)
;;
-u | --umount)
umount-cpcdos
;;
-r | --run)
if [ -d ./cpcdos ]; then
umount-cpcdos
fi
qemu-system-x86_64 -m 4G -smp 4 -cpu host -serial stdio -enable-kvm -rtc base=localtime -display sdl -net nic,model=e1000 -hda ./cpcdos.qcow2 || command_not_found qemu
;;
*)
usage
exit 1
;;
esac
@chrapati24
Copy link

Yeah ! Thanks man :D

@Ficelloo
Copy link

coolll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment