download necessary qcow2-files automatically

This commit is contained in:
Raphael Dannecker 2023-07-18 13:19:45 +02:00
parent 406b79bec4
commit b7a0c9fa30
2 changed files with 54 additions and 3 deletions

View file

@ -48,14 +48,40 @@ if [[ $# -ne 1 ]] ; then
exit 1
fi
# sync vm-torrents and machine definition file
sudo /usr/local/bin/sync-vm.sh -t
VM_NAME=$1
VM_DIR="/tmp/${UID}/vmimages"
if [[ ! -f "/var/lib/libvirt/images/${VM_NAME}.qcow2" && ! -f "${VM_DIR}/${VM_NAME}.qcow2" ]]; then
echo "no base VM disk '${VM_NAME}.qcow2' found" >&2
exit 1
if [[ ! -f "/var/lib/libvirt/images/${VM_NAME}.qcow2.torrent" ]]; then
echo "no base VM disk '${VM_NAME}.qcow2' found and/or ${VM_NAME} not found on server" >&2
exit 1
fi
# sync vm-disk image by torrent
sudo /usr/local/bin/sync-vm.sh "${VM_NAME}"
echo "sudo /usr/local/bin/sync-vm.sh ${VM_NAME}"
fi
echo "qcow2 seems to be available"
imgfile="/var/lib/libvirt/images/${VM_NAME}.qcow2" && [[ -f "${VM_DIR}/${VM_NAME}.qcow2" ]] && imgfile="${VM_DIR}/${VM_NAME}.qcow2"
#backingfile=$(qemu-img info -U "${imgfile}" | grep ^image: | cut -d' ' -f2)
backingfile=$(qemu-img info -U "${imgfile}" | grep "^backing file:" | cut -d ' ' -f 3)
while [[ ! -z "${backingfile}" ]]; do
echo $backingfile
if [[ ! -f "/var/lib/libvirt/images/${backingfile}" && ! -f "${VM_DIR}/${backingfile}" ]]; then
# sync vm-disk image by torrent
sudo /usr/local/bin/sync-vm.sh "${backingfile//.qcow2/}"
echo "sudo /usr/local/bin/sync-vm.sh ${backingfile//.qcow2/}"
fi
imgfile="/var/lib/libvirt/images/${backingfile}" && [[ -f "${VM_DIR}/${backingfile}" ]] && imgfile="${VM_DIR}/${backingfile}"
backingfile=$(qemu-img info -U "${imgfile}" | grep "^backing file:" | cut -d ' ' -f 3)
done
# check, if we have to start squid
if ! killall -s 0 squid; then
echo "starting squid."