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() goodbye()
{ {
rm -f $tmp_files :
# rm -f $tmp_files
} }
usage() usage()
@ -19,17 +20,19 @@ EOT
log() log()
{ {
echo "=========================== $*" echo "$log_delim $*"
/usr/bin/logger -t "$myname" "$*"
} }
err() err()
{ {
echo $* >&2 echo "$log_delim $*" >&2
/usr/bin/logger -t "$myname" "$*"
} }
fatal() fatal()
{ {
err $@ err "Fatal: $@ ... giving up"
exit 1 exit 1
} }
@ -37,10 +40,11 @@ do_sudo()
{ {
if [ "$UID" = 0 ]; then if [ "$UID" = 0 ]; then
while [[ $1 =~ ^- ]]; do shift; done while [[ $1 =~ ^- ]]; do shift; done
log running $@
eval "$@" eval "$@"
return $? return $?
else else
echo running sudo $@ log running sudo $@
#sudo -p "Password for $myname:" $@ #sudo -p "Password for $myname:" $@
eval sudo "$@" eval sudo "$@"
return $? return $?
@ -65,7 +69,7 @@ boot_net()
{ {
local mac local mac
[ "$hostname" ] && { [ "$hostname" ] && {
set -x #set -x
mac=`ldap_search -LLL "(cn=$short_hostname) dhcpHWAddress" | mac=`ldap_search -LLL "(cn=$short_hostname) dhcpHWAddress" |
sed '/dhcpHWAddress:/ !d; s/dhcpHWAddress: ethernet *//'` sed '/dhcpHWAddress:/ !d; s/dhcpHWAddress: ethernet *//'`
macaddr=",macaddr=$mac" macaddr=",macaddr=$mac"
@ -106,7 +110,7 @@ boot_image()
#-net nic,vlan=1$nic_model,macaddr=00:02:36:22:13:6c \ #-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 \ #-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 \ do_sudo -E /usr/bin/$qemu_exe \
-net nic,vlan=0$nic_model$macaddr \ -net nic,vlan=0$nic_model$macaddr \
-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 \
@ -124,6 +128,7 @@ boot()
) )
#do_sudo /sbin/modprobe kvm-intel #do_sudo /sbin/modprobe kvm-intel
tmp_files="$tmp_files $tmpdir"
xhost + xhost +
case $1 in case $1 in
@ -134,15 +139,14 @@ boot()
boot_image "$@" boot_image "$@"
;; ;;
esac esac
rm -rf $tmpdir
} }
# -- here we go # -- here we go
log running $0 $@
myname=`basename $0` myname=`basename $0`
log_delim="==========================="
log running $0 $@
[ -x $0 ] || fatal "$0 is not executable"
exe=`readlink -f $0` exe=`readlink -f $0`
dirname=`dirname $exe` dirname=`dirname $exe`
bridge=priv0 bridge=priv0
@ -191,7 +195,7 @@ shift $(($OPTIND - 1))
case $myname in case $myname in
*ifup*) *ifup*)
set -x #set -x
#[ "$1" = tap1 ] || exit 0 #[ "$1" = tap1 ] || exit 0
#do_sudo /sbin/ifconfig tap1 up #do_sudo /sbin/ifconfig tap1 up
#do_sudo $brctl addif in1 tap0 #do_sudo $brctl addif in1 tap0
@ -200,6 +204,7 @@ case $myname in
#exit 0 #exit 0
virt_if=$1 virt_if=$1
touch /tmp/i-ran-$myname
do_sudo /sbin/ifconfig $virt_if up do_sudo /sbin/ifconfig $virt_if up
# this is most certainly always priv0 # this is most certainly always priv0
do_sudo $brctl addif $bridge $virt_if do_sudo $brctl addif $bridge $virt_if