Blame tests/scripts/build-image.sh
|
Petr Šabata |
f5bf49 |
#!/usr/bin/env bash
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
if [ $# -lt 2 ]; then
|
|
Petr Šabata |
f5bf49 |
echo "Usage: $(basename $0) <base-image> <output-image> <build-script> [<build-script-args>]
|
|
Petr Šabata |
f5bf49 |
Build a new <output-image> on top of <base-image>, and install
|
|
Petr Šabata |
f5bf49 |
contents defined in <build-script>. <args> are directly passed
|
|
Petr Šabata |
f5bf49 |
to <build-script>.
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
If <base-image> is raw, will copy it and create <output-image>
|
|
Petr Šabata |
f5bf49 |
in qcow2 format.
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
If <base-image> is qcow2, will create <output-image> as a snapshot
|
|
Petr Šabata |
f5bf49 |
on top of <base-image>"
|
|
Petr Šabata |
f5bf49 |
exit 1
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
BASEDIR=$(realpath $(dirname "$0"))
|
|
Petr Šabata |
f5bf49 |
. $BASEDIR/image-init-lib.sh
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
# Base image to build from
|
|
Petr Šabata |
f5bf49 |
BASE_IMAGE=$1 && shift
|
|
Petr Šabata |
f5bf49 |
if [[ ! -e $BASE_IMAGE ]]; then
|
|
Petr Šabata |
f5bf49 |
perror_exit "Base image '$BASE_IMAGE' not found"
|
|
Petr Šabata |
f5bf49 |
else
|
|
Petr Šabata |
f5bf49 |
BASE_IMAGE=$(realpath "$BASE_IMAGE")
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
OUTPUT_IMAGE=$1 && shift
|
|
Petr Šabata |
f5bf49 |
if [[ ! -d $(dirname $OUTPUT_IMAGE) ]]; then
|
|
Petr Šabata |
f5bf49 |
perror_exit "Path '$(dirname $OUTPUT_IMAGE)' doesn't exists"
|
|
Petr Šabata |
f5bf49 |
fi
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
INST_SCRIPT=$1 && shift
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
create_image_from_base_image $BASE_IMAGE $OUTPUT_IMAGE.building
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
mount_image $OUTPUT_IMAGE.building
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
img_inst() {
|
|
Petr Šabata |
f5bf49 |
inst_in_image $OUTPUT_IMAGE.building $@
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
img_inst_pkg() {
|
|
Petr Šabata |
f5bf49 |
inst_pkg_in_image $OUTPUT_IMAGE.building $@
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
img_run_cmd() {
|
|
Petr Šabata |
f5bf49 |
run_in_image $OUTPUT_IMAGE.building "$@"
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
img_add_qemu_cmd() {
|
|
Petr Šabata |
f5bf49 |
QEMU_CMD+="$@"
|
|
Petr Šabata |
f5bf49 |
}
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
[ -e "$INST_SCRIPT" ] && source $INST_SCRIPT
|
|
Petr Šabata |
f5bf49 |
|
|
Petr Šabata |
f5bf49 |
mv $OUTPUT_IMAGE.building $OUTPUT_IMAGE
|