To streamline the management of Nextcloud instances, especially in command-line environments, a global wrapper script for Nextcloud's occ command would be highly beneficial. This script would allow administrators to execute occ commands from any location in the system without needing to navigate to the Nextcloud directory or switch users manually.
Proposed Change
Create a wrapper script named occ and place it in /usr/local/bin/. This script will handle running the occ command as the www-data user (or the user under which Nextcloud runs), facilitating easy and secure management of Nextcloud instances.
Here is a proposed script:
#!/bin/bash
# Path to your Nextcloud installation
NEXTCLOUD_PATH="/var/www/nextcloud"
# OCC command within Nextcloud
OCC_COMMAND="$NEXTCLOUD_PATH/occ"
# Check if the user is running the script with sudo
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run with sudo!" >&2
exit 1
fi
# Execute the OCC command as the www-data user
sudo -u www-data php "$OCC_COMMAND" "$@"
Deployment
Create a new file at sudo nano /usr/local/bin/occ with the content above.
Make the script executable by running sudo chmod +x /usr/local/bin/occ.
Test the script by running occ from any location. It should behave exactly like your Nextcloud's occ command, but now it's accessible system-wide.
Example: sudo occ files:scan --unscanned --all
Description
To streamline the management of Nextcloud instances, especially in command-line environments, a global wrapper script for Nextcloud's
occ
command would be highly beneficial. This script would allow administrators to executeocc
commands from any location in the system without needing to navigate to the Nextcloud directory or switch users manually.Proposed Change
Create a wrapper script named
occ
and place it in/usr/local/bin/
. This script will handle running theocc
command as thewww-data
user (or the user under which Nextcloud runs), facilitating easy and secure management of Nextcloud instances.Here is a proposed script:
Deployment
sudo nano /usr/local/bin/occ
with the content above.sudo chmod +x /usr/local/bin/occ
.occ
from any location. It should behave exactly like your Nextcloud'socc
command, but now it's accessible system-wide. Example:sudo occ files:scan --unscanned --all