diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-04-05 20:06:39 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-04-05 20:46:47 +1200 |
commit | c8ab406749124d2e762ad5cf53963070113afd0f (patch) | |
tree | 54c9721a06957ebe7098a211eea803b0230c0f5d /bin/gms.sh | |
parent | Handle POSIX correctness in ~/.bash_profile (diff) | |
download | dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.tar.gz dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.zip |
Apply runtime shebanging to POSIX shell
Diffstat (limited to 'bin/gms.sh')
-rw-r--r-- | bin/gms.sh | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/bin/gms.sh b/bin/gms.sh new file mode 100644 index 00000000..b77da6fa --- /dev/null +++ b/bin/gms.sh @@ -0,0 +1,30 @@ +# Run getmail(1) over every getmailrc.* file in ~/.getmail + +# Trap to remove whatever's set in lockdir if we're killed +lockdir= +cleanup() { + [ -n "$lockdir" ] && rm -fr -- "$lockdir" + if [ "$1" != EXIT ] ; then + trap - "$1" + kill "-$1" "$$" + fi +} +for sig in EXIT HUP INT TERM ; do + # shellcheck disable=SC2064 + trap "cleanup $sig" "$sig" +done + +# Don't trust the environment $UID, use id(1) instead +uid=$(id -u) || exit + +# Iterate through the getmailrc.* files in $GETMAIL if defined, or +# $HOME/.getmail if not +for rcfile in "${GETMAIL:-"$HOME"/.getmail}"/getmailrc.* ; do ( + lockdir=${TMPDIR:-/tmp}/getmail.$uid.${rcfile##*/}.lock + mkdir -m 0700 -- "$lockdir" 2>/dev/null || exit + try -n 3 -s 15 getmail --rcfile "$rcfile" "$@" + rm -fr -- "$lockdir" && lockdir= +) & done + +# Wait for all of the enqueued tasks to finish +wait |