diff --git a/scripts/org-todo-pwa.service b/scripts/org-todo-pwa.service new file mode 100644 index 0000000..d508869 --- /dev/null +++ b/scripts/org-todo-pwa.service @@ -0,0 +1,10 @@ +[Unit] +Description=Synka Fredriks org-todo-pwa + +[Service] +ExecStart=/home/fredrik/bin/todo-watcher.sh +Restart=always +User=fredrik + +[Install] +WantedBy=multi-user.target diff --git a/scripts/todo-watcher.sh b/scripts/todo-watcher.sh new file mode 100755 index 0000000..8e5aced --- /dev/null +++ b/scripts/todo-watcher.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Set paths to the files +SOURCE_FILE="/srv/swarm/org-todo-pwa/data/tasks.org" +DEST_FILE="/home/fredrik/org-mode/pwa.org" + +# Watch for multiple events on the source file (e.g., modify, close_write, attrib) +inotifywait -m -e modify "$SOURCE_FILE" | while read path action file; do + # Compare the full path of the file being watched to the source file + if [ "$path$file" == "$SOURCE_FILE" ]; then + # Check if the file is empty (size 0) to avoid appending empty content + if [ -s "$SOURCE_FILE" ]; then + # Append the contents of the source file to the destination file + cat "$SOURCE_FILE" >> "$DEST_FILE" + + # Empty the source file + > "$SOURCE_FILE" + + echo "Appended contents of $SOURCE_FILE to $DEST_FILE and emptied the source file." + else + echo "$SOURCE_FILE is empty, skipping append." + fi + fi +done