You should; As Eric said, it was my main reason to start using VDE as well: no root authority needed to start a VM with "true" networking support.
Btw; got a bit early home tonight, so started on the script; the crude 1st part of parsing the ini file is done now, more or less. It's very basic and won't start your VM yet; in fact it does nothing other than echo stuff, but it gives an idea of the direction I'm thinking of going... Share your ideas with me and it may grow to something quite funny :-)
Code:
#!/bin/ksh
# ksh is more or less required due to scoping of variables
# bash is picky and doesn't scope outside piped loops :-(
machine=${1}
inifile="check.ini"
parse_inifile()
{
section_start=`cat ${inifile} | grep -v "^#" | grep -n "^\[${machine}\]$" | cut -d ':' -f 1`
if [ -z "${section_start}" ]
then
echo "Not found; valid sections are: "
cat ${inifile} | grep -v "^#" | grep -e "^\[.*\]$" | cut -d '[' -f 2 - | cut -d ']' -f 1
exit
fi
section_end=`cat ${inifile} | grep -v "^#" | grep -e "^$" -n | cut -d ':' -f 1 | while read num
do
if [ ${num} -gt ${section_start} ]
then
echo ${num}
fi
done | head -n 1`
((diff=section_end - section_start))
echo "Start: ${section_start}"
echo "End : ${section_end}"
echo "Diff : ${diff}"
cat ${inifile} | grep -v "^#" | tail -n +${section_start} | head -n ${diff} | while read option
do
echo "${#OPT[*]}: ${option}"
OPT[${#OPT[*]}]=${option}
done
}
parse_options()
{
COUNT=0
PARAMETERS=""
while [ ${COUNT} -lt ${#OPT[*]} ]
do
((COUNT+=1)) # we can safely do this; as OPT[0] is the section header
ARG=`echo ${OPT[${COUNT}]} | cut -d '=' -f 1`
VAL=`echo ${OPT[${COUNT}]} | cut -d '=' -f 2-`
case ${ARG} in
"")
PARAMETERS=${PARAMETERS}
;; # yes pretty silly, right?
"machine")
PARAMETERS="${PARAMETERS}-M ${VAL} "
;;
*)
PARAMETERS="${PARAMETERS} -${ARG} ${VAL} "
;;
esac
done
echo ${PARAMETERS}
}
main()
{
parse_inifile
parse_options
}
main
The idea is to have an ini file that has these requirements:
- Each machine starts with [<machine name>]
- an empty line means the end of the machine definition
- comments are possible with an # at the very start of the line
- parameters to be passed to qemu are similar put as <parameter minus the leading ->=<value>
- other things can be put in the ini file, for which I have to write the support yet; e.g. qemu_binary=/usr/bin/qemu