From ee9143ff857acfc34caa7dda078017d4a29b1891 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Thu, 8 Oct 2009 20:51:38 -0400 Subject: ensure that /etc/sv/kvm/* exists before trying to get default values from it. --- kvm-creator | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'kvm-creator') diff --git a/kvm-creator b/kvm-creator index 7847198..b24c6f6 100755 --- a/kvm-creator +++ b/kvm-creator @@ -1,5 +1,5 @@ #!/bin/bash -set -x +#set -x # Author: Daniel Kahn Gillmor # Date: 2009-10-08 @@ -12,8 +12,21 @@ NAME="$1" VG="$2" SIZE="${3:-3G}" RAM="${4:-512}" -TAP="${5:-$(( $( cat /etc/sv/kvm/*/env/TAP | sed 's/^tap//' | sort -n | tail -n 1 ) + 1 ))}" -MAC="${6:-$(cat /etc/sv/kvm/*/env/MAC | head -n1 | cut -f 1-5 -d: ):$(( $( cat /etc/sv/kvm/*/env/MAC | cut -f 6 -d: | sort -n | tail -n 1 ) + 1 ))}" + +if [ ls /etc/sv/kvm/* &> /dev/null ]; then + TAP="${5:-$(( $( cat /etc/sv/kvm/*/env/TAP | sed 's/^tap//' | sort -n | tail -n 1 ) + 1 ))}" + MAC="${6:-$(cat /etc/sv/kvm/*/env/MAC | head -n1 | cut -f 1-5 -d: ):$(( $( cat /etc/sv/kvm/*/env/MAC | cut -f 6 -d: | sort -n | tail -n 1 ) + 1 ))}" +else + TAP=1 + MAC=:1 +fi + +die() { + echo "$1" + exit_code=1 + [ -n "$2" ] && exit_code="$2" + exit $exit_code +} destroy() { @@ -30,6 +43,8 @@ create() { # FIXME: check that this stuff doesn't exist yet: + [ -z "$NAME" ] && die "Please pass the name of the virtual server to create" + [ -z "$VG" ] && die "Please pass the name of the volume group to use" adduser "$NAME" --disabled-password --gecos "$NAME KVM user,,," mkdir "/home/$NAME/"{.ssh,vms,"vms/$NAME"} touch "/home/$NAME/vms/$NAME/netboot" -- cgit v1.2.3