Last active
January 6, 2016 09:52
-
-
Save fabiand/97aae986ef4c846fb7e3 to your computer and use it in GitHub Desktop.
Convenience script to modify the qcow image inside an RHEV OVA using guestfish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
err() { echo "ERROR $@" >&2 ; } | |
info() { echo "INFO $@" ; } | |
usage() { echo -e "Usage: $0 OVAFILENAME [<guestfish arguments>]\nExtracts the given OVA, runs guestfish on the image, and creates an OVA again after quitting guestfish." ; } | |
[[ ! -f "$1" ]] && { usage ; exit 1 ; } | |
OVA=$(realpath $1) | |
shift | |
TMPDIR=$(mktemp -d -p $PWD --suffix "-ova.d") | |
NEWOVA=${OVA%.ova}-$(date +%Y%m%d%H%M%S).ova | |
( # Try | |
set -e | |
cd "$TMPDIR" | |
info "Extracting OVA '$OVA' to '$TMPDIR' (this can take a while)" | |
tar xf "$OVA" | |
IMAGEFILE=$(ls -1 images/*/*.meta | sed "s/\.meta//") | |
info "Found image file '$IMAGEFILE', running guestfish" | |
info "Once you are done, exit guestfish and the new OVA will be generated" | |
guestfish --network -i -a "$IMAGEFILE" $@ | |
info "Wrapping up new OVA '$NEWOVA' (this can take a while)." | |
tar cvzSf "$NEWOVA" * | |
) | |
test $? -gt 0 && { # Except | |
err "Something failed" | |
err "Temporary files: $TMPDIR" | |
err "New OVA: $NEWOVA" | |
exit 1 | |
} | |
# Finally | |
rm -rf "$TMPDIR" | |
info "Old OVA: $OVA" | |
info "New OVA: $NEWOVA" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment