#!/bin/sh # Purpose {{{ ## Create a temp file (to monitor) if an upgrade is available for Alacritty ## 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.alacritty.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.alacritty.update repo ### 3. Monitor the temp file : /tmp/.github.alacritty.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.alacritty.update -- Compare current version of an installed Alacritty and the last available. EXAMPLE : - Compare the current version installed from .deb file check.alacritty.update - Compare the current version from apt's repository check.alacritty.update repo HELP exit 1 fi # }}} # Vars {{{ DEBUG=1 script_wd=$(dirname "${0}") alacritty_repo_url="https://github.com/barnumbirr/alacritty-debian" if [ $# -eq 1 ] && [ "${1}" = "repo" ] ## If repository's version should be compared then alacritty_current_version=$(apt-cache policy alacritty | awk '/Candidate:/ {print $2}' | sed 's/.:\(.*\)-.*/\1/') else alacritty_current_version=$(dpkg -l alacritty | awk '/^ii.*alacritty/ {print $3}' | sed 's/.:\(.*\)-.*/\1/') fi alacritty_new_version=$("${script_wd}"/releasetags "${alacritty_repo_url}" | head -n1 | sed 's/v//g') alacritty_new_version_file="/tmp/.github.alacritty.upgrade" alacritty_new_pkg_url="${alacritty_repo_url}/releases/download/v${alacritty_new_version}/alacritty_${alacritty_new_version}_amd64_unstable.deb" alacritty_tmp_pkg_path="/tmp/.alacritty_${alacritty_new_version}_amd64_unstable.deb" alacritty_new_pkg_path="/tmp/alacritty_${alacritty_new_version}_amd64_unstable.deb" # }}} # Check if the current version is the last one {{{ if [ "${alacritty_current_version}" != "${alacritty_new_version}" ]; then [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test version — Current version (${alacritty_current_version}) and new one (${alacritty_new_version}) seems to be different." ## If it doesn't already exists, download this new package if [ ! -f "${alacritty_new_pkg_path}" ]; then [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Download .deb file from Alacritty repository on Github to: ${alacritty_new_pkg_path} ." wget --quiet "${alacritty_new_pkg_url}" --output-document="${alacritty_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 --force -- "${alacritty_new_version_file}" "${alacritty_new_pkg_path}" "${alacritty_tmp_pkg_path}" ## Exit exit 0 fi # }}} # Verify downloaded package {{{ ## If the downloaded package has a size greater than zero {{{ if [ -s "${alacritty_new_pkg_path}" ]; then [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Empty file ? — \ Downloaded package looks good." ### Create a temp file to monitor touch -- "${alacritty_new_version_file}" printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Alacritty terminal (current : ${alacritty_current_version}) : ${alacritty_new_version}." >> "${alacritty_new_version_file}" ### Exit exit 0 else [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Empty file ? — \ Empty file, don't need to go further." ### Ensure to remove the file to monitor rm --force -- "${alacritty_new_version_file}" ### Keep a record of the downloaded package because as a new release might come soon mv --force -- "${alacritty_new_pkg_path}" "${alacritty_tmp_pkg_path}" ### Exit exit 0 fi ## }}} # }}} exit 255