#!/bin/sh

# sample script to test an install with qemu

cmdline=""
while [ -n "$1" ]; do
  case "$1" in
    -r|--root) ROOT="$2"
      shift ;;
    -n|--nfsroot) nfsroot="$2"
      shift ;;
    -i|--ip) ip="$2"
      shift ;;
    --console) console="$2"
      shift ;;
    --rootdev) rootdev="$2"
      shift ;;
    -a|--append|-append) kernel_opts="$2"
      shift ;;
    -hda) hda="$2" 
      shift ;;
    -nographic) nographic="-nographic"
      ;;
    -h|--help) head -n 24 $0
      exit 0
      ;;
    *) cmdline="$cmdline $1"
      ;;
  esac
  shift
done

if [ -n "$nographic" ]; then
  test -z "$console" && console="ttyS0,38400"
fi

if [ -n "$console" ]; then
  console="console=ttyS0,38400"
fi

if [ -n "$rootdev" ]; then
  root="root=$rootdev"
fi

if [ -z "$hda" ]; then
  # See Debian bug#260935 (fixed post-sarge)
  hda=/dev/zero 
fi

if [ -n "$ip" ]; then
  ip="ip=$ip"
fi

if [ -z "$ROOT" ]; then
  ROOT=/opt/ltsp/i386
fi

if [ -z "$server" ]; then
  server=10.0.2.2
fi

if [ -z "$nfsroot" ]; then
  nfsroot="$server:$ROOT"
fi

# set default kernel parameters
if [ -z "$kernel_opts" ]; then
  kernel_opts="$root nfsroot=$nfsroot $ip $console"
fi

qemu $nographic -hda $hda -kernel $ROOT/boot/vmlinuz \
  -initrd $ROOT/boot/initrd.img \
  -append "$kernel_opts" $cmdline
