diff --git a/dockcheck.sh b/dockcheck.sh index fe9e819..f39bfce 100755 --- a/dockcheck.sh +++ b/dockcheck.sh @@ -52,7 +52,7 @@ while getopts "aynpfrhlisme:d:" options; do p) AutoPrune="yes" ;; l) OnlyLabel=true ;; f) ForceRestartStacks=true ;; - i) [ -s $ScriptWorkDir/notify.sh ] && { source $ScriptWorkDir/notify.sh ; Notify="yes" ; } ;; + i) [ -s "$ScriptWorkDir"/notify.sh ] && { source "$ScriptWorkDir"/notify.sh ; Notify="yes" ; } ;; e) Exclude=${OPTARG} ;; m) declare c_{red,green,yellow,blue,teal,reset}="" ;; s) Stopped="-a" ;; @@ -90,7 +90,7 @@ self_update() { exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments exit 1 # exit the old instance else - cd - + cd - || { printf "Path error.\n" ; return ; } self_update_curl fi } @@ -123,7 +123,7 @@ choosecontainers() { datecheck() { ImageDate=$($regbin image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 ) ImageAge=$(( ( $(date +%s) - $(date -d "$ImageDate" +%s) )/86400 )) - if [ $ImageAge -gt $DaysOld ] ; then + if [ "$ImageAge" -gt "$DaysOld" ] ; then return 0 else return 1 @@ -133,13 +133,13 @@ datecheck() { progress_bar() { QueCurrent="$1" QueTotal="$2" - ((Percent=100*${QueCurrent}/${QueTotal})) - ((Complete=50*${Percent}/100)) # change first number for width (50) - ((Left=50-${Complete})) # change first number for width (50) + ((Percent=100*QueCurrent/QueTotal)) + ((Complete=50*Percent/100)) # change first number for width (50) + ((Left=50-Complete)) # change first number for width (50) BarComplete=$(printf "%${Complete}s" | tr " " "#") BarLeft=$(printf "%${Left}s" | tr " " "-") - [[ $QueTotal == $QueCurrent ]] || printf "\r[%s%s] %s/%s " $BarComplete $BarLeft $QueCurrent $QueTotal - [[ $QueTotal == $QueCurrent ]] && printf "\r[%b%s%b] %s/%s \n" $c_teal $BarComplete $c_reset $QueCurrent $QueTotal + [[ "$QueTotal" == "$QueCurrent" ]] || printf "\r[%s%s] %s/%s " "$BarComplete" "$BarLeft" "$QueCurrent" "$QueTotal" + [[ "$QueTotal" == "$QueCurrent" ]] && printf "\r[%b%s%b] %s/%s \n" "$c_teal" "$BarComplete" "$c_reset" "$QueCurrent" "$QueTotal" } ### Version check & initiate self update @@ -204,7 +204,7 @@ done ### Listing typed exclusions: if [[ -n ${Excludes[*]} ]] ; then - printf "\n%bExcluding these names:%b\n" $c_blue $c_reset + printf "\n%bExcluding these names:%b\n" "$c_blue" "$c_reset" printf "%s\n" "${Excludes[@]}" printf "\n" fi @@ -216,7 +216,7 @@ RegCheckQue=0 ### Check the image-hash of every running container VS the registry for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}') ; do ((RegCheckQue+=1)) - progress_bar $RegCheckQue $DocCount + progress_bar "$RegCheckQue" "$DocCount" ### Looping every item over the list of excluded names and skipping: for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}') @@ -260,7 +260,7 @@ fi if [[ -n ${GotUpdates[*]} ]] ; then printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset" [[ -z "$AutoUp" ]] && options || printf "%s\n" "${GotUpdates[@]}" - [[ ! -z "$Notify" ]] && { [[ $(type -t send_notification) == function ]] && send_notification "${GotUpdates[@]}" || printf "Could not source notification function.\n" ; } + [[ -n "$Notify" ]] && { [[ $(type -t send_notification) == function ]] && send_notification "${GotUpdates[@]}" || printf "Could not source notification function.\n" ; } fi ### Optionally get updates if there's any @@ -313,7 +313,7 @@ if [ -n "$GotUpdates" ] ; then ### Check if the container got an environment file set, use it if so: if [ -n "$ContEnv" ]; then ### prepare env-files arguments - ContEnvs=$(for env in ${ContEnv//,/ } ; do printf -- "--env-file %s " $env; done) + ContEnvs=$(for env in ${ContEnv//,/ } ; do printf -- "--env-file %s " "$env"; done) ### Check if the whole stack should be restarted if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]] ; then $DockerBin ${CompleteConfs[@]} stop ; $DockerBin ${CompleteConfs[@]} ${ContEnvs} up -d