From c1c49aa7d349d7bdf4cc0223b7e0bc870f12abd6 Mon Sep 17 00:00:00 2001 From: Siina Mashek Date: Mon, 22 Apr 2024 06:47:34 +0300 Subject: [PATCH] Adding lock to nc-sync to ensure only one runs at a time --- apsalar/nc-sync | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/apsalar/nc-sync b/apsalar/nc-sync index 310a79f..eea0a2d 100755 --- a/apsalar/nc-sync +++ b/apsalar/nc-sync @@ -1,6 +1,22 @@ #!/bin/sh -NC_DIR="$HOME/Nextcloud" -NC_URL="https://cloud.criminallycute.fi" +( + if flock -n 9 + then + notify-send 'Not doing the critical operation (lock present).' + exit; + fi + + # Needed for cronjob + source /home/siina/.config/private.env + + NC_DIR="/home/siina/Nextcloud" + NC_URL="https://cloud.criminallycute.fi" + + notify-send "Nextcloud Sync Syncing ..." + nextcloudcmd -u $NC_USER -p $NC_PASS $NC_DIR $NC_URL + notify-send "Nextcloud Sync Done syncing" + +) 9>'/tmp/nc-sync.lock' +rm -f '/tmp/nc-sync.lock' -nextcloudcmd -s -u $NC_USER -p $NC_PASS $NC_DIR $NC_URL