diff options
Diffstat (limited to 'virtualenv/virt')
-rwxr-xr-x | virtualenv/virt | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/virtualenv/virt b/virtualenv/virt index b88d04e..043589f 100755 --- a/virtualenv/virt +++ b/virtualenv/virt @@ -10,7 +10,7 @@ set -ue root=$(dirname "$0") -help() { +usage() { cat >&2 <<-EOF Usage: $0 install <libvirt domain> [<QEMU image>] @@ -41,7 +41,7 @@ isActive() { } install() { - [ $# -eq 1 -o $# -eq 2 ] || help + [ $# -eq 1 -o $# -eq 2 ] || usage local name=$1 local disk=${2:-$root/images/${name}.qcow2} @@ -103,7 +103,7 @@ install() { | sed '/^\s*$/d' \ | sort -n \ | tail -1 ) - [ -n "$ip" ] || \ + [ "$ip" ] || \ ip=$( /usr/bin/virsh net-dumpxml $network \ | /usr/bin/xmlstarlet sel -t -m /network/ip -v @address ) ip=${ip%.*}.$(( 1 + ${ip##*.} )) @@ -123,7 +123,7 @@ install() { } view(){ - [ $# -eq 1 ] || help + [ $# -eq 1 ] || usage local domain="$1" if ! doesExist "$domain"; then @@ -141,17 +141,18 @@ view(){ local type=$(get_XML_attribute "$domain" devices/graphics type) local port=$(get_XML_attribute "$domain" devices/graphics port) || true - if [ "$type" != spice -o -z "$port" ]; then + if ! [ "$type" = spice -a "$port" ]; then echo "Error: Could not find a valid Spice server on domain '$domain'." >&2 exit 1 fi /usr/bin/spicec -h 127.0.0.1 -p $port } -command="${1:-}" +[ $# -gt 0 ] || usage +command="$1" shift; case "$command" in install|view) $command "$@";; - *) help + *) usage esac |