blob: 301eb989c9e85546785210a75390ea3719a43f1d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!/usr/bin/env bash
# systemd daemon: sync quick channels on first run, then full channels every 10 minutes
# while neomutt is open. Started/stopped by the wrapped neomutt launcher.
set -uo pipefail
INTERVAL="$((10 * 60))"
MBSYNCRC="${MBSYNCRC:-$HOME/.config/mbsync/.mbsyncrc}"
QUICK_CHANNELS_STR="@@QUICK_CHANNELS@@"
FULL_CHANNELS_STR="@@FULL_CHANNELS@@"
IFS=',' read -ra QUICK_CHANNELS <<<"$QUICK_CHANNELS_STR"
IFS=',' read -ra FULL_CHANNELS <<<"$FULL_CHANNELS_STR"
sync_once() {
echo "Syncing: $*"
mbsync -c "$MBSYNCRC" "$@"
local status=$?
if ((status != 0)); then
echo "mbsync failed (status $status) for: $*" >&2
return "$status"
fi
echo "Indexing new mail with notmuch..."
notmuch new --quiet
}
first_run=true
while true; do
if [[ $first_run == true ]]; then
sync_once "${QUICK_CHANNELS[@]}"
first_run=false
else
sync_once "${FULL_CHANNELS[@]}"
fi
# Safety net: the launcher stops this service when neomutt exits; if that
# didn't happen (hard kill), bail out once neomutt is gone.
if ! pgrep -x neomutt-launche >/dev/null; then
echo "neomutt is not running; stopping sync daemon" >&2
exit 0
fi
# Sleep after syncing and trying to exit, this makes sure that it runs once
# after all neomutt instances closes
sleep "$INTERVAL"
done
|