#!/bin/sh # This script ensures my `nextcloud` clients operate in a uniform way set -eu XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" NEXTCLOUD_CFG="${XDG_CONFIG_HOME:-$HOME/.config}/Nextcloud/nextcloud.cfg" SERVER_URL_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/Nextcloud/server.txt" if [ -r "$SERVER_URL_FILE" ]; then # `tr` strips spaces, tabs, and CR/LF SERVER_URL=$(head -n 1 "$SERVER_URL_FILE" | tr -d '[:space:]') else SERVER_URL="" fi [ "${1:-}" = "--force" ] && force=1 || force=0 if [ -z "$SERVER_URL" ]; then if [ "$force" -eq 1 ]; then echo "" >&2 echo "WARN: No usable server URL at $SERVER_URL_FILE, leaving the server URL unmanaged" >&2 echo "" >&2 else echo "" >&2 echo "No usable server URL found at $SERVER_URL_FILE" >&2 echo "" >&2 echo "Create it with a single line, e.g., 'https://cloud.example.com'," >&2 echo "or re-run with --force to skip the URL settings" >&2 echo "" >&2 exit 1 fi fi if ! command -v crudini >/dev/null 2>&1; then echo "crudini is not installed => cannot configure nextcloud" >&2 exit 1 fi if ! command -v nextcloud >/dev/null 2>&1; then echo "Nextcloud is not installed" >&2 exit 1 fi del_key() { # section key crudini --del "$NEXTCLOUD_CFG" "$1" "$2" } set_key() { # section key value crudini --set "$NEXTCLOUD_CFG" "$1" "$2" "$3" } # Stop `nextcloud` nextcloud --quit 2>/dev/null || true for _ in $(seq 30); do pgrep -x nextcloud >/dev/null || break sleep 0.5 done if pgrep -x nextcloud >/dev/null; then echo "Nextcloud did not exit; aborting" >&2 exit 1 fi mkdir -p "$(dirname "$NEXTCLOUD_CFG")" touch "$NEXTCLOUD_CFG" # Configure base settings for `nextcloud` if [ -n "$SERVER_URL" ]; then set_key General forceOverrideServerUrl true set_key General overrideServerUrl "$SERVER_URL" fi set_key General overrideLocalDir "$HOME/Cloud" set_key General launchOnSystemStartup true set_key General monoIcons true set_key General crashReporter false # Windows-only, kept for completeness set_key General showInExplorerNavigationPane true set_key General optionalServerNotifications false set_key General showCallNotifications false set_key General showChatNotifications false set_key General isVfsEnabled false # `true` is also not good for `gocryptfs` syncs set_key General confirmExternalStorage true set_key General useNewBigFolderSizeLimit false set_key General newBigFolderSizeLimit 999 set_key General notifyExistingFoldersOverLimit false set_key General stopSyncingExistingFoldersOverLimit false set_key General moveToTrash true set_key General promptDeleteAllFiles true set_key Proxy type 0 # Make `nextcloud` sync at full speed, with sane fallback limits # Modes: # - 0 => unlimited # - -1 => automatic limit # - +1 => manually set limit # Limits: # - values are in KBytes/s # - we assume line speeds of 100/30 Mbit/s, to be capped at 80% set_key BWLimit useDownloadLimit 0 # 100 Mbit/s / 8 => 12500 KBytes/s * 0.8 => 10000 set_key BWLimit downloadLimit 10000 set_key BWLimit useUploadLimit 0 # 30 Mbit/s / 8 => 3750 KBytes/s * 0.8 => 3000 set_key BWLimit uploadLimit 3000 set_key Nextcloud remotePollInterval 60000 # Because of a bug, `nextcloud` wants to create logs at a deprecated location # => An empty file at that location makes `nextcloud` use the new location # inside ~/.config/Nextcloud rm -rf "$XDG_DATA_HOME/Nextcloud" touch "$XDG_DATA_HOME/Nextcloud" # Resume `nextcloud` setsid nextcloud --background >/dev/null 2>&1 &