#!/bin/sh
# CPU
ARCH=sparc
# Use 224 when installing SunOS 4. After that, use 256.
MEM=256

# Disks
HD="-drive file=/vm/solaris2.6-sparc.qcow2,bus=0,unit=3,media=disk"
# CDROM="-drive file=/vm/sol26.iso,bus=0,unit=6,media=cdrom,readonly=on"

# GPU
VNC="1"
GPU="-vga cg3 -vnc :$VNC"
# Serial Only
# remove --daemonize option below and add &
# GPU=""-nographic -vga none"

# System
SPORT=1006
MPORT=1007
NAME="Solaris2.6"

# Network
VDE_SOCKET=/tmp/vde_bridge

MAC="02:00:01:9d:a2:f5"
CPU="-M SS-5 -bios ss5.bin"
NET="-nic vde,sock=$VDE_SOCKET,model=lance,mac=$MAC"
MONITOR="-monitor telnet::$MPORT,server,nowait"
SERIAL="-serial telnet::$SPORT,server,nowait"
SYSTEM="-name $NAME  -daemonize"
function startvm
{
  qemu-system-$ARCH -m $MEM $CPU $HD $CDROM $NET $GPU $MONITOR $SERIAL $SYSTEM
  echo "VNC is $(hostname) $VNC"
  echo "Serial Port is $(hostname) $SPORT"
  echo "Management Port $(hostname) $MPORT"
}

function stopvm
{
#  echo system_powerdown | nc localhost $MPORT  # Graceful
  echo q | nc localhost $MPORT # Immediate

#  Alternate
#  echo system_powerdown | socat STDIN TCP:localhost:1003

}
case $1 in
 "start"   ) startvm
             ;;
 "stop"    ) stopvm
             ;;
 "restart" ) stopvm
             startvm
             ;;
 * )         echo "VNC is $(hostname) $VNC"
             echo "Serial Port is $(hostname) $SPORT"
             echo "Management Port $(hostname) $MPORT" ;;

esac



