scripts/github/check.rocketchat-electron.u...

87 lines
3.3 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.

This file contains Unicode characters that might be confused with other characters. 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.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"
rkt_new_pkg_url="https://github.com/RocketChat/Rocket.Chat.Electron/releases/download/${rkt_new_version}/rocketchat_${rkt_new_version}_amd64.deb"
rkt_new_pkg_path="/tmp/rocketchat_${rkt_new_version}_amd64.deb"
# }}}
# 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}"
## If it doesn't already exists, download this new package
if [ ! -f "${rkt_new_pkg_path}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Download .deb file from Rocket.Chat.Electron repository on Github to ${rkt_new_pkg_path} ."
wget --quiet "${rkt_new_pkg_url}" --output-document="${rkt_new_pkg_path}"
fi
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current version is up-to-date."
## Ensure to remove any temp file and useless .deb file
rm -f -- "${rkt_new_version_file}" "${rkt_new_pkg_path}"
fi
# }}}
exit 0