From ab30f2234324335241ff70f847d396614e24bb97 Mon Sep 17 00:00:00 2001 From: mag37 Date: Tue, 19 Dec 2023 20:24:34 +0100 Subject: [PATCH 1/4] rework of the printf's color escape codes --- dockcheck.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) 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 From e39ea0748f7dc3c3e7f25b8f1228ca7be6b887b6 Mon Sep 17 00:00:00 2001 From: mag37 Date: Tue, 19 Dec 2023 22:52:11 +0100 Subject: [PATCH 2/4] Update dockcheck.sh Added -m, Monochrome Mode. --- dockcheck.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dockcheck.sh b/dockcheck.sh index 3135171..c7730ab 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -27,6 +27,7 @@ Help() { echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower." echo "-p Auto-Prune dangling images after update." echo "-r Allow updating images for docker run, wont update the container" + echo "-m Monochrome mode, no printf color codes." echo "-s Include stopped containers in the check. (Logic: docker ps -a)" } @@ -40,13 +41,14 @@ c_reset="\033[0m" Stopped="" -while getopts "aynprhse:d:" options; do +while getopts "aynprhsme:d:" options; do case "${options}" in a|y) UpdYes="yes" ;; n) UpdYes="no" ;; r) DrUp="yes" ;; p) PruneQ="yes" ;; e) Exclude=${OPTARG} ;; + m) declare c_{red,green,yellow,blue,teal,reset}="" ;; s) Stopped="-a" ;; d) DaysOld=${OPTARG} if ! [[ $DaysOld =~ ^[0-9]+$ ]] ; then { printf "Days -d argument given (%s) is not a number.\n" "${DaysOld}" ; exit 2 ; } ; fi ;; From 24438124ebfc813c270ad872bd1c7ab432de3bf7 Mon Sep 17 00:00:00 2001 From: mag37 Date: Sat, 23 Dec 2023 20:47:23 +0100 Subject: [PATCH 3/4] cleaned up some variable names and help-section --- dockcheck.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/dockcheck.sh b/dockcheck.sh index c7730ab..f0795c1 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -20,14 +20,14 @@ Help() { echo "Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall" echo echo "Options:" - echo "-h Print this Help." echo "-a|y Automatic updates, without interaction." - echo "-n No updates, only checking availability." - echo "-e X Exclude containers, separated by comma." echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower." + echo "-e X Exclude containers, separated by comma." + echo "-h Print this Help." + echo "-m Monochrome mode, no printf color codes." + echo "-n No updates, only checking availability." echo "-p Auto-Prune dangling images after update." echo "-r Allow updating images for docker run, wont update the container" - echo "-m Monochrome mode, no printf color codes." echo "-s Include stopped containers in the check. (Logic: docker ps -a)" } @@ -43,10 +43,10 @@ c_reset="\033[0m" Stopped="" while getopts "aynprhsme:d:" options; do case "${options}" in - a|y) UpdYes="yes" ;; - n) UpdYes="no" ;; - r) DrUp="yes" ;; - p) PruneQ="yes" ;; + a|y) AutoUp="yes" ;; + n) AutoUp="no" ;; + r) DRunUp="yes" ;; + p) AutoPrune="yes" ;; e) Exclude=${OPTARG} ;; m) declare c_{red,green,yellow,blue,teal,reset}="" ;; s) Stopped="-a" ;; @@ -128,7 +128,7 @@ datecheck() { ### Version check & initiate self update -[[ "$VERSION" != "$LatestRelease" ]] && { printf "New version available! Local: %s - Latest: %s \n Change Notes: %s \n" "$VERSION" "$LatestRelease" "$LatestChanges" ; [[ -z "$UpdYes" ]] && self_update_select ; } +[[ "$VERSION" != "$LatestRelease" ]] && { printf "New version available! Local: %s - Latest: %s \n Change Notes: %s \n" "$VERSION" "$LatestRelease" "$LatestChanges" ; [[ -z "$AutoUp" ]] && self_update_select ; } ### Set $1 to a variable for name filtering later. SearchName="$1" @@ -231,18 +231,18 @@ if [[ -n ${GotErrors[*]} ]] ; then fi if [[ -n ${GotUpdates[*]} ]] ; then printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset" - [[ -z "$UpdYes" ]] && options || printf "%s\n" "${GotUpdates[@]}" + [[ -z "$AutoUp" ]] && options || printf "%s\n" "${GotUpdates[@]}" fi ### Optionally get updates if there's any if [ -n "$GotUpdates" ] ; then - if [ -z "$UpdYes" ] ; then + if [ -z "$AutoUp" ] ; then printf "\n%bChoose what containers to update.%b\n" "$c_teal" "$c_reset" choosecontainers else SelectedUpdates=( "${GotUpdates[@]}" ) fi - if [ "$UpdYes" == "${UpdYes#[Nn]}" ] ; then + if [ "$AutoUp" == "${AutoUp#[Nn]}" ] ; then NumberofUpdates="${#SelectedUpdates[@]}" CurrentQue=0 for i in "${SelectedUpdates[@]}" @@ -256,7 +256,7 @@ if [ -n "$GotUpdates" ] ; then ContImage=$(docker inspect "$i" --format='{{.Config.Image}}') ### Checking if compose-values are empty - hence started with docker run: if [ -z "$ContPath" ] ; then - if [ "$DrUp" == "yes" ] ; then + if [ "$DRunUp" == "yes" ] ; then docker pull "$ContImage" printf "%s\n" "$i got a new image downloaded, rebuild manually with preferred 'docker run'-parameters" else @@ -286,8 +286,8 @@ if [ -n "$GotUpdates" ] ; then fi done 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 + [[ -z "$AutoPrune" ]] && read -r -p "Would you like to prune dangling images? y/[n]: " AutoPrune + [[ "$AutoPrune" =~ [yY] ]] && docker image prune -f else printf "\nNo updates installed, exiting.\n" fi From ba3f436ac97015ada983552a356ae6cd990a1c94 Mon Sep 17 00:00:00 2001 From: mag37 Date: Sat, 23 Dec 2023 20:52:04 +0100 Subject: [PATCH 4/4] Added -m option, monochrome mode. --- README.md | 1 + dockcheck.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0e149ed..8a602b9 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ ### :bell: Recent changes +- **v0.3.1**: Addded option `-m` , monochrome mode - no printf color codes. - **v0.3.0**: Added option `-d N`, age (days) new images have to be before being pulled and updated. - **v0.2.6**: regctl check / download logic changed. Now using the scripts directory as primary location. - **v0.2.5**: Added a new option `-s` to include stopped containers in the check for updates. diff --git a/dockcheck.sh b/dockcheck.sh index f0795c1..1d822a7 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERSION="v0.3.0" -### ChangeNotes: Added feature (-d N) to only update to new images that are N+ days old. +VERSION="v0.3.1" +### ChangeNotes: Added feature (-m) Monochrome Mode, no printf color codes. Github="https://github.com/mag37/dockcheck" RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"