#!/bin/sh
# CPU
ARCH=ppc-aix
MEM=192

# Disks
HD="-hda /vm/aix433.qcow2"
# CDROM="-cdrom /vm/aix433_1.iso"

# GPU
# VNC="1"
# GPU="-vga std -vnc :$VNC"
# Serial Only
GPU="-display none -nographic" 

# System
SPORT=1008
MPORT=1009
NAME="AIX433"

# Network
VDE_SOCKET=/tmp/vde_bridge

MAC="02:00:01:0a:47:68"
CPU="-M 40p -bios q40pofw-serial.rom"
NET="-nic vde,sock=$VDE_SOCKET,model=pcnet,mac=$MAC"
MONITOR="-monitor telnet::$MPORT,server,nowait"
SERIAL="-serial telnet::$SPORT,server,nowait"
SYSTEM="-name $NAME"
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



