Skip to content

Instantly share code, notes, and snippets.

@alainwolf
Created January 18, 2022 21:26
Show Gist options
  • Save alainwolf/9facf318c2d21850142c691b2e16f5dd to your computer and use it in GitHub Desktop.
Save alainwolf/9facf318c2d21850142c691b2e16f5dd to your computer and use it in GitHub Desktop.
Nextcloud Command-Line Interface
#!/bin/env sh
# shellcheck shell=dash
#
# Nextcloud Command-Line Interface
#
# See https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html
#
# --------------------------------------------------
# Configuration Settings
# --------------------------------------------------
# Installed Nextcloud instance
_NEXTCLOUD_INSTALL_DIR="/var/www/example.net/nextcloud"
# Ensure PHP version of web-server matches
_PHP_CLI="/usr/bin/php7.4"
# System user running the web-server
_NEXTCLOUD_OWNER="www-data"
# Recomended PHP.INI options
_PHP_OPTIONS="
memory_limit=-1
apc.enable_cli=1
opcache.enable_cli=1"
# --------------------------------------------------
# End Of Settings
# --------------------------------------------------
# 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
cd "$_NEXTCLOUD_INSTALL_DIR" || exit 1
# shellcheck disable=SC2086
sudo -u "$_NEXTCLOUD_OWNER" \
"$_PHP_CLI" $_php_cmd_opts -f ./occ -- "$@"
@alainwolf
Copy link
Author

Convenient and safe command for sys-admins to manage your nextcloud instance from the command-line. without the need to remember or lookup all the caveats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment