From 66865574a156df914c89cf304466d84ba1fc13fb Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Thu, 20 Apr 2017 13:05:49 +0000 Subject: [PATCH] qemu-boot.sh: Beautify logging Signed-off-by: Jan Lindemann --- scripts/qemu-boot.sh | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/scripts/qemu-boot.sh b/scripts/qemu-boot.sh index c4f41290..368faae3 100644 --- a/scripts/qemu-boot.sh +++ b/scripts/qemu-boot.sh @@ -2,7 +2,8 @@ goodbye() { - rm -f $tmp_files + : + # rm -f $tmp_files } usage() @@ -19,17 +20,19 @@ EOT log() { - echo "=========================== $*" + echo "$log_delim $*" + /usr/bin/logger -t "$myname" "$*" } err() { - echo $* >&2 + echo "$log_delim $*" >&2 + /usr/bin/logger -t "$myname" "$*" } fatal() { - err $@ + err "Fatal: $@ ... giving up" exit 1 } @@ -37,10 +40,11 @@ do_sudo() { if [ "$UID" = 0 ]; then while [[ $1 =~ ^- ]]; do shift; done + log running $@ eval "$@" return $? else - echo running sudo $@ + log running sudo $@ #sudo -p "Password for $myname:" $@ eval sudo "$@" return $? @@ -65,7 +69,7 @@ boot_net() { local mac [ "$hostname" ] && { - set -x + #set -x mac=`ldap_search -LLL "(cn=$short_hostname) dhcpHWAddress" | sed '/dhcpHWAddress:/ !d; s/dhcpHWAddress: ethernet *//'` macaddr=",macaddr=$mac" @@ -106,7 +110,7 @@ boot_image() #-net nic,vlan=1$nic_model,macaddr=00:02:36:22:13:6c \ #-net tap,ifname=tap1,vlan=1,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \ - set -x + #set -x do_sudo -E /usr/bin/$qemu_exe \ -net nic,vlan=0$nic_model$macaddr \ -net tap,ifname=tap0,vlan=0,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \ @@ -124,6 +128,7 @@ boot() ) #do_sudo /sbin/modprobe kvm-intel + tmp_files="$tmp_files $tmpdir" xhost + case $1 in @@ -134,15 +139,14 @@ boot() boot_image "$@" ;; esac - - rm -rf $tmpdir } # -- here we go -log running $0 $@ - myname=`basename $0` +log_delim="===========================" +log running $0 $@ +[ -x $0 ] || fatal "$0 is not executable" exe=`readlink -f $0` dirname=`dirname $exe` bridge=priv0 @@ -191,7 +195,7 @@ shift $(($OPTIND - 1)) case $myname in *ifup*) - set -x + #set -x #[ "$1" = tap1 ] || exit 0 #do_sudo /sbin/ifconfig tap1 up #do_sudo $brctl addif in1 tap0 @@ -200,6 +204,7 @@ case $myname in #exit 0 virt_if=$1 + touch /tmp/i-ran-$myname do_sudo /sbin/ifconfig $virt_if up # this is most certainly always priv0 do_sudo $brctl addif $bridge $virt_if