aboutsummaryrefslogtreecommitdiff
path: root/local/bin/allsync
diff options
context:
space:
mode:
Diffstat (limited to 'local/bin/allsync')
-rwxr-xr-xlocal/bin/allsync32
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