chiark / gitweb /
my-debmirror: miscellaneous updates - lenny and squeeze are long-obsolete, wheezy...
[bin.git] / bsmtp-pull
index 5a2c474c6c68fc09bdf879bda76c08221888eae8..8723a4f787fb81ee4353d74f88ec7606b9f02fec 100755 (executable)
@@ -1,4 +1,4 @@
-#! /bin/sh
+#! /bin/bash
 # Depends: lockfile-progs, ssh
 set -e
 
@@ -7,7 +7,7 @@ if [ -z "$1" ]; then
     exit 1
 fi
 
-DIR="$HOME/.bsmtp"
+DIR="$HOME/tmp/.bsmtp"
 mkdir -p "$DIR"
 cd "$DIR"
 
@@ -19,13 +19,19 @@ HOST="$1"
 # By default, lockfile-create gives up after three minutes, so don't cron
 # this any more frequently than that without supplying a --retry argument.
 lockfile-create "$HOST"
+# Race condition pointed out by pjb: this doesn't guarantee that the lock is
+# held before the critical section starts.
 lockfile-touch "$HOST" &
 TOUCH="$!"
 trap 'kill "$TOUCH"; lockfile-remove "$HOST"' EXIT ERR HUP INT QUIT TERM
+disown %1
 
-ssh -2 -C "$HOST" bsmtp-pull-server > "$HOST"
+ssh -2 -i "$HOME/.ssh/id-bsmtp-$HOST" -C "$HOST" bsmtp-pull-server > "$HOST"
+if [ "$BSMTP_PULL_DEBUG" ]; then
+       ls -l "$HOST" || true
+fi
 [ -s "$HOST" ] || exit 0
-/usr/sbin/sendmail -bS < "$HOST"
+/usr/sbin/sendmail -bS -odq < "$HOST"
 rm -f "$HOST"
 
 exit 0