chiark / gitweb /
bsmtp-pull, bsmtp-pull-server: Initial implementation of batch SMTP
authorColin Watson <cjwatson@chiark.greenend.org.uk>
Thu, 24 Oct 2002 00:48:14 +0000 (00:48 +0000)
committerColin Watson <cjwatson@chiark.greenend.org.uk>
Thu, 24 Oct 2002 00:48:14 +0000 (00:48 +0000)
scripts. Currently they're capable of pulling spooled mail from the
debian.net system on gluck.debian.org and delivering it locally.

bsmtp-pull [new file with mode: 0755]
bsmtp-pull-server [new file with mode: 0755]

diff --git a/bsmtp-pull b/bsmtp-pull
new file mode 100755 (executable)
index 0000000..5a2c474
--- /dev/null
@@ -0,0 +1,31 @@
+#! /bin/sh
+# Depends: lockfile-progs, ssh
+set -e
+
+if [ -z "$1" ]; then
+    echo "Usage: $0 hostname" 2>&1
+    exit 1
+fi
+
+DIR="$HOME/.bsmtp"
+mkdir -p "$DIR"
+cd "$DIR"
+
+HOST="$1"
+
+# TODO: Note that this scheme may currently lose mail if the local disk
+# fills up! This is obviously very bad. Fix this.
+
+# 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"
+lockfile-touch "$HOST" &
+TOUCH="$!"
+trap 'kill "$TOUCH"; lockfile-remove "$HOST"' EXIT ERR HUP INT QUIT TERM
+
+ssh -2 -C "$HOST" bsmtp-pull-server > "$HOST"
+[ -s "$HOST" ] || exit 0
+/usr/sbin/sendmail -bS < "$HOST"
+rm -f "$HOST"
+
+exit 0
diff --git a/bsmtp-pull-server b/bsmtp-pull-server
new file mode 100755 (executable)
index 0000000..031b2b1
--- /dev/null
@@ -0,0 +1,27 @@
+#! /bin/sh
+set -e
+
+DIR="$HOME/bsmtp"
+FILE="riva.debian.net"
+TRANSIT="$FILE.transit"
+
+cd "$DIR" || exit 0
+
+# Is there anything to send?
+[ -s "$FILE" ] || exit 0
+
+lockfile-create "$FILE"
+lockfile-touch "$FILE" &
+TOUCH="$!"
+trap 'kill "$TOUCH"; lockfile-remove "$FILE"' EXIT ERR HUP INT QUIT TERM
+
+if [ -f "$TRANSIT" ]; then
+    cat "$FILE" >> "$TRANSIT" && rm -f "$FILE"
+else
+    mv -f "$FILE" "$TRANSIT"
+fi
+
+cat "$TRANSIT"
+rm -f "$TRANSIT"
+
+exit 0