Created
February 14, 2015 02:33
-
-
Save phaer/2cb58105661be034fa86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh -f | |
set -e | |
HOSTNAME=$1 | |
PASSWORD=toor | |
VMNAME=$HOSTNAME | |
FILE="$VMNAME.img" | |
SIZE=2G | |
ARCH=amd64 | |
MEMORY=2048 | |
CPUS=3 | |
DEBIAN_RELEASE=wheezy | |
DEBIAN_MIRROR=debian.inode.at/debian | |
function apt_cacher() { | |
aptitude install apt-cacher-ng | |
DEBIAN_MIRROR="http://localhost:$(cat /etc/apt-cacher-ng/acng.conf \ | |
| grep 'Port:' | cut -d ':' -f 2)/$DEBIAN_MIRROR" | |
} | |
function create_disk() { | |
qemu-img create -f qcow2 $FILE.qcow2 $SIZE | |
modprobe nbd | |
qemu-nbd -c /dev/nbd0 $FILE.qcow2 | |
} | |
function grml_debootstrap() { | |
grml-debootstrap \ | |
--hostname $HOSTNAME --password "$PASSWORD" \ | |
--vmfile --target $FILE --vmsize $SIZE \ | |
--arch $ARCH --release $DEBIAN_RELEASE \ | |
--mirror $DEBIAN_MIRROR | |
} | |
function install_vm() { | |
virt-install \ | |
--name=$VMNAME \ | |
--network network=default \ | |
--memory=$MEMORY --vcpus=$CPUS \ | |
--disk=$FILE --import \ | |
--graphics vnc \ | |
--noautoconsole | |
} | |
function get_ip() { | |
IP="" | |
until [ "$IP" ]; do | |
IP=$(virsh net-dhcp-leases default \ | |
| awk "{if (\$6 == \"$VMNAME\") print \$5}" \ | |
| cut -d "/" -f 1) | |
done | |
echo $IP | |
} | |
apt_cacher | |
grml_debootstrap | |
install_vm | |
echo "virsh start $VMNAME; ssh root@$(get_ip), password: $PASSWORD" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment