#!/bin/bash #set -x set -e function usage() { cat < /dev/null; then echo "Error: virt-install is not installed" exit 1 fi libvirt_dir=/var/lib/libvirt/images img_name=$NAME tmpdir=$(mktemp -d /tmp/virt-install_XXXXX) tmp_ks_file=$tmpdir/$img_name.ks function cleanup() { set +e [[ -d "$tmpdir" ]] && rm -fr "$tmpdir" local destroy_kvm=n [[ -f "/etc/libvirt/qemu/$img_name.xml" ]] && read -p "Destroy libvirt VM (y/n)? " destroy_kvm if [[ "$destroy_kvm" != n* ]]; then virsh destroy $img_name virsh undefine $img_name virsh vol-delete $img_name.img --pool default $sudo rm -f $libvirt_dir/$img_name.img fi } trap cleanup EXIT ruby <