diff options
author | Karel Kočí <cynerd@email.cz> | 2020-12-12 08:46:34 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2020-12-12 08:46:34 +0100 |
commit | 1cb6094dac854e543247a8cc605a1d882ba1c5b8 (patch) | |
tree | 36ca2c39a521dffd05e928a08e4e10202656253e | |
parent | adda549c329d83aa94f2571ac6de52c232413bc9 (diff) | |
download | myconfigs-1cb6094dac854e543247a8cc605a1d882ba1c5b8.tar.gz myconfigs-1cb6094dac854e543247a8cc605a1d882ba1c5b8.tar.bz2 myconfigs-1cb6094dac854e543247a8cc605a1d882ba1c5b8.zip |
allsync: automatic synchronization
-rw-r--r-- | config/i3/config | 2 | ||||
-rw-r--r-- | config/i3blocks/config | 6 | ||||
-rwxr-xr-x | config/i3blocks/scripts/allsync | 6 | ||||
-rwxr-xr-x | local/bin/allsync | 87 |
4 files changed, 99 insertions, 2 deletions
diff --git a/config/i3/config b/config/i3/config index 8bf7048..354722c 100644 --- a/config/i3/config +++ b/config/i3/config @@ -184,7 +184,7 @@ for_window [ title="Pulsemixer" ] resize set 50 ppt 50 ppt for_window [ title="Pulsemixer" ] move position center # Run and configure synchronization bindsym $mod+i exec alacritty -t "Synchronization" -e allsync -bindsym $mod+Shift+i exec alacritty -t "Synchronization" -e allsync toggle +bindsym $mod+Shift+i exec --no-startup-id allsync toggle for_window [ title="Synchronization" ] floating enable # Screen brightness controls diff --git a/config/i3blocks/config b/config/i3blocks/config index ab6cf62..50289c5 100644 --- a/config/i3blocks/config +++ b/config/i3blocks/config @@ -55,9 +55,15 @@ interval=10 markup=pango interval=30 +[allsync] +command=~/.config/i3blocks/scripts/allsync +interval=120 +signal=13 + [email] command=~/.config/i3blocks/scripts/email interval=30 +signal=13 [time] command=date '+%Y-%m-%d %H:%M:%S' diff --git a/config/i3blocks/scripts/allsync b/config/i3blocks/scripts/allsync new file mode 100755 index 0000000..211799d --- /dev/null +++ b/config/i3blocks/scripts/allsync @@ -0,0 +1,6 @@ +#!/bin/bash +if allsync enabled; then + echo "sync" + echo + echo "#ffff00" +fi diff --git a/local/bin/allsync b/local/bin/allsync index 51d6bef..11c0ddb 100755 --- a/local/bin/allsync +++ b/local/bin/allsync @@ -1,5 +1,86 @@ -#!/bin/sh +#!/bin/bash set -eu +cronline="* * * * * /bin/sh -c 'AUTORUN=y /home/cynerd/.local/bin/allsync'" + +notify_i3block() { + pkill -RTMIN+13 i3blocks +} + +i3_astroid() { + pkill -0 astroid || return 0 + find "/run/user/$(id -u)/i3" "/tmp/i3-$(id -un)".* -name ipc-socket\* 2>/dev/null | \ + while read -r socket; do + i3-msg -s "$socket" "exec" "astroid" "$@" + done +} + +cron_enable() { + pass mail/cynerd@email.cz >/dev/null # Cache keys + { + crontab -l + echo "$cronline" + } | crontab - + notify_i3block +} + +cron_disable() { + crontab -l | grep -Fv "$cronline" | crontab - + notify_i3block +} + +cron_enabled() { + crontab -l | grep -Fq "$cronline" +} + +if [ "$#" -gt 0 ]; then + case "$1" in + enable) + cron_enable + ;; + disable) + cron_disable + ;; + enabled) + cron_enabled + ;; + state) + if cron_enabled; then + echo "Enabled" + else + echo "Disabled" + fi + ;; + toggle) + if cron_enabled; then + cron_disable + else + cron_enable + fi + ;; + *) + echo "${0##*/}: Unknown argument: $1" >&2 + exit 1 + ;; + esac + exit +fi + +################################################################################## + +if [ "${AUTORUN:-n}" = "y" ]; then + exec &> >(logger -t "${0##*/}") + + if [ "$(gpg-connect-agent 'KEYINFO C3D57FE2473E5CF5327C17874A73717E504E409A' /bye | awk '{print $7}')" != "1" ]; then + echo "Key not accessible. Disabling cron.." >&2 + cron_disable + exit 1 + fi +fi + +if [ "${ALLSYNC_FLOCK:-n}" != "y" ]; then + ALLSYNC_FLOCK=y exec flock --exclusive "$HOME/.mail" "$0" "$@" +fi + sec() { echo -e '\e[1;34m==========' "$@" '==========\e[0m' @@ -13,10 +94,14 @@ fail() { sec "Mail" +i3_astroid --start-polling mbsync -a || fail "Mail synchronization reported failure" notmuch new ~/.local/sbin/newmail-notify notmuch tag --batch --input="$HOME/.notmuch-tag-new" +i3_astroid --stop-polling +pkill -RTMIN+13 i3blocks +notify_i3block sec "Calendar and contacts" vdirsyncer sync || fail "Calendar and contacts synchronization reported failure" |