#!/bin/sh # Purpose {{{ ## Create a temp file (to monitor) if an upgrade is available for Nextcloud ## project on Github or one of it's application. ## It based on the nextcloud's root directory to get the current version and ## supposed to be install from source (github) or at least get a VERSION file. ## For Nextcloud's apps, the `occ` command is used with sudo www-data. ## 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 Nextcloud directory as first argument, eg. #00 20 * * * root /opt/repos/gardouille.scripts/github/check_nextcloud_update /var/www/nextcloud ### 3. Monitor the temp file : /tmp/.github.nextcloud.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.nextcloud.update -- Compare current version of an installed Nextcloud and the last available. EXAMPLE : - Compare the current version installed in /var/www/nextcloud.domain.tld check.nextcloud.update /var/www/nextcloud.domain.tld HELP exit 1 fi # }}} # Vars {{{ DEBUG=1 script_wd=$(dirname "${0}") nc_install_dir="${1}" nc_occ_path="${nc_install_dir}/occ" ## Nextcloud core {{{ nc_current_version=$(grep -- OC_VersionString "${nc_install_dir}"/version.php | sed "s/^\$OC.* = '\(.*\)';$/\1/" || exit 1) nc_current_major=$(grep -- OC_VersionString "${nc_install_dir}"/version.php | sed "s/^\$OC.* = '\(.*\)';$/\1/" | cut -d"." -f1 || exit 2) nc_repo_url="https://github.com/nextcloud/server" nc_new_version_list="/tmp/.github.nextcloud.taglist" #nc_new_version=$("${script_wd}"/releasetags "${nc_repo_url}" | grep -v -E -- "(^v|alpha|beta|RC)" | head -n3) nc_new_version_file="/tmp/.github.nextcloud.upgrade" ## }}} ## Apps {{{ nc_app_upgrade=$(sudo -u www-data php --file "${nc_occ_path}" app:update --showonly) nc_app_new_version_file="/tmp/.github.nextcloud.app.upgrade" ## }}} # }}} # Check Nextcloud upgrade {{{ # Get the 3 last tags releses for Nextcloud ## Exclude tag starting with "v", and those contains alpha, beta or RC rm --force -- "${nc_new_version_list}" ; touch -- "${nc_new_version_list}" "${script_wd}"/releasetags "${nc_repo_url}" | grep -v -E -- "(alpha|beta|RC|rc)" | sed 's/^v//' | head -n3 >> "${nc_new_version_list}" # For all tags contained in the tag list while IFS= read -r nc_new_version; do # Check if the current version is the last one {{{ if [ "${nc_current_version}" != "${nc_new_version}" ]; then [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test version — Current version (${nc_current_version}) and latest available (${nc_new_version}) seems to be different." nc_new_major=$(echo "${nc_new_version}" | cut -d"." -f1) ## If it's a minor release for stable or a new stable version {{{ if [ "${nc_current_major}" -le "${nc_new_major}" ]; then [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test release major — A minor or major upgrade needs to be apply." ### Create a temp file to monitor touch -- "${nc_new_version_file}" printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Nextcloud (current : ${nc_current_version}) : ${nc_new_version}." >> "${nc_new_version_file}" printf '\e[1;35m%-6s\e[m\n' "Please also take a look to the CHANGELOG : https://nextcloud.com/changelog/#latest${nc_new_major}" >> "${nc_new_version_file}" ## }}} ## It's an upgrade for a previous major release {{{ else [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test release major — It looks like an upgrade for a previous major release." fi ## }}} # }}} # Same version {{{ else ## If no previous upgrade was already detected if [ ! -s "${nc_app_new_version_file}" ]; then [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Test version — The current version is up-to-date." rm --force -- "${nc_new_version_file}" ### Exit while loop break fi fi # }}} done < "${nc_new_version_list}" rm --force -- "${nc_new_version_list}" # }}} # Check apps upgrade {{{ rm --force -- "${nc_app_new_version_file}" ; touch -- "${nc_app_new_version_file}" printf '%s' "${nc_app_upgrade}" >> "${nc_app_new_version_file}" ## If the file contains a part of the message if ane upgrade is available ## Example of message if at least one upgrade : ## files_antivirus new version available: 5.5.3 if grep --quiet -- "new version available" "${nc_app_new_version_file}"; then [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Apps test — Upgrade seems to be available for apps. Please check ${nc_app_new_version_file}." else ## Example of message if NO upgrade: ## All apps are up-to-date or no updates could be found [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Apps test — All apps seems up-to-date." rm --force -- "${nc_app_new_version_file}" fi # }}} exit 0