Skip to content

Commit 97a46e2

Browse files
committed
Suppress most log messages unless debug
1 parent c721923 commit 97a46e2

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

lib.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ function execute_install_script {
2020
local package_name=$(basename ${2} | awk -F\= '{print $1}')
2121
local install_script_filepath=$(\
2222
get_install_script_filepath "${1}" "${package_name}" "${3}")
23+
echocmd=""
2324
if test ! -z "${install_script_filepath}"; then
24-
log "- Executing ${install_script_filepath}..."
25+
if [ "${debug}" == "true" ] ; then
26+
log "- Executing ${install_script_filepath}..."
27+
echocmd="-x"
28+
fi
2529
# Don't abort on errors; dpkg-trigger may error normally since it is
2630
# outside its run environment. We'll set DPKG_MAINTSCRIPT_NAME though
2731
# to increase the odds of success.
28-
sudo DPKG_MAINTSCRIPT_NAME="${3}" sh -x "${install_script_filepath}" "${4}" || true
29-
log " done"
32+
sudo DPKG_MAINTSCRIPT_NAME="${3}" sh ${echocmd} "${install_script_filepath}" "${4}" || true
33+
log_debug " done"
3034
fi
3135
}
3236

@@ -175,6 +179,7 @@ function log { echo "${@}"; }
175179
function log_err { >&2 echo "${@}"; }
176180

177181
function log_empty_line { echo ""; }
182+
function log_debug { test "${debug}" == "true" && echo "${@}" || : ; }
178183

179184
###############################################################################
180185
# Validates an argument to be of a boolean value.

pre_cache_action.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ log "done"
4242
# Create cache directory so artifacts can be saved.
4343
mkdir -p ${cache_dir}
4444

45-
log "Validating action arguments (version='${version}', packages='${packages}')...";
45+
log_debug "Validating action arguments (version='${version}', packages='${packages}')...";
4646
if grep -q " " <<< "${version}"; then
4747
log "aborted"
4848
log "Version value '${version}' cannot contain spaces." >&2
@@ -115,7 +115,7 @@ if [ "${cpu_arch}" != "x86_64" ]; then
115115
log "- Architecture '${cpu_arch}' added to value."
116116
fi
117117

118-
log "- Value to hash is '${value}'."
118+
log_debug "- Value to hash is '${value}'."
119119

120120
key="$(echo "${value}" | md5sum | cut -f1 -d' ')"
121121
log "- Value hashed as '${key}'."

restore_pkgs.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,20 @@ execute_install_scripts="${3}"
2525

2626
cache_filepaths="$(ls -1 "${cache_dir}" | sort)"
2727
log "Found $(echo ${cache_filepaths} | wc -w) files in the cache."
28-
for cache_filepath in ${cache_filepaths}; do
29-
log "- "$(basename ${cache_filepath})""
30-
done
28+
if test "${debug}" == "true" ; then
29+
for cache_filepath in ${cache_filepaths}; do
30+
log "- $(basename ${cache_filepath})"
31+
done
32+
fi
3133

3234
log_empty_line
3335

3436
log "Reading from main requested packages manifest..."
35-
for logline in $(cat "${cache_dir}/manifest_main.log" | tr ',' '\n' ); do
36-
log "- $(echo "${logline}" | tr ':' ' ')"
37-
done
37+
if test "${debug}" == "true" ; then
38+
for logline in $(cat "${cache_dir}/manifest_main.log" | tr ',' '\n' ); do
39+
log "- $(echo "${logline}" | tr ':' ' ')"
40+
done
41+
fi
3842
log "done"
3943

4044
log_empty_line
@@ -53,7 +57,7 @@ restore_dpkg_status() {
5357

5458
for package in "${packages[@]}"; do
5559
cached_filepath="${cache_dir}/${package}.tar"
56-
log "- ${package} restoring..."
60+
log_debug "- ${package} restoring..."
5761
sudo tar -xf "${cached_filepath}" -C "${cache_restore_root}" > /dev/null
5862

5963
package_name="${package%%=*}"
@@ -62,7 +66,7 @@ for package in "${packages[@]}"; do
6266
else
6367
log "Status file ${cache_restore_root}/var/tmp/dpkg-restore/${package_name}.status not found"
6468
fi
65-
log " done"
69+
log_debug " done"
6670

6771
# Execute install scripts if available.
6872
if test ${execute_install_scripts} == "true"; then

0 commit comments

Comments
 (0)