#!/bin/bash # https://github.com/kraxel/imagefish ###################################################################### # defaults iso="" img="" cfg="" ###################################################################### # create work dir function msg() { local txt="$1" local bold="\x1b[1m" local normal="\x1b[0m" echo -e "${bold}### ${txt}${normal}" } function do_cleanup() { msg "cleaning up ..." if test "$GUESTFISH_PID" != ""; then guestfish --remote -- exit >/dev/null 2>&1 || true fi sudo rm -rf "$WORK" } WORK="${TMPDIR-/var/tmp}/${0##*/}-$$" mkdir "$WORK" || exit 1 trap 'do_cleanup' EXIT BASE="$(dirname $0)" ###################################################################### # parse args function print_help() { cat < --img --cfg EOF } while test "$1" != ""; do case "$1" in --iso) iso="$2" shift; shift ;; --img) img="$2" shift; shift ;; --cfg) cfg="$2" shift; shift ;; esac done ###################################################################### # guestfish script helpers function fish() { echo "#" "$@" guestfish --remote -- "$@" || exit 1 } function fish_init() { local format case "$img" in *.raw) format="raw" ;; *) format="qcow2";; esac msg "creating and adding disk image" fish disk-create $img $format 256M fish add $img fish run } function fish_fini() { fish umount-all } ###################################################################### # sanity checks if test ! -f "$iso"; then echo "ERROR: iso not found: $iso" exit 1 fi if test ! -f "$cfg"; then echo "ERROR: cfg not found: $cfg" exit 1 fi if test -f "$img"; then if test "$allow_override" = "yes"; then rm -f "$img" else echo "ERROR: image exists: $img" exit 1 fi fi ###################################################################### # go! msg "copy files from iso" guestfish -a "$iso" -m "/dev/sda:/:norock" <