#!/bin/sh

# these have defaults
NAME=
MiB=

# boot/install from this (if set and non-null)
# if unset or null use first --disk
PATHTOISO=
# default PATHTOISO:
PATHTOISO="${PATHTOISO:-$(awk '/^[ 	]*#/ {next;};{if($2=="/media/cdrom9"){print $1;exit;};}' /etc/fstab)}"

# set non-null for PXE boot
PXE=

# specify first disk (will boot if PATHTOISO and PXE both unset or null
# unset or null for none
DISK=
#DISK=/dev/tigger/LV,format=raw
#DISK=/dev/sr0,device=cdrom,bus=scsi,perms=ro
#DISK=/var/tmp/scratch/HD,format=raw,sparse=true

# set non-null to skip OS installation, build guest image around disk image
IMPORT=

# set non-null to configure permanently to boot from CDROM
LIVECD=

# unset or null for none
NETWORK=
NETWORK=network=default
#NETWORK=bridge=br0
#NETWORK=bridge=br0,mac=52:54:00:3f:c0:75

# set non-null to boot UEFI
UEFI=

# set non-null for don't automatically reboot after install completes
NOREBOOT=

# minutes to wait for VM to install (-1 forever); null or unset for default
WAIT=
WAIT=-1

# autodetection attempted if unset or null, none for no autodetection
#OS_VARIANT=
#OS_VARIANT=debian9
OS_VARIANT=debiantesting
#OS_VARIANT=fedora16
#OS_VARIANT=ubuntusaucy
#OS_VARIANT=none

# Request a non-native CPU architecture
# null or unset to use default
ARCH=
#ARCH=arm i386 i486 i586 i686 mips mipsel ppc sparc x86_64
#ARCH=486
#ARCH=athlon
#ARCH=core2duo
#ARCH=coreduo
#ARCH=kvm64
#ARCH=n270
#ARCH=pentium
#ARCH=pentium2
#ARCH=pentium3
#ARCH=phenom
#ARCH=qemu32
#ARCH=qemu64

### DEFAUTLTS ###
# default name:
NAME="${NAME:-$(basename $0)}"
# default MiB:
MiB="${MiB:-1024}"

DISPLAY="${DISPLAY-:0}" export DISPLAY
XAUTHORITY="${XAUTHORITY:-/home/m/michael/.Xauthority}" export XAUTHORITY

# common options
#VIRTINSTALLOPTS='--virt-type qemu --hvm'
VIRTINSTALLOPTS='--virt-type kvm --hvm'
# virtualization type
# --virt-type kvm \
# full hardware virtualization
# --hvm \

########################################################################
# most of the stuff one likely wants to customize should be above
########################################################################

if [ x"$DISK" = x ]; then
	DISKarg=--nodisks
else
	DISKarg=--disk="$DISK"
fi

if [ x"$NETWORK" = x ]; then
	NETWORKarg=--nonetworks
else
	NETWORKarg=--network="$NETWORK"
fi

virt-install \
	--name="$NAME" \
	${PATHTOISO:+--cdrom="$PATHTOISO"} \
	${PXE:+--pxe} \
	${DISKarg:+"$DISKarg"} \
	${IMPORT:+--import} \
	${LIVECD:+--livecd} \
	${UEFI:+--boot uefi} \
	${NETWORKarg:+"$NETWORKarg"} \
	--ram="$MiB" \
	${NOREBOOT:+--noreboot} \
	${WAIT:+--wait="$WAIT"} \
	${OS_VARIANT:+--os-variant="$OS_VARIANT"} \
	${ARCH:+--arch="$ARCH"} \
	$VIRTINSTALLOPTS
