#!/bin/sh # Purpose {{{ ## Create a temp file (to monitor) if an upgrade is available for Rocket.Chat.Electron ## project on Github. ## It's based on .deb package installation to check the current version. ## It can also compare the current available version in APT repositories ## if "repo" is given as first argument. ## How-to use {{{ ### 1. Needs releasetags script, in the same directory ### cf. https://git.ipr.univ-rennes1.fr/cellinfo/scripts/src/master/github/releasetags # wget https://git.ipr.univ-rennes1.fr/cellinfo/scripts/raw/master/github/releasetags ### 2. Create a cron job, eg : #00 20 * * * root /opt/repos/ipr.scripts/github/check.rocketchat-electron.update ### 2-1 Create a cron job to compare the version available in a Debian repository : #00 20 * * * root /opt/repos/ipr.scripts/github/check.rocketchat-electron.update repo ### 3. Monitor the temp file : /tmp/.github.rocketchat-electron.upgrade # Or enable MAILTO in cronjob and edit the script to print a message. # Or send a mail. # … ## }}} # }}} # Expect maximum 1 argument {{{ if [ $# -gt 1 ] then cat << HELP check.rocketchat-electron.update -- Compare current version of an installed Rocket.Chat.Electron and the last available. EXAMPLE : - Compare the current version installed from .deb file check.rocketchat-electron.update - Compare the current version from apt's repository check.rocketchat-electron.update repo HELP exit 1 fi # }}} # Vars {{{ DEBUG=1 script_wd=$(dirname "${0}") rkt_repo_url="https://github.com/RocketChat/Rocket.Chat.Electron" if [ $# -eq 1 ] && [ "${1}" = "repo" ] ## If repository's version should be compared then rkt_current_version=$(apt-cache policy rocketchat | awk '/Candidate:/ {print $2}' | sed 's/.:\(.*\)-.*/\1/') else rkt_current_version=$(dpkg -l rocketchat | awk '/^ii.*rocketchat/ {print $3}' | sed 's/.:\(.*\)-.*/\1/') fi rkt_new_version=$("${script_wd}"/releasetags "${rkt_repo_url}" | head -n1 | sed 's/v//g') rkt_new_version_file="/tmp/.github.rocketchat-electron.upgrade" # }}} # 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 — Current version (${rkt_current_version}) and new one (${rkt_new_version}) seems to be different." ## Create a temp file to monitor touch -- "${rkt_new_version_file}" printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Rocket.Chat client − Electron (current : ${rkt_current_version}) : ${rkt_new_version}." >> "${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