# Copyright 2012 Hewlett-Packard Development Company, L.P. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. 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" if [ `echo "$TEMP" | grep -s "$2"` ]; then TEMP=`echo "$TEMP" | grep "$2"` eval "$TEMP" fi }