66 lines
2.8 KiB
Plaintext
66 lines
2.8 KiB
Plaintext
|
#!/bin/sh
|
|||
|
# Purpose {{{
|
|||
|
## Create a temp file (to monitor) if an upgrade is available for Sharelatex
|
|||
|
## 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.sharelatex.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}")
|
|||
|
|
|||
|
sharelatex_repo_name="sharelatex"
|
|||
|
sharelatex_image_name="sharelatex"
|
|||
|
|
|||
|
#sharelatex_current_version=$(docker container ls | grep -- "${sharelatex_repo_name}/${sharelatex_image_name}" | sed -- "s/.*${sharelatex_repo_name}\/${sharelatex_image_name}:\([^ ]*\) .*/\1/")
|
|||
|
sharelatex_current_version="v1.2.1"
|
|||
|
|
|||
|
sharelatex_grep_pattern="v[[:digit:]]\\.\\+[[:digit:]]*\\.\\?[[:digit:]]*$"
|
|||
|
sharelatex_new_version=$("${script_wd}"/imagetags "${sharelatex_repo_name}/${sharelatex_image_name}" "${sharelatex_grep_pattern}" | tail -n1)
|
|||
|
|
|||
|
sharelatex_new_version_file="/tmp/.docker.sharelatex.upgrade"
|
|||
|
# }}}
|
|||
|
|
|||
|
# Check if a container already runs with the wanted image {{{
|
|||
|
#if [ ! $(docker container ls | grep -q -- "${sharelatex_repo_name}${sharelatex_image_name}") ]; then
|
|||
|
#[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test ${sharelatex_image_name} — Current version is ${sharelatex_current_version}."
|
|||
|
#else
|
|||
|
#[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test ${sharelatex_image_name} — No container runs with ${sharelatex_image_name} image on this host."
|
|||
|
#rm -f -- "${sharelatex_new_version_file}"
|
|||
|
#exit 1
|
|||
|
#fi
|
|||
|
|
|||
|
## I am currently using a homemade version of Sharelatex in order to :
|
|||
|
## * use the last version of LaTeX/tlmgr env (2018)
|
|||
|
## * add severals packages used for Physics papers
|
|||
|
## For more informations, see :
|
|||
|
## https://github.com/ipr-cnrs/sharelatex-docker-image
|
|||
|
|
|||
|
# }}}
|
|||
|
|
|||
|
# Check if the current version is the last one {{{
|
|||
|
if [ "${sharelatex_current_version}" != "${sharelatex_new_version}" ]; then
|
|||
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test version — An upgrade is available for ${sharelatex_image_name}: ${sharelatex_new_version}."
|
|||
|
# Create a temp file to monitor
|
|||
|
touch -- "${sharelatex_new_version_file}"
|
|||
|
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for ${sharelatex_image_name}: ${sharelatex_new_version}." >> "${sharelatex_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 -- "${sharelatex_new_version_file}"
|
|||
|
fi
|
|||
|
# }}}
|
|||
|
|
|||
|
exit 0
|