diff --git a/README.md b/README.md index 56bfe5a..1505105 100644 --- a/README.md +++ b/README.md @@ -51,4 +51,10 @@ cd docker-bench-security sh docker-bench-security.sh ``` +Coloured output may be switched off to ease parsing: + +```sh +sh docker-bench-security.sh -n |& grep '^\[WARN\]' +``` + This script was build to be POSIX 2004 compliant, so it should be portable across any Unix platform. diff --git a/docker-bench-security.sh b/docker-bench-security.sh index 0659d07..cad4122 100755 --- a/docker-bench-security.sh +++ b/docker-bench-security.sh @@ -18,6 +18,9 @@ this_path=$(abspath "$0") ## Path of this file including filenamel myname=$(basename "${this_path}") ## file name of this script. +# Defaults +set_colours default + export PATH=/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin/ # Check for required program(s) @@ -37,6 +40,7 @@ usage () { cat <<EOF usage: ${myname} [options] + -n optional Don't colourise results -h optional Print this help message -l PATH optional Log output in PATH EOF @@ -49,6 +53,7 @@ while getopts hl: args do case $args in h) usage; exit 0 ;; + n) set_colour none;; l) logger="$OPTARG" ;; *) usage; exit 1 ;; esac diff --git a/helper_lib.sh b/helper_lib.sh index 7577816..29ff20a 100644 --- a/helper_lib.sh +++ b/helper_lib.sh @@ -46,3 +46,24 @@ get_command_line_args() { tr "\0" " " < /proc/"$PID"/cmdline done } + +# Set terminal colours used by functions in output_lib +set_colours() { + + case "$?" in + none) + bldred= + bldgrn= + bldblu= + bldylw= + txtrst= + ;; + default|*) + bldred='\033[1;31m' + bldgrn='\033[1;32m' + bldblu='\033[1;34m' + bldylw='\033[1;33m' # Yellow + txtrst='\033[0m' + ;; + esac +} diff --git a/output_lib.sh b/output_lib.sh index f4f61bc..13dccde 100644 --- a/output_lib.sh +++ b/output_lib.sh @@ -1,9 +1,4 @@ #!/bin/sh -bldred='\033[1;31m' -bldgrn='\033[1;32m' -bldblu='\033[1;34m' -bldylw='\033[1;33m' # Yellow -txtrst='\033[0m' logit () { printf "%b\n" "$1" | tee -a "$logger"