From 5b4c5549c2c1f4f9b43dce8012fe1445dd2b548b Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 20 Apr 2024 12:55:58 +0200 Subject: [PATCH] Allow setting cache duration for individual syncs --- scripts/Common/Config/UserProfile/install.sh | 2 +- scripts/Common/Config/rclone/InstallSync.sh | 6 ++++++ scripts/Common/Config/rclone/rclone@.service | 15 ++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/Common/Config/UserProfile/install.sh b/scripts/Common/Config/UserProfile/install.sh index 8abede33..20b4ebd8 100755 --- a/scripts/Common/Config/UserProfile/install.sh +++ b/scripts/Common/Config/UserProfile/install.sh @@ -33,7 +33,7 @@ else # Sync clouds echo "Please complete the setup of your profile!"; NEXTCLOUD_DIR="${NEXTCLOUD_DIR}" . "../rclone/InstallSync.sh" nextcloud "$NEXTCLOUD_DIR"; - PROTON_DIR="${PROTON_DIR}" . "../rclone/InstallSync.sh" proton "$PROTON_DIR"; + PROTON_DIR="${PROTON_DIR}" . "../rclone/InstallSync.sh" proton "$PROTON_DIR" "2w"; if isTruthy "$INSTALL_FONTS" then diff --git a/scripts/Common/Config/rclone/InstallSync.sh b/scripts/Common/Config/rclone/InstallSync.sh index 81a66964..585b3acf 100755 --- a/scripts/Common/Config/rclone/InstallSync.sh +++ b/scripts/Common/Config/rclone/InstallSync.sh @@ -1,8 +1,14 @@ #!/bin/bash provider="$1"; dirname="$2"; +cacheDuration="$3"; serviceName="rclone@$provider:$dirname"; +if [ ! -z "${cacheDuration}" ] +then + serviceName="${serviceName}:$cacheDuration"; +fi; + echo "Please create a remote called \`$1\`"; rclone config || true; systemctl --user enable "$serviceName" --now || true; diff --git a/scripts/Common/Config/rclone/rclone@.service b/scripts/Common/Config/rclone/rclone@.service index 5337198f..13175acf 100644 --- a/scripts/Common/Config/rclone/rclone@.service +++ b/scripts/Common/Config/rclone/rclone@.service @@ -7,8 +7,16 @@ Type=notify Environment="EXPRESSION=%i" ExecStart= \ bash -c ' \ - target="${EXPRESSION%%":"*}"; \ - dirname="${EXPRESSION#*":"}"; \ + args=; \ + target="$(echo "$EXPRESSION" | cut -d":" -f1)"; \ + dirname="$(echo "$EXPRESSION" | cut -d":" -f2)"; \ + cacheDuration="$(echo "$EXPRESSION" | cut -d":" -f3)"; \ + \ + if [ ! -z "$cacheDuration" ]; \ + then \ + args="--vfs-cache-max-age=$cacheDuration"; \ + fi; \ + \ destination="`cd "%h/.mnt"; realpath -m "$dirname"`"; \ mkdir -p "$destination"; \ mkdir -p /tmp/rclone; \ @@ -16,8 +24,9 @@ ExecStart= \ --config="%h/.config/rclone/rclone.conf" \ --vfs-cache-mode full \ --log-file /tmp/rclone/$target.log \ + $args \ $target: "$destination";' -ExecStop=bash -c '/bin/fusermount -zu "`cd "%h/.mnt"; realpath "${EXPRESSION#*":"}"`"' +ExecStop=bash -c '/bin/fusermount -zu "`cd "%h/.mnt"; realpath "$(echo "$EXPRESSION" | cut -d":" -f2)"`"' Restart=always RestartSec=10