#!/bin/sh # Purpose {{{ ## Create a temp file (to monitor) if an upgrade is available for Wallabag ## project on Github. ## It based on the wallabag's root directory to get the current version and ## supposed to be install from source (github). ## How-to use {{{ ### 1. Needs releasetags script, in the same directory ### cf. https://git.101010.fr/gardouille-dotfiles/scripts/src/branch/master/github/releasetags # wget https://git.101010.fr/gardouille-dotfiles/scripts/raw/branch/master/github/releasetags ### 2. Create a cron job with Wallabag directory as first argument, eg. #00 20 * * * root /opt/repos/gardouille.scripts/github/check_wallabag_update /var/www/wallabag ### 3. Monitor the temp file : /tmp/.github.wallabag.upgrade # Or enable MAILTO in cronjob and edit the script to print a message. # Or send a mail. # … ## }}} # }}} # Expect 1 argument {{{ if [ $# -ne 1 ] then cat << HELP check.wallabag.update -- Compare current version of an installed Wallabag and the last available. EXAMPLE : - Compare the current version installed in /var/www/bag.domain.tld check.wallabag.update /var/www/bag.domain.tld HELP exit 1 fi # }}} # Vars {{{ DEBUG=1 script_wd=$(dirname "${0}") wb_install_dir="${1}" wb_current_version=$(cd "${wb_install_dir}" || exit 1 ; git status | head -n1 | cut -d" " -f4 ; cd - > /dev/null || exit 1) wb_repo_url="https://github.com/wallabag/wallabag" wb_new_version=$("${script_wd}"/releasetags "${wb_repo_url}" | head -n1) wb_new_version_file="/tmp/.github.wallabag.upgrade" # }}} # Check if the current version is the last one {{{ if [ "${wb_current_version}" != "${wb_new_version}" ]; then [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test version — Current version (${wb_current_version}) and new one (${wb_new_version}) seems to be different." ## Create a temp file to monitor touch -- "${wb_new_version_file}" printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Wallabag (current : ${wb_current_version}) : ${wb_new_version}." >> "${wb_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 -- "${wb_new_version_file}" fi # }}} exit 0