aboutsummaryrefslogtreecommitdiff
path: root/kvm-creator
diff options
context:
space:
mode:
authorJamie McClelland <jm@mayfirst.org>2009-10-09 11:43:55 -0400
committerJamie McClelland <jm@mayfirst.org>2009-10-09 11:43:55 -0400
commit5e6ae8672b32dce26f273af156f73d950a06c198 (patch)
tree017668de985099c31b0881a0ab7592b1e4cbc520 /kvm-creator
parentd08cb053ffe3392616cdcf8abf57b448db9c549d (diff)
downloadkvm-manager-5e6ae8672b32dce26f273af156f73d950a06c198.tar.gz
kvm-manager-5e6ae8672b32dce26f273af156f73d950a06c198.tar.bz2
more consistent lines spacing in functions and replaced my tabs with
spaces in the hopes of not making a mess in other text editors.
Diffstat (limited to 'kvm-creator')
-rwxr-xr-xkvm-creator57
1 files changed, 32 insertions, 25 deletions
diff --git a/kvm-creator b/kvm-creator
index eb7fb96..763b6b9 100755
--- a/kvm-creator
+++ b/kvm-creator
@@ -17,18 +17,20 @@ RAM="${4:-512}"
ls /etc/sv/kvm/* &> /dev/null
if [ "$?" -eq 0 ]; then
- TAP="${5:-tap$(( $( 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 ))}"
+ TAP="${5:-tap$(( $( 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=tap0
- MAC=00:00:00:00:00:00
+ TAP=tap0
+ MAC=00:00:00:00:00:00
fi
die() {
- echo "$1"
- exit_code=1
- [ -n "$2" ] && exit_code="$2"
- exit $exit_code
+
+ echo "$1"
+ exit_code=1
+ [ -n "$2" ] && exit_code="$2"
+ exit $exit_code
+
}
destroy() {
@@ -42,26 +44,29 @@ destroy() {
}
validate() {
- # Make sure none of the pieces already exist.
- [ -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"
- getent passwd "$NAME" > /dev/null
- [ "$?" -eq "0" ] && die "The username '$NAME' already exists."
- getent group "$NAME" > /dev/null
- [ "$?" -eq 0 ] && die "The group '$NAME' already exists."
- [ -d /home/"$NAME" ] && die "The directory '/home/$NAME' already exists."
- [ -d /etc/sv/kvm/"$NAME" ] && die "The directory '/etc/sv/kvm/$NAME' already exists."
- [ -d /dev/mapper/${VG}-${NAME} ] && die "The logical volume $NAME already exists."
+
+ # Make sure none of the pieces already exist.
+ [ -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"
+ getent passwd "$NAME" > /dev/null
+ [ "$?" -eq "0" ] && die "The username '$NAME' already exists."
+ getent group "$NAME" > /dev/null
+ [ "$?" -eq 0 ] && die "The group '$NAME' already exists."
+ [ -d /home/"$NAME" ] && die "The directory '/home/$NAME' already exists."
+ [ -d /etc/sv/kvm/"$NAME" ] && die "The directory '/etc/sv/kvm/$NAME' already exists."
+ [ -d /dev/mapper/${VG}-${NAME} ] && die "The logical volume $NAME already exists."
+
}
create() {
+
set -e
- validate
+ validate
adduser "$NAME" --disabled-password --gecos "$NAME KVM user,,,"
- addgroup "$NAME" kvm
- for dir in .ssh vms "vms/$NAME"; do
- [ ! -d "/home/$NAME/$dir" ] && mkdir "/home/$NAME/$dir"
- done
+ addgroup "$NAME" kvm
+ for dir in .ssh vms "vms/$NAME"; do
+ [ ! -d "/home/$NAME/$dir" ] && mkdir "/home/$NAME/$dir"
+ done
touch "/home/$NAME/vms/$NAME/netboot"
chown "$NAME:$NAME" "/home/$NAME/"{.ssh,vms,"vms/$NAME","vms/$NAME/netboot"}
cp /root/.ssh/authorized_keys "/home/$NAME/.ssh/"
@@ -95,10 +100,12 @@ EOF
}
demo() {
- validate
+
+ validate
for foo in NAME VG TAP RAM MAC SIZE ; do
- echo "$foo : ${!foo}"
+ echo "$foo : ${!foo}"
done
+
}
"$CMD"