#!/usr/bin/env bash # This script ensures my `nextcloud` clients operate in a uniform way set -eu CFG="${XDG_CONFIG_HOME:-$HOME/.config}/Nextcloud/nextcloud.cfg" SERVER_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/Nextcloud/server.txt" XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share} FORCE=0 [ "${1:-}" = "--force" ] && FORCE=1 if [ -r "$SERVER_FILE" ]; then SERVER_URL=$(head -n 1 "$SERVER_FILE") elif [ "$FORCE" -eq 1 ]; then SERVER_URL="" echo "WARN: $SERVER_FILE not found, leaving the server URL unmanaged" >&2 else echo "Server URL not found at: $SERVER_FILE" >&2 echo "" 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 exit 1 fi if ! command -v crudini >/dev/null 2>&1; then echo "crudini is not installed => Cannot configure nextcloud" >&2 exit 1 fi del_key() { # section key crudini --del "$CFG" "$1" "$2" } set_key() { # section key value crudini --set "$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 "$CFG")" touch "$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 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` nextcloud --background & disown