From c09d91fe95fca4367f47c06fc808cd02a1a8e6a5 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Tue, 13 Aug 2019 14:40:54 -0400 Subject: add bins --- templates/.bin/mailsync | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 templates/.bin/mailsync (limited to 'templates/.bin/mailsync') diff --git a/templates/.bin/mailsync b/templates/.bin/mailsync new file mode 100755 index 0000000..9bb013f --- /dev/null +++ b/templates/.bin/mailsync @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +BUNDLE=com.benburwell.mailsync +PLIST="$HOME/Library/LaunchAgents/$BUNDLE.plist" + +monitor () { + local pid=$1 i=0 + while ps "$pid" &>/dev/null; do + if (( i++ > 10 )); then + echo "Max checks reached. Sending SIGKILL to $pid..." >&2 + kill -9 "$pid"; return 1 + fi + sleep 10 + done + return 0 +} + +if [[ "$1" == "install" ]]; then + SCRIPTPATH="$( cd "$(dirname "$0")" || exit 1; pwd -P )/$(basename "$0")" + cat > "$PLIST" < + + + + Label + $BUNDLE + + ProgramArguments + + $SCRIPTPATH + + + StartInterval + 180 + + StandardErrorPath + /tmp/offlineimap.err.log + + StandardOutPath + /tmp/offlineimap.log + + +EOF + launchctl load "$PLIST" + exit 0 +elif [[ "$1" == "uninstall" ]]; then + launchctl unload "$PLIST" + rm -f "$PLIST" + exit $? +elif [[ $# -gt 0 ]]; then + echo "Unrecognized options, did you mean 'install' or 'uninstall'?" + exit 1 +fi + +echo "STARTING $(date)" +offlineimap -o & monitor $! +echo "DONE $(date)" -- cgit v1.2.3