Skip to content

Instantly share code, notes, and snippets.

@tensorpudding
Created May 26, 2010 01:35
Show Gist options
  • Save tensorpudding/413933 to your computer and use it in GitHub Desktop.
Save tensorpudding/413933 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#######################################################
# Call qemu without having to remember stupid options.#
#######################################################
require 'yaml'
$qemu = "qemu-system-i386"
config = File.open("/home/michael/.qemu.yaml") {|yf| YAML::load(yf) }
def parse_machine(config,machine)
x = config["machines"][machine].each_pair.map.reduce "" do |acc,key|
case key[0]
when :mem
acc += (" -m " + key[1].to_s)
when :hda
acc += (" -hda " + config["hddir"] + key[1].to_s)
when :hdb
acc += (" -hdb " + config["hddir"] + key[1].to_s)
when :cd
acc += (" -cdrom " + Dir[config["cddir"] + key[1].to_s])
when :opts
acc += (" " + key[1].to_s + " ")
when :port
acc += "-redir tcp:" + (key[1] + 26000).to_s + "::22 -vnc :" + key[1].to_s + " "
when :vesa
if key[1] then acc += " -std-vga " end
when :localtime
if key[1] then acc += " -localtime " end
when :kqemu
if key[1] then acc += " -kernel-kqemu " end
when :arch
if key[1] == "i386" || key[1] == "x86" then
$qemu = "qemu-system-i386"
return acc
elsif key[1] == "x86_64" || key[1] == "amd64" then
$qemu = "qemu-system-x86_64"
return acc
else
puts "Unrecognized architecture: " + key[1].to_s
abort
end
else
puts "Unrecognized option: " + key[0].to_s
abort
end
end
return x
end
if config["machines"].has_key? ARGV[0] then
%x{ #{$qemu + " " + parse_machine(config,ARGV[0]) + " &"} }
end
hddir: /store/qemu/hd/
cddir: /store/qemu/cdrom/
machines:
openbsd:
:mem: 64
:port: 3
:hda: openbsd.img
:arch: i386
xo:
:mem: 128
:port: 13
:vesa: true
:hda: xo.img
:arch: i386
debian:
:mem: 256
:port: 0
:vesa: true
:arch: i386
:hda: debian.img
winxp:
:mem: 256
:port: 11
:localtime: true
:vesa: true
:hda: winxp.img
:arch: i386
syllable:
:mem: 128
:port: 8
:vesa: true
:hda: syllable.img
:arch: i386
win2k:
:mem: 64
:port: 12
:hda: win2k.img
:arch: i386
arch:
:mem: 256
:port: 5
:kqemu: true
:hda: arch.img
:arch: x86_64
:hdb: linux_btrfs.img
deb-kfbsd:
:mem: 64
:port: 6
:hda: deb-kfbsd.img
:arch: i386
dflybsd:
:mem: 128
:port: 2
:localtime:
:hda: dflybsd.img
:arch: i386
plan9:
:mem: 32
:port: 10
:hda: plan9.img
:arch: i386
freedos:
:mem: 16
:port: 7
:hda: freedos.img
:arch: i386
gentoo:
:mem: 256
:port: 4
:kqemu: true
:vesa: true
:hda: gentoo.img
:arch: x86_64
puppy:
:mem: 256
:port: 9
:arch: i386
:cd: puppy.iso
freebsd:
:mem: 128
:port: 1
:hda: freebsd.img
:arch: i386
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment