]> git.donarmstrong.com Git - bin.git/commitdiff
use cmd_exists and test for multiple MUAS
authorDon Armstrong <don@donarmstrong.com>
Thu, 25 Jan 2018 17:52:17 +0000 (09:52 -0800)
committerDon Armstrong <don@donarmstrong.com>
Thu, 25 Jan 2018 17:52:17 +0000 (09:52 -0800)
getmail

diff --git a/getmail b/getmail
index 96933ef48384691b3d09c55569dff0e930e65b5f..5d739a9609d9ddde25157eb82d67d73250e6f381 100755 (executable)
--- a/getmail
+++ b/getmail
@@ -4,9 +4,17 @@ if [ -n "$VERBOSE" ]; then
     set -x
 fi;
 
     set -x
 fi;
 
+cmd_exists () {
+    if which "$1" >/dev/null 2>&1; then
+        return 0;
+    else
+        return 1;
+    fi;
+}
+
 # Configure the two things below for your MUA and the host being run.
 IMAPHOST=$( awk -F= '/remotehost/{print $2}' ~/.offlineimaprc | head -n 1 )
 # Configure the two things below for your MUA and the host being run.
 IMAPHOST=$( awk -F= '/remotehost/{print $2}' ~/.offlineimaprc | head -n 1 )
-MUA=mutt
+MUAS="neomutt mutt mutt-ng"
 
 # Don't check mail if ~/.nocheck exists and we're not running
 # interactively.
 
 # Don't check mail if ~/.nocheck exists and we're not running
 # interactively.
@@ -19,18 +27,20 @@ if [ -z "$HOSTNAME" ]; then
 fi;
 
 IONICE=""
 fi;
 
 IONICE=""
-if which ionice >/dev/null 2>&1; then
+if cmd_exists "ionice"; then
     IONICE="ionice -c 3"
 fi;
 
     IONICE="ionice -c 3"
 fi;
 
-# if we are running under cron
+# if we are running under cron and there is no running MUA, exit
 if [ -n "$CRON" ]; then
 if [ -n "$CRON" ]; then
-    # and there is no MUA open, exit
-    if ! kill -0 `pgrep -U $(id -u) -x $MUA` 2>/dev/null; then
-        exit 0;
-    fi;
-    # if there is not a working ssh master, exit.
-    if ! ssh -O check $IMAPHOST 2>&1|grep -q running; then
+    RUNNING_MUA=0
+    for MUA in $MUAS;  do 
+        if kill -0 `pgrep -U $(id -u) -x $MUA` 2>/dev/null; then
+            RUNNING_MUA=1
+            break;
+        fi;
+    done;
+    if [ "x$RUNNING_MUA" = "x0" ]; then
         exit 0;
     fi;
 fi;
         exit 0;
     fi;
 fi;
@@ -56,7 +66,7 @@ if [ -z "$PID" ]; then
            perl -ne 'my ($account,$list) = /UID validity problem for folder ([\w-]+)\.([\w-]+)/;
                   next unless defined $account and length $account;
                   qx(/home/don/bin/deletemailbox -a Inbox $account.$list > /dev/null);';
            perl -ne 'my ($account,$list) = /UID validity problem for folder ([\w-]+)\.([\w-]+)/;
                   next unless defined $account and length $account;
                   qx(/home/don/bin/deletemailbox -a Inbox $account.$list > /dev/null);';
-    if which notmuch >/dev/null 2>&1; then
+    if cmd_exists "notmuch"; then
         nice -n 19 ${IONICE} notmuch new >/dev/null 2>&1;
     fi;
 fi;
         nice -n 19 ${IONICE} notmuch new >/dev/null 2>&1;
     fi;
 fi;