49 lines
1.3 KiB
Bash
Executable file
49 lines
1.3 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
DATA="$HOME/.local/share/task"
|
|
|
|
n=0
|
|
while IFS= read -r _; do
|
|
n=$((n + 1))
|
|
done
|
|
|
|
if [ "$n" -gt 0 ]; then
|
|
{
|
|
lockfile="$DATA/sync_hook.lock"
|
|
errfile="$DATA/sync_hook.err"
|
|
lerrfile="$DATA/sync_hook.errl"
|
|
logfile="$DATA/sync_hook.log"
|
|
|
|
flock "$lockfile" sh -c '
|
|
task sync >>"$1" 2>"$2"
|
|
status=$?
|
|
if [ "$status" -ne 0 ]; then
|
|
echo "Taskwarrior sync failed at $(date)" >>"$2"
|
|
|
|
if command -v sendmail >/dev/null 2>&1; then
|
|
{
|
|
echo "To: daniel@ficd.ca"
|
|
echo "From: daniel@ficd.ca"
|
|
echo "Subject: Taskwarrior Sync Failed on $(hostname)"
|
|
echo "Date: $(date -R)"
|
|
echo ""
|
|
echo "task sync failed at $(date)"
|
|
echo ""
|
|
cat "$2"
|
|
} | sendmail -t
|
|
fi
|
|
|
|
cat "$2" >>"$3"
|
|
|
|
if command -v notify-send >/dev/null 2>&1; then
|
|
notify-send --urgency=critical "taskwarrior sync failed"
|
|
fi
|
|
|
|
exit 1
|
|
fi
|
|
' sh "$logfile" "$lerrfile" "$errfile" "$(hostname)"
|
|
} >/dev/null 2>&1 </dev/null &
|
|
fi
|
|
|
|
exit 0
|
|
|