The problem here isn’t so much that you want to do it automatically, but you’re making it cumbersome and extremely insecure. No database dump is created and no other backup either and that per cron. Your instance is not set into maintenance mode during the update. Steps are performed that are not needed at all! It looks like a typical chat-gpt mess.
Nextcloud comes with its own update script that you should use:
sudo chmod +x updater/updater.phar
updater/updater.phar --help
Description:
Updates the code of an Nextcloud instance
Usage:
update [options]
Options:
--no-backup Skip backup of current Nextcloud version
--no-upgrade Don't automatically run occ upgrade
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Help:
This command fetches the latest code that is announced via the updater server and safely replaces the existing code with the new one.
This determines whether all requirements such as php version etc. are met and makes a backup in a secure way. You can do it without interaction (for your purpose) but i would never advice to do so.
You should do your updates on the console and create aliases for your automations, one for pre-update-steps (database dump and backup) and post-update-steps (fix all integrity tests, create missing indices, check if all services like notify_push etc. are up and runing)
Then you should never start using automations when you do not have created the revert script as well. So before I perform an update, I create the backup and with an other atomation I am able to revert everything to that snapshot-state, so that if something goes wrong, I am able to revert to my old state.
I am using my cloud server, because I want to get rid of oldschool mail. Why should I look in my mailserver for the results of an update?
As you hardly could oversee, I am not impressed by this script and I want to extremely discourage its use and will not give any support for those, who thought it might be a good idea to shoot in his own foot with it.
much luck!