nextcloud / vm

💻☁📦 The Nextcloud VM (virtual machine appliance), Home/SME Server and scripts for RPi (4). Community developed and maintained.
https://download.nextcloudvm.com
GNU General Public License v3.0
1.31k stars 661 forks source link

Create a Global Wrapper Script for Nextcloud's OCC Command #2586

Closed n0one42 closed 1 year ago

n0one42 commented 1 year ago

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 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

  1. Create a new file at sudo nano /usr/local/bin/occ with the content above.
  2. Make the script executable by running sudo chmod +x /usr/local/bin/occ.
  3. 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
enoch85 commented 1 year ago

Have you tried:

  1. sudo -i
  2. nextcloud_occ -V
n0one42 commented 1 year ago

Ah, did not knew about this. Thanks

stefanp2021 commented 4 months ago

2. nextcloud_occ -V

This doesn't work for me!

enoch85 commented 4 months ago
  1. nextcloud_occ -V

This doesn't work for me!

Try this:

  1. sudo -i
  2. nextcloud_occ -V