Compare commits

...

18 Commits

Author SHA1 Message Date
mag37
488669b99a Update README.md
added recent change info.
2023-12-09 10:59:27 +01:00
mag37
e20fdd9e85 regctl logic changes, check and download will match the scripts workdir. 2023-12-09 10:56:22 +01:00
mag37
3d1c424d23 Update dockcheck.sh
added a regctl-check for when regctl is within the pwd.
(as suggested by @yoyoma2 )
2023-11-19 20:20:05 +01:00
mag37
132fda3388 Update README.md 2023-08-29 20:42:00 +02:00
mag37
cc9b3b0828 Update README.md 2023-08-28 21:31:18 +02:00
mag37
29c2c5e961 Merge pull request #41 from elchanly/elchanly-patch-1
Update dockcheck.sh to include stopped containers
2023-08-28 21:26:12 +02:00
mag37
5dc9af9874 Update dockcheck.sh
Did some changes to the logic, cleaned some whitespace.
2023-08-28 21:24:23 +02:00
elchanly
f91ca08d54 Update dockcheck.sh to include stopped containers
as suggested in reddit, this is proposed to include stopped containers
take into account im not skilled in this programming language but i wanted to contribute.
2023-08-21 23:56:03 +02:00
mag37
9a246b52c4 Merge pull request #39 from mag37/fixing
Fixes `dc_brief.sh` to only exclude exact matches.
2023-07-11 23:33:02 +02:00
mag37
0c33f581f7 Removed old exclude-logic 2023-07-11 23:30:46 +02:00
mag37
b492aacf0f minor edits 2023-07-11 23:11:14 +02:00
mag37
f498138d4b Added recent "exclude containers"-bugfix to the dc_brief.sh 2023-07-11 23:05:34 +02:00
mag37
6a3198eb08 Update dockcheck.sh
patched the self_update logic to respect (and skip interaction) if `-y|a` flag is passed.
2023-06-28 18:03:56 +02:00
mag37
48bfea9fbf Merge pull request #36 from mag37/dev1
Fixes the Exclude-option to only exclude exact matches. 
Formatting: Added counter and info message on current update.
2023-06-27 20:45:12 +02:00
mag37
f2fc5a4d34 Updated: 2.4 info 2023-06-27 19:45:21 +02:00
mag37
f0940e81ec Fixes to the Exclude-option to only exclude exact matches, instead of
wildcarding and excluding by mistake.

Added a counter + message about which container updating.
2023-06-27 19:34:20 +02:00
mag37
a25e648557 Changes to the Exclude-option to only exclude exact matches. 2023-06-21 20:09:31 +02:00
mag37
0e2bdc94ad Update README.md 2023-03-08 12:48:36 +01:00
3 changed files with 35 additions and 19 deletions

View File

@@ -2,7 +2,8 @@
<img src="extras/dockcheck_logo_by_booYah187.png" width="160" title="dockcheck">
</p>
<p align="center">
<img src="https://img.shields.io/badge/-bash-grey?style=flat-square&logo=gnubash" alt="bash">
<img src="https://img.shields.io/badge/coded%20by%20Human-100%25-yellow?style=flat-square" alt="No AI!">
<img src="https://img.shields.io/badge/bash-4.3-green?style=flat-square&logo=gnubash" alt="bash">
<a href="https://www.gnu.org/licenses/gpl-3.0.html"><img src="https://img.shields.io/badge/license-GPLv3-red?style=flat-square" alt="GPLv3"></a>
<img src="https://img.shields.io/github/v/tag/mag37/dockcheck?style=flat-square&label=release" alt="release">
<a href="https://ko-fi.com/mag37"><img src="https://img.shields.io/badge/-Ko--fi-grey?style=flat-square&logo=Ko-fi" alt="Buy me a Coffee"></a>
@@ -14,11 +15,10 @@
<h4 align="center">With features like excluding specific containers, filter by name, auto-prune dangling images and more.</h4</h3>
### :warning: URGENT! The 2.1 change had a breaking error - make sure you run an updated version.
If you've had errors, inspect your containers and look for odd compose paths, volumes or ports.
[errorCheck.sh](https://github.com/mag37/dockcheck/blob/main/errorCheck.sh) lists the important bits of each running container. If anything suspicious, recreate the container manually with `docker compose`.
### :pushpin: Recent changes:
- **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.
- **v0.2.4**: Fixed a bug with the Exclude-logic to only exclude exact matches. Added a counter.
- **v0.2.3**: Added a self updating function (curl/git) and a ugly changenote-message for updates.
- **v0.2.2**: Fixed breaking errors with multi-compose, odd breakage and working dir error.
- **v0.2.1**: Added option to exclude a list of containers.
@@ -46,9 +46,10 @@ Options:
-h Print this Help.
-a|y Automatic updates, without interaction.
-n No updates, only checking availability.
-p Auto-Prune dangling images after update.
-e Exclude containers, separated by comma.
-p Auto-Prune dangling images after update.
-r Allow updating images for docker run, wont update the container.
-s Include stopped containers in the check. (Logic: docker ps -a).
```
Basic example:
@@ -78,8 +79,9 @@ After the updates are complete, you'll get prompted if you'd like to prune dangl
Containers need to be manually stopped, removed and created again to run on the new image.
### :hammer: Known issues
- No detailed error feedback (just skip + list what's skipped) .
- No detailed error feedback (just skip + list what's skipped).
- Not respecting `--profile` options when re-creating the container.
- Not working well with containers created by Portainer.
## `dc_brief.sh`
Just a brief, slimmed down version of the script to only print what containers got updates, no updates or errors.
@@ -89,7 +91,7 @@ dockcheck is created and released under the [GNU GPL v3.0](https://www.gnu.org/l
___
## Check out a spinoff brother-project:
### [Palleri/dockcheck-web](https://github.com/Palleri/dockcheck-web) for a WebUI-front!
### [Palleri/DCW](https://github.com/Palleri/DCW) for a WebUI-front with exporters and notifications.
## Special Thanks:
- :bison: [t0rnis](https://github.com/t0rnis)

View File

@@ -16,7 +16,7 @@ IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
SearchName="$1"
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
[[ " ${Excludes[*]} " =~ ${i} ]] && continue; # Skip if the container is excluded
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
printf ". "
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
VERSION="v0.2.3"
### ChangeNotes: Added self-updating git/curl-function and a dirty changenote.
VERSION="v0.2.6"
### ChangeNotes: Logic change on regctl check/download. Will match the scripts workdir.
Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
@@ -26,15 +26,18 @@ Help() {
echo "-e Exclude containers, separated by comma."
echo "-p Auto-Prune dangling images after update."
echo "-r Allow updating images for docker run, wont update the container"
echo "-s Include stopped containers in the check. (Logic: docker ps -a)"
}
while getopts "aynprhe:" options; do
Stopped=""
while getopts "aynprhse:" options; do
case "${options}" in
a|y) UpdYes="yes" ;;
n) UpdYes="no" ;;
r) DrUp="yes" ;;
p) PruneQ="yes" ;;
e) Exclude=${OPTARG} ;;
s) Stopped="-a" ;;
h|*) Help ; exit 0 ;;
esac
done
@@ -47,7 +50,6 @@ self_update_git() {
git fetch
[ -n "$(git diff --name-only "$ScriptUpstream" "$ScriptName")" ] && {
printf "%s\n" "Pulling the latest version."
# git checkout "$ScriptUpstream"
git pull --force
printf "%s\n" "--- starting over with the updated version ---"
cd - || { printf "Path error.\n" ; return ; }
@@ -101,7 +103,7 @@ choosecontainers() {
}
### Version check & initiate self update
[[ "$VERSION" != "$LatestRelease" ]] && { printf "New version available! Local: %s - Latest: %s \n Change Notes: %s \n" "$VERSION" "$LatestRelease" "$LatestChanges" ; self_update_select ; }
[[ "$VERSION" != "$LatestRelease" ]] && { printf "New version available! Local: %s - Latest: %s \n Change Notes: %s \n" "$VERSION" "$LatestRelease" "$LatestChanges" ; [[ -z "$UpdYes" ]] && self_update_select ; }
### Set $1 to a variable for name filtering later.
SearchName="$1"
@@ -110,7 +112,7 @@ IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
### Check if required binary exists in PATH or directory:
if [[ $(builtin type -P "regctl") ]]; then regbin="regctl" ;
elif [[ -f "./regctl" ]]; then regbin="./regctl" ;
elif [[ -f "$ScriptWorkDir/regctl" ]]; then regbin="$ScriptWorkDir/regctl" ;
else
read -r -p "Required dependency 'regctl' missing, do you want it downloaded? y/[n] " GetDep
if [[ "$GetDep" =~ [yY] ]] ; then
@@ -121,8 +123,8 @@ else
*) echo "Architecture not supported, exiting." ; exit 1;;
esac
RegUrl="https://github.com/regclient/regclient/releases/latest/download/regctl-linux-$architecture"
if [[ $(builtin type -P curl) ]]; then curl -L $RegUrl > ./regctl ; chmod +x ./regctl ; regbin="./regctl" ;
elif [[ $(builtin type -P wget) ]]; then wget $RegUrl -O ./regctl ; chmod +x ./regctl ; regbin="./regctl" ;
if [[ $(builtin type -P curl) ]]; then curl -L $RegUrl > "$ScriptWorkDir/regctl" ; chmod +x "$ScriptWorkDir/regctl" ; regbin="$ScriptWorkDir/regctl" ;
elif [[ $(builtin type -P wget) ]]; then wget $RegUrl -O "$ScriptWorkDir/regctl" ; chmod +x "$ScriptWorkDir/regctl" ; regbin="$ScriptWorkDir/regctl" ;
else
printf "%s\n" "curl/wget not available - get regctl manually from the repo link, quitting."
fi
@@ -154,9 +156,17 @@ for i in "${GotUpdates[@]}"; do
done
}
### Listing typed exclusions:
if [[ -n ${Excludes[*]} ]] ; then
printf "\n\033[0;34mExcluding these names:\033[0m\n"
printf "%s\n" "${Excludes[@]}"
printf "\n"
fi
### Check the image-hash of every running container VS the registry
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
[[ " ${Excludes[*]} " =~ ${i} ]] && continue; # Skip if the container is excluded
for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}') ; do
### Looping every item over the list of excluded names and skipping:
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
printf ". "
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
@@ -200,8 +210,11 @@ if [ -n "$GotUpdates" ] ; then
SelectedUpdates=( "${GotUpdates[@]}" )
fi
if [ "$UpdYes" == "${UpdYes#[Nn]}" ] ; then
NumberofUpdates="${#SelectedUpdates[@]}"
CurrentQue=0
for i in "${SelectedUpdates[@]}"
do
((CurrentQue+=1))
unset CompleteConfs
ContPath=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.working_dir" }}')
ContConfigFile=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.project.config_files" }}')
@@ -226,6 +239,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"
docker pull "$ContImage"
### Reformat for multi-compose:
IFS=',' read -r -a Confs <<< "$ComposeFile" ; unset IFS