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 }