diff --git a/dockcheck.sh b/dockcheck.sh index e217855..3135171 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -30,6 +30,15 @@ Help() { echo "-s Include stopped containers in the check. (Logic: docker ps -a)" } +### Colors: +c_red="\033[0;31m" +c_green="\033[0;32m" +c_yellow="\033[0;33m" +c_blue="\033[0;34m" +c_teal="\033[0;36m" +c_reset="\033[0m" + + Stopped="" while getopts "aynprhse:d:" options; do case "${options}" in @@ -172,7 +181,7 @@ done ### Listing typed exclusions: if [[ -n ${Excludes[*]} ]] ; then - printf "\n\033[0;34mExcluding these names:\033[0m\n" + printf "\n%bExcluding these names:%b\n" $c_blue $c_reset printf "%s\n" "${Excludes[@]}" printf "\n" fi @@ -211,22 +220,22 @@ UpdCount="${#GotUpdates[@]}" ### List what containers got updates or not if [[ -n ${NoUpdates[*]} ]] ; then - printf "\n\033[0;32mContainers on latest version:\033[0m\n" + printf "\n%bContainers on latest version:%b\n" "$c_green" "$c_reset" printf "%s\n" "${NoUpdates[@]}" fi if [[ -n ${GotErrors[*]} ]] ; then - printf "\n\033[0;31mContainers with errors, wont get updated:\033[0m\n" + printf "\n%bContainers with errors, wont get updated:%b\n" "$c_red" "$c_reset" printf "%s\n" "${GotErrors[@]}" fi if [[ -n ${GotUpdates[*]} ]] ; then - printf "\n\033[0;33mContainers with updates available:\033[0m\n" + printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset" [[ -z "$UpdYes" ]] && options || printf "%s\n" "${GotUpdates[@]}" fi ### Optionally get updates if there's any if [ -n "$GotUpdates" ] ; then if [ -z "$UpdYes" ] ; then - printf "\n\033[0;36mChoose what containers to update.\033[0m\n" + printf "\n%bChoose what containers to update.%b\n" "$c_teal" "$c_reset" choosecontainers else SelectedUpdates=( "${GotUpdates[@]}" ) @@ -249,7 +258,7 @@ if [ -n "$GotUpdates" ] ; then docker pull "$ContImage" printf "%s\n" "$i got a new image downloaded, rebuild manually with preferred 'docker run'-parameters" else - printf "\n\033[33;1m%s\033[0m has no compose labels, probably started with docker run - \033[33;1mskipping\033[0m\n\n" "$i" + printf "\n%b%s%b has no compose labels, probably started with docker run - %bskipping%b\n\n" "$c_yellow" "$i" "$c_reset" "$c_yellow" "$c_reset" fi continue fi @@ -261,7 +270,7 @@ if [ -n "$GotUpdates" ] ; then fi ### cd to the compose-file directory to account for people who use relative volumes, eg - ${PWD}/data:data cd "$ContPath" || { echo "Path error - skipping $i" ; continue ; } - printf "\n\033[0;36mNow updating (%s/%s): \033[0;34m%s\033[0m\n" "$CurrentQue" "$NumberofUpdates" "$i" + printf "\n%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset" docker pull "$ContImage" ### Reformat for multi-compose: IFS=',' read -r -a Confs <<< "$ComposeFile" ; unset IFS @@ -274,7 +283,7 @@ if [ -n "$GotUpdates" ] ; then $DockerBin ${CompleteConfs[@]} up -d "$ContName" # unquoted array to allow split - rework? fi done - printf "\033[0;32mAll done!\033[0m\n" + printf "\n%bAll done!%b\n" "$c_green" "$c_reset" [[ -z "$PruneQ" ]] && read -r -p "Would you like to prune dangling images? y/[n]: " PruneQ [[ "$PruneQ" =~ [yY] ]] && docker image prune -f else