X-Git-Url: https://git.madduck.net/etc/offlineimap.git/blobdiff_plain/7ab076e9a34703804e9559bacb050342f3b65f6f..5f592047c76878128f6b5a123e38e119538ba00b:/.bin/offlineimap diff --git a/.bin/offlineimap b/.bin/offlineimap index ad01298..0145696 100755 --- a/.bin/offlineimap +++ b/.bin/offlineimap @@ -1,17 +1,27 @@ #!/bin/sh set -eu +[ "${1:-}" = -q ] && exec >/dev/null + +VAR=$HOME/.var/offlineimap +LOCKFILE="$VAR/.cron.lock" +trapfn() { rm -f "$LOCKFILE"; trap - 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15; } +trap trapfn 1 2 3 4 5 6 7 8 10 11 12 13 14 15 +if ! lockfile -0 -r0 -l 3600 "$LOCKFILE" 2>/dev/null; then + echo "E: offlineimap is already running." >&2 + exit 1 +fi + +trap trapfn 0 + if ! test -t 0; then - echo Renicing because we are not run interactively… >&2 + echo Renicing because we are not run interactively… renice 20 -p $$ >/dev/null - ionice -c2 -n7 -p $$ + ionice -c3 -p $$ fi ret=0 -/usr/bin/offlineimap -o "$@" || ret=$? - -if [ -x "$(command -v notmuch)" ]; then - notmuch new -fi +strace -tfo /tmp/offlineimap.strace /usr/bin/offlineimap "$@" || ret=$? +trapfn exit $ret