blob: 635a65e354681f2f37b7b5d4ef29fcb95b22ced4 (
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
51
52
53
54
55
|
#!/bin/sh
set -eu
reap_proc()
{
local domn="${1}"
local user="${2}"
shift 2
local pid=
local t=0
{ read -r pid <~/".cache/offlineimap/Account-${domn}-${user}.pid"; } \
2>/dev/null || return 0
while ps -p ${pid} -o cmd | grep -Fq offlineimap; do
case ${t} in
0 | 10) kill ${pid} 1>/dev/null 2>&1 || return 0;;
20) return 1;; # Give up after 20 seconds.
esac
sleep 1
t=$((${t} + 1))
done
return 0
}
ping_srvr()
{
local user="${1}"
local host="${2}"
shift 2
# ping -c 1 -W 10 "${host}" || return 1
ssh -o ConnectTimeout=10 "${user}@${host}" exit 0 || return 1
return 0
}
sync()
{
local domn="${1}"
local user="${2}"
local host="${3}"
shift 3
reap_proc "${domn}" "${user}" || return 1
ping_srvr "${user}" "${host}" || return 1
offlineimap -a "${domn}-${user}" \
1>>~/".cache/offlineimap/Account-${domn}-${user}.log" 2>&1 &
printf '%d\n' ${!} >~/".cache/offlineimap/Account-${domn}-${user}.pid"
}
#sync 'pehjota.net' 'pj' 'mail.pehjota.net' || :
sync 'libiquity.com' 'patrick.mcdermott' 'mail.libiquity.com' || :
|