Skip time consuming VM syncing during installation, cleanup.

This commit is contained in:
Andreas B. Mundt 2023-02-18 10:00:23 +01:00
parent 354075f530
commit cb9f5fdb23
3 changed files with 14 additions and 16 deletions

View file

@ -9,7 +9,7 @@ This script takes as input the name of the VM to rebase one level down
-n new name of the rebased image
EOF
}
while getopts ':n:' OPTION; do
case "$OPTION" in
n)
@ -21,10 +21,10 @@ while getopts ':n:' OPTION; do
;;
esac
done
shift "$((OPTIND -1))"
# if less or more than one arguments supplied, display usage
# if less or more than one arguments supplied, display usage
if [[ $# -ne 1 ]]; then
show_help
exit 1
@ -51,7 +51,7 @@ NUMBASES=$(qemu-img info --backing-chain "${VM_NAME}.qcow2" | grep -c image)
NEWBASE=$(qemu-img info --backing-chain "${VM_NAME}.qcow2" | grep image | head -n 3 | tail -n 1 | cut -d' ' -f2)
CURRENTBASE=$(qemu-img info --backing-chain "${VM_NAME}.qcow2" | grep image | head -n 2 | tail -n 1 | cut -d' ' -f2)
if [[ ! "${NUMBASES}" -ge 3 ]]; then
if [[ ! "${NUMBASES}" -ge 3 ]]; then
echo "Image must have at least 2 backing-files"
exit 1
fi
@ -64,7 +64,7 @@ fi
# rebasing disk image
qemu-img rebase -f qcow2 -b "${NEWBASE}" -F qcow2 "${VM_NAME}.qcow2"
if [[ -v NEWNAME ]]; then
if [[ -v NEWNAME ]]; then
# copy and adapt machine definition file
CURRENTNAME="${CURRENTBASE/.qcow2/}"
cp "xml/${CURRENTNAME}.xml" "xml/${NEWNAME}.xml"