From 6f85cca3813dd25822a3cf9a9067ada2d2dc8932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Tue, 28 Aug 2018 11:32:05 +0200 Subject: [PATCH] Script to watch upgrade on Sharelatex Docker img --- docker/check.sharelatex.update | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 docker/check.sharelatex.update diff --git a/docker/check.sharelatex.update b/docker/check.sharelatex.update new file mode 100755 index 0000000..96b2700 --- /dev/null +++ b/docker/check.sharelatex.update @@ -0,0 +1,65 @@ +#!/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