Show tracing around sourcing environment.d files

Sourcing of environment files is a bit different than running scripts,
because they are imported into the current environment.  That means
that if they are fiddling with "set -x" you can get odd things in the
output -- for example, if one environment file enables tracing then
all proceeding sourcing will have it on, but all the files sourced
before will not have output.  This is super confusing.

It's also very helpful to see how things are being expanded as they
set environment variables.

Thus I think the best idea is for environment files to leave tracing
alone and dib-run-parts can a) give a useful output about what file it
is sourcing and b) enable tracing around the import, then restore it
to the previous state afterwards.

Change-Id: I29f7df1514aeb988222d1094e8269eddb485c2a0
changes/68/388968/1 0.0.11
Ian Wienand 6 years ago
parent 67fc832177
commit 51661c33a5
  1. 7

@ -57,13 +57,20 @@ source_environment() {
local dir=$target_dir/../environment.d
local env_files
local xtrace
if [ -d ${dir} ] ; then
env_files=$(find ${dir} -maxdepth 1 -xtype f | \
grep -E "/[0-9A-Za-z_\.-]+$" | \
LANG=C sort -n)
for env_file in $env_files ; do
output "Sourcing environment file ${env_file}"
# Set tracing as we import these environment files; it's
# nice to see the definitions in the logs
xtrace=$(set +o | grep xtrace)
set -o xtrace
source $env_file