Compare commits

..

30 Commits

Author SHA1 Message Date
mag37
aa9421adda Merge pull request #68 from mag37/selfup_cleanup
selfupdate rework, -v option, syntax cleanup
2024-02-02 21:27:43 +01:00
mag37
f853bfd318 typos 2024-02-02 21:21:56 +01:00
mag37
292b3e1a32 Version bump + readme 2024-02-02 21:18:19 +01:00
mag37
4c26768374 Added -v option, prints version 2024-02-02 20:52:01 +01:00
mag37
b7f8b67232 Merge pull request #65 from Nionor/main
Added Telegram template.
2024-02-02 20:47:42 +01:00
Nionor
a63a509bd2 Add files via upload
Added Telegram template.
2024-02-02 16:00:04 +01:00
mag37
5ed3b90ca4 syntax cleanup 2024-02-01 20:19:04 +01:00
mag37
78d11d1b37 Self update rework
Now just y/n and checking if it's the right git directory, else
curl/wget.
2024-01-31 21:33:14 +01:00
mag37
dfe6cf3e08 arithmetic formatting 2024-01-28 20:08:17 +01:00
mag37
3bc7352b54 Bugfix zerodivision -s option 2024-01-28 15:43:33 +01:00
mag37
1470055329 Merge pull request #62 from mag37/env-rework
Reworked --env-file logic.
2024-01-27 09:41:41 +01:00
mag37
904cd508d1 --env-file version bump 2024-01-27 09:39:37 +01:00
mag37
8ee1366505 typo 2024-01-26 21:53:15 +01:00
mag37
c063b09003 reworked --env-file logic 2024-01-26 20:45:32 +01:00
mag37
ea096b5dbc Merge pull request #58 from thomas-mc-work/patch-1
modified update notification
2024-01-24 22:17:37 +01:00
Thomas McWork
038a30b628 add colors to version update notice 2024-01-24 21:28:53 +01:00
Thomas McWork
24d82d74b3 modified update notification
Slightly changed the notation of the local/latest version to simplify the visual impression. But it's a matter of taste.
2024-01-24 21:22:49 +01:00
mag37
8ecc354663 Update README.md
link formatting
2024-01-24 19:49:41 +01:00
mag37
4a2daa9899 Merge pull request #57 from mag37/new_labels-force
Labels support and -f force option.
2024-01-24 19:44:57 +01:00
mag37
ae8a232a1a Merge branch 'main' into new_labels-force 2024-01-24 19:44:29 +01:00
mag37
abbb924867 labels and -f option 2024-01-24 19:37:15 +01:00
mag37
05d21a707a added readme about labels 2024-01-21 20:30:05 +01:00
mag37
4817d75d94 pushbullet template version bump. 2024-01-21 20:30:05 +01:00
mag37
32f6d428d3 pushbullet info 2024-01-21 20:30:05 +01:00
mag37
4a8afde790 Added pushbullet template.
Suggested and contributed by [@arpanghosh8453](https://github.com/arpanghosh8453)
2024-01-21 20:30:05 +01:00
mag37
ae53fe2cc7 pushbullet template version bump. 2024-01-20 10:38:11 +01:00
mag37
722fb90ce2 pushbullet info 2024-01-20 10:36:41 +01:00
mag37
18947a462d Added pushbullet template.
Suggested and contributed by [@arpanghosh8453](https://github.com/arpanghosh8453)
2024-01-20 10:33:32 +01:00
mag37
0887025412 Added functionality for labels and force restarts. 2024-01-18 20:59:55 +01:00
mag37
e331dda080 Added a simple progress bar 2024-01-17 20:26:18 +01:00
4 changed files with 179 additions and 56 deletions

View File

@@ -17,19 +17,23 @@
___ ___
## :bell: Changelog ## :bell: Changelog
- **v0.4.0**: Reworked selfupdate (auto git/curl/wget), general syntax cleanup, added -v for version.
- **v0.3.8**: Fixed `--env-file` logic to work with multiple env-files.
- **v0.3.7**: Added support for [labels](#bookmark-labels), added the `-f` option (force restart stack).
- **v0.3.6**: Added pushbullet template.
- **v0.3.5**: Added a simple progress bar for the registry checkup.
- **v0.3.4**: Added ntfy.sh template and error message on registry fail. - **v0.3.4**: Added ntfy.sh template and error message on registry fail.
- **v0.3.3**: Added Apprise template and the option `-i` inform - to send notifications. - **v0.3.3**: Added Apprise template and the option `-i` inform - to send notifications.
- **v0.3.2**: Added a notify function to wrap a notify-script, currently DSM/Ssmtp + template script. - **v0.3.2**: Added a notify function to wrap a notify-script, currently DSM/Ssmtp + template script.
- **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.
___ ___
## :nut_and_bolt: Dependencies ## :nut_and_bolt: Dependencies
- Running docker (duh) and compose, either standalone or plugin. - Running docker (duh) and compose, either standalone or plugin.
- [regclient/regctl](https://github.com/regclient/regclient) (Licensed under [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0)) - [regclient/regctl](https://github.com/regclient/regclient) (Licensed under [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0))
- User will be prompted to download `regctl` if not in `PATH` or `PWD`. - User will be prompted to download `regctl` if not in `PATH` or `PWD`.
- regctl requires `amd64/arm64` - see [workaround](#workaround-for-non-amd64--arm64) if other architecture is used. - regctl requires `amd64/arm64` - see [workaround](#roller_coaster-workaround-for-non-amd64--arm64) if other architecture is used.
___ ___
@@ -38,22 +42,26 @@ ___
## :mag_right: `dockcheck.sh` ## :mag_right: `dockcheck.sh`
``` ```
$ ./dockcheck.sh -h $ ./dockcheck.sh -h
Syntax: dockcheck.sh [OPTION] [part of name to filter] Syntax: dockcheck.sh [OPTION] [part of name to filter]
Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall Example: dockcheck.sh -y -d 10 -e nextcloud,heimdall
Options: Options:"
-a|y Automatic updates, without interaction. -a|y Automatic updates, without interaction.
-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower. -d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower.
-e X Exclude containers, separated by comma. -e X Exclude containers, separated by comma.
-h Print this Help. -f Force stack restart after update. Caution: restarts once for every updated container within stack.
-i Inform - send a preconfigured notification. -h Print this Help.
-m Monochrome mode, no printf color codes. -i Inform - send a preconfigured notification.
-n No updates, only checking availability. -l Only update if label is set. See readme.
-p Auto-Prune dangling images after update. -m Monochrome mode, no printf color codes.
-r Allow updating images for docker run, wont update the container. -n No updates, only checking availability.
-s Include stopped containers in the check. (Logic: docker ps -a) -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).
-v Prints current version.
``` ```
### Basic example: ### Basic example:
``` ```
$ ./dockcheck.sh $ ./dockcheck.sh
@@ -84,10 +92,22 @@ Current templates:
- Apprise (with it's [multitude](https://github.com/caronc/apprise#supported-notifications) of notifications) - Apprise (with it's [multitude](https://github.com/caronc/apprise#supported-notifications) of notifications)
- both native [caronc/apprise](https://github.com/caronc/apprise) and the standalone [linuxserver/docker-apprise-api](https://github.com/linuxserver/docker-apprise-api) - both native [caronc/apprise](https://github.com/caronc/apprise) and the standalone [linuxserver/docker-apprise-api](https://github.com/linuxserver/docker-apprise-api)
- Read the [QuickStart](extras/apprise_quickstart.md) - Read the [QuickStart](extras/apprise_quickstart.md)
- [ntfy.sh](https://ntfy.sh/) - HTTP-based pub-sub notifications.
- [Pushbullet](https://www.pushbullet.com/) - connecting different devices with cross-platform features.
Further additions are welcome - suggestions or PR! Further additions are welcome - suggestions or PR!
<sub><sup>Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).</sup></sub> <sub><sup>Initiated and first contributed by [yoyoma2](https://github.com/yoyoma2).</sup></sub>
## :bookmark: Labels
Optionally add labels to compose-files. Currently these are the usable labels:
```
labels:
mag37.dockcheck.restart-stack: true
mag37.dockcheck.update: true
```
- `mag37.dockcheck.restart-stack: true` works instead of the `-f` option, forcing stop+restart on the whole compose-stack (Caution: Will restart on every updated container within stack).
- `mag37.dockcheck.update: true` will when used with the `-l` option only update containers with this label and skip the rest. Will still list updates as usual.
## :roller_coaster: Workaround for non **amd64** / **arm64** ## :roller_coaster: Workaround for non **amd64** / **arm64**
`regctl` provides binaries for amd64/arm64, to use on other architecture you could try this workaround. `regctl` provides binaries for amd64/arm64, to use on other architecture you could try this workaround.
Run regctl in a container wrapped in a shell script. Copied from [regclient/docs/install.md](https://github.com/regclient/regclient/blob/main/docs/install.md): Run regctl in a container wrapped in a shell script. Copied from [regclient/docs/install.md](https://github.com/regclient/regclient/blob/main/docs/install.md):
@@ -108,6 +128,15 @@ chmod 755 regctl
``` ```
Test it with `./regctl --help` and then either add the file to the same path as *dockcheck.sh* or in your path (eg. `~/.local/bin/regctl`). Test it with `./regctl --help` and then either add the file to the same path as *dockcheck.sh* or in your path (eg. `~/.local/bin/regctl`).
## :open_hands: Function to auth with docker hub before running
**Example** - Change names, paths, and remove cat+password flag if you rather get prompted:
```sh
function dchk {
cat ~/pwd.txt | docker login --username YourUser --password-stdin
~/dockcheck.sh "$@"
}
```
## :hammer: Known issues ## :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 respecting `--profile` options when re-creating the container.
@@ -121,7 +150,7 @@ Containers need to be manually stopped, removed and created again to run on the
## :scroll: License ## :scroll: License
dockcheck is created and released under the [GNU GPL v3.0](https://www.gnu.org/licenses/gpl-3.0-standalone.html) license. dockcheck is created and released under the [GNU GPL v3.0](https://www.gnu.org/licenses/gpl-3.0-standalone.html) license.
### :floppy_disk: The [story](https://mag37.org/posts/project_dockcheck/) behind it. 1 year in the mirror. ### :floppy_disk: The [story](https://mag37.org/posts/project_dockcheck/) behind it. 1 year in retrospect.
___ ___

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
VERSION="v0.3.4" VERSION="v0.4.0"
### ChangeNotes: Added ntfy.sh template and error message on registry fail. ### ChangeNotes: Reworked selfupdate (auto git/curl/wget), cleanups, -v for version.
Github="https://github.com/mag37/dockcheck" Github="https://github.com/mag37/dockcheck"
RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh" RawUrl="https://raw.githubusercontent.com/mag37/dockcheck/main/dockcheck.sh"
@@ -24,13 +24,16 @@ Help() {
echo "-a|y Automatic updates, without interaction." echo "-a|y Automatic updates, without interaction."
echo "-d N Only update to new images that are N+ days old. Lists too recent with +prefix and age. 2xSlower." 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 "-e X Exclude containers, separated by comma."
echo "-f Force stack restart after update. Caution: restarts once for every updated container within stack."
echo "-h Print this Help." echo "-h Print this Help."
echo "-i Inform - send a preconfigured notification." echo "-i Inform - send a preconfigured notification."
echo "-l Only update if label is set. See readme."
echo "-m Monochrome mode, no printf color codes." echo "-m Monochrome mode, no printf color codes."
echo "-n No updates, only checking availability." echo "-n No updates, only checking availability."
echo "-p Auto-Prune dangling images after update." echo "-p Auto-Prune dangling images after update."
echo "-r Allow updating images for docker run, wont update the container" echo "-r Allow updating images for docker run, wont update the container."
echo "-s Include stopped containers in the check. (Logic: docker ps -a)" echo "-s Include stopped containers in the check. (Logic: docker ps -a)."
echo "-v Prints current version."
} }
### Colors: ### Colors:
@@ -42,16 +45,19 @@ c_teal="\033[0;36m"
c_reset="\033[0m" c_reset="\033[0m"
Stopped="" Stopped=""
while getopts "aynprhisme:d:" options; do while getopts "aynpfrhlisvme:d:" options; do
case "${options}" in case "${options}" in
a|y) AutoUp="yes" ;; a|y) AutoUp="yes" ;;
n) AutoUp="no" ;; n) AutoUp="no" ;;
r) DRunUp="yes" ;; r) DRunUp="yes" ;;
p) AutoPrune="yes" ;; p) AutoPrune="yes" ;;
i) [ -s $ScriptWorkDir/notify.sh ] && { source $ScriptWorkDir/notify.sh ; Notify="yes" ; } ;; l) OnlyLabel=true ;;
f) ForceRestartStacks=true ;;
i) [ -s "$ScriptWorkDir"/notify.sh ] && { source "$ScriptWorkDir"/notify.sh ; Notify="yes" ; } ;;
e) Exclude=${OPTARG} ;; e) Exclude=${OPTARG} ;;
m) declare c_{red,green,yellow,blue,teal,reset}="" ;; m) declare c_{red,green,yellow,blue,teal,reset}="" ;;
s) Stopped="-a" ;; s) Stopped="-a" ;;
v) printf "%s\n" "$VERSION" ; exit 0 ;;
d) DaysOld=${OPTARG} d) DaysOld=${OPTARG}
if ! [[ $DaysOld =~ ^[0-9]+$ ]] ; then { printf "Days -d argument given (%s) is not a number.\n" "${DaysOld}" ; exit 2 ; } ; fi ;; if ! [[ $DaysOld =~ ^[0-9]+$ ]] ; then { printf "Days -d argument given (%s) is not a number.\n" "${DaysOld}" ; exit 2 ; } ; fi ;;
h|*) Help ; exit 2 ;; h|*) Help ; exit 2 ;;
@@ -59,37 +65,35 @@ while getopts "aynprhisme:d:" options; do
done done
shift "$((OPTIND-1))" shift "$((OPTIND-1))"
self_update_git() {
cd "$ScriptWorkDir" || { printf "Path error, skipping update.\n" ; return ; }
[[ $(builtin type -P git) ]] || { printf "Git not installed, skipping update.\n" ; return ; }
ScriptUpstream=$(git rev-parse --abbrev-ref --symbolic-full-name "@{upstream}") || { printf "Script not in git directory, choose a different method.\n" ; self_update_select ; return ; }
git fetch
[ -n "$(git diff --name-only "$ScriptUpstream" "$ScriptName")" ] && {
printf "%s\n" "Pulling the latest version."
git pull --force
printf "%s\n" "--- starting over with the updated version ---"
cd - || { printf "Path error.\n" ; return ; }
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
exit 1 # exit the old instance
}
echo "Local is already latest."
}
self_update_curl() { self_update_curl() {
cp "$ScriptPath" "$ScriptPath".bak cp "$ScriptPath" "$ScriptPath".bak
if [[ $(builtin type -P curl) ]]; then if [[ $(builtin type -P curl) ]]; then
curl -L $RawUrl > "$ScriptPath" ; chmod +x "$ScriptPath" curl -L $RawUrl > "$ScriptPath" ; chmod +x "$ScriptPath"
printf "%s\n" "--- starting over with the updated version ---" printf "\n%s\n" "--- starting over with the updated version ---"
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
exit 1 # exit the old instance
elif [[ $(builtin type -P wget) ]]; then
wget $RawUrl -O "$ScriptPath" ; chmod +x "$ScriptPath"
printf "\n%s\n" "--- starting over with the updated version ---"
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
exit 1 # exit the old instance exit 1 # exit the old instance
else else
printf "curl not available - download the update manually: %s \n" "$RawUrl" printf "curl/wget not available - download the update manually: %s \n" "$RawUrl"
fi fi
} }
self_update_select() {
read -r -p "Choose update procedure (or do it manually) - git/curl/[no]: " SelfUpQ self_update() {
if [[ "$SelfUpQ" == "git" ]]; then self_update_git ; cd "$ScriptWorkDir" || { printf "Path error, skipping update.\n" ; return ; }
elif [[ "$SelfUpQ" == "curl" ]]; then self_update_curl ; if [[ $(builtin type -P git) ]] && [[ "$(git ls-remote --get-url)" =~ .*"mag37/dockcheck".* ]] ; then
else printf "Download it manually from the repo: %s \n\n" "$Github" printf "\n%s\n" "Pulling the latest version."
git pull --force || { printf "Git error, manually pull/clone.\n" ; return ; }
printf "\n%s\n" "--- starting over with the updated version ---"
cd - || { printf "Path error.\n" ; return ; }
exec "$ScriptPath" "${ScriptArgs[@]}" # run the new script with old arguments
exit 1 # exit the old instance
else
cd - || { printf "Path error.\n" ; return ; }
self_update_curl
fi fi
} }
@@ -120,17 +124,34 @@ choosecontainers() {
datecheck() { datecheck() {
ImageDate=$($regbin image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 ) ImageDate=$($regbin image inspect "$RepoUrl" --format='{{.Created}}' | cut -d" " -f1 )
ImageAge=$((($(date +%s) - $(date -d "$ImageDate" +%s))/86400)) ImageAge=$(( ( $(date +%s) - $(date -d "$ImageDate" +%s) )/86400 ))
if [ $ImageAge -gt $DaysOld ] ; then if [ "$ImageAge" -gt "$DaysOld" ] ; then
return 0 return 0
else else
return 1 return 1
fi fi
} }
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)
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"
}
### Version check & initiate self update ### Version check & initiate self update
[[ "$VERSION" != "$LatestRelease" ]] && { printf "New version available! Local: %s - Latest: %s \n Change Notes: %s \n" "$VERSION" "$LatestRelease" "$LatestChanges" ; [[ -z "$AutoUp" ]] && self_update_select ; } if [[ "$VERSION" != "$LatestRelease" ]] ; then
printf "New version available! %b%s%b ⇒ %b%s%b \n Change Notes: %s \n" "$c_yellow" "$VERSION" "$c_reset" "$c_green" "$LatestRelease" "$c_reset" "$LatestChanges"
if [[ -z "$AutoUp" ]] ; then
read -r -p "Would you like to update? y/[n]: " SelfUpdate
[[ "$SelfUpdate" =~ [yY] ]] && self_update
fi
fi
### Set $1 to a variable for name filtering later. ### Set $1 to a variable for name filtering later.
SearchName="$1" SearchName="$1"
@@ -185,16 +206,21 @@ done
### Listing typed exclusions: ### Listing typed exclusions:
if [[ -n ${Excludes[*]} ]] ; then 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 "%s\n" "${Excludes[@]}"
printf "\n" printf "\n"
fi fi
# Variables for progress_bar function
DocCount=$(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}' | wc -l)
RegCheckQue=0
### Check the image-hash of every running container VS the registry ### Check the image-hash of every running container VS the registry
for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}') ; do for i in $(docker ps $Stopped --filter "name=$SearchName" --format '{{.Names}}') ; do
((RegCheckQue+=1))
progress_bar "$RegCheckQue" "$DocCount"
### Looping every item over the list of excluded names and skipping: ### Looping every item over the list of excluded names and skipping:
for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
printf ". "
RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}') RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}') LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
### Checking for errors while setting the variable: ### Checking for errors while setting the variable:
@@ -236,7 +262,7 @@ fi
if [[ -n ${GotUpdates[*]} ]] ; then if [[ -n ${GotUpdates[*]} ]] ; then
printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset" printf "\n%bContainers with updates available:%b\n" "$c_yellow" "$c_reset"
[[ -z "$AutoUp" ]] && options || printf "%s\n" "${GotUpdates[@]}" [[ -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 fi
### Optionally get updates if there's any ### Optionally get updates if there's any
@@ -259,6 +285,8 @@ if [ -n "$GotUpdates" ] ; then
ContName=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.service" }}') ContName=$(docker inspect "$i" --format '{{ index .Config.Labels "com.docker.compose.service" }}')
ContEnv=$(docker inspect "$i" --format '{{index .Config.Labels "com.docker.compose.project.environment_file" }}') ContEnv=$(docker inspect "$i" --format '{{index .Config.Labels "com.docker.compose.project.environment_file" }}')
ContImage=$(docker inspect "$i" --format='{{.Config.Image}}') ContImage=$(docker inspect "$i" --format='{{.Config.Image}}')
ContUpdateLabel=$(docker inspect "$i" --format '{{ index .Config.Labels "mag37.dockcheck.update" }}')
ContRestartStack=$(docker inspect "$i" --format '{{ index .Config.Labels "mag37.dockcheck.restart-stack" }}')
### Checking if compose-values are empty - hence started with docker run: ### Checking if compose-values are empty - hence started with docker run:
if [ -z "$ContPath" ] ; then if [ -z "$ContPath" ] ; then
if [ "$DRunUp" == "yes" ] ; then if [ "$DRunUp" == "yes" ] ; then
@@ -278,16 +306,28 @@ if [ -n "$GotUpdates" ] ; then
### cd to the compose-file directory to account for people who use relative volumes, eg - ${PWD}/data:data ### 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 ; } cd "$ContPath" || { echo "Path error - skipping $i" ; continue ; }
printf "\n%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset" printf "\n%bNow updating (%s/%s): %b%s%b\n" "$c_teal" "$CurrentQue" "$NumberofUpdates" "$c_blue" "$i" "$c_reset"
### Checking if Label Only -option is set, and if container got the label
[[ "$OnlyLabel" == true ]] && { [[ "$ContUpdateLabel" != true ]] && { echo "No update label, skipping." ; continue ; } }
docker pull "$ContImage" docker pull "$ContImage"
### Reformat for multi-compose: ### Reformat for multi-compose:
IFS=',' read -r -a Confs <<< "$ComposeFile" ; unset IFS IFS=',' read -r -a Confs <<< "$ComposeFile" ; unset IFS
for conf in "${Confs[@]}"; do CompleteConfs+="-f $conf " ; done for conf in "${Confs[@]}"; do CompleteConfs+="-f $conf " ; done
### Check if the container got an environment file set, use it if so: ### Check if the container got an environment file set, use it if so:
if [ -n "$ContEnv" ]; then if [ -n "$ContEnv" ]; then
$DockerBin ${CompleteConfs[@]} --env-file "$ContEnv" up -d "$ContName" # unquoted array to allow split - rework? ### prepare env-files arguments
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
else else
$DockerBin ${CompleteConfs[@]} up -d "$ContName" # unquoted array to allow split - rework? $DockerBin ${CompleteConfs[@]} ${ContEnvs} up -d "$ContName" # unquoted array to allow split - rework?
fi
else
if [[ "$ContRestartStack" == true ]] || [[ "$ForceRestartStacks" == true ]] ; then
$DockerBin ${CompleteConfs[@]} stop ; $DockerBin ${CompleteConfs[@]} up -d
else
$DockerBin ${CompleteConfs[@]} up -d "$ContName"
fi
fi fi
done done
printf "\n%bAll done!%b\n" "$c_green" "$c_reset" printf "\n%bAll done!%b\n" "$c_green" "$c_reset"
@@ -301,3 +341,4 @@ else
fi fi
exit 0 exit 0

27
notify_pushbullet.sh Normal file
View File

@@ -0,0 +1,27 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
#
# Copy/rename this file to notify.sh to enable the notification snippet.
# Required receiving services must already be set up.
# Requires jq installed and in PATH.
# Modify to fit your setup - set Url and Token.
send_notification() {
Updates=("$@")
UpdToString=$( printf "%s\n" "${Updates[@]}" )
FromHost=$(hostname)
# platform specific notification code would go here
printf "\nSending pushbullet notification\n"
MessageTitle="$FromHost - updates available."
# Setting the MessageBody variable here.
MessageBody="Containers on $FromHost with updates available: $UpdToString"
# Modify to fit your setup:
PushUrl="https://api.pushbullet.com/v2/pushes"
PushToken="Your Pushbullet token here"
# Requires jq to process json data
jq -n --arg title "$MessageTitle" --arg body "$MessageBody" '{body: $body, title: $title, type: "note"}' | curl -sS -o /dev/null --show-error --fail -X POST -H "Access-Token: $PushToken" -H "Content-type: application/json" $PushUrl -d @-
}

26
notify_telegram.sh Normal file
View File

@@ -0,0 +1,26 @@
### DISCLAIMER: This is a third party addition to dockcheck - best effort testing.
#
# Copy/rename this file to notify.sh to enable the notification snippet.
# Required receiving services must already be set up.
# Modify to fit your setup - set TelegramChatId and TelegramToken.
send_notification() {
Updates=("$@")
UpdToString=$( printf "%s\n" "${Updates[@]}" )
FromHost=$(hostname)
# platform specific notification code would go here
printf "\nSending Telegram notification\n"
# Setting the MessageBody variable here.
MessageBody="🐋 Containers on $FromHost with updates available: \n$UpdToString"
# Modify to fit your setup:
TelegramToken="Your Telegram token here"
TelegramChatId="Your Telegram ChatId here"
TelegramUrl="https://api.telegram.org/bot$TelegramToken"
TelegramData="{\"chat_id\":\"$TelegramChatId\",\"text\":\"$MessageBody\",\"disable_notification\": false}"
curl -sS -o /dev/null --fail -X POST "$TelegramUrl/sendMessage" -H 'Content-Type: application/json' -d "$TelegramData"
}