diff --git a/roles/lmn_vm/files/sync-vm.sh b/roles/lmn_vm/files/sync-vm.sh index 4e896dc..3d92482 100755 --- a/roles/lmn_vm/files/sync-vm.sh +++ b/roles/lmn_vm/files/sync-vm.sh @@ -50,12 +50,18 @@ upload_image() { } download_image() { - rsync -av --password-file=/etc/rsync.secret \ + if [[ -f "/var/lib/libvirt/images/${VM_NAME}.qcow2.torrent" ]]; then + cd /var/lib/libvirt/images + ctorrent -e 0 "${VM_NAME}.qcow2.torrent" + /usr/local/bin/vmimage-torrent restart "${VM_NAME}.qcow2" + else + rsync -av --password-file=/etc/rsync.secret \ "rsync://vmuser@server:/vmimages-download/${VM_NAME}.qcow2" \ /var/lib/libvirt/images/ - rsync -av --password-file=/etc/rsync.secret \ + rsync -av --password-file=/etc/rsync.secret \ "rsync://vmuser@server:/vmimages-download/xml/${VM_NAME}.xml" \ /var/lib/libvirt/images/xml/ + fi } sync_all_images() { @@ -72,7 +78,7 @@ sync_all_torrents() { /var/lib/libvirt/images/ } -while getopts ':u:d:a:t' OPTION; do +while getopts ':u:d:at' OPTION; do case "$OPTION" in u) VM_NAME=$OPTARG