]> 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:

set a default account
[etc/offlineimap.git] / .bin / offlineimap
1 #!/bin/sh
2 set -eu
3
4 VAR=$HOME/.var/offlineimap
5 DEFAULT_ACCOUNT=madduck.net
6
7 opts=
8 accounts=
9 quiet=
10 for opt in "$@"; do
11   case "$opt" in
12     --quiet)
13       opts="${opts:+$opts }-uQuiet -l/dev/null"
14       quiet=1
15       ;;
16     -a) continue;;
17     -*) opts="${opts:+$opts }$opt";;
18     *) accounts="${accounts:+$accounts }$opt";;
19   esac
20 done
21
22 say() { [ -n "$quiet" ] || echo >&2 "$@"; }
23 err() { echo >&2 "$@"; }
24
25 if [ -z "$accounts" ]; then
26   accounts=$DEFAULT_ACCOUNT
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