Hide messages away unless DEBUG is set to non-zero value.

master
Icedream 2018-02-19 09:37:47 +01:00
parent 9944474ae6
commit 922ce287d2
Signed by: icedream
GPG Key ID: 1573F6D8EFE4D0CF
1 changed files with 15 additions and 7 deletions

View File

@ -3,10 +3,18 @@
tag_file="$(mktemp)"
trap 'rm "${tag_file}"' EXIT
DEBUG="${DEBUG:-0}"
log() {
if [ "${DEBUG}" -gt 0 ]; then
printf "$@"
fi
}
add_tag() {
for tag in "$@"; do
if ! has_tags "$tag"; then
echo "Adding detected tag: $tag"
log "Adding detected tag: $tag\n"
echo "${tag}" >> "${tag_file}"
fi
done
@ -14,17 +22,17 @@ add_tag() {
has_tags() {
for req in "$@"; do
printf "Checking for tag: $req... "
log "Checking for tag: $req... "
detected=0
while IFS= read -r line; do
if [ "$line" = "$req" ]; then
echo "yes"
log "yes\n"
detected=1
break
fi
done < "$tag_file"
if [ "$detected" -eq 0 ]; then
echo "no"
log "no\n"
return 1
fi
done
@ -32,12 +40,12 @@ has_tags() {
}
has_binary() {
printf "Checking for binary: $1... "
log "Checking for binary: $1... "
if ! command -v "$1" >/dev/null 2>&1; then
echo "no"
log "no\n"
return 1
fi
echo "yes"
log "yes\n"
return 0
}