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

# Disks
HD="-drive file=/vm/sunos414-sparc.qcow2,bus=0,unit=3,media=disk"
# CDROM=/vm/image.iso

# GPU
VNC="1"
GPU="-vga cg3 -vnc :$VNC"
# Serial Only
# remove --daemonize option below and add &
# GPU=""-nographic -vga none" 
# System
SPORT=1004
MPORT=1005
NAME="SunOS414-SPARC"

# Network
VDE_SOCKET=/tmp/vde_bridge

MAC="02:00:01:37:6f:7"
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 $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



