#!/bin/bash set -- $(getopt h?H:D?s:B:M:C:R:i:g:n:I:G:N: "$@") src_image="" size="1G" dhcp="no" hostname="default" bridge="br0" cpus="1" mem="1024" repo="https://yourhost/myproj-cosmos.git" tag="cosmos-ops" ip="" gateway="" netmask="" resolver="" ip6="" gateway6="" netmask6="64" while [ $# -gt 0 ]; do case "$1" in (-h) echo "Usage: $0 [-h] [-H hostname] [-M ] [-C <#cpus>] [-B ] [-D (dhcp)] [-i/-I ] [-n/-N ] [-g/-G ] [-R ] [-s ]"; exit 0;; (-H) hostname="$2"; shift;; (-s) src_image="$2"; shift;; (-D) dhcp="yes" ;; (-S) size="$2"; shift;; (-B) bridge="$2"; shift;; (-M) mem="$2"; shift;; (-C) cpus="$2"; shift;; (-R) resolver="$2"; shift;; (-i) ip="$2"; shift;; (-g) gateway="$2"; shift;; (-n) netmask="$2"; shift;; (-I) ip6="$2"; shift;; (-G) gateway6="$2"; shift;; (-N) netmask6="$2"; shift;; (--) shift; break;; (-*) echo "Unknown option $1\nUsage: $0 [-h] [-H hostname] [-M ] [-C <#cpus>] [-B ] [-D (dhcp)] [-i/-I ] [-n/-N ] [-g/-G ] [-R ] [-s ]"; exit 1;; (*) break;; esac shift done id=$(uuidgen) seed=${id}_seed.img disk=${id}.img rm -f ${seed} truncate --size 2M ${seed} mkfs.vfat -n cidata ${seed} 2>/dev/null user_data=$(mktemp) cat > ${user_data} < ${meta_data} <> ${meta_data} <> ${meta_data} <> ${meta_data} </dev/null mcopy -i ${seed} ${meta_data} ::meta-data 2>/dev/null mcopy -i ${seed} /etc/cosmos/apt/bootstrap-cosmos.sh /etc/cosmos/apt/cosmos_1.2-2_all.deb :: mv ${seed} /var/lib/libvirt/images/ virsh pool-refresh default virsh vol-clone --pool default ${src_image} ${disk} virt-install -r ${mem} -n ${hostname} --vcpus=${cpus} --autostart --memballoon virtio --network bridge=${bridge} --boot hd --disk vol=default/${disk},format=qcow2,bus=virtio --disk vol=default/${seed},bus=virtio rm -f ${user_data} rm -f ${meta_data}