scripts/functions
changeset 2155 5374ab57d331
parent 2154 250cdcc86441
child 2203 ac3e215141a1
     1.1 --- a/scripts/functions	Fri Oct 22 22:02:57 2010 +0200
     1.2 +++ b/scripts/functions	Fri Oct 22 22:02:49 2010 +0200
     1.3 @@ -1,4 +1,4 @@
     1.4 -# This file contains some usefull common functions
     1.5 +# This file contains some usefull common functions -*- sh -*-
     1.6  # Copyright 2007 Yann E. MORIN
     1.7  # Licensed under the GPL v2. See COPYING in the root of this package
     1.8  
     1.9 @@ -51,8 +51,9 @@
    1.10  CT_LOG_LEVEL_EXTRA=3
    1.11  CT_LOG_LEVEL_CFG=4
    1.12  CT_LOG_LEVEL_FILE=5
    1.13 -CT_LOG_LEVEL_ALL=6
    1.14 -CT_LOG_LEVEL_DEBUG=7
    1.15 +CT_LOG_LEVEL_STATE=6
    1.16 +CT_LOG_LEVEL_ALL=7
    1.17 +CT_LOG_LEVEL_DEBUG=8
    1.18  
    1.19  # Make it easy to use \n and !
    1.20  CR=$(printf "\n")
    1.21 @@ -64,10 +65,11 @@
    1.22  #   - WARN:    A non fatal, non serious error occurred, take your responsbility with the generated build
    1.23  #   - INFO:    Informational messages
    1.24  #   - EXTRA:   Extra informational messages
    1.25 -#   - DEBUG:   Debug messages
    1.26  #   - CFG:     Output of various "./configure"-type scripts
    1.27  #   - FILE:    File / archive unpacking.
    1.28 +#   - STATE:   State save & restore
    1.29  #   - ALL:     Component's build messages
    1.30 +#   - DEBUG:   Internal debug messages
    1.31  # Usage: CT_DoLog <level> [message]
    1.32  # If message is empty, then stdin will be logged.
    1.33  CT_DoLog() {
    1.34 @@ -961,15 +963,15 @@
    1.35          CT_DoLog DEBUG "  Saving '${dir}'"
    1.36          { tar c -C "${dir}" -v -f - "${extra_tar_opts[@]}" .    \
    1.37            |"${compress[@]}" >"${tarball}.tar${tar_ext}"         ;
    1.38 -        } 2>&1 |sed -r -e 's/^/    /;' |CT_DoLog DEBUG
    1.39 +        } 2>&1 |sed -r -e 's/^/    /;' |CT_DoLog STATE
    1.40      else
    1.41 -        CT_DoLog DEBUG "  Not saving '${dir}': does not exist"
    1.42 +        CT_DoLog STATE "  Not saving '${dir}': does not exist"
    1.43      fi
    1.44  }
    1.45  
    1.46  # This function extracts a tarball to the specified directory, but
    1.47  # only if the tarball exists
    1.48 -# Usage: CT_DoTarballIfExists <tarball_basename> <dir> [extra_tar_options [...]]
    1.49 +# Usage: CT_DoExtractTarballIfExists <tarball_basename> <dir> [extra_tar_options [...]]
    1.50  CT_DoExtractTarballIfExists() {
    1.51      local tarball="$1"
    1.52      local dir="$2"
    1.53 @@ -988,9 +990,9 @@
    1.54          CT_DoExecLog DEBUG mkdir -p "${dir}"
    1.55          { "${uncompress[@]}" "${tarball}.tar${tar_ext}"     \
    1.56            |tar x -C "${dir}" -v -f - "${extra_tar_opts[@]}" ;
    1.57 -        } 2>&1 |sed -r -e 's/^/    /;' |CT_DoLog DEBUG
    1.58 +        } 2>&1 |sed -r -e 's/^/    /;' |CT_DoLog STATE
    1.59      else
    1.60 -        CT_DoLog DEBUG "  Not restoring '${dir}': does not exist"
    1.61 +        CT_DoLog STATE "  Not restoring '${dir}': does not exist"
    1.62      fi
    1.63  }
    1.64  
    1.65 @@ -1008,7 +1010,7 @@
    1.66      rm -rf "${state_dir}"
    1.67      mkdir -p "${state_dir}"
    1.68  
    1.69 -    CT_DoLog DEBUG "  Saving environment and aliases"
    1.70 +    CT_DoLog STATE "  Saving environment and aliases"
    1.71      # We must omit shell functions, and some specific bash variables
    1.72      # that break when restoring the environment, later. We could do
    1.73      # all the processing in the awk script, but a sed is easier...
    1.74 @@ -1030,7 +1032,7 @@
    1.75      CT_DoTarballIfExists "${CT_PREFIX_DIR}" "${state_dir}/prefix_dir" --exclude '*.log'
    1.76  
    1.77      if [ "${CT_LOG_TO_FILE}" = "y" ]; then
    1.78 -        CT_DoLog DEBUG "  Saving log file"
    1.79 +        CT_DoLog STATE "  Saving log file"
    1.80          exec >/dev/null
    1.81          case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
    1.82              y)  gzip -3 -c "${CT_LOG_FILE}"  >"${state_dir}/log.gz";;
    1.83 @@ -1068,7 +1070,7 @@
    1.84  
    1.85      # Restore the environment, discarding any error message
    1.86      # (for example, read-only bash internals)
    1.87 -    CT_DoLog DEBUG "  Restoring environment"
    1.88 +    CT_DoLog STATE "  Restoring environment"
    1.89      . "${state_dir}/env.sh" >/dev/null 2>&1 || true
    1.90  
    1.91      # Restore the new RESTART and STOP steps
    1.92 @@ -1077,7 +1079,7 @@
    1.93      unset old_stop old_restart
    1.94  
    1.95      if [ "${CT_LOG_TO_FILE}" = "y" ]; then
    1.96 -        CT_DoLog DEBUG "  Restoring log file"
    1.97 +        CT_DoLog STATE "  Restoring log file"
    1.98          exec >/dev/null
    1.99          case "${CT_DEBUG_CT_SAVE_STEPS_GZIP}" in
   1.100              y)  zcat "${state_dir}/log.gz" >"${CT_LOG_FILE}";;