aboutsummaryrefslogtreecommitdiff
path: root/bin/gms
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-06-22 10:13:10 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-06-22 10:13:10 +1200
commitc83042d6701f275bd792fb15c889e780deddb14a (patch)
treecc6f6615267ce1ce8aae52e59477d8cea4dd8e73 /bin/gms
parentRemove reference to GitHub dotfiles pages (diff)
downloaddotfiles-c83042d6701f275bd792fb15c889e780deddb14a.tar.gz
dotfiles-c83042d6701f275bd792fb15c889e780deddb14a.zip
Rename binscripts more tersely
Diffstat (limited to 'bin/gms')
-rwxr-xr-xbin/gms36
1 files changed, 36 insertions, 0 deletions
diff --git a/bin/gms b/bin/gms
new file mode 100755
index 00000000..7ab865f2
--- /dev/null
+++ b/bin/gms
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+
+#
+# Run getmail(1) over every getmailrc.* file in ~/.getmail (I didn't like the
+# included getmails(1) script).
+#
+# Author: Tom Ryder <tom@sanctum.geek.nz>
+# Copyright: 2016
+#
+self=gms
+
+# Check for existence of needed commands
+hash flock getmail try || exit
+
+# Create a directory for our lockfiles if need be; we'll just leave it there
+lockdir=${TMPDIR:-/tmp}/getmail-$UID
+if ! mkdir -p -- "$lockdir" ; then
+ printf "%s: Could not create lockdir %s\n" \
+ "$self" "$lockdir" >&2
+ exit 1
+fi
+
+# Iterate through the getmailrc.* files in $GETMAIL if defined, or
+# $HOME/.getmail if not
+for rcfile in "${GETMAIL:-$HOME/.getmail}"/getmailrc.* ; do
+
+ # Run the current rcfile with getmail quietly, using its basename with
+ # .lock appended as the lockfile in the lock directory
+ (
+ flock -n 9 || exit 1
+ try -i 15 -n 3 getmail --rcfile "$rcfile" "$@"
+ ) 9>"$lockdir"/"${rcfile##*/}".lock &
+done
+
+# Wait for all of the enqueued tasks to finish
+wait