Last active
May 13, 2022 15:27
-
-
Save alainwolf/798cf72bb850e7bcba1e3e8ce177bdec to your computer and use it in GitHub Desktop.
Nextcloud Core Update Checker and Apps Updater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env ash | |
# shellcheck shell=dash | |
# | |
# Check Nextcloud core for available updates. | |
# * Update all Nextcloud apps to their latest available versions. | |
# * Notify if core update is available or any apps have been updated. | |
# * Stay silent otherwise (for cron-jobs or scheduled tasks). | |
# * Runs on standard Linux (Ubuntu, etc.), as well as Synology NAS DSM (if you get your settings right). | |
# * Works with different instances with dedicated Linux user profiles. | |
# | |
# See https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html | |
# | |
# -------------------------------------------------- | |
# Configuration Settings | |
# -------------------------------------------------- | |
# Installed Nextcloud instances | |
_NEXTCLOUD_DIRS=" | |
/var/services/web/nextcloud | |
/var/www/example.net/nextcloud | |
/var/www/example.org/nextcloud | |
/var/www/example.com/nextcloud | |
" | |
# Ensure PHP version of web-server matches | |
_PHP_CLI="/usr/local/bin/php74" | |
# Recomended PHP.INI options | |
_PHP_OPTIONS=" | |
memory_limit=-1 | |
extension_dir=/volume1/@appstore/PHP7.4/usr/local/lib/php74/modules | |
extension=apcu.so | |
apc.enable_cli=1 | |
opcache.enable_cli=1" | |
# Abort on any error on unset variable | |
set -e -u | |
_php_cmd_opts="" | |
for _php_option in $_PHP_OPTIONS; do | |
_php_cmd_opts="$_php_cmd_opts --define $_php_option" | |
done | |
for _nc_dir in $_NEXTCLOUD_DIRS; do | |
# Get the Linux system user who owns this Nextcloud instance | |
_nextcloud_owner=$(stat -c '%U' "$_nc_dir") | |
cd "$_nc_dir" || exit | |
_occ_cmd="sudo -u $_nextcloud_owner $_PHP_CLI $_php_cmd_opts -f ./occ --" | |
# Update any app, regardeless | |
_occ_app_result=$( $_occ_cmd --no-ansi app:update --all ) | |
# Check for Nextcloud core and apps updates | |
_occ_core_result=$( $_occ_cmd --no-ansi update:check ) | |
if [ "$_occ_core_result" != "Everything up to date" ] || [ -n "$_occ_app_result" ]; then | |
echo "Updates for $(basename "$( dirname "$_nc_dir" )" ):" | |
echo "$_occ_core_result\n" | |
echo "$_occ_app_result\n" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment