diff options
author | Jamie McClelland <jm@mayfirst.org> | 2009-10-08 20:51:38 -0400 |
---|---|---|
committer | Jamie McClelland <jm@mayfirst.org> | 2009-10-08 20:51:38 -0400 |
commit | ee9143ff857acfc34caa7dda078017d4a29b1891 (patch) | |
tree | 83f061dc62277d7c2b3a4ebf7e182dcf282aead2 /kvm-creator | |
parent | 3f4c4b22ee9a37a4ef9de51a7e830ae8b923dd28 (diff) | |
download | kvm-manager-ee9143ff857acfc34caa7dda078017d4a29b1891.tar.gz kvm-manager-ee9143ff857acfc34caa7dda078017d4a29b1891.tar.bz2 |
ensure that /etc/sv/kvm/* exists before trying to get default
values from it.
Diffstat (limited to 'kvm-creator')
-rwxr-xr-x | kvm-creator | 21 |
1 files changed, 18 insertions, 3 deletions
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 <dkg@fifthhorseman.net> # 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" |