chiark / gitweb /
taskbot: Remove; no longer used. Never was, really.
[bin.git] / bsmtp-pull
1 #! /bin/sh
2 # Depends: lockfile-progs, ssh
3 set -e
4
5 if [ -z "$1" ]; then
6     echo "Usage: $0 hostname" 2>&1
7     exit 1
8 fi
9
10 DIR="$HOME/tmp/.bsmtp"
11 mkdir -p "$DIR"
12 cd "$DIR"
13
14 HOST="$1"
15
16 # TODO: Note that this scheme may currently lose mail if the local disk
17 # fills up! This is obviously very bad. Fix this.
18
19 # By default, lockfile-create gives up after three minutes, so don't cron
20 # this any more frequently than that without supplying a --retry argument.
21 lockfile-create "$HOST"
22 lockfile-touch "$HOST" &
23 TOUCH="$!"
24 trap 'kill "$TOUCH"; lockfile-remove "$HOST"' EXIT ERR HUP INT QUIT TERM
25
26 ssh -2 -i "$HOME/.ssh/id-bsmtp-$HOST" -C "$HOST" bsmtp-pull-server > "$HOST"
27 [ -s "$HOST" ] || exit 0
28 /usr/sbin/sendmail -bS < "$HOST"
29 rm -f "$HOST"
30
31 exit 0