Skip to content

Commit 690d585

Browse files
committed
Suppress detailed log messages unless debug is enabled
1 parent 539c354 commit 690d585

4 files changed

Lines changed: 33 additions & 22 deletions

File tree

install_and_cache_pkgs.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ log "Clean installing and caching ${package_count} package(s)."
5959
log_empty_line
6060

6161
manifest_main=""
62-
log "Package list:"
62+
log_debug "Package list:"
6363
for package in ${packages}; do
6464
manifest_main="${manifest_main}${package},"
65-
log "- ${package}"
65+
log_debug "- ${package}"
6666
done
6767
write_manifest "main" "${manifest_main}" "${cache_dir}/manifest_main.log"
6868

@@ -92,11 +92,13 @@ log "Installation log written to ${install_log_filepath}"
9292
log_empty_line
9393

9494
installed_packages=$(get_installed_packages "${install_log_filepath}")
95-
log "Installed package list:"
96-
for installed_package in ${installed_packages}; do
97-
# Reformat for human friendly reading.
98-
log "- $(echo ${installed_package} | awk -F\= '{print $1" ("$2")"}')"
99-
done
95+
if [ "${debug}" == "true" ] ; then
96+
log "Installed package list:"
97+
for installed_package in ${installed_packages}; do
98+
# Reformat for human friendly reading.
99+
log "- $(echo ${installed_package} | awk -F\= '{print $1" ("$2")"}')"
100+
done
101+
fi
100102

101103
log_empty_line
102104

@@ -108,7 +110,7 @@ for installed_package in ${installed_packages}; do
108110
# Sanity test in case APT enumerates duplicates.
109111
if test ! -f "${cache_filepath}"; then
110112
read package_name package_ver < <(get_package_name_ver "${installed_package}")
111-
log " * Caching ${package_name} to ${cache_filepath}..."
113+
log_debug " * Caching ${package_name} to ${cache_filepath}..."
112114

113115
# Get the entry in /var/lib/dpkg/status
114116
mkdir -p /var/tmp/dpkg-restore || :
@@ -131,7 +133,7 @@ for installed_package in ${installed_packages}; do
131133
done
132134
)
133135

134-
log " done (compressed size $(du -h "${cache_filepath}" | cut -f1))."
136+
log_debug " done (compressed size $(du -h "${cache_filepath}" | cut -f1))."
135137
fi
136138

137139
# Comma delimited name:ver pairs in the all packages manifest.

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)