download necessary qcow2-files automatically
This commit is contained in:
		
							parent
							
								
									406b79bec4
								
							
						
					
					
						commit
						b7a0c9fa30
					
				
					 2 changed files with 54 additions and 3 deletions
				
			
		| 
						 | 
					@ -48,13 +48,39 @@ if [[  $# -ne 1 ]] ; then
 | 
				
			||||||
    exit 1
 | 
					    exit 1
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# sync vm-torrents and machine definition file
 | 
				
			||||||
 | 
					sudo /usr/local/bin/sync-vm.sh -t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
VM_NAME=$1
 | 
					VM_NAME=$1
 | 
				
			||||||
VM_DIR="/tmp/${UID}/vmimages"
 | 
					VM_DIR="/tmp/${UID}/vmimages"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [[ ! -f "/var/lib/libvirt/images/${VM_NAME}.qcow2" && ! -f "${VM_DIR}/${VM_NAME}.qcow2" ]]; then
 | 
					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
 | 
					    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
 | 
					        exit 1
 | 
				
			||||||
    fi
 | 
					    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
 | 
					# check, if we have to start squid
 | 
				
			||||||
if ! killall -s 0 squid; then
 | 
					if ! killall -s 0 squid; then
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,6 +48,30 @@ sync_all_torrents() {
 | 
				
			||||||
	  /var/lib/libvirt/images/
 | 
						  /var/lib/libvirt/images/
 | 
				
			||||||
    rsync -av --password-file=/etc/rsync.secret rsync://vmuser@server:/vmimages-download/xml \
 | 
					    rsync -av --password-file=/etc/rsync.secret rsync://vmuser@server:/vmimages-download/xml \
 | 
				
			||||||
	  /var/lib/libvirt/images/
 | 
						  /var/lib/libvirt/images/
 | 
				
			||||||
 | 
					    rsync -av --password-file=/etc/rsync.secret rsync://vmuser@server:/vmimages-download/desktop/*.desktop \
 | 
				
			||||||
 | 
						  /usr/share/applications/
 | 
				
			||||||
 | 
					    update-desktop-database /usr/share/applications
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					create_starter() {
 | 
				
			||||||
 | 
					    if [[ ! -f "/usr/share/applications/VM_${VM_NAME}_starter.desktop" ]]; then 
 | 
				
			||||||
 | 
					        cat << EOF >"/usr/share/applications/VM_${VM_NAME}_starter.desktop"
 | 
				
			||||||
 | 
					[Desktop Entry]
 | 
				
			||||||
 | 
					Version=1.0
 | 
				
			||||||
 | 
					Type=Application
 | 
				
			||||||
 | 
					Name=VMstart: ${VM_NAME}
 | 
				
			||||||
 | 
					GenericName=VM starter ${VM_NAME}
 | 
				
			||||||
 | 
					Comment=Start VM ${VM_NAME}
 | 
				
			||||||
 | 
					#TryExec=konsole
 | 
				
			||||||
 | 
					Exec=/usr/local/bin/run-vm.sh ${VM_NAME}
 | 
				
			||||||
 | 
					Icon=clementine
 | 
				
			||||||
 | 
					Categories=VM;Engineering;
 | 
				
			||||||
 | 
					MimeType=image/vnd.dxf;
 | 
				
			||||||
 | 
					Keywords=design;VM;diagrams;graphics
 | 
				
			||||||
 | 
					Terminal=true
 | 
				
			||||||
 | 
					EOF
 | 
				
			||||||
 | 
					        update-desktop-database /usr/share/applications
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
while getopts ':dat' OPTION; do
 | 
					while getopts ':dat' OPTION; do
 | 
				
			||||||
| 
						 | 
					@ -57,10 +81,11 @@ while getopts ':dat' OPTION; do
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
        a)
 | 
					        a)
 | 
				
			||||||
            sync_all_images
 | 
					            sync_all_images
 | 
				
			||||||
            exit 1
 | 
					            exit 0
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
        t)
 | 
					        t)
 | 
				
			||||||
            sync_all_torrents
 | 
					            sync_all_torrents
 | 
				
			||||||
 | 
					            exit 0
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
        ?)
 | 
					        ?)
 | 
				
			||||||
            show_help
 | 
					            show_help
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue