scripts/github/check.nextcloud.update

98 lines
3.7 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Nextcloud
## project on Github.
## 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.
## 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 with Nextcloud directory as first argument, eg.
#00 20 * * * root /opt/repos/ipr.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_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"
# }}}
# Get the 3 last tags releses for Nextcloud
## Exclude tag starting with "v", and those contains alpha, beta or RC
rm -f -- "${nc_new_version_list}" ; touch -- "${nc_new_version_list}"
"${script_wd}"/releasetags "${nc_repo_url}" | grep -v -E -- "(^v|alpha|beta|RC)" | 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}"
### Exit to ensure to keep the file in place
exit 0
## }}}
## 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
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current version is up-to-date."
rm -f -- "${nc_new_version_file}"
fi
# }}}
done < "${nc_new_version_list}"
rm -f -- "${nc_new_version_list}"
exit 0