qemu-boot.sh: Add support for -n (network card model)

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2016-11-14 14:05:59 +00:00
commit f6af9442c1

View file

@ -21,6 +21,16 @@ EOT
exit 0 exit 0
} }
err()
{
echo $* >&2
}
fatal()
{
err $@
exit 1
}
do_sudo() do_sudo()
{ {
@ -41,6 +51,7 @@ ldap_search()
local ldap_server=ldap.lcl local ldap_server=ldap.lcl
local binddn=cn=ldapadm,dc=jannet,dc=de local binddn=cn=ldapadm,dc=jannet,dc=de
local password_file=$HOME/.feedfs-ldap/passwords/$binddn@$ldap_server local password_file=$HOME/.feedfs-ldap/passwords/$binddn@$ldap_server
[ -r "$password_file" ] || fatal "Password file $password_file doesn't exist"
ldapsearch -y $password_file -xZ -h $ldap_server -D $binddn -b $base,ou=networks,dc=jannet,dc=de $@ ldapsearch -y $password_file -xZ -h $ldap_server -D $binddn -b $base,ou=networks,dc=jannet,dc=de $@
} }
@ -52,7 +63,7 @@ list_hostnames()
boot_net() boot_net()
{ {
[ "$hostname" ] && { [ "$hostname" ] && {
local short_hostname=`echo $hostname | sed 's/\..*//'` set -x
macaddr=`ldap_search -LLL "(cn=$short_hostname) dhcpHWAddress" | macaddr=`ldap_search -LLL "(cn=$short_hostname) dhcpHWAddress" |
sed '/dhcpHWAddress:/ !d; s/dhcpHWAddress: ethernet *//'` sed '/dhcpHWAddress:/ !d; s/dhcpHWAddress: ethernet *//'`
} }
@ -63,12 +74,13 @@ boot_net()
ps aux | grep -v grep | grep -q dhcpd || /etc/init.d/dhcpd start ps aux | grep -v grep | grep -q dhcpd || /etc/init.d/dhcpd start
ps aux | grep -v grep | grep -q nfsd || /etc/init.d/nfsserver start ps aux | grep -v grep | grep -q nfsd || /etc/init.d/nfsserver start
[ "$nic_model" ] || nic_model=",model=e1000"
# need this for net access, would be nicer if it didn't run as root # need this for net access, would be nicer if it didn't run as root
# -nographic # -nographic
do_sudo -E /usr/bin/$exe \ do_sudo -E /usr/bin/$exe \
-boot n \ -boot n \
-net tap,ifname=tap0,vlan=0,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \ -net tap,ifname=tap0,vlan=0,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \
-net nic,vlan=0,model=e1000,macaddr=$macaddr \ -net nic,vlan=0$nic_model,macaddr=$macaddr \
"$qemu_opts" "$qemu_opts"
} }
@ -76,17 +88,14 @@ boot_image()
{ {
local boot_image="$1" local boot_image="$1"
test -r "$boot_image" || { test -r "$boot_image" || fatal "inaccessible boot image \"$boot_image\""
echo "inaccessible boot image \"$boot_image\"" >&2
exit 1
}
xhost + xhost +
do_sudo -E /usr/bin/$exe \ do_sudo -E /usr/bin/$exe \
-net tap,ifname=tap0,vlan=0,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \ -net tap,ifname=tap0,vlan=0,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \
-net nic,vlan=0$nic_model,macaddr=$macaddr \ -net nic,vlan=0$nic_model,macaddr=$macaddr \
"$qemu_opts" \ "$qemu_opts" \
$boot_image -drive format=raw,file=$boot_image
} }
boot() boot()
@ -113,7 +122,7 @@ boot()
# -- here we go # -- here we go
OPTIND=1 OPTIND=1
while getopts lhb:o:x: flag; do while getopts lhb:o:x:n: flag; do
case $flag in case $flag in
h) h)
usage 0;; usage 0;;
@ -121,11 +130,17 @@ while getopts lhb:o:x: flag; do
list_hostnames list_hostnames
exit 0;; exit 0;;
b) b)
hostname="$OPTARG";; hostname="$OPTARG"
short_hostname=`echo $hostname | sed 's/\..*//'`
dns_domain=`echo $hostname | cut -d. -f2-`
base=`echo $dns_domain | sed 's/\./,/g; s/\(^\|,\)/\1dc=/g'`
;;
x) x)
exe="$OPTARG";; exe="$OPTARG";;
o) o)
qemu_opts="$OPTARG";; qemu_opts="$OPTARG";;
n)
nic_model=",model=$OPTARG";;
*) *)
usage 1;; usage 1;;
esac esac