dib-run-parts: stop leaving PROFILE_DIR behind
When a build fails, we can exit and leave ${PROFILE_DIR} behind. Make sure this is cleaned up with an exit trap. While we're adding a function, update the syntax of the others for consistency. Change-Id: I14499b5ebaaa30126aaa6b3d1bd86ed64f110fda
This commit is contained in:
parent
d7becbeb2b
commit
7c8e9f8733
@ -23,7 +23,7 @@ set -o pipefail
|
|||||||
|
|
||||||
name=$(basename $0)
|
name=$(basename $0)
|
||||||
|
|
||||||
usage() {
|
function usage {
|
||||||
echo "Usage: $name [OPTION] scripts_directory"
|
echo "Usage: $name [OPTION] scripts_directory"
|
||||||
echo "Option:"
|
echo "Option:"
|
||||||
echo " --list print names of all valid files"
|
echo " --list print names of all valid files"
|
||||||
@ -35,25 +35,29 @@ usage() {
|
|||||||
} >&2
|
} >&2
|
||||||
|
|
||||||
|
|
||||||
output_prefix() {
|
function output_prefix {
|
||||||
printf "%s " "${name}" >&2
|
printf "%s " "${name}" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
output () {
|
function output {
|
||||||
output_prefix
|
output_prefix
|
||||||
echo $* >&2
|
echo $* >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
output_printf () {
|
function output_printf {
|
||||||
local FORMAT="$1"
|
local FORMAT="$1"
|
||||||
shift
|
shift
|
||||||
output_prefix
|
output_prefix
|
||||||
printf "${FORMAT}" $@ >&2
|
printf "${FORMAT}" $@ >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cleanup {
|
||||||
|
rm -rf ${PROFILE_DIR}
|
||||||
|
}
|
||||||
|
|
||||||
# source the environment files from environment.d
|
# source the environment files from environment.d
|
||||||
# arg : target_dir
|
# arg : target_dir
|
||||||
source_environment() {
|
function source_environment {
|
||||||
|
|
||||||
local dir=$target_dir/../environment.d
|
local dir=$target_dir/../environment.d
|
||||||
local env_files
|
local env_files
|
||||||
@ -118,6 +122,7 @@ if [ ${DIB_DEBUG_TRACE} -gt 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
PROFILE_DIR=$(mktemp -d --tmpdir profiledir.XXXXXX)
|
PROFILE_DIR=$(mktemp -d --tmpdir profiledir.XXXXXX)
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
# note, run this in a sub-shell so we don't pollute our
|
# note, run this in a sub-shell so we don't pollute our
|
||||||
# own environment with source_environment
|
# own environment with source_environment
|
||||||
|
Loading…
Reference in New Issue
Block a user