diff options
author | Karel Kočí <cynerd@email.cz> | 2022-06-10 14:14:22 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2022-06-10 14:14:22 +0200 |
commit | c5510367db582d1c0683f182dd0e151ea0ab3b5f (patch) | |
tree | e43d7d6a4eae8d586ac8b43ef436ae178465bcfe /local/bin/allsync | |
parent | 3c905d717a331b9be6d7036624378d0617234a82 (diff) | |
download | myconfigs-c5510367db582d1c0683f182dd0e151ea0ab3b5f.tar.gz myconfigs-c5510367db582d1c0683f182dd0e151ea0ab3b5f.tar.bz2 myconfigs-c5510367db582d1c0683f182dd0e151ea0ab3b5f.zip |
Improvements for NixOS
Diffstat (limited to 'local/bin/allsync')
-rwxr-xr-x | local/bin/allsync | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/local/bin/allsync b/local/bin/allsync index c268b97..e5bb633 100755 --- a/local/bin/allsync +++ b/local/bin/allsync @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -eu cronline="* * * * * /bin/sh -c 'AUTORUN=y /home/cynerd/.local/bin/allsync'" @@ -16,20 +16,32 @@ i3_astroid() { cron_enable() { pass mail/cynerd@email.cz >/dev/null # Cache keys - { - crontab -l - echo "$cronline" - } | crontab - + if command -v crontab >/dev/null; then + { + crontab -l + echo "$cronline" + } | crontab - + else + systemctl --user start allsync.timer + fi notify_i3block } cron_disable() { - crontab -l | grep -Fv "$cronline" | crontab - + if command -v crontab >/dev/null; then + crontab -l | grep -Fv "$cronline" | crontab - + else + systemctl --user stop allsync.timer + fi notify_i3block } cron_enabled() { - crontab -l | grep -Fq "$cronline" + if command -v crontab >/dev/null; then + crontab -l | grep -Fq "$cronline" + else + systemctl --user is-active allsync.timer >/dev/null + fi } if [ "$#" -gt 0 ]; then @@ -67,6 +79,7 @@ fi ################################################################################## +flock_nonblock="" if [ "${AUTORUN:-n}" = "y" ]; then exec &> >(logger -t "${0##*/}") @@ -75,10 +88,13 @@ if [ "${AUTORUN:-n}" = "y" ]; then cron_disable exit 1 fi + flock_nonblock="--nonblock" fi if [ "${ALLSYNC_FLOCK:-n}" != "y" ]; then - ALLSYNC_FLOCK=y exec flock --exclusive "$HOME/.mail" "$0" "$@" + ALLSYNC_FLOCK=y exec flock $flock_nonblock --exclusive "$HOME/.mail" "$0" "$@" + echo "Another instance is alredy running" >&2 + exit 1 fi |