72 lines
2.3 KiB
Bash
Executable file
72 lines
2.3 KiB
Bash
Executable file
#!/usr/bin/bash
|
|
# Push VM-Disk-Image on server
|
|
set -eu
|
|
|
|
show_help() {
|
|
cat << EOF >&2
|
|
Usage: $(basename "$0") vmname"
|
|
Create torrent and upload disk and xml-VM-Definiton on server.
|
|
EOF
|
|
}
|
|
|
|
|
|
upload_image() {
|
|
# check if VM-Diskimage exists
|
|
if [[ ! (-f "${VM_SYSDIR}/${VM_NAME}.qcow2" || -f "${VM_DIR}/${VM_NAME}.qcow2") ]]; then
|
|
echo "File not found ${VM_NAME}.qcow2" >&2
|
|
exit 1
|
|
fi
|
|
# check if VM-Machine-Definition XML exists
|
|
if [[ ! (-f "${VM_SYSDIR}/${VM_NAME}.xml" || -f "${VM_DIR}/${VM_NAME}.xml") ]]; then
|
|
echo "File not found ${VM_NAME}.xml" >&2
|
|
exit 1
|
|
fi
|
|
sudo vm-aria2 stop "${VM_NAME}" || echo "VMImage-torrent not running"
|
|
# link private VM-Diskimage to system-Dir
|
|
if [[ -f "${VM_DIR}/${VM_NAME}.qcow2" \
|
|
&& ( -f "${VM_SYSDIR}/${VM_NAME}.qcow2" && ("${VM_DIR}/${VM_NAME}.qcow2" -nt "${VM_SYSDIR}/${VM_NAME}.qcow2") \
|
|
|| ! -f "${VM_SYSDIR}/${VM_NAME}.qcow2") ]]; then
|
|
echo "copy private VM-Diskimage to system-dir"
|
|
chown lmnsynci:lmnsynci "${VM_DIR}/${VM_NAME}.qcow2"
|
|
ln -f "${VM_DIR}/${VM_NAME}.qcow2" "${VM_SYSDIR}/${VM_NAME}.qcow2"
|
|
fi
|
|
# copy private VM-Maschine-Definition XML to system-Dir
|
|
if [[ -f "${VM_DIR}/${VM_NAME}.xml" \
|
|
&& ( -f "${VM_SYSDIR}/${VM_NAME}.xml" && $(cmp -s "${VM_DIR}/${VM_NAME}.xml" "${VM_SYSDIR}/${VM_NAME}.xml") \
|
|
|| ! -f "${VM_SYSDIR}/${VM_NAME}.xml") ]]; then
|
|
echo "copy private VM-Maschine-Definition XML to system-dir"
|
|
chown lmnsynci:lmnsynci "${VM_DIR}/${VM_NAME}.xml"
|
|
cp -a "${VM_DIR}/${VM_NAME}.xml" "${VM_SYSDIR}"
|
|
fi
|
|
cd "${VM_SYSDIR}"
|
|
uploadseed --server "${SEEDBOX_HOST}:${SEEDBOX_RPC_PORT}" --dht-port "${SEEDBOX_PORT}" \
|
|
--pwdfile "${SEEDBOX_PWFILE}" --no-cert "${VM_NAME}.qcow2"
|
|
uploadseed --server "${SEEDBOX_HOST}:${SEEDBOX_RPC_PORT}" --dht-port "${SEEDBOX_PORT}" \
|
|
--pwdfile "${SEEDBOX_PWFILE}" --no-cert "${VM_NAME}.xml"
|
|
}
|
|
|
|
source /etc/lmn/vm.conf
|
|
|
|
while getopts ':p' OPTION; do
|
|
case "$OPTION" in
|
|
p)
|
|
VM_DIR="${VM_DIR_PERSISTENT}"
|
|
;;
|
|
?)
|
|
show_help
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
shift "$((OPTIND -1))"
|
|
|
|
# if less than one arguments supplied, display usage
|
|
if [[ $# -ne 1 ]] ; then
|
|
show_help
|
|
exit 1
|
|
fi
|
|
|
|
VM_NAME=$1
|
|
|
|
upload_image
|