diskimage-builder/lib/common-functions

45 lines
1.2 KiB
Text

function mk_build_dir () {
export TMP_BUILD_DIR=$(mktemp -t -d image.XXXXXXXX)
[ $? -eq 0 ] || die "Failed to create tmp directory"
trap cleanup EXIT
echo Building in $TMP_BUILD_DIR
export TMP_IMAGE_PATH=$TMP_BUILD_DIR/image
export TMP_HOOKS_PATH=$TMP_BUILD_DIR/hooks
}
function save_image () {
# TODO: this really should rename the old file
if [ -f $1 ] ; then
echo "Old Image file Found REMOVING"
rm -f $1
fi
cp $TMP_IMAGE_PATH $1
rm -r $TMP_BUILD_DIR
# All done!
trap EXIT
echo "Image file $1 created..."
}
function generate_hooks () {
mkdir -p $TMP_HOOKS_PATH
for _FLAVOUR in $IMAGE_FLAVOUR ; do
[ -d $FLAVOURS_DIR/$_FLAVOUR ] || die "The flavour does not exist." ;
cp -t $TMP_HOOKS_PATH -a $FLAVOURS_DIR/$_FLAVOUR/* ;
done
}
# Check that a real flavour has been chosen (prevents foot-guns)
function check_flavour () {
[ -d $TMP_HOOKS_PATH ] || generate_hooks
}
# Run a hook, looking for a regex in its stdout, and eval the matched lines.
# $1 is the hook to run
# $2 is the regex to look for
function eval_run_d () {
local TEMP=`run_d $1`
echo "$TEMP"
TEMP=`echo "$TEMP" | grep "$2"`
eval "$TEMP"
}