scripts/github/check.nextcloud.update

126 lines
4.7 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# Purpose {{{
## Create a temp file (to monitor) if an upgrade is available for Nextcloud
2019-10-16 16:55:42 +02:00
## 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.
2019-10-16 16:55:42 +02:00
## 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.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}"
2019-10-16 16:55:42 +02:00
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"
2019-10-16 16:55:42 +02:00
## }}}
## 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"
## }}}
# }}}
2019-10-16 16:55:42 +02:00
# Check 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 -- "(alpha|beta|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 -f -- "${nc_new_version_file}"
fi
fi
# }}}
done < "${nc_new_version_list}"
rm -f -- "${nc_new_version_list}"
2019-10-16 16:55:42 +02:00
# }}}
# Check apps upgrade {{{
rm -f -- "${nc_app_new_version_file}" ; touch -- "${nc_app_new_version_file}"
printf '%s' "${nc_app_upgrade}" >> "${nc_app_new_version_file}"
## If the file exists with a size bigger than 0
if [ -s "${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
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Apps test — All apps seems up-to-date."
rm -f -- "${nc_app_new_version_file}"
fi
# }}}
exit 0