]> git.madduck.net Git - etc/offlineimap.git/blob - .bin/offlineimap

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

fix function name
[etc/offlineimap.git] / .bin / offlineimap
1 #!/bin/sh
2 set -eu
3
4 VAR=$HOME/.var/offlineimap
5
6 opts=
7 accounts=
8 quiet=
9 for opt in "$@"; do
10   case "$opt" in
11     --quiet)
12       opts="${opts:+$opts }-uQuiet -l/dev/null"
13       quiet=1
14       ;;
15     -a) continue;;
16     -*) opts="${opts:+$opts }$opt";;
17     *) accounts="${accounts:+$accounts }$opt";;
18   esac
19 done
20
21 say() { [ -n "$quiet" ] || echo >&2 "$@"; }
22 err() { echo >&2 "$@"; }
23
24 if [ -z "$accounts" ]; then
25   err "E: no account(s) specified…"
26   exit 1
27 else
28   accounts=$(echo "$accounts" | sed -e 's/,/ /g')
29 fi
30
31 if ! test -t 0; then
32   say "I: Renicing because we are not run interactively…"
33   renice 20 -p $$ >/dev/null
34   ionice -c3 -p $$
35 fi
36
37 getlock()
38 {
39   lockfile="$VAR/.$1.lock"
40   trapfn() { rm -f "$lockfile"; trap - 0 1 2 3 4 5 6 7 8 10 11 12 13 14 15; }
41   trap trapfn 1 2 3 4 5 6 7 8 10 11 12 13 14 15
42   if [ -d "$VAR" ] && ! lockfile -0 -r0 -l 3600 "$lockfile" 2>/dev/null; then
43     return 1
44   fi
45   trap trapfn 0
46 }
47
48 failures=0
49 for account in $accounts; do
50   getlock "$account" || {
51     err "E: unable to acquire lock for account $account, already running?"
52     failures=$(($failures + 1))
53     continue
54   }
55
56   eval /usr/bin/offlineimap -a $account -k metadata=$VAR/$account $opts || \
57     failures=$(($failures + 1))
58
59   trapfn
60 done
61
62 if [ $failures -gt 0 ]; then
63   exit 1
64 else
65   exit 0
66 fi