From c5510367db582d1c0683f182dd0e151ea0ab3b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Fri, 10 Jun 2022 14:14:22 +0200 Subject: Improvements for NixOS --- local/bin/allsync | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'local/bin/allsync') 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 -- cgit v1.2.3