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.

Revisions

  1. keyboard-slayer revised this gist Dec 30, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cpcdos-setup.sh
    Original file line number Diff line number Diff line change
    @@ -34,6 +34,7 @@ function umount-cpcdos
    $sudo umount ./cpcdos
    $sudo qemu-nbd --disconnect /dev/nbd0 || command_not_found qemu-nbd
    $sudo rmmod nbd
    rmdir ./cpcdos
    }

    function usage
    @@ -71,7 +72,6 @@ case $1 in

    -u | --umount)
    umount-cpcdos
    rmdir ./cpcdos
    ;;

    -r | --run)
  2. keyboard-slayer created this gist Dec 30, 2021.
    89 changes: 89 additions & 0 deletions cpcdos-setup.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,89 @@
    #!/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
    }

    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
    rmdir ./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