#!/bin/sh set -e # defaults RAM=512 DISK=20 STORAGE_POOL=default QEMU_URI=qemu:///system SUITE=wheezy CONSOLE='console=tty0 console=ttyS0,115200n8' while [ -n "$1" ]; do case "$1" in (-n|--name) shift if [ -z "$1" ]; then echo >&2 'E: --name/-n needs hostname argument' exit 1 fi HOSTNAME="$1" ;; (-i|--ipaddress) shift if [ -z "$1" ]; then echo >&2 'E: --ipaddress/-i needs IP address/netmask' exit 1 fi case "$1" in (*/*) :;; (*) echo >&2 'E: missing netmask' exit 1 ;; esac IPADDRESS="$1" ;; (-r|--ram) shift if [ -z "$1" ]; then echo >&2 'E: --ram/-r needs number (megabytes)' exit 1 fi RAM="$1" ;; (-s|--size) shift if [ -z "$1" ]; then echo >&2 'E: --size/-s needs size argument' exit 1 fi DISK="$1" ;; esac shift done if [ -z "${HOSTNAME:-}" ]; then echo >&2 'E: hostname is required' exit 2 fi BASEDIR=$(cd ${0%/*}; pwd) tmpdir=$(mktemp -d) tar -C $BASEDIR/preseed/$SUITE -cf $tmpdir/commands.tar commands extra_args="auto $CONSOLE \ hostname=${HOSTNAME%%.*} \ domain=${HOSTNAME#*.}" if [ -n "$IPADDRESS" ]; then if [ -z "$GATEWAY" ]; then # default to the first IP in the network GATEWAY=$(ipcalc $IPADDRESS | grep HostMin | awk '{print $2}') fi NETMASK="${IPADDRESS#*/}" IPADDRESS="${IPADDRESS%/*}" : ${NAMESERVER:=$GATEWAY} extra_args="$extra_args netcfg/disable_dhcp=true \ netcfg/get_ipaddress=$IPADDRESS \ netcfg/get_netmask=$NETMASK \ netcfg/get_gateway=$GATEWAY \ netcfg/get_nameservers=$NAMESERVER" else extra_args="$extra_args netcfg/disable_dhcp=false" fi cat >&2 <<_eof hostname: $HOSTNAME ram: $RAM MiB disk: $DISK GiB console: $CONSOLE _eof if [ -n "$IPADDRESS" ]; then cat >&2 <<_eof ipaddress: $IPADDRESS netmask: $NETMASK gateway: $GATEWAY nameserver: $NAMESERVER _eof else cat >&2 <<_eof dhcp: true _eof fi exit 0 exec virt-install --connect=$QEMU_URI \ -n $HOSTNAME \ -r $RAM \ --disk pool=default,size=$SIZE \ -w bridge=virt-br \ --graphics=vnc \ --serial=pty \ --watchdog i6300esb,action=reset \ --os-variant=debian$SUITE \ -l $BASEDIR/installer-amd64 \ --initrd-inject=$BASEDIR/preseed/$SUITE/preseed.cfg \ --initrd-inject=$tmpdir/commands.tar \ --extra-args="$extra_args" \ --autostart \ "$@"