From 11bf30fb20816229316afe7eda6618f16b9769be Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Mon, 16 Jan 2023 13:13:33 +0100 Subject: add pimsync script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- bin/pimsync | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 bin/pimsync (limited to 'bin') diff --git a/bin/pimsync b/bin/pimsync new file mode 100755 index 0000000..b1a51ac --- /dev/null +++ b/bin/pimsync @@ -0,0 +1,59 @@ +#!/bin/bash + +set -e +[ -n "$DEBUG" ] && set -x + +# check requirements +for tool in vdirsyncer notify-send iconez; do + if ! command -v "$tool" >/dev/null; then + printf '%s: %s not installed but required\n' "$(basename "$0")" "$tool" >&2 + exit 1 + fi +done + +while getopts h opt; do + case "${opt}" in + h | ?) + printf "usage: %s [-h] [ACCOUNT...]\n\n" "$(basename "$0")" + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +# allow explicitely syncing accounts, otherwise all +accounts=("$*") + +notifysend() { + if [ $# -lt 3 ]; then + return 1 + fi + local summary=$1 msg=$2 ico=$3 + shift 3 + #shellcheck disable=2068 + notify-send $@ -a pimsync -c audible -i "$(iconez -sn "$ico")" "$summary" "$msg" +} + +sync_vdir() { + local account=$1 ico_sync=sync ico_nosync=sync-off + + case "$account" in + *calendar*) ico_sync=calendar-sync ;; + esac + + # exit if we're already running + if pgrep vdirsyncer >/dev/null; then + notifysend "Syncing stopped" "vdirsyncer is already running" "$ico_nosync" + return + fi + + # persistent notification + id=$(notifysend "Syncing ${account:-contacts and calendars}" "running vdirsyncer" "$ico_sync" --print-id --expire-time=0) + trap '{ clear-notification "$id"; }' EXIT + + #shellcheck disable=2086 + vdirsyncer sync $account +} + +sync_vdir "${accounts[*]}" & +wait -- cgit 1.4.1