qemu-boot.sh: Beautify logging

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2017-04-20 13:05:49 +00:00
commit 66865574a1

View file

@ -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