scripts/docker/check.rocketchat.update

56 lines
2.1 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for rocket.chat
## image on the Docker Hub.
## How-to use {{{
### 1. Needs imagetags script, in the same directory
### cf. https://git.ipr.univ-rennes1.fr/cellinfo/scripts/src/master/docker/imagetags
# wget https://git.ipr.univ-rennes1.fr/cellinfo/scripts/raw/master/docker/imagetags
### 2. Ensure to run with a user member of the docker group.
### 3. Create a cron job, eg.
#00 20 * * * root /opt/repos/ipr.scripts/docker/check.rocketchat.update
### 4. Monitor the temp file.
# Or enable MAILTO in cronjob and print a message in the script.
# Or send a mail.
# …
## }}}
# }}}
# Vars {{{
DEBUG=1
script_wd=$(dirname "${0}")
rkt_repo_name="rocketchat"
rkt_image_name="rocket.chat"
rkt_current_version=$(docker container ls | grep -- "${rkt_repo_name}/${rkt_image_name}" | sed -- "s/.*${rkt_repo_name}\/${rkt_image_name}:\([^ ]*\) .*/\1/")
rkt_grep_pattern="[[:digit:]]\\.\\+[[:digit:]]*\\.\\?[[:digit:]]*$"
rkt_new_version=$("${script_wd}"/imagetags "${rkt_repo_name}/${rkt_image_name}" "${rkt_grep_pattern}" | tail -n1)
rkt_new_version_file="/tmp/.docker.rocket.chat.upgrade"
# }}}
# Check if a container already runs with the wanted image {{{
if [ ! $(docker container ls | grep -q -- "${rkt_repo_name}${rkt_image_name}") ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test ${rkt_image_name} — Current version is ${rkt_current_version}."
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test ${rkt_image_name} — No container runs with ${rkt_image_name} image on this host."
exit 1
fi
# }}}
# Check if the current version is the last one {{{
if [ "${rkt_current_version}" != "${rkt_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — An upgrade is available for ${rkt_image_name}: ${rkt_new_version}."
# Create a temp file to monitor
touch -- "${rkt_new_version_file}"
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current version is up-to-date."
rm -f -- "${rkt_new_version_file}"
fi
# }}}
exit 0