run-reactos-spice.sh 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env bash
  2. # Script that runs ReactOS through SPICE
  3. # License: CC0
  4. # Requirements:
  5. # - qemu
  6. # - qemu-kvm or libvirt
  7. # - spice-gtk (provides spicy binary)
  8. # - spice-vdagent (optional, for auto mouse capture, mouse movement
  9. # improvements)
  10. # - cdrtools or libisofs or libisofs6, libisofs1 etc. or search with "isofs"
  11. # if those are not in repo (optional, to share files to ReactOS from host)
  12. cd $(dirname $0)
  13. [ -z "$(command -v qemu-system-$(uname -m))" ] && echo "qemu-system-$(uname -m) binary not found. Please install qemu and qemu-kvm or libvirt" && exit 111
  14. [ -z "$(command -v spicy)" ] && echo 'spicy binary not found. Please install spice-client-gtk, spice-gtk or search repo for spice' && exit 121
  15. [ ! -f 'reactos.iso' ] && echo 'Please put the ReactOS boot ISO as reactos.iso' && exit 122
  16. [ ! -f 'reactos.img' ] && echo 'Please create a QEMU supported disk image as reactos.img. e.g. qemu-img create -f qcow2 reactos.img 4G' && exit 123
  17. # SPICE host
  18. SPICE_HOST='127.0.0.1'
  19. # SPICE port
  20. SPICE_PORT=5929
  21. # QEMU PID is stored on this file with -pidfile param
  22. QEMU_PID_FILE='/tmp/reactos-spice-qemu-pid.txt'
  23. # How much RAM to allow ReactOS to use. e.g. 1300M for 1300mb, 4G for 4gb
  24. RAM_AMOUNT=2G
  25. qemu_args=(
  26. # RAM
  27. -m ${RAM_AMOUNT}
  28. # Enable KVM
  29. -enable-kvm
  30. # Network
  31. -net nic,model=ne2k_pci -net user
  32. # Audio
  33. -audiodev driver=pa,id=pa1,server=`pactl info | grep 'Server String' | awk '{print $3}'` -device AC97,audiodev=pa1
  34. # USB redirection - for 3 devices
  35. -device ich9-usb-ehci1,id=usb
  36. -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,multifunction=on
  37. -device ich9-usb-uhci2,masterbus=usb.0,firstport=2
  38. -device ich9-usb-uhci3,masterbus=usb.0,firstport=4
  39. -chardev spicevmc,name=usbredir,id=usbredirchardev1 -device usb-redir,chardev=usbredirchardev1,id=usbredirdev1
  40. -chardev spicevmc,name=usbredir,id=usbredirchardev2 -device usb-redir,chardev=usbredirchardev2,id=usbredirdev2
  41. -chardev spicevmc,name=usbredir,id=usbredirchardev3 -device usb-redir,chardev=usbredirchardev3,id=usbredirdev3
  42. # ReactOS CD image
  43. -cdrom reactos.iso \
  44. # Disk image
  45. -hda reactos.img \
  46. # SPICE related
  47. -vga qxl -spice port=${SPICE_PORT},addr=${SPICE_HOST},disable-ticketing=on -usbdevice tablet
  48. -device virtio-serial-pci
  49. -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0
  50. -chardev spicevmc,id=spicechannel0,name=vdagent
  51. # Let the script run as is after QEMU has started successfully.
  52. -daemonize
  53. # -daemonize doesn't return PID with $!. So we need to store the PID in a file.
  54. -pidfile "${QEMU_PID_FILE}"
  55. )
  56. # Create share CD ROM ISO image to share files with ReactOS
  57. [ ! -d _share ] && mkdir _share
  58. if [ -n "$(command -v mkisofs)" ] && [ "$(stat -t _share)" != "$(cat _share_stat)" ]; then # if anything inside _share changed, create iso
  59. [ -f _share.iso ] && rm _share.iso
  60. if [ "$(ls -A _share)" ]; then
  61. mkisofs -iso-level 4 -J -l -D -N -joliet-long -untranslated-filenames -V "SHARE" -o _share.iso _share
  62. [ "$?" != '0' ] && echo 'ISO creation failed!' && rm _share.iso &>/dev/null && exit 1
  63. fi
  64. stat -t _share > _share_stat
  65. fi
  66. [ -f _share.iso ] && qemu_args+=(-drive file=_share.iso,media=cdrom)
  67. # Run the QEMU command
  68. qemu-system-$(uname -m) "${qemu_args[@]}"
  69. [ "$?" -gt 0 ] && echo 'QEMU failed to start. Please check previous messages. Exiting...' && exit 131 # in case QEMU exits due to error
  70. # Get QEMU PID from -pidfile file set previously
  71. qemu_pid=$(cat "${QEMU_PID_FILE}" 2>/dev/null)
  72. # Run spicy SPICE viewer
  73. echo "QEMU is running on pid ${qemu_pid}..."
  74. spicy --title 'ReactOS' -h "${SPICE_HOST}" -p "${SPICE_PORT}"
  75. # When spice window is closed...
  76. echo "Killing QEMU on pid ${qemu_pid}..."
  77. kill -9 ${qemu_pid} && rm "${QEMU_PID_FILE}"
  78. [ "$?" -eq 0 ] && echo 'Killed QEMU successfully. Exiting...'